Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 10007043: Attempt to fix ChromeFrameTestWithWebServer tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added retry logic for WidgetModeIE_Version. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/file_util.h"
18 #include "base/json/json_reader.h" 19 #include "base/json/json_reader.h"
19 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
20 #include "base/message_loop.h" 21 #include "base/message_loop.h"
21 #include "base/path_service.h" 22 #include "base/path_service.h"
22 #include "base/process_util.h" 23 #include "base/process_util.h"
23 #include "base/rand_util.h" 24 #include "base/rand_util.h"
24 #include "base/string_number_conversions.h" 25 #include "base/string_number_conversions.h"
25 #include "base/test/test_timeouts.h" 26 #include "base/test/test_timeouts.h"
27 #include "base/time.h"
26 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
27 #include "base/values.h" 29 #include "base/values.h"
28 #include "chrome/browser/bookmarks/bookmark_model.h" 30 #include "chrome/browser/bookmarks/bookmark_model.h"
29 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/search_engines/template_url_service.h" 33 #include "chrome/browser/search_engines/template_url_service.h"
32 #include "chrome/browser/search_engines/template_url_service_test_util.h" 34 #include "chrome/browser/search_engines/template_url_service_test_util.h"
33 #include "chrome/browser/tab_contents/thumbnail_generator.h" 35 #include "chrome/browser/tab_contents/thumbnail_generator.h"
34 #include "chrome/browser/ui/browser.h" 36 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/browser_list.h" 37 #include "chrome/browser/ui/browser_list.h"
36 #include "chrome/browser/ui/browser_navigator.h" 38 #include "chrome/browser/ui/browser_navigator.h"
37 #include "chrome/browser/ui/browser_window.h" 39 #include "chrome/browser/ui/browser_window.h"
38 #include "chrome/browser/ui/find_bar/find_notification_details.h" 40 #include "chrome/browser/ui/find_bar/find_notification_details.h"
39 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 41 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
40 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 42 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
43 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
41 #include "chrome/common/chrome_notification_types.h" 44 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_paths.h" 45 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/extensions/extension_action.h" 46 #include "chrome/common/extensions/extension_action.h"
44 #include "chrome/test/automation/javascript_execution_controller.h" 47 #include "chrome/test/automation/javascript_execution_controller.h"
45 #include "chrome/test/base/bookmark_load_observer.h" 48 #include "chrome/test/base/bookmark_load_observer.h"
46 #include "content/public/browser/dom_operation_notification_details.h" 49 #include "content/public/browser/dom_operation_notification_details.h"
47 #include "content/public/browser/download_item.h" 50 #include "content/public/browser/download_item.h"
48 #include "content/public/browser/download_manager.h" 51 #include "content/public/browser/download_manager.h"
49 #include "content/public/browser/navigation_controller.h" 52 #include "content/public/browser/navigation_controller.h"
50 #include "content/public/browser/navigation_entry.h" 53 #include "content/public/browser/navigation_entry.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return true; 268 return true;
266 } 269 }
267 270
268 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { 271 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) {
269 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 272 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
270 RunMessageLoop(); 273 RunMessageLoop();
271 content::BrowserThread::PostTask(thread_id, FROM_HERE, 274 content::BrowserThread::PostTask(thread_id, FROM_HERE,
272 MessageLoop::QuitClosure()); 275 MessageLoop::QuitClosure());
273 } 276 }
274 277
278 #if defined(OS_WIN)
279 const char kSnapshotBaseName[] = "ChromiumSnapshot";
280 const char kSnapshotExtension[] = ".png";
281
282 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) {
283 base::Time::Exploded the_time;
284
285 base::Time::Now().LocalExplode(&the_time);
286 std::string filename(StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
287 kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
288 the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
289
290 FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
291 if (file_util::PathExists(snapshot_file)) {
292 int index = 0;
293 std::string suffix;
294 FilePath trial_file;
295 do {
296 suffix = StringPrintf(" (%d)", ++index);
297 trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
298 } while (file_util::PathExists(trial_file));
299 snapshot_file = trial_file;
300 }
301 return snapshot_file;
302 }
303 #endif
304
275 } // namespace 305 } // namespace
276 306
277 void RunMessageLoop() { 307 void RunMessageLoop() {
278 MessageLoop* loop = MessageLoop::current(); 308 MessageLoop* loop = MessageLoop::current();
279 MessageLoopForUI* ui_loop = 309 MessageLoopForUI* ui_loop =
280 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ? 310 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ?
281 MessageLoopForUI::current() : NULL; 311 MessageLoopForUI::current() : NULL;
282 MessageLoop::ScopedNestableTaskAllower allow(loop); 312 MessageLoop::ScopedNestableTaskAllower allow(loop);
283 if (ui_loop) { 313 if (ui_loop) {
284 #if defined(USE_AURA) 314 #if defined(USE_AURA)
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 SnapshotTaker taker; 1171 SnapshotTaker taker;
1142 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 1172 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
1143 } 1173 }
1144 1174
1145 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 1175 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
1146 DCHECK(bitmap); 1176 DCHECK(bitmap);
1147 SnapshotTaker taker; 1177 SnapshotTaker taker;
1148 return taker.TakeEntirePageSnapshot(rvh, bitmap); 1178 return taker.TakeEntirePageSnapshot(rvh, bitmap);
1149 } 1179 }
1150 1180
1181 #if defined(OS_WIN)
1182 bool SaveScreenSnapshotToDirectory(const FilePath& directory,
1183 FilePath* screenshot_path) {
1184 bool succeeded = false;
1185 FilePath out_path(GetSnapshotFileName(directory));
1186
1187 MONITORINFO monitor_info = {};
1188 monitor_info.cbSize = sizeof(monitor_info);
1189 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
1190 if (GetMonitorInfo(main_monitor, &monitor_info)) {
1191 RECT& rect = monitor_info.rcMonitor;
1192
1193 std::vector<unsigned char> png_data;
1194 if (browser::GrabWindowSnapshot(NULL, &png_data,
1195 gfx::Rect(rect.right - rect.left,
1196 rect.bottom - rect.top)) &&
1197 png_data.size() <= INT_MAX) {
1198 int bytes = static_cast<int>(png_data.size());
1199 int written = file_util::WriteFile(
1200 out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
robertshield 2012/04/11 17:03:36 should we also first check that png_data is not em
grt (UTC plus 2) 2012/04/11 17:33:08 I don't see why. GrabWindowSnapshot's contract is
1201 succeeded = (written == bytes);
1202 }
1203 }
1204
1205 if (succeeded && screenshot_path != NULL)
1206 *screenshot_path = out_path;
1207
1208 return succeeded;
1209 }
1210
1211 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) {
1212 FilePath desktop;
1213
1214 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) &&
1215 SaveScreenSnapshotToDirectory(desktop, screenshot_path);
1216 }
1217 #endif
1218
1151 namespace internal { 1219 namespace internal {
1152 1220
1153 void ClickTask(ui_controls::MouseButton button, 1221 void ClickTask(ui_controls::MouseButton button,
1154 int state, 1222 int state,
1155 const base::Closure& followup) { 1223 const base::Closure& followup) {
1156 if (!followup.is_null()) 1224 if (!followup.is_null())
1157 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 1225 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
1158 else 1226 else
1159 ui_controls::SendMouseEvents(button, state); 1227 ui_controls::SendMouseEvents(button, state);
1160 } 1228 }
1161 1229
1162 } // namespace internal 1230 } // namespace internal
1163 } // namespace ui_test_utils 1231 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698