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

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

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 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) 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 #ifndef CHROME_TEST_BASE_UI_TEST_UTILS_H_ 5 #ifndef CHROME_TEST_BASE_UI_TEST_UTILS_H_
6 #define CHROME_TEST_BASE_UI_TEST_UTILS_H_ 6 #define CHROME_TEST_BASE_UI_TEST_UTILS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "chrome/browser/history/history.h" 17 #include "chrome/browser/history/history.h"
18 #include "chrome/browser/ui/view_ids.h"
19 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
23 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
24 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/base/keycodes/keyboard_codes.h" 25 #include "ui/base/keycodes/keyboard_codes.h"
27 #include "ui/gfx/native_widget_types.h" 26 #include "ui/gfx/native_widget_types.h"
28 #include "ui/ui_controls/ui_controls.h"
29 #include "webkit/glue/window_open_disposition.h" 27 #include "webkit/glue/window_open_disposition.h"
30 28
31 #if defined(TOOLKIT_VIEWS)
32 #include "ui/views/view.h"
33 #endif
34
35 class AppModalDialog; 29 class AppModalDialog;
36 class BookmarkModel; 30 class BookmarkModel;
37 class Browser; 31 class Browser;
38 class FilePath; 32 class FilePath;
39 class LocationBar; 33 class LocationBar;
40 class Profile; 34 class Profile;
41 class SkBitmap; 35 class SkBitmap;
42 class TemplateURLService; 36 class TemplateURLService;
43 37
44 namespace chrome { 38 namespace chrome {
45 struct NavigateParams; 39 struct NavigateParams;
46 } 40 }
47 41
48 namespace content { 42 namespace content {
49 class MessageLoopRunner; 43 class MessageLoopRunner;
50 class RenderViewHost; 44 class RenderViewHost;
51 class RenderWidgetHost; 45 class RenderWidgetHost;
52 class WebContents; 46 class WebContents;
53 } 47 }
54 48
55 namespace gfx { 49 namespace gfx {
56 class Point;
57 class Rect; 50 class Rect;
58 class Size; 51 class Size;
59 } 52 }
60 53
61 // A collections of functions designed for use with InProcessBrowserTest. 54 // A collections of functions designed for use with InProcessBrowserTest.
62 namespace ui_test_utils { 55 namespace ui_test_utils {
63 56
64 // Flags to indicate what to wait for in a navigation test. 57 // Flags to indicate what to wait for in a navigation test.
65 // They can be ORed together. 58 // They can be ORed together.
66 // The order in which the waits happen when more than one is selected, is: 59 // The order in which the waits happen when more than one is selected, is:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // matches found. |ordinal| is an optional parameter which is set to the index 130 // matches found. |ordinal| is an optional parameter which is set to the index
138 // of the current match. |selection_rect| is an optional parameter which is set 131 // of the current match. |selection_rect| is an optional parameter which is set
139 // to the location of the current match. 132 // to the location of the current match.
140 int FindInPage(content::WebContents* tab, 133 int FindInPage(content::WebContents* tab,
141 const string16& search_string, 134 const string16& search_string,
142 bool forward, 135 bool forward,
143 bool case_sensitive, 136 bool case_sensitive,
144 int* ordinal, 137 int* ordinal,
145 gfx::Rect* selection_rect); 138 gfx::Rect* selection_rect);
146 139
147 // Returns true if the View is focused.
148 bool IsViewFocused(const Browser* browser, ViewID vid);
149
150 // Simulates a mouse click on a View in the browser.
151 void ClickOnView(const Browser* browser, ViewID vid);
152
153 // Register |observer| for the given |type| and |source| and run 140 // Register |observer| for the given |type| and |source| and run
154 // the message loop until the observer posts a quit task. 141 // the message loop until the observer posts a quit task.
155 void RegisterAndWait(content::NotificationObserver* observer, 142 void RegisterAndWait(content::NotificationObserver* observer,
156 int type, 143 int type,
157 const content::NotificationSource& source); 144 const content::NotificationSource& source);
158 145
159 // Blocks until |model| finishes loading. 146 // Blocks until |model| finishes loading.
160 void WaitForBookmarkModelToLoad(BookmarkModel* model); 147 void WaitForBookmarkModelToLoad(BookmarkModel* model);
161 148
162 // Blocks until |service| finishes loading. 149 // Blocks until |service| finishes loading.
163 void WaitForTemplateURLServiceToLoad(TemplateURLService* service); 150 void WaitForTemplateURLServiceToLoad(TemplateURLService* service);
164 151
165 // Blocks until the |history_service|'s history finishes loading. 152 // Blocks until the |history_service|'s history finishes loading.
166 void WaitForHistoryToLoad(HistoryService* history_service); 153 void WaitForHistoryToLoad(HistoryService* history_service);
167 154
168 // Download the given file and waits for the download to complete. 155 // Download the given file and waits for the download to complete.
169 void DownloadURL(Browser* browser, const GURL& download_url); 156 void DownloadURL(Browser* browser, const GURL& download_url);
170 157
171 // Send the given text to the omnibox and wait until it's updated. 158 // Send the given text to the omnibox and wait until it's updated.
172 void SendToOmniboxAndSubmit(LocationBar* location_bar, 159 void SendToOmniboxAndSubmit(LocationBar* location_bar,
173 const std::string& input); 160 const std::string& input);
174 161
175 // Brings the native window for |browser| to the foreground. Returns true on
176 // success.
177 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT;
178
179 // Gets the first browser that is not in the specified set. 162 // Gets the first browser that is not in the specified set.
180 Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers); 163 Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers);
181 164
182 // Sends a key press, blocking until the key press is received or the test times
183 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true
184 // if the event was successfully sent and received.
185 bool SendKeyPressSync(const Browser* browser,
186 ui::KeyboardCode key,
187 bool control,
188 bool shift,
189 bool alt,
190 bool command) WARN_UNUSED_RESULT;
191
192 // Sends a key press, blocking until both the key press and a notification from
193 // |source| of type |type| are received, or until the test times out. This uses
194 // ui_controls::SendKeyPress, see it for details. Returns true if the event was
195 // successfully sent and both the event and notification were received.
196 bool SendKeyPressAndWait(const Browser* browser,
197 ui::KeyboardCode key,
198 bool control,
199 bool shift,
200 bool alt,
201 bool command,
202 int type,
203 const content::NotificationSource& source)
204 WARN_UNUSED_RESULT;
205
206 // Sends a move event blocking until received. Returns true if the event was
207 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone,
208 // see it for details.
209 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
210 bool SendMouseEventsSync(ui_controls::MouseButton type,
211 int state) WARN_UNUSED_RESULT;
212
213 // A WindowedNotificationObserver hard-wired to observe 165 // A WindowedNotificationObserver hard-wired to observe
214 // chrome::NOTIFICATION_TAB_ADDED. 166 // chrome::NOTIFICATION_TAB_ADDED.
215 class WindowedTabAddedNotificationObserver 167 class WindowedTabAddedNotificationObserver
216 : public content::WindowedNotificationObserver { 168 : public content::WindowedNotificationObserver {
217 public: 169 public:
218 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either 170 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either
219 // a specific source, or from all sources if |source| is 171 // a specific source, or from all sources if |source| is
220 // NotificationService::AllSources(). 172 // NotificationService::AllSources().
221 explicit WindowedTabAddedNotificationObserver( 173 explicit WindowedTabAddedNotificationObserver(
222 const content::NotificationSource& source); 174 const content::NotificationSource& source);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Wait for a new browser to be created, and return a pointer to it. 256 // Wait for a new browser to be created, and return a pointer to it.
305 Browser* WaitForSingleNewBrowser(); 257 Browser* WaitForSingleNewBrowser();
306 258
307 private: 259 private:
308 content::WindowedNotificationObserver notification_observer_; 260 content::WindowedNotificationObserver notification_observer_;
309 std::set<Browser*> original_browsers_; 261 std::set<Browser*> original_browsers_;
310 262
311 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); 263 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver);
312 }; 264 };
313 265
314 // See SendKeyPressAndWait. This function additionally performs a check on the
315 // NotificationDetails using the provided Details<U>.
316 template <class U>
317 bool SendKeyPressAndWaitWithDetails(
318 const Browser* browser,
319 ui::KeyboardCode key,
320 bool control,
321 bool shift,
322 bool alt,
323 bool command,
324 int type,
325 const content::NotificationSource& source,
326 const content::Details<U>& details) WARN_UNUSED_RESULT;
327
328 template <class U>
329 bool SendKeyPressAndWaitWithDetails(
330 const Browser* browser,
331 ui::KeyboardCode key,
332 bool control,
333 bool shift,
334 bool alt,
335 bool command,
336 int type,
337 const content::NotificationSource& source,
338 const content::Details<U>& details) {
339 WindowedNotificationObserverWithDetails<U> observer(type, source);
340
341 if (!SendKeyPressSync(browser, key, control, shift, alt, command))
342 return false;
343
344 observer.Wait();
345
346 U my_details;
347 if (!observer.GetDetailsFor(source.map_key(), &my_details))
348 return false;
349
350 return *details.ptr() == my_details && !testing::Test::HasFatalFailure();
351 }
352
353 // Hide a native window.
354 void HideNativeWindow(gfx::NativeWindow window);
355
356 // Show and focus a native window. Returns true on success.
357 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) WARN_UNUSED_RESULT;
358
359 // Takes a snapshot of the given render widget, rendered at |page_size|. The 266 // Takes a snapshot of the given render widget, rendered at |page_size|. The
360 // snapshot is set to |bitmap|. Returns true on success. 267 // snapshot is set to |bitmap|. Returns true on success.
361 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh, 268 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh,
362 const gfx::Size& page_size, 269 const gfx::Size& page_size,
363 SkBitmap* bitmap) WARN_UNUSED_RESULT; 270 SkBitmap* bitmap) WARN_UNUSED_RESULT;
364 271
365 // Takes a snapshot of the entire page, according to the width and height 272 // Takes a snapshot of the entire page, according to the width and height
366 // properties of the DOM's document. Returns true on success. DOMAutomation 273 // properties of the DOM's document. Returns true on success. DOMAutomation
367 // must be enabled. 274 // must be enabled.
368 bool TakeEntirePageSnapshot(content::RenderViewHost* rvh, 275 bool TakeEntirePageSnapshot(content::RenderViewHost* rvh,
369 SkBitmap* bitmap) WARN_UNUSED_RESULT; 276 SkBitmap* bitmap) WARN_UNUSED_RESULT;
370 277
371 // A combination of SendMouseMove to the middle of the view followed by
372 // SendMouseEvents.
373 void MoveMouseToCenterAndPress(
374 #if defined(TOOLKIT_VIEWS)
375 views::View* view,
376 #elif defined(TOOLKIT_GTK)
377 GtkWidget* widget,
378 #elif defined(OS_IOS)
379 UIView* view,
380 #elif defined(OS_MACOSX)
381 NSView* view,
382 #endif
383 ui_controls::MouseButton button,
384 int state,
385 const base::Closure& task);
386
387 #if defined(OS_WIN) 278 #if defined(OS_WIN)
388 // Saves a snapshot of the entire screen to a file named 279 // Saves a snapshot of the entire screen to a file named
389 // ChromiumSnapshotYYYYMMDDHHMMSS.png to |directory|, returning true on success. 280 // ChromiumSnapshotYYYYMMDDHHMMSS.png to |directory|, returning true on success.
390 // The path to the file produced is returned in |screenshot_path| if non-NULL. 281 // The path to the file produced is returned in |screenshot_path| if non-NULL.
391 bool SaveScreenSnapshotToDirectory(const FilePath& directory, 282 bool SaveScreenSnapshotToDirectory(const FilePath& directory,
392 FilePath* screenshot_path); 283 FilePath* screenshot_path);
393 284
394 // Saves a snapshot of the entire screen as above to the current user's desktop. 285 // Saves a snapshot of the entire screen as above to the current user's desktop.
395 // The Chrome path provider must be registered prior to calling this function. 286 // The Chrome path provider must be registered prior to calling this function.
396 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path); 287 bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path);
397 #endif 288 #endif
398 289
399 // Configures the geolocation provider to always return the given position. 290 // Configures the geolocation provider to always return the given position.
400 void OverrideGeolocation(double latitude, double longitude); 291 void OverrideGeolocation(double latitude, double longitude);
401 292
402 namespace internal {
403
404 // A utility function to send a mouse click event in a closure. It's shared by
405 // ui_controls_linux.cc and ui_controls_mac.cc
406 void ClickTask(ui_controls::MouseButton button,
407 int state,
408 const base::Closure& followup);
409
410 } // namespace internal
411
412 // Enumerates all history contents on the backend thread. Returns them in 293 // Enumerates all history contents on the backend thread. Returns them in
413 // descending order by time. 294 // descending order by time.
414 class HistoryEnumerator { 295 class HistoryEnumerator {
415 public: 296 public:
416 explicit HistoryEnumerator(Profile* profile); 297 explicit HistoryEnumerator(Profile* profile);
417 ~HistoryEnumerator(); 298 ~HistoryEnumerator();
418 299
419 std::vector<GURL>& urls() { return urls_; } 300 std::vector<GURL>& urls() { return urls_; }
420 301
421 private: 302 private:
422 void HistoryQueryComplete( 303 void HistoryQueryComplete(
423 const base::Closure& quit_task, 304 const base::Closure& quit_task,
424 HistoryService::Handle request_handle, 305 HistoryService::Handle request_handle,
425 history::QueryResults* results); 306 history::QueryResults* results);
426 307
427 std::vector<GURL> urls_; 308 std::vector<GURL> urls_;
428 309
429 CancelableRequestConsumer consumer_; 310 CancelableRequestConsumer consumer_;
430 311
431 DISALLOW_COPY_AND_ASSIGN(HistoryEnumerator); 312 DISALLOW_COPY_AND_ASSIGN(HistoryEnumerator);
432 }; 313 };
433 314
434 } // namespace ui_test_utils 315 } // namespace ui_test_utils
435 316
436 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ 317 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698