| 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 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | |
| 18 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 19 #include "ui/base/win/foreground_helper.h" | 18 #include "ui/base/win/foreground_helper.h" |
| 20 #include "ui/ui_controls/ui_controls.h" | 19 #include "ui/ui_controls/ui_controls.h" |
| 21 #include "ui/views/focus/focus_manager.h" | 20 #include "ui/views/focus/focus_manager.h" |
| 21 #include "ui/window_snapshot/window_snapshot.h" |
| 22 |
| 22 | 23 |
| 23 namespace ui_test_utils { | 24 namespace ui_test_utils { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kSnapshotBaseName[] = "ChromiumSnapshot"; | 28 const char kSnapshotBaseName[] = "ChromiumSnapshot"; |
| 28 const char kSnapshotExtension[] = ".png"; | 29 const char kSnapshotExtension[] = ".png"; |
| 29 | 30 |
| 30 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) { | 31 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) { |
| 31 base::Time::Exploded the_time; | 32 base::Time::Exploded the_time; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bool succeeded = false; | 118 bool succeeded = false; |
| 118 FilePath out_path(GetSnapshotFileName(directory)); | 119 FilePath out_path(GetSnapshotFileName(directory)); |
| 119 | 120 |
| 120 MONITORINFO monitor_info = {}; | 121 MONITORINFO monitor_info = {}; |
| 121 monitor_info.cbSize = sizeof(monitor_info); | 122 monitor_info.cbSize = sizeof(monitor_info); |
| 122 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY); | 123 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY); |
| 123 if (GetMonitorInfo(main_monitor, &monitor_info)) { | 124 if (GetMonitorInfo(main_monitor, &monitor_info)) { |
| 124 RECT& rect = monitor_info.rcMonitor; | 125 RECT& rect = monitor_info.rcMonitor; |
| 125 | 126 |
| 126 std::vector<unsigned char> png_data; | 127 std::vector<unsigned char> png_data; |
| 127 if (chrome::GrabWindowSnapshot(NULL, &png_data, | 128 if (ui::GrabWindowSnapshot(NULL, &png_data, |
| 128 gfx::Rect(rect.right - rect.left, | 129 gfx::Rect(rect.right - rect.left, |
| 129 rect.bottom - rect.top)) && | 130 rect.bottom - rect.top)) && |
| 130 png_data.size() <= INT_MAX) { | 131 png_data.size() <= INT_MAX) { |
| 131 int bytes = static_cast<int>(png_data.size()); | 132 int bytes = static_cast<int>(png_data.size()); |
| 132 int written = file_util::WriteFile( | 133 int written = file_util::WriteFile( |
| 133 out_path, reinterpret_cast<char*>(&png_data[0]), bytes); | 134 out_path, reinterpret_cast<char*>(&png_data[0]), bytes); |
| 134 succeeded = (written == bytes); | 135 succeeded = (written == bytes); |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 if (succeeded && screenshot_path != NULL) | 139 if (succeeded && screenshot_path != NULL) |
| 139 *screenshot_path = out_path; | 140 *screenshot_path = out_path; |
| 140 | 141 |
| 141 return succeeded; | 142 return succeeded; |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) { | 145 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) { |
| 145 FilePath desktop; | 146 FilePath desktop; |
| 146 | 147 |
| 147 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) && | 148 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) && |
| 148 SaveScreenSnapshotToDirectory(desktop, screenshot_path); | 149 SaveScreenSnapshotToDirectory(desktop, screenshot_path); |
| 149 } | 150 } |
| 150 | 151 |
| 151 } // namespace ui_test_utils | 152 } // namespace ui_test_utils |
| OLD | NEW |