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

Unified Diff: chrome/test/base/ui_test_utils.cc

Issue 11414223: Move the test functions that deal with focus to interactive_ui_tets_utils.h and into the interactiv… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/ui_test_utils.cc
===================================================================
--- chrome/test/base/ui_test_utils.cc (revision 170118)
+++ chrome/test/base/ui_test_utils.cc (working copy)
@@ -45,6 +45,7 @@
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
+#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
@@ -150,6 +151,31 @@
DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
};
+const char kSnapshotBaseName[] = "ChromiumSnapshot";
+const char kSnapshotExtension[] = ".png";
+
+FilePath GetSnapshotFileName(const FilePath& snapshot_directory) {
+ base::Time::Exploded the_time;
+
+ base::Time::Now().LocalExplode(&the_time);
+ std::string filename(StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
+ kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
+ the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
+
+ FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
+ if (file_util::PathExists(snapshot_file)) {
+ int index = 0;
+ std::string suffix;
+ FilePath trial_file;
+ do {
+ suffix = StringPrintf(" (%d)", ++index);
+ trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
+ } while (file_util::PathExists(trial_file));
+ snapshot_file = trial_file;
+ }
+ return snapshot_file;
+}
+
} // namespace
bool GetCurrentTabTitle(const Browser* browser, string16* title) {
@@ -453,23 +479,6 @@
}
}
-bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
- BrowserWindow* window = browser->window();
- if (!window)
- return false;
-
- *native_window = window->GetNativeWindow();
- return *native_window;
-}
-
-bool BringBrowserWindowToFront(const Browser* browser) {
- gfx::NativeWindow window = NULL;
- if (!GetNativeWindow(browser, &window))
- return false;
-
- return ui_test_utils::ShowAndFocusNativeWindow(window);
-}
-
Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) {
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end();
@@ -481,77 +490,6 @@
return NULL;
}
-bool SendKeyPressSync(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command) {
- gfx::NativeWindow window = NULL;
- if (!GetNativeWindow(browser, &window))
- return false;
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- bool result;
- result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, runner->QuitClosure());
-#if defined(OS_WIN)
- if (!result && BringBrowserWindowToFront(browser)) {
- result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, runner->QuitClosure());
- }
-#endif
- if (!result) {
- LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed";
- return false;
- }
-
- // Run the message loop. It'll stop running when either the key was received
- // or the test timed out (in which case testing::Test::HasFatalFailure should
- // be set).
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendKeyPressAndWait(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command,
- int type,
- const content::NotificationSource& source) {
- content::WindowedNotificationObserver observer(type, source);
-
- if (!SendKeyPressSync(browser, key, control, shift, alt, command))
- return false;
-
- observer.Wait();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendMouseMoveSync(const gfx::Point& location) {
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- if (!ui_controls::SendMouseMoveNotifyWhenDone(
- location.x(), location.y(), runner->QuitClosure())) {
- return false;
- }
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- if (!ui_controls::SendMouseEventsNotifyWhenDone(
- type, state, runner->QuitClosure())) {
- return false;
- }
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver(
const content::NotificationSource& source)
: WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source),
@@ -680,6 +618,46 @@
return taker.TakeEntirePageSnapshot(rvh, bitmap);
}
+#if defined(OS_WIN)
+
+bool SaveScreenSnapshotToDirectory(const FilePath& directory,
+ FilePath* screenshot_path) {
+ bool succeeded = false;
+ FilePath out_path(GetSnapshotFileName(directory));
+
+ MONITORINFO monitor_info = {};
+ monitor_info.cbSize = sizeof(monitor_info);
+ HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
+ if (GetMonitorInfo(main_monitor, &monitor_info)) {
+ RECT& rect = monitor_info.rcMonitor;
+
+ std::vector<unsigned char> png_data;
+ gfx::Rect bounds(
+ gfx::Size(rect.right - rect.left, rect.bottom - rect.top));
+ if (chrome::internal::GrabWindowSnapshot(NULL, &png_data, bounds) &&
+ png_data.size() <= INT_MAX) {
+ int bytes = static_cast<int>(png_data.size());
+ int written = file_util::WriteFile(
+ out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
+ succeeded = (written == bytes);
+ }
+ }
+
+ if (succeeded && screenshot_path != NULL)
+ *screenshot_path = out_path;
+
+ return succeeded;
+}
+
+bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) {
+ FilePath desktop;
+
+ return PathService::Get(base::DIR_USER_DESKTOP, &desktop) &&
+ SaveScreenSnapshotToDirectory(desktop, screenshot_path);
+}
+
+#endif // defined(OS_WIN)
+
void OverrideGeolocation(double latitude, double longitude) {
content::Geoposition position;
position.latitude = latitude;

Powered by Google App Engine
This is Rietveld 408576698