Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_UI_TEST_UTILS_H_ | 5 #ifndef CHROME_TEST_UI_TEST_UTILS_H_ |
| 6 #define CHROME_TEST_UI_TEST_UTILS_H_ | 6 #define CHROME_TEST_UI_TEST_UTILS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "app/keyboard_codes.h" | 14 #include "app/keyboard_codes.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/scoped_temp_dir.h" | 17 #include "base/scoped_temp_dir.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "chrome/browser/ui/view_ids.h" | 19 #include "chrome/browser/ui/view_ids.h" |
| 20 #include "chrome/common/notification_observer.h" | 20 #include "chrome/common/notification_observer.h" |
| 21 #include "chrome/common/notification_registrar.h" | 21 #include "chrome/common/notification_registrar.h" |
| 22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/notification_source.h" | 23 #include "chrome/common/notification_source.h" |
| 24 #include "chrome/test/automation/dom_element_proxy.h" | 24 #include "chrome/test/automation/dom_element_proxy.h" |
| 25 #include "gfx/native_widget_types.h" | 25 #include "gfx/native_widget_types.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "webkit/glue/window_open_disposition.h" | |
| 27 | 28 |
| 28 class AppModalDialog; | 29 class AppModalDialog; |
| 29 class BookmarkModel; | 30 class BookmarkModel; |
| 30 class BookmarkNode; | 31 class BookmarkNode; |
| 31 class Browser; | 32 class Browser; |
| 32 class CommandLine; | 33 class CommandLine; |
| 33 class DownloadManager; | 34 class DownloadManager; |
| 34 class ExtensionAction; | 35 class ExtensionAction; |
| 35 class FilePath; | 36 class FilePath; |
| 36 class GURL; | 37 class GURL; |
| 37 class MessageLoop; | 38 class MessageLoop; |
| 38 class NavigationController; | 39 class NavigationController; |
| 39 class NotificationType; | 40 class NotificationType; |
| 40 class Profile; | 41 class Profile; |
| 41 class RenderViewHost; | 42 class RenderViewHost; |
| 42 class RenderWidgetHost; | 43 class RenderWidgetHost; |
| 43 class ScopedTempDir; | 44 class ScopedTempDir; |
| 44 class SkBitmap; | 45 class SkBitmap; |
| 45 class TabContents; | 46 class TabContents; |
| 46 class Value; | 47 class Value; |
| 47 | 48 |
| 48 namespace gfx { | 49 namespace gfx { |
| 49 class Size; | 50 class Size; |
| 50 } | 51 } |
| 51 | 52 |
| 52 // A collections of functions designed for use with InProcessBrowserTest. | 53 // A collections of functions designed for use with InProcessBrowserTest. |
| 53 namespace ui_test_utils { | 54 namespace ui_test_utils { |
| 54 | 55 |
| 56 // Flags to indicate what to wait for in a navigation test. | |
| 57 // They can be ORed together. | |
| 58 // The order in which the waits happen when more than one is selected, is: | |
| 59 // Browser | |
| 60 // Tab | |
| 61 // Navigation | |
| 62 enum BrowserTestFlags { | |
| 63 BROWSER_TEST_NONE = 0, // Don't wait for anything. | |
| 64 BROWSER_TEST_WAIT_FOR_BROWSER = 1 << 0, // Wait for a new browser. | |
| 65 BROWSER_TEST_WAIT_FOR_TAB = 1 << 1, // Wait for a new tab. | |
|
Randy Smith (Not in Mondays)
2010/12/13 21:44:58
So just confirming: If I WAIT_FOR_TAB but don't WA
ahendrickson
2010/12/16 19:26:41
Correct.
| |
| 66 BROWSER_TEST_WAIT_FOR_NAVIGATION = 1 << 2, // Wait for navigation to finish. | |
| 67 | |
| 68 BROWSER_TEST_MASK = BROWSER_TEST_WAIT_FOR_BROWSER | | |
| 69 BROWSER_TEST_WAIT_FOR_TAB | | |
| 70 BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 71 }; | |
| 72 | |
| 55 // Turns on nestable tasks, runs the message loop, then resets nestable tasks | 73 // Turns on nestable tasks, runs the message loop, then resets nestable tasks |
| 56 // to what they were originally. Prefer this over MessageLoop::Run for in | 74 // to what they were originally. Prefer this over MessageLoop::Run for in |
| 57 // process browser tests that need to block until a condition is met. | 75 // process browser tests that need to block until a condition is met. |
| 58 void RunMessageLoop(); | 76 void RunMessageLoop(); |
| 59 | 77 |
| 60 // Turns on nestable tasks, runs all pending tasks in the message loop, | 78 // Turns on nestable tasks, runs all pending tasks in the message loop, |
| 61 // then resets nestable tasks to what they were originally. Prefer this | 79 // then resets nestable tasks to what they were originally. Prefer this |
| 62 // over MessageLoop::RunAllPending for in process browser tests to run | 80 // over MessageLoop::RunAllPending for in process browser tests to run |
| 63 // all pending tasks. | 81 // all pending tasks. |
| 64 void RunAllPendingInMessageLoop(); | 82 void RunAllPendingInMessageLoop(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 77 | 95 |
| 78 // Waits for |controller| to complete a navigation. This blocks until | 96 // Waits for |controller| to complete a navigation. This blocks until |
| 79 // the navigation finishes. | 97 // the navigation finishes. |
| 80 void WaitForNavigation(NavigationController* controller); | 98 void WaitForNavigation(NavigationController* controller); |
| 81 | 99 |
| 82 // Waits for |controller| to complete a navigation. This blocks until | 100 // Waits for |controller| to complete a navigation. This blocks until |
| 83 // the specified number of navigations complete. | 101 // the specified number of navigations complete. |
| 84 void WaitForNavigations(NavigationController* controller, | 102 void WaitForNavigations(NavigationController* controller, |
| 85 int number_of_navigations); | 103 int number_of_navigations); |
| 86 | 104 |
| 105 // Waits for the |browser| to close its window. | |
| 106 void WaitForWindowClosed(Browser* browser); | |
| 107 | |
| 108 // Waits for a new tab to be added anywhere. | |
| 109 Browser* WaitForAnyNewTab(); | |
|
Randy Smith (Not in Mondays)
2010/12/13 21:44:58
This is only used in one place, which is inside ui
ahendrickson
2010/12/16 19:26:41
Moved. I do think it could be used by other files
| |
| 110 | |
| 87 // Waits for a new tab to be added to |browser|. | 111 // Waits for a new tab to be added to |browser|. |
| 88 void WaitForNewTab(Browser* browser); | 112 void WaitForNewTab(Browser* browser); |
| 89 | 113 |
| 90 // Waits for a |browser_action| to be updated. | 114 // Waits for a |browser_action| to be updated. |
| 91 void WaitForBrowserActionUpdated(ExtensionAction* browser_action); | 115 void WaitForBrowserActionUpdated(ExtensionAction* browser_action); |
| 92 | 116 |
| 93 // Waits for a load stop for the specified |controller|. | 117 // Waits for a load stop for the specified |controller|. |
| 94 void WaitForLoadStop(NavigationController* controller); | 118 void WaitForLoadStop(NavigationController* controller); |
| 95 | 119 |
| 96 // Waits for a new browser to be created, returning the browser. | 120 // Waits for a new browser to be created, returning the browser. |
| 97 Browser* WaitForNewBrowser(); | 121 Browser* WaitForNewBrowser(); |
| 98 | 122 |
| 123 // Waits for a new browser to be created, returning the browser. | |
| 124 // Pass in the number of browsers that exist before the navigation starts in | |
| 125 // |start_count|, and it will exit even if the notification occurs before it's | |
| 126 // called. | |
| 127 Browser* WaitForNewBrowserWithCount(size_t start_count); | |
| 128 | |
| 99 // Opens |url| in an incognito browser window with the off the record profile of | 129 // Opens |url| in an incognito browser window with the off the record profile of |
| 100 // |profile|, blocking until the navigation finishes. This will create a new | 130 // |profile|, blocking until the navigation finishes. This will create a new |
| 101 // browser if a browser with the off the record profile does not exist. | 131 // browser if a browser with the off the record profile does not exist. |
| 102 void OpenURLOffTheRecord(Profile* profile, const GURL& url); | 132 void OpenURLOffTheRecord(Profile* profile, const GURL& url); |
| 103 | 133 |
| 104 // Navigates the selected tab of |browser| to |url|, blocking until the | 134 // Navigates the selected tab of |browser| to |url|, blocking until the |
| 105 // navigation finishes. | 135 // navigation finishes. |
| 106 void NavigateToURL(Browser* browser, const GURL& url); | 136 void NavigateToURL(Browser* browser, const GURL& url); |
| 107 | 137 |
| 138 // Navigates the specified tab of |browser| to |url|, blocking until the | |
| 139 // navigation finishes. | |
| 140 // |disposition| indicates what tab the download occurs in, and | |
|
Randy Smith (Not in Mondays)
2010/12/13 21:44:58
nit: This call isn't about downloads specifically.
ahendrickson
2010/12/16 19:26:41
Done.
| |
| 141 // |browser_test_flags| controls what to wait for before continuing. | |
| 142 void NavigateToURLWithDisposition(Browser* browser, | |
| 143 const GURL& url, | |
| 144 WindowOpenDisposition disposition, | |
| 145 int browser_test_flags); | |
| 146 | |
| 108 // Navigates the selected tab of |browser| to |url|, blocking until the | 147 // Navigates the selected tab of |browser| to |url|, blocking until the |
| 109 // number of navigations specified complete. | 148 // number of navigations specified complete. |
| 110 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, | 149 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, |
| 111 const GURL& url, | 150 const GURL& url, |
| 112 int number_of_navigations); | 151 int number_of_navigations); |
| 113 | 152 |
| 153 // Navigates the specified tab (via |disposition|) of |browser| to |url|, | |
| 154 // blocking until the |number_of_navigations| specified complete. | |
|
Randy Smith (Not in Mondays)
2010/12/13 21:44:58
This is a bit confusing, at least to an untutored
ahendrickson
2010/12/16 19:26:41
Yeah, I found it a bit odd too -- I copied the com
| |
| 155 // |disposition| indicates what tab the download occurs in, and | |
| 156 // |browser_test_flags| controls what to wait for before continuing. | |
| 157 void NavigateToURLWithDispositionBlockUntilNavigationsComplete( | |
| 158 Browser* browser, | |
| 159 const GURL& url, | |
| 160 int number_of_navigations, | |
| 161 WindowOpenDisposition disposition, | |
| 162 int browser_test_flags); | |
| 163 | |
| 114 // Gets the DOMDocument for the active tab in |browser|. | 164 // Gets the DOMDocument for the active tab in |browser|. |
| 115 // Returns a NULL reference on failure. | 165 // Returns a NULL reference on failure. |
| 116 DOMElementProxyRef GetActiveDOMDocument(Browser* browser); | 166 DOMElementProxyRef GetActiveDOMDocument(Browser* browser); |
| 117 | 167 |
| 118 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use | 168 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use |
| 119 // empty string for main frame). The |script| should not invoke | 169 // empty string for main frame). The |script| should not invoke |
| 120 // domAutomationController.send(); otherwise, your test will hang or be flaky. | 170 // domAutomationController.send(); otherwise, your test will hang or be flaky. |
| 121 // If you want to extract a result, use one of the below functions. | 171 // If you want to extract a result, use one of the below functions. |
| 122 // Returns true on success. | 172 // Returns true on success. |
| 123 bool ExecuteJavaScript(RenderViewHost* render_view_host, | 173 bool ExecuteJavaScript(RenderViewHost* render_view_host, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 255 |
| 206 // Puts the native window for |browser| in |native_window|. Returns true on | 256 // Puts the native window for |browser| in |native_window|. Returns true on |
| 207 // success. | 257 // success. |
| 208 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) | 258 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) |
| 209 WARN_UNUSED_RESULT; | 259 WARN_UNUSED_RESULT; |
| 210 | 260 |
| 211 // Brings the native window for |browser| to the foreground. Returns true on | 261 // Brings the native window for |browser| to the foreground. Returns true on |
| 212 // success. | 262 // success. |
| 213 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT; | 263 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT; |
| 214 | 264 |
| 265 // Gets the browser at the specified |index|. | |
| 266 Browser* GetBrowser(int index); | |
| 267 | |
| 215 // Sends a key press, blocking until the key press is received or the test times | 268 // Sends a key press, blocking until the key press is received or the test times |
| 216 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true | 269 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true |
| 217 // if the event was successfully sent and received. | 270 // if the event was successfully sent and received. |
| 218 bool SendKeyPressSync(const Browser* browser, | 271 bool SendKeyPressSync(const Browser* browser, |
| 219 app::KeyboardCode key, | 272 app::KeyboardCode key, |
| 220 bool control, | 273 bool control, |
| 221 bool shift, | 274 bool shift, |
| 222 bool alt, | 275 bool alt, |
| 223 bool command) WARN_UNUSED_RESULT; | 276 bool command) WARN_UNUSED_RESULT; |
| 224 | 277 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 | 560 |
| 508 // Takes a snapshot of the entire page, according to the width and height | 561 // Takes a snapshot of the entire page, according to the width and height |
| 509 // properties of the DOM's document. Returns true on success. DOMAutomation | 562 // properties of the DOM's document. Returns true on success. DOMAutomation |
| 510 // must be enabled. | 563 // must be enabled. |
| 511 bool TakeEntirePageSnapshot(RenderViewHost* rvh, | 564 bool TakeEntirePageSnapshot(RenderViewHost* rvh, |
| 512 SkBitmap* bitmap) WARN_UNUSED_RESULT; | 565 SkBitmap* bitmap) WARN_UNUSED_RESULT; |
| 513 | 566 |
| 514 } // namespace ui_test_utils | 567 } // namespace ui_test_utils |
| 515 | 568 |
| 516 #endif // CHROME_TEST_UI_TEST_UTILS_H_ | 569 #endif // CHROME_TEST_UI_TEST_UTILS_H_ |
| OLD | NEW |