OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ | 5 #ifndef CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ |
6 #define CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ | 6 #define CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ |
7 | 7 |
8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
9 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "chrome/test/remoting/remote_test_helper.h" |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
14 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
15 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 // Command line arguments specific to the chromoting browser tests. | 19 // Command line arguments specific to the chromoting browser tests. |
19 const char kOverrideUserDataDir[] = "override-user-data-dir"; | 20 const char kOverrideUserDataDir[] = "override-user-data-dir"; |
20 const char kNoCleanup[] = "no-cleanup"; | 21 const char kNoCleanup[] = "no-cleanup"; |
21 const char kNoInstall[] = "no-install"; | 22 const char kNoInstall[] = "no-install"; |
22 const char kWebAppCrx[] = "webapp-crx"; | 23 const char kWebAppCrx[] = "webapp-crx"; |
23 const char kWebAppUnpacked[] = "webapp-unpacked"; | 24 const char kWebAppUnpacked[] = "webapp-unpacked"; |
24 const char kUserName[] = "username"; | 25 const char kUserName[] = "username"; |
25 const char kUserPassword[] = "password"; | 26 const char kUserPassword[] = "password"; |
26 const char kAccountsFile[] = "accounts-file"; | 27 const char kAccountsFile[] = "accounts-file"; |
27 const char kAccountType[] = "account-type"; | 28 const char kAccountType[] = "account-type"; |
28 const char kMe2MePin[] = "me2me-pin"; | 29 const char kMe2MePin[] = "me2me-pin"; |
29 const char kRemoteHostName[] = "remote-host-name"; | 30 const char kRemoteHostName[] = "remote-host-name"; |
30 const char kExtensionName[] = "extension-name"; | 31 const char kExtensionName[] = "extension-name"; |
31 const char kHttpServer[] = "http-server"; | 32 const char kHttpServer[] = "http-server"; |
32 | 33 |
33 // ASSERT_TRUE can only be used in void returning functions. This version | |
34 // should be used in non-void-returning functions. | |
35 inline void _ASSERT_TRUE(bool condition) { | |
36 if (!condition) { | |
37 // ASSERT_TRUE only prints the first call frame in the error message. | |
38 // In our case, this is the _ASSERT_TRUE wrapper function, which is not | |
39 // useful. To help with debugging, we will dump the full callstack. | |
40 LOG(ERROR) << "Assertion failed."; | |
41 LOG(ERROR) << base::debug::StackTrace().ToString(); | |
42 } | |
43 ASSERT_TRUE(condition); | |
44 return; | |
45 } | |
46 | |
47 } // namespace | 34 } // namespace |
48 | 35 |
49 using extensions::Extension; | 36 using extensions::Extension; |
50 | 37 |
51 namespace remoting { | 38 namespace remoting { |
52 | 39 |
53 class RemoteDesktopBrowserTest : public extensions::PlatformAppBrowserTest { | 40 class RemoteDesktopBrowserTest : public extensions::PlatformAppBrowserTest { |
54 public: | 41 public: |
55 RemoteDesktopBrowserTest(); | 42 RemoteDesktopBrowserTest(); |
56 ~RemoteDesktopBrowserTest() override; | 43 ~RemoteDesktopBrowserTest() override; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 205 |
219 // The client WebContents instance the test needs to interact with. | 206 // The client WebContents instance the test needs to interact with. |
220 content::WebContents* client_web_content() { | 207 content::WebContents* client_web_content() { |
221 return client_web_content_; | 208 return client_web_content_; |
222 } | 209 } |
223 | 210 |
224 content::WebContents* app_web_content() { | 211 content::WebContents* app_web_content() { |
225 return app_web_content_; | 212 return app_web_content_; |
226 } | 213 } |
227 | 214 |
| 215 RemoteTestHelper* remote_test_helper() const { |
| 216 return remote_test_helper_.get(); |
| 217 } |
| 218 |
228 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). | 219 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). |
229 // This is useful for diagnostic purposes. | 220 // This is useful for diagnostic purposes. |
230 bool NoCleanup() { return no_cleanup_; } | 221 bool NoCleanup() { return no_cleanup_; } |
231 | 222 |
232 // Whether to install the chromoting extension before running the test cases. | 223 // Whether to install the chromoting extension before running the test cases. |
233 // This is useful for diagnostic purposes. | 224 // This is useful for diagnostic purposes. |
234 bool NoInstall() { return no_install_; } | 225 bool NoInstall() { return no_install_; } |
235 | 226 |
236 // Helper to construct the starting URL of the installed chromoting webapp. | 227 // Helper to construct the starting URL of the installed chromoting webapp. |
237 GURL Chromoting_Main_URL() { | 228 GURL Chromoting_Main_URL() { |
(...skipping 14 matching lines...) Expand all Loading... |
252 // Helper to execute a JavaScript code snippet in the active WebContents. | 243 // Helper to execute a JavaScript code snippet in the active WebContents. |
253 void ExecuteScript(const std::string& script); | 244 void ExecuteScript(const std::string& script); |
254 | 245 |
255 // Helper to execute a JavaScript code snippet in the active WebContents | 246 // Helper to execute a JavaScript code snippet in the active WebContents |
256 // and wait for page load to complete. | 247 // and wait for page load to complete. |
257 void ExecuteScriptAndWaitForAnyPageLoad(const std::string& script); | 248 void ExecuteScriptAndWaitForAnyPageLoad(const std::string& script); |
258 | 249 |
259 // Helper to execute a JavaScript code snippet in the active WebContents | 250 // Helper to execute a JavaScript code snippet in the active WebContents |
260 // and extract the boolean result. | 251 // and extract the boolean result. |
261 bool ExecuteScriptAndExtractBool(const std::string& script) { | 252 bool ExecuteScriptAndExtractBool(const std::string& script) { |
262 return ExecuteScriptAndExtractBool(active_web_contents(), script); | 253 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 254 active_web_contents(), script); |
263 } | 255 } |
264 | 256 |
265 // Helper to execute a JavaScript code snippet and extract the boolean result. | |
266 static bool ExecuteScriptAndExtractBool(content::WebContents* web_contents, | |
267 const std::string& script); | |
268 | |
269 // Helper to execute a JavaScript code snippet in the active WebContents | 257 // Helper to execute a JavaScript code snippet in the active WebContents |
270 // and extract the int result. | 258 // and extract the int result. |
271 int ExecuteScriptAndExtractInt(const std::string& script) { | 259 int ExecuteScriptAndExtractInt(const std::string& script) { |
272 return ExecuteScriptAndExtractInt(active_web_contents(), script); | 260 return RemoteTestHelper::ExecuteScriptAndExtractInt( |
| 261 active_web_contents(), script); |
273 } | 262 } |
274 | 263 |
275 // Helper to execute a JavaScript code snippet and extract the int result. | |
276 static int ExecuteScriptAndExtractInt(content::WebContents* web_contents, | |
277 const std::string& script); | |
278 | |
279 // Helper to execute a JavaScript code snippet in the active WebContents | 264 // Helper to execute a JavaScript code snippet in the active WebContents |
280 // and extract the string result. | 265 // and extract the string result. |
281 std::string ExecuteScriptAndExtractString(const std::string& script) { | 266 std::string ExecuteScriptAndExtractString(const std::string& script) { |
282 return ExecuteScriptAndExtractString(active_web_contents(), script); | 267 return RemoteTestHelper::ExecuteScriptAndExtractString( |
| 268 active_web_contents(), script); |
283 } | 269 } |
284 | 270 |
285 // Helper to execute a JavaScript code snippet and extract the string result. | |
286 static std::string ExecuteScriptAndExtractString( | |
287 content::WebContents* web_contents, const std::string& script); | |
288 | |
289 // Helper to load a JavaScript file from |path| and inject it to | 271 // Helper to load a JavaScript file from |path| and inject it to |
290 // current web_content. The variable |path| is relative to the directory of | 272 // current web_content. The variable |path| is relative to the directory of |
291 // the |browsertest| executable. | 273 // the |browsertest| executable. |
292 static bool LoadScript(content::WebContents* web_contents, | 274 static bool LoadScript(content::WebContents* web_contents, |
293 const base::FilePath::StringType& path); | 275 const base::FilePath::StringType& path); |
294 | 276 |
295 // Helper to execute a JavaScript browser test. It creates an object using | 277 // Helper to execute a JavaScript browser test. It creates an object using |
296 // the |browserTest.testName| ctor and calls |run| on the created object with | 278 // the |browserTest.testName| ctor and calls |run| on the created object with |
297 // |testData|, which can be any arbitrary object literal. The script | 279 // |testData|, which can be any arbitrary object literal. The script |
298 // browser_test.js must be loaded (using LoadScript) before calling this | 280 // browser_test.js must be loaded (using LoadScript) before calling this |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // push it onto the stack and that becomes the active instance. | 354 // push it onto the stack and that becomes the active instance. |
373 // And once we are done with the current WebContents instance | 355 // And once we are done with the current WebContents instance |
374 // we pop it off the stack, returning to the previous instance. | 356 // we pop it off the stack, returning to the previous instance. |
375 std::vector<content::WebContents*> web_contents_stack_; | 357 std::vector<content::WebContents*> web_contents_stack_; |
376 | 358 |
377 // WebContent of the client page that facilitates communication with | 359 // WebContent of the client page that facilitates communication with |
378 // the HTTP server. This is how the remoting browser tests | 360 // the HTTP server. This is how the remoting browser tests |
379 // will get acknowledgments of actions completed on the host. | 361 // will get acknowledgments of actions completed on the host. |
380 content::WebContents* client_web_content_; | 362 content::WebContents* client_web_content_; |
381 | 363 |
| 364 // Helper class to assist in performing and verifying remote operations. |
| 365 scoped_ptr<RemoteTestHelper> remote_test_helper_; |
| 366 |
382 // WebContent of the landing page in the chromoting app. | 367 // WebContent of the landing page in the chromoting app. |
383 content::WebContents* app_web_content_; | 368 content::WebContents* app_web_content_; |
384 | 369 |
385 bool no_cleanup_; | 370 bool no_cleanup_; |
386 bool no_install_; | 371 bool no_install_; |
387 const Extension* extension_; | 372 const Extension* extension_; |
388 base::FilePath webapp_crx_; | 373 base::FilePath webapp_crx_; |
389 base::FilePath webapp_unpacked_; | 374 base::FilePath webapp_unpacked_; |
390 std::string username_; | 375 std::string username_; |
391 std::string password_; | 376 std::string password_; |
392 std::string me2me_pin_; | 377 std::string me2me_pin_; |
393 std::string remote_host_name_; | 378 std::string remote_host_name_; |
394 std::string extension_name_; | 379 std::string extension_name_; |
395 std::string http_server_; | 380 std::string http_server_; |
396 }; | 381 }; |
397 | 382 |
398 } // namespace remoting | 383 } // namespace remoting |
399 | 384 |
400 #endif // CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ | 385 #endif // CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ |
OLD | NEW |