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

Side by Side Diff: chrome/test/ui_test_utils.h

Issue 5610006: Converted download UI tests to Browser tests. (Closed) Base URL: http://git.chromium.org/git/chromium.git@browser_tests
Patch Set: Changes per Pawel & Brett's comments. Created 9 years, 11 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
OLDNEW
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 BrowserTestWaitFlags {
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.
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
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
87 // Waits for a new tab to be added to |browser|. 108 // Waits for a new tab to be added to |browser|.
88 void WaitForNewTab(Browser* browser); 109 void WaitForNewTab(Browser* browser);
89 110
90 // Waits for a |browser_action| to be updated. 111 // Waits for a |browser_action| to be updated.
91 void WaitForBrowserActionUpdated(ExtensionAction* browser_action); 112 void WaitForBrowserActionUpdated(ExtensionAction* browser_action);
92 113
93 // Waits for a load stop for the specified |controller|. 114 // Waits for a load stop for the specified |controller|.
94 void WaitForLoadStop(NavigationController* controller); 115 void WaitForLoadStop(NavigationController* controller);
95 116
96 // Waits for a new browser to be created, returning the browser. 117 // Waits for a new browser to be created, returning the browser.
97 Browser* WaitForNewBrowser(); 118 Browser* WaitForNewBrowser();
98 119
120 // Waits for a new browser to be created, returning the browser.
121 // Pass in the number of browsers that exist before the navigation starts in
122 // |start_count|, and it will exit even if the notification occurs before it's
123 // called.
124 Browser* WaitForNewBrowserWithCount(size_t start_count);
125
99 // Opens |url| in an incognito browser window with the off the record profile of 126 // 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 127 // |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. 128 // browser if a browser with the off the record profile does not exist.
102 void OpenURLOffTheRecord(Profile* profile, const GURL& url); 129 void OpenURLOffTheRecord(Profile* profile, const GURL& url);
103 130
104 // Navigates the selected tab of |browser| to |url|, blocking until the 131 // Navigates the selected tab of |browser| to |url|, blocking until the
105 // navigation finishes. 132 // navigation finishes.
106 void NavigateToURL(Browser* browser, const GURL& url); 133 void NavigateToURL(Browser* browser, const GURL& url);
107 134
135 // Navigates the specified tab of |browser| to |url|, blocking until the
136 // navigation finishes.
137 // |disposition| indicates what tab the navigation occurs in, and
138 // |browser_test_flags| controls what to wait for before continuing.
139 void NavigateToURLWithDisposition(Browser* browser,
140 const GURL& url,
141 WindowOpenDisposition disposition,
142 int browser_test_flags);
143
108 // Navigates the selected tab of |browser| to |url|, blocking until the 144 // Navigates the selected tab of |browser| to |url|, blocking until the
109 // number of navigations specified complete. 145 // number of navigations specified complete.
110 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, 146 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
111 const GURL& url, 147 const GURL& url,
112 int number_of_navigations); 148 int number_of_navigations);
113 149
114 // Gets the DOMDocument for the active tab in |browser|. 150 // Gets the DOMDocument for the active tab in |browser|.
115 // Returns a NULL reference on failure. 151 // Returns a NULL reference on failure.
116 DOMElementProxyRef GetActiveDOMDocument(Browser* browser); 152 DOMElementProxyRef GetActiveDOMDocument(Browser* browser);
117 153
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 220
185 // Returns true if the View is focused. 221 // Returns true if the View is focused.
186 bool IsViewFocused(const Browser* browser, ViewID vid); 222 bool IsViewFocused(const Browser* browser, ViewID vid);
187 223
188 // Simulates a mouse click on a View in the browser. 224 // Simulates a mouse click on a View in the browser.
189 void ClickOnView(const Browser* browser, ViewID vid); 225 void ClickOnView(const Browser* browser, ViewID vid);
190 226
191 // Blocks until a notification for given |type| is received. 227 // Blocks until a notification for given |type| is received.
192 void WaitForNotification(NotificationType type); 228 void WaitForNotification(NotificationType type);
193 229
230 // Blocks until a notification for given |type| from the specified |source|
231 // is received.
232 void WaitForNotificationFrom(NotificationType type,
233 const NotificationSource& source);
234
194 // Register |observer| for the given |type| and |source| and run 235 // Register |observer| for the given |type| and |source| and run
195 // the message loop until the observer posts a quit task. 236 // the message loop until the observer posts a quit task.
196 void RegisterAndWait(NotificationObserver* observer, 237 void RegisterAndWait(NotificationObserver* observer,
197 NotificationType type, 238 NotificationType type,
198 const NotificationSource& source); 239 const NotificationSource& source);
199 240
200 // Blocks until |model| finishes loading. 241 // Blocks until |model| finishes loading.
201 void WaitForBookmarkModelToLoad(BookmarkModel* model); 242 void WaitForBookmarkModelToLoad(BookmarkModel* model);
202 243
203 // Blocks until the |browser|'s history finishes loading. 244 // Blocks until the |browser|'s history finishes loading.
204 void WaitForHistoryToLoad(Browser* browser); 245 void WaitForHistoryToLoad(Browser* browser);
205 246
206 // Puts the native window for |browser| in |native_window|. Returns true on 247 // Puts the native window for |browser| in |native_window|. Returns true on
207 // success. 248 // success.
208 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) 249 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window)
209 WARN_UNUSED_RESULT; 250 WARN_UNUSED_RESULT;
210 251
211 // Brings the native window for |browser| to the foreground. Returns true on 252 // Brings the native window for |browser| to the foreground. Returns true on
212 // success. 253 // success.
213 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT; 254 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT;
214 255
256 // Gets the first browser that is not in the specified set.
257 Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers);
258
215 // Sends a key press, blocking until the key press is received or the test times 259 // 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 260 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true
217 // if the event was successfully sent and received. 261 // if the event was successfully sent and received.
218 bool SendKeyPressSync(const Browser* browser, 262 bool SendKeyPressSync(const Browser* browser,
219 app::KeyboardCode key, 263 app::KeyboardCode key,
220 bool control, 264 bool control,
221 bool shift, 265 bool shift,
222 bool alt, 266 bool alt,
223 bool command) WARN_UNUSED_RESULT; 267 bool command) WARN_UNUSED_RESULT;
224 268
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 551
508 // Takes a snapshot of the entire page, according to the width and height 552 // 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 553 // properties of the DOM's document. Returns true on success. DOMAutomation
510 // must be enabled. 554 // must be enabled.
511 bool TakeEntirePageSnapshot(RenderViewHost* rvh, 555 bool TakeEntirePageSnapshot(RenderViewHost* rvh,
512 SkBitmap* bitmap) WARN_UNUSED_RESULT; 556 SkBitmap* bitmap) WARN_UNUSED_RESULT;
513 557
514 } // namespace ui_test_utils 558 } // namespace ui_test_utils
515 559
516 #endif // CHROME_TEST_UI_TEST_UTILS_H_ 560 #endif // CHROME_TEST_UI_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698