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

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

Issue 101013: Migrating the SSL UI tests to be browser tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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
« no previous file with comments | « chrome/test/data/ssl/google.html ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "chrome/common/notification_observer.h" 11 #include "chrome/common/notification_observer.h"
12 12
13 class Browser; 13 class Browser;
14 class GURL; 14 class GURL;
15 class NavigationController; 15 class NavigationController;
16 class WebContents; 16 class Value;
17 class TabContents;
17 18
18 // A collections of functions designed for use with InProcessBrowserTest. 19 // A collections of functions designed for use with InProcessBrowserTest.
19 namespace ui_test_utils { 20 namespace ui_test_utils {
20 21
21 // Turns on nestable tasks, runs the message loop, then resets nestable tasks 22 // Turns on nestable tasks, runs the message loop, then resets nestable tasks
22 // to what they were originally. Prefer this over MessageLoop::Run for in 23 // to what they were originally. Prefer this over MessageLoop::Run for in
23 // process browser tests that need to block until a condition is met. 24 // process browser tests that need to block until a condition is met.
24 void RunMessageLoop(); 25 void RunMessageLoop();
25 26
26 // Waits for |controller| to complete a navigation. This blocks until 27 // Waits for |controller| to complete a navigation. This blocks until
27 // the navigation finishes. 28 // the navigation finishes.
28 void WaitForNavigation(NavigationController* controller); 29 void WaitForNavigation(NavigationController* controller);
29 30
30 // Waits for |controller| to complete a navigation. This blocks until 31 // Waits for |controller| to complete a navigation. This blocks until
31 // the specified number of navigations complete. 32 // the specified number of navigations complete.
32 void WaitForNavigations(NavigationController* controller, 33 void WaitForNavigations(NavigationController* controller,
33 int number_of_navigations); 34 int number_of_navigations);
34 35
35 // Navigates the selected tab of |browser| to |url|, blocking until the 36 // Navigates the selected tab of |browser| to |url|, blocking until the
36 // navigation finishes. 37 // navigation finishes.
37 void NavigateToURL(Browser* browser, const GURL& url); 38 void NavigateToURL(Browser* browser, const GURL& url);
38 39
39 // Navigates the selected tab of |browser| to |url|, blocking until the 40 // Navigates the selected tab of |browser| to |url|, blocking until the
40 // number of navigations specified complete. 41 // number of navigations specified complete.
41 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, 42 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
42 const GURL& url, 43 const GURL& url,
43 int number_of_navigations); 44 int number_of_navigations);
44 45
45 46
46 // This class enables you to send JavaScript as a string from the browser to the 47 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use
47 // renderer for execution in a frame of your choice. 48 // empty string for main frame) and returns the value the evaluation of the
48 class JavaScriptRunner : public NotificationObserver { 49 // script returned. The caller owns the returned value.
49 public: 50 Value* ExecuteJavaScript(TabContents* tab_contents,
50 // Constructor. |web_contents| is a pointer to the WebContents you want to run 51 const std::wstring& frame_xpath,
51 // the JavaScript code in. |frame_xpath| is a path to the frame to run it in. 52 const std::wstring& script);
52 // |jscript| is a string containing the JavaScript code to run, for example:
53 // "window.domAutomationController.send(alert('hello world'));". The
54 // JavaScript code will execute when Run is called. Note: In order for the
55 // domAutomationController to work, you must call EnableDOMAutomation() in
56 // your test class first.
57 JavaScriptRunner(WebContents* web_contents,
58 const std::wstring& frame_xpath,
59 const std::wstring& jscript);
60 53
61 virtual void Observe(NotificationType type, 54 // The following methods executes the passed |script| in the frame pointed to by
62 const NotificationSource& source, 55 // |frame_xpath| (use empty string for main frame) and sets |result| to the
63 const NotificationDetails& details); 56 // value returned by the script evaluation.
64 57 // They return true on success, false if the script evaluation failed or did not
65 // Executes the JavaScript code passed in to the constructor. See also comment 58 // evaluate to the expected type.
66 // about EnableDOMAutomation in the constructor. 59 // Note: In order for the domAutomationController to work, you must call
67 std::string Run(); 60 // EnableDOMAutomation() in your test first.
68 61 bool ExecuteJavaScriptAndExtractInt(TabContents* tab_contents,
69 private: 62 const std::wstring& frame_xpath,
70 WebContents* web_contents_; 63 const std::wstring& script,
71 std::wstring frame_xpath_; 64 int* result);
72 std::wstring jscript_; 65 bool ExecuteJavaScriptAndExtractBool(TabContents* tab_contents,
73 std::string result_; 66 const std::wstring& frame_xpath,
74 67 const std::wstring& script,
75 DISALLOW_COPY_AND_ASSIGN(JavaScriptRunner); 68 bool* result);
76 }; 69 bool ExecuteJavaScriptAndExtractString(TabContents* tab_contents,
77 70 const std::wstring& frame_xpath,
71 const std::wstring& script,
72 std::string* result);
78 } 73 }
79 74
80 #endif // CHROME_TEST_UI_TEST_UTILS_H_ 75 #endif // CHROME_TEST_UI_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « chrome/test/data/ssl/google.html ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698