OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Runs a test that may include calls to functions in test_api.js. | 65 // Runs a test that may include calls to functions in test_api.js. |
66 bool RunJavascriptTest(const std::string& test_name); | 66 bool RunJavascriptTest(const std::string& test_name); |
67 bool RunJavascriptTest(const std::string& test_name, | 67 bool RunJavascriptTest(const std::string& test_name, |
68 const base::Value& arg); | 68 const base::Value& arg); |
69 bool RunJavascriptTest(const std::string& test_name, | 69 bool RunJavascriptTest(const std::string& test_name, |
70 const base::Value& arg1, | 70 const base::Value& arg1, |
71 const base::Value& arg2); | 71 const base::Value& arg2); |
72 bool RunJavascriptTest(const std::string& test_name, | 72 bool RunJavascriptTest(const std::string& test_name, |
73 const ConstValueVector& test_arguments); | 73 const ConstValueVector& test_arguments); |
74 | 74 |
| 75 // Runs a test that may include calls to functions in test_api.js, and waits |
| 76 // for call to asyncTestDone(). |
| 77 bool RunJavascriptAsyncTest(const std::string& test_name); |
| 78 bool RunJavascriptAsyncTest(const std::string& test_name, |
| 79 const base::Value& arg); |
| 80 bool RunJavascriptAsyncTest(const std::string& test_name, |
| 81 const base::Value& arg1, |
| 82 const base::Value& arg2); |
| 83 bool RunJavascriptAsyncTest(const std::string& test_name, |
| 84 const ConstValueVector& test_arguments); |
| 85 |
75 // Sends message through |preload_host| to preload javascript libraries and | 86 // Sends message through |preload_host| to preload javascript libraries and |
76 // sets the |libraries_preloaded| flag to prevent re-loading at next | 87 // sets the |libraries_preloaded| flag to prevent re-loading at next |
77 // javascript invocation. | 88 // javascript invocation. |
78 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture, | 89 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture, |
79 const std::string& preload_test_name, | 90 const std::string& preload_test_name, |
80 RenderViewHost* preload_host); | 91 RenderViewHost* preload_host); |
81 | 92 |
82 // Called by javascript-generated test bodies to browse to a page and preload | 93 // Called by javascript-generated test bodies to browse to a page and preload |
83 // the javascript for the given |preload_test_fixture| and | 94 // the javascript for the given |preload_test_fixture| and |
84 // |preload_test_name|. chrome.send will be overridden to allow javascript | 95 // |preload_test_name|. chrome.send will be overridden to allow javascript |
(...skipping 24 matching lines...) Expand all Loading... |
109 static GURL WebUITestDataPathToURL(const FilePath::StringType& path); | 120 static GURL WebUITestDataPathToURL(const FilePath::StringType& path); |
110 | 121 |
111 private: | 122 private: |
112 // TestNavigationObserver::JsInjectionReadyObserver implementation. | 123 // TestNavigationObserver::JsInjectionReadyObserver implementation. |
113 virtual void OnJsInjectionReady(RenderViewHost* render_view_host) OVERRIDE; | 124 virtual void OnJsInjectionReady(RenderViewHost* render_view_host) OVERRIDE; |
114 | 125 |
115 // Builds a string containing all added javascript libraries. | 126 // Builds a string containing all added javascript libraries. |
116 void BuildJavascriptLibraries(string16* content); | 127 void BuildJavascriptLibraries(string16* content); |
117 | 128 |
118 // Builds a string with a call to the runTest JS function, passing the | 129 // Builds a string with a call to the runTest JS function, passing the |
119 // given test and its arguments. | 130 // given |is_async|, |test_name| and its |args|. |
120 string16 BuildRunTestJSCall(const std::string& test_name, | 131 string16 BuildRunTestJSCall(bool is_async, |
| 132 const std::string& test_name, |
121 const WebUIBrowserTest::ConstValueVector& args); | 133 const WebUIBrowserTest::ConstValueVector& args); |
122 | 134 |
123 // Loads all libraries added with AddLibrary(), and calls |function_name| with | 135 // Loads all libraries added with AddLibrary(), and calls |function_name| with |
124 // |function_arguments|. When |is_test| is true, the framework wraps | 136 // |function_arguments|. When |is_test| is true, the framework wraps |
125 // |function_name| with a test helper function, which waits for completion, | 137 // |function_name| with a test helper function, which waits for completion, |
126 // logging an error message on failure, otherwise |function_name| is called | 138 // logging an error message on failure, otherwise |function_name| is called |
127 // asynchronously. When |preload_host| is non-NULL, sends the javascript to | 139 // asynchronously. When |preload_host| is non-NULL, sends the javascript to |
128 // the RenderView for evaluation at the appropriate time before the onload | 140 // the RenderView for evaluation at the appropriate time before the onload |
129 // call is made. | 141 // call is made. Passes |is_async| along to runTest wrapper. |
130 bool RunJavascriptUsingHandler(const std::string& function_name, | 142 bool RunJavascriptUsingHandler(const std::string& function_name, |
131 const ConstValueVector& function_arguments, | 143 const ConstValueVector& function_arguments, |
132 bool is_test, | 144 bool is_test, |
| 145 bool is_async, |
133 RenderViewHost* preload_host); | 146 RenderViewHost* preload_host); |
134 | 147 |
135 // Attaches mock and test handlers. | 148 // Attaches mock and test handlers. |
136 void SetupHandlers(); | 149 void SetupHandlers(); |
137 | 150 |
138 // Handles test framework messages. | 151 // Handles test framework messages. |
139 scoped_ptr<WebUITestHandler> test_handler_; | 152 scoped_ptr<WebUITestHandler> test_handler_; |
140 | 153 |
141 // Location of test data (currently test/data/webui). | 154 // Location of test data (currently test/data/webui). |
142 FilePath test_data_directory_; | 155 FilePath test_data_directory_; |
143 | 156 |
144 // User added libraries | 157 // User added libraries |
145 std::vector<FilePath> user_libraries_; | 158 std::vector<FilePath> user_libraries_; |
146 | 159 |
147 // Indicates that the libraries have been pre-loaded and to not load them | 160 // Indicates that the libraries have been pre-loaded and to not load them |
148 // again. | 161 // again. |
149 bool libraries_preloaded_; | 162 bool libraries_preloaded_; |
150 | 163 |
151 // Saves the states of |test_fixture| and |test_name| for calling | 164 // Saves the states of |test_fixture| and |test_name| for calling |
152 // PreloadJavascriptLibraries(). | 165 // PreloadJavascriptLibraries(). |
153 std::string preload_test_fixture_; | 166 std::string preload_test_fixture_; |
154 std::string preload_test_name_; | 167 std::string preload_test_name_; |
155 }; | 168 }; |
156 | 169 |
157 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 170 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
OLD | NEW |