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

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

Issue 621883004: Remove Windows snapshot code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | ui/snapshot/BUILD.gn » ('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
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "net/base/filename_util.h" 70 #include "net/base/filename_util.h"
71 #include "net/cookies/cookie_constants.h" 71 #include "net/cookies/cookie_constants.h"
72 #include "net/cookies/cookie_monster.h" 72 #include "net/cookies/cookie_monster.h"
73 #include "net/cookies/cookie_store.h" 73 #include "net/cookies/cookie_store.h"
74 #include "net/test/python_utils.h" 74 #include "net/test/python_utils.h"
75 #include "net/url_request/url_request_context.h" 75 #include "net/url_request/url_request_context.h"
76 #include "net/url_request/url_request_context_getter.h" 76 #include "net/url_request/url_request_context_getter.h"
77 #include "third_party/skia/include/core/SkBitmap.h" 77 #include "third_party/skia/include/core/SkBitmap.h"
78 #include "third_party/skia/include/core/SkColor.h" 78 #include "third_party/skia/include/core/SkColor.h"
79 #include "ui/gfx/size.h" 79 #include "ui/gfx/size.h"
80 #include "ui/snapshot/test/snapshot_desktop.h"
81 80
82 #if defined(USE_AURA) 81 #if defined(USE_AURA)
83 #include "ash/shell.h" 82 #include "ash/shell.h"
84 #include "ui/aura/window_event_dispatcher.h" 83 #include "ui/aura/window_event_dispatcher.h"
85 #endif 84 #endif
86 85
87 using content::DomOperationNotificationDetails; 86 using content::DomOperationNotificationDetails;
88 using content::NativeWebKeyboardEvent; 87 using content::NativeWebKeyboardEvent;
89 using content::NavigationController; 88 using content::NavigationController;
90 using content::NavigationEntry; 89 using content::NavigationEntry;
91 using content::OpenURLParams; 90 using content::OpenURLParams;
92 using content::RenderViewHost; 91 using content::RenderViewHost;
93 using content::RenderWidgetHost; 92 using content::RenderWidgetHost;
94 using content::Referrer; 93 using content::Referrer;
95 using content::WebContents; 94 using content::WebContents;
96 95
97 namespace ui_test_utils { 96 namespace ui_test_utils {
98 97
99 namespace { 98 namespace {
100 99
101 #if defined(OS_WIN)
102 const char kSnapshotBaseName[] = "ChromiumSnapshot";
103 const char kSnapshotExtension[] = ".png";
104
105 base::FilePath GetSnapshotFileName(const base::FilePath& snapshot_directory) {
106 base::Time::Exploded the_time;
107
108 base::Time::Now().LocalExplode(&the_time);
109 std::string filename(base::StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
110 kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
111 the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
112
113 base::FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
114 if (base::PathExists(snapshot_file)) {
115 int index = 0;
116 std::string suffix;
117 base::FilePath trial_file;
118 do {
119 suffix = base::StringPrintf(" (%d)", ++index);
120 trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
121 } while (base::PathExists(trial_file));
122 snapshot_file = trial_file;
123 }
124 return snapshot_file;
125 }
126 #endif // defined(OS_WIN)
127
128 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { 100 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
129 Browser* new_browser = GetBrowserNotInSet(excluded_browsers); 101 Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
130 if (new_browser == NULL) { 102 if (new_browser == NULL) {
131 BrowserAddedObserver observer; 103 BrowserAddedObserver observer;
132 new_browser = observer.WaitForSingleNewBrowser(); 104 new_browser = observer.WaitForSingleNewBrowser();
133 // The new browser should never be in |excluded_browsers|. 105 // The new browser should never be in |excluded_browsers|.
134 DCHECK(!ContainsKey(excluded_browsers, new_browser)); 106 DCHECK(!ContainsKey(excluded_browsers, new_browser));
135 } 107 }
136 return new_browser; 108 return new_browser;
137 } 109 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 BrowserAddedObserver::~BrowserAddedObserver() { 470 BrowserAddedObserver::~BrowserAddedObserver() {
499 } 471 }
500 472
501 Browser* BrowserAddedObserver::WaitForSingleNewBrowser() { 473 Browser* BrowserAddedObserver::WaitForSingleNewBrowser() {
502 notification_observer_.Wait(); 474 notification_observer_.Wait();
503 // Ensure that only a single new browser has appeared. 475 // Ensure that only a single new browser has appeared.
504 EXPECT_EQ(original_browsers_.size() + 1, chrome::GetTotalBrowserCount()); 476 EXPECT_EQ(original_browsers_.size() + 1, chrome::GetTotalBrowserCount());
505 return GetBrowserNotInSet(original_browsers_); 477 return GetBrowserNotInSet(original_browsers_);
506 } 478 }
507 479
508 #if defined(OS_WIN)
509
510 bool SaveScreenSnapshotToDirectory(const base::FilePath& directory,
511 base::FilePath* screenshot_path) {
512 bool succeeded = false;
513 base::FilePath out_path(GetSnapshotFileName(directory));
514
515 MONITORINFO monitor_info = {};
516 monitor_info.cbSize = sizeof(monitor_info);
517 HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
518 if (GetMonitorInfo(main_monitor, &monitor_info)) {
519 RECT& rect = monitor_info.rcMonitor;
520
521 std::vector<unsigned char> png_data;
522 gfx::Rect bounds(
523 gfx::Size(rect.right - rect.left, rect.bottom - rect.top));
524 if (ui::GrabDesktopSnapshot(bounds, &png_data) &&
525 png_data.size() <= INT_MAX) {
526 int bytes = static_cast<int>(png_data.size());
527 int written = base::WriteFile(
528 out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
529 succeeded = (written == bytes);
530 }
531 }
532
533 if (succeeded && screenshot_path != NULL)
534 *screenshot_path = out_path;
535
536 return succeeded;
537 }
538
539 bool SaveScreenSnapshotToDesktop(base::FilePath* screenshot_path) {
540 base::FilePath desktop;
541
542 return PathService::Get(base::DIR_USER_DESKTOP, &desktop) &&
543 SaveScreenSnapshotToDirectory(desktop, screenshot_path);
544 }
545
546 #endif // defined(OS_WIN)
547
548 void OverrideGeolocation(double latitude, double longitude) { 480 void OverrideGeolocation(double latitude, double longitude) {
549 content::Geoposition position; 481 content::Geoposition position;
550 position.latitude = latitude; 482 position.latitude = latitude;
551 position.longitude = longitude; 483 position.longitude = longitude;
552 position.altitude = 0.; 484 position.altitude = 0.;
553 position.accuracy = 0.; 485 position.accuracy = 0.;
554 position.timestamp = base::Time::Now(); 486 position.timestamp = base::Time::Now();
555 content::GeolocationProvider::GetInstance()->OverrideLocationForTesting( 487 content::GeolocationProvider::GetInstance()->OverrideLocationForTesting(
556 position); 488 position);
557 } 489 }
(...skipping 17 matching lines...) Expand all
575 507
576 void HistoryEnumerator::HistoryQueryComplete( 508 void HistoryEnumerator::HistoryQueryComplete(
577 const base::Closure& quit_task, 509 const base::Closure& quit_task,
578 history::QueryResults* results) { 510 history::QueryResults* results) {
579 for (size_t i = 0; i < results->size(); ++i) 511 for (size_t i = 0; i < results->size(); ++i)
580 urls_.push_back((*results)[i].url()); 512 urls_.push_back((*results)[i].url());
581 quit_task.Run(); 513 quit_task.Run();
582 } 514 }
583 515
584 } // namespace ui_test_utils 516 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | ui/snapshot/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698