Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | |
|
grt (UTC plus 2)
2012/04/09 14:02:39
remove these
| |
| 12 #include <limits> | |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/bind.h" | 15 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 17 #include "base/callback.h" |
| 16 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 17 #include "base/file_path.h" | 19 #include "base/file_path.h" |
| 20 #include "base/file_util.h" | |
| 18 #include "base/json/json_reader.h" | 21 #include "base/json/json_reader.h" |
| 19 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/message_loop.h" | 23 #include "base/message_loop.h" |
| 21 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 22 #include "base/process_util.h" | 25 #include "base/process_util.h" |
| 23 #include "base/rand_util.h" | 26 #include "base/rand_util.h" |
| 24 #include "base/string_number_conversions.h" | 27 #include "base/string_number_conversions.h" |
| 25 #include "base/test/test_timeouts.h" | 28 #include "base/test/test_timeouts.h" |
| 29 #include "base/time.h" | |
| 26 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
| 27 #include "base/values.h" | 31 #include "base/values.h" |
| 28 #include "chrome/browser/bookmarks/bookmark_model.h" | 32 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 29 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/search_engines/template_url_service.h" | 35 #include "chrome/browser/search_engines/template_url_service.h" |
| 32 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 36 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 33 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 37 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 34 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 35 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
| 36 #include "chrome/browser/ui/browser_navigator.h" | 40 #include "chrome/browser/ui/browser_navigator.h" |
| 37 #include "chrome/browser/ui/browser_window.h" | 41 #include "chrome/browser/ui/browser_window.h" |
| 38 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 42 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 39 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 43 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 40 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 45 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | |
| 41 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/extensions/extension_action.h" | 48 #include "chrome/common/extensions/extension_action.h" |
| 44 #include "chrome/test/automation/javascript_execution_controller.h" | 49 #include "chrome/test/automation/javascript_execution_controller.h" |
| 45 #include "chrome/test/base/bookmark_load_observer.h" | 50 #include "chrome/test/base/bookmark_load_observer.h" |
| 46 #include "content/public/browser/dom_operation_notification_details.h" | 51 #include "content/public/browser/dom_operation_notification_details.h" |
| 47 #include "content/public/browser/download_item.h" | 52 #include "content/public/browser/download_item.h" |
| 48 #include "content/public/browser/download_manager.h" | 53 #include "content/public/browser/download_manager.h" |
| 49 #include "content/public/browser/navigation_controller.h" | 54 #include "content/public/browser/navigation_controller.h" |
| 50 #include "content/public/browser/navigation_entry.h" | 55 #include "content/public/browser/navigation_entry.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 return true; | 270 return true; |
| 266 } | 271 } |
| 267 | 272 |
| 268 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { | 273 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { |
| 269 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 274 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 270 RunMessageLoop(); | 275 RunMessageLoop(); |
| 271 content::BrowserThread::PostTask(thread_id, FROM_HERE, | 276 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
| 272 MessageLoop::QuitClosure()); | 277 MessageLoop::QuitClosure()); |
| 273 } | 278 } |
| 274 | 279 |
| 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 | |
| 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 Loading... | |
| 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 bool SaveScreenSnapshotToDirectory(const FilePath& directory, | |
| 1182 FilePath* screenshot_path) { | |
| 1183 bool succeeded = false; | |
| 1184 FilePath out_path(GetSnapshotFileName(directory)); | |
| 1185 | |
| 1186 MONITORINFO monitor_info = {}; | |
| 1187 monitor_info.cbSize = sizeof(monitor_info); | |
| 1188 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY); | |
| 1189 if (GetMonitorInfo(main_monitor, &monitor_info)) { | |
| 1190 RECT& rect = monitor_info.rcMonitor; | |
| 1191 | |
| 1192 std::vector<unsigned char> png_data; | |
| 1193 if (browser::GrabWindowSnapshot(NULL, &png_data, | |
| 1194 gfx::Rect(rect.right - rect.left, | |
| 1195 rect.bottom - rect.top)) && | |
| 1196 png_data.size() <= INT_MAX) { | |
| 1197 int bytes = static_cast<int>(png_data.size()); | |
| 1198 int written = file_util::WriteFile( | |
| 1199 out_path, reinterpret_cast<char*>(&png_data[0]), bytes); | |
| 1200 succeeded = (written == bytes); | |
| 1201 } | |
| 1202 } | |
| 1203 | |
| 1204 if (succeeded && screenshot_path != NULL) | |
| 1205 *screenshot_path = out_path; | |
| 1206 | |
| 1207 return succeeded; | |
| 1208 } | |
| 1209 | |
| 1151 namespace internal { | 1210 namespace internal { |
| 1152 | 1211 |
| 1153 void ClickTask(ui_controls::MouseButton button, | 1212 void ClickTask(ui_controls::MouseButton button, |
| 1154 int state, | 1213 int state, |
| 1155 const base::Closure& followup) { | 1214 const base::Closure& followup) { |
| 1156 if (!followup.is_null()) | 1215 if (!followup.is_null()) |
| 1157 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1216 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
| 1158 else | 1217 else |
| 1159 ui_controls::SendMouseEvents(button, state); | 1218 ui_controls::SendMouseEvents(button, state); |
| 1160 } | 1219 } |
| 1161 | 1220 |
| 1162 } // namespace internal | 1221 } // namespace internal |
| 1163 } // namespace ui_test_utils | 1222 } // namespace ui_test_utils |
| OLD | NEW |