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

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

Powered by Google App Engine
This is Rietveld 408576698