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

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

Issue 10830135: Revert 149604 - Support calling GrabWindowSnapshot when no BrowserProcess instance is avaliable (eg… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/chrome_tests.gypi ('k') | chrome_frame/test/test_with_web_server.cc » ('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 #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"
17 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
18 #include "ui/base/win/foreground_helper.h" 19 #include "ui/base/win/foreground_helper.h"
19 #include "ui/ui_controls/ui_controls.h" 20 #include "ui/ui_controls/ui_controls.h"
20 #include "ui/views/focus/focus_manager.h" 21 #include "ui/views/focus/focus_manager.h"
21 #include "ui/window_snapshot/window_snapshot.h"
22
23 22
24 namespace ui_test_utils { 23 namespace ui_test_utils {
25 24
26 namespace { 25 namespace {
27 26
28 const char kSnapshotBaseName[] = "ChromiumSnapshot"; 27 const char kSnapshotBaseName[] = "ChromiumSnapshot";
29 const char kSnapshotExtension[] = ".png"; 28 const char kSnapshotExtension[] = ".png";
30 29
31 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) { 30 FilePath GetSnapshotFileName(const FilePath& snapshot_directory) {
32 base::Time::Exploded the_time; 31 base::Time::Exploded the_time;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 bool succeeded = false; 117 bool succeeded = false;
119 FilePath out_path(GetSnapshotFileName(directory)); 118 FilePath out_path(GetSnapshotFileName(directory));
120 119
121 MONITORINFO monitor_info = {}; 120 MONITORINFO monitor_info = {};
122 monitor_info.cbSize = sizeof(monitor_info); 121 monitor_info.cbSize = sizeof(monitor_info);
123 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY); 122 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
124 if (GetMonitorInfo(main_monitor, &monitor_info)) { 123 if (GetMonitorInfo(main_monitor, &monitor_info)) {
125 RECT& rect = monitor_info.rcMonitor; 124 RECT& rect = monitor_info.rcMonitor;
126 125
127 std::vector<unsigned char> png_data; 126 std::vector<unsigned char> png_data;
128 if (ui::GrabWindowSnapshot(NULL, &png_data, 127 if (chrome::GrabWindowSnapshot(NULL, &png_data,
129 gfx::Rect(rect.right - rect.left, 128 gfx::Rect(rect.right - rect.left,
130 rect.bottom - rect.top)) && 129 rect.bottom - rect.top)) &&
131 png_data.size() <= INT_MAX) { 130 png_data.size() <= INT_MAX) {
132 int bytes = static_cast<int>(png_data.size()); 131 int bytes = static_cast<int>(png_data.size());
133 int written = file_util::WriteFile( 132 int written = file_util::WriteFile(
134 out_path, reinterpret_cast<char*>(&png_data[0]), bytes); 133 out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
135 succeeded = (written == bytes); 134 succeeded = (written == bytes);
136 } 135 }
137 } 136 }
138 137
139 if (succeeded && screenshot_path != NULL) 138 if (succeeded && screenshot_path != NULL)
140 *screenshot_path = out_path; 139 *screenshot_path = out_path;
141 140
142 return succeeded; 141 return succeeded;
143 } 142 }
144 143
145 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) { 144 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) {
146 FilePath desktop; 145 FilePath desktop;
147 146
148 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) && 147 return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) &&
149 SaveScreenSnapshotToDirectory(desktop, screenshot_path); 148 SaveScreenSnapshotToDirectory(desktop, screenshot_path);
150 } 149 }
151 150
152 } // namespace ui_test_utils 151 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome_frame/test/test_with_web_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698