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

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: TimeDelta change landed at r131813 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
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome_frame/chrome_frame.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 return true; 269 return true;
267 } 270 }
268 271
269 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { 272 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) {
270 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 273 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
271 RunMessageLoop(); 274 RunMessageLoop();
272 content::BrowserThread::PostTask(thread_id, FROM_HERE, 275 content::BrowserThread::PostTask(thread_id, FROM_HERE,
273 MessageLoop::QuitClosure()); 276 MessageLoop::QuitClosure());
274 } 277 }
275 278
279 #if defined(OS_WIN)
Paweł Hajdan Jr. 2012/04/14 10:42:56 Please extract this and any other possible Windows
grt (UTC plus 2) 2012/04/14 23:18:04 Done.
280 const char kSnapshotBaseName[] = "ChromiumSnapshot";
281 const char kSnapshotExtension[] = ".png";
282
283 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) {
284 base::Time::Exploded the_time;
285
286 base::Time::Now().LocalExplode(&the_time);
287 std::string filename(StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
288 kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
289 the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
290
291 FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
292 if (file_util::PathExists(snapshot_file)) {
293 int index = 0;
294 std::string suffix;
295 FilePath trial_file;
296 do {
297 suffix = StringPrintf(" (%d)", ++index);
298 trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
299 } while (file_util::PathExists(trial_file));
300 snapshot_file = trial_file;
301 }
302 return snapshot_file;
303 }
304 #endif
305
276 } // namespace 306 } // namespace
277 307
278 void RunMessageLoop() { 308 void RunMessageLoop() {
279 MessageLoop* loop = MessageLoop::current(); 309 MessageLoop* loop = MessageLoop::current();
280 MessageLoopForUI* ui_loop = 310 MessageLoopForUI* ui_loop =
281 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ? 311 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ?
282 MessageLoopForUI::current() : NULL; 312 MessageLoopForUI::current() : NULL;
283 MessageLoop::ScopedNestableTaskAllower allow(loop); 313 MessageLoop::ScopedNestableTaskAllower allow(loop);
284 if (ui_loop) { 314 if (ui_loop) {
285 #if defined(USE_AURA) 315 #if defined(USE_AURA)
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 SnapshotTaker taker; 1181 SnapshotTaker taker;
1152 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 1182 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
1153 } 1183 }
1154 1184
1155 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 1185 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
1156 DCHECK(bitmap); 1186 DCHECK(bitmap);
1157 SnapshotTaker taker; 1187 SnapshotTaker taker;
1158 return taker.TakeEntirePageSnapshot(rvh, bitmap); 1188 return taker.TakeEntirePageSnapshot(rvh, bitmap);
1159 } 1189 }
1160 1190
1191 #if defined(OS_WIN)
1192 bool SaveScreenSnapshotToDirectory(const FilePath& directory,
1193 FilePath* screenshot_path) {
1194 bool succeeded = false;
1195 FilePath out_path(GetSnapshotFileName(directory));
1196
1197 MONITORINFO monitor_info = {};
1198 monitor_info.cbSize = sizeof(monitor_info);
1199 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
1200 if (GetMonitorInfo(main_monitor, &monitor_info)) {
1201 RECT& rect = monitor_info.rcMonitor;
1202
1203 std::vector<unsigned char> png_data;
1204 if (browser::GrabWindowSnapshot(NULL, &png_data,
1205 gfx::Rect(rect.right - rect.left,
1206 rect.bottom - rect.top)) &&
1207 png_data.size() <= INT_MAX) {
1208 int bytes = static_cast<int>(png_data.size());
1209 int written = file_util::WriteFile(
1210 out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
1211 succeeded = (written == bytes);
1212 }
1213 }
1214
1215 if (succeeded && screenshot_path != NULL)
1216 *screenshot_path = out_path;
1217
1218 return succeeded;
1219 }
1220
1221 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) {
1222 FilePath desktop;
1223
1224 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) &&
1225 SaveScreenSnapshotToDirectory(desktop, screenshot_path);
1226 }
1227 #endif
1228
1161 namespace internal { 1229 namespace internal {
1162 1230
1163 void ClickTask(ui_controls::MouseButton button, 1231 void ClickTask(ui_controls::MouseButton button,
1164 int state, 1232 int state,
1165 const base::Closure& followup) { 1233 const base::Closure& followup) {
1166 if (!followup.is_null()) 1234 if (!followup.is_null())
1167 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 1235 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
1168 else 1236 else
1169 ui_controls::SendMouseEvents(button, state); 1237 ui_controls::SendMouseEvents(button, state);
1170 } 1238 }
1171 1239
1172 } // namespace internal 1240 } // namespace internal
1173 } // namespace ui_test_utils 1241 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome_frame/chrome_frame.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698