| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 201 |
| 215 // The client WebContents instance the test needs to interact with. | 202 // The client WebContents instance the test needs to interact with. |
| 216 content::WebContents* client_web_content() { | 203 content::WebContents* client_web_content() { |
| 217 return client_web_content_; | 204 return client_web_content_; |
| 218 } | 205 } |
| 219 | 206 |
| 220 content::WebContents* app_web_content() { | 207 content::WebContents* app_web_content() { |
| 221 return app_web_content_; | 208 return app_web_content_; |
| 222 } | 209 } |
| 223 | 210 |
| 211 RemoteTestHelper* remote_test_helper() const { |
| 212 return remote_test_helper_.get(); |
| 213 } |
| 214 |
| 224 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). | 215 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). |
| 225 // This is useful for diagnostic purposes. | 216 // This is useful for diagnostic purposes. |
| 226 bool NoCleanup() { return no_cleanup_; } | 217 bool NoCleanup() { return no_cleanup_; } |
| 227 | 218 |
| 228 // Whether to install the chromoting extension before running the test cases. | 219 // Whether to install the chromoting extension before running the test cases. |
| 229 // This is useful for diagnostic purposes. | 220 // This is useful for diagnostic purposes. |
| 230 bool NoInstall() { return no_install_; } | 221 bool NoInstall() { return no_install_; } |
| 231 | 222 |
| 232 // Helper to construct the starting URL of the installed chromoting webapp. | 223 // Helper to construct the starting URL of the installed chromoting webapp. |
| 233 GURL Chromoting_Main_URL() { | 224 GURL Chromoting_Main_URL() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 248 // Helper to execute a JavaScript code snippet in the active WebContents. | 239 // Helper to execute a JavaScript code snippet in the active WebContents. |
| 249 void ExecuteScript(const std::string& script); | 240 void ExecuteScript(const std::string& script); |
| 250 | 241 |
| 251 // Helper to execute a JavaScript code snippet in the active WebContents | 242 // Helper to execute a JavaScript code snippet in the active WebContents |
| 252 // and wait for page load to complete. | 243 // and wait for page load to complete. |
| 253 void ExecuteScriptAndWaitForAnyPageLoad(const std::string& script); | 244 void ExecuteScriptAndWaitForAnyPageLoad(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 extract the boolean result. | 247 // and extract the boolean result. |
| 257 bool ExecuteScriptAndExtractBool(const std::string& script) { | 248 bool ExecuteScriptAndExtractBool(const std::string& script) { |
| 258 return ExecuteScriptAndExtractBool(active_web_contents(), script); | 249 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 250 active_web_contents(), script); |
| 259 } | 251 } |
| 260 | 252 |
| 261 // Helper to execute a JavaScript code snippet and extract the boolean result. | |
| 262 static bool ExecuteScriptAndExtractBool(content::WebContents* web_contents, | |
| 263 const std::string& script); | |
| 264 | |
| 265 // Helper to execute a JavaScript code snippet in the active WebContents | 253 // Helper to execute a JavaScript code snippet in the active WebContents |
| 266 // and extract the int result. | 254 // and extract the int result. |
| 267 int ExecuteScriptAndExtractInt(const std::string& script) { | 255 int ExecuteScriptAndExtractInt(const std::string& script) { |
| 268 return ExecuteScriptAndExtractInt(active_web_contents(), script); | 256 return RemoteTestHelper::ExecuteScriptAndExtractInt( |
| 257 active_web_contents(), script); |
| 269 } | 258 } |
| 270 | 259 |
| 271 // Helper to execute a JavaScript code snippet and extract the int result. | |
| 272 static int ExecuteScriptAndExtractInt(content::WebContents* web_contents, | |
| 273 const std::string& script); | |
| 274 | |
| 275 // Helper to execute a JavaScript code snippet in the active WebContents | 260 // Helper to execute a JavaScript code snippet in the active WebContents |
| 276 // and extract the string result. | 261 // and extract the string result. |
| 277 std::string ExecuteScriptAndExtractString(const std::string& script) { | 262 std::string ExecuteScriptAndExtractString(const std::string& script) { |
| 278 return ExecuteScriptAndExtractString(active_web_contents(), script); | 263 return RemoteTestHelper::ExecuteScriptAndExtractString( |
| 264 active_web_contents(), script); |
| 279 } | 265 } |
| 280 | 266 |
| 281 // Helper to execute a JavaScript code snippet and extract the string result. | |
| 282 static std::string ExecuteScriptAndExtractString( | |
| 283 content::WebContents* web_contents, const std::string& script); | |
| 284 | |
| 285 // Helper to load a JavaScript file from |path| and inject it to | 267 // Helper to load a JavaScript file from |path| and inject it to |
| 286 // current web_content. The variable |path| is relative to the directory of | 268 // current web_content. The variable |path| is relative to the directory of |
| 287 // the |browsertest| executable. | 269 // the |browsertest| executable. |
| 288 static bool LoadScript(content::WebContents* web_contents, | 270 static bool LoadScript(content::WebContents* web_contents, |
| 289 const base::FilePath::StringType& path); | 271 const base::FilePath::StringType& path); |
| 290 | 272 |
| 291 // Helper to execute a JavaScript browser test. It creates an object using | 273 // Helper to execute a JavaScript browser test. It creates an object using |
| 292 // the |browserTest.testName| ctor and calls |run| on the created object with | 274 // the |browserTest.testName| ctor and calls |run| on the created object with |
| 293 // |testData|, which can be any arbitrary object literal. The script | 275 // |testData|, which can be any arbitrary object literal. The script |
| 294 // browser_test.js must be loaded (using LoadScript) before calling this | 276 // browser_test.js must be loaded (using LoadScript) before calling this |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // push it onto the stack and that becomes the active instance. | 350 // push it onto the stack and that becomes the active instance. |
| 369 // And once we are done with the current WebContents instance | 351 // And once we are done with the current WebContents instance |
| 370 // we pop it off the stack, returning to the previous instance. | 352 // we pop it off the stack, returning to the previous instance. |
| 371 std::vector<content::WebContents*> web_contents_stack_; | 353 std::vector<content::WebContents*> web_contents_stack_; |
| 372 | 354 |
| 373 // WebContent of the client page that facilitates communication with | 355 // WebContent of the client page that facilitates communication with |
| 374 // the HTTP server. This is how the remoting browser tests | 356 // the HTTP server. This is how the remoting browser tests |
| 375 // will get acknowledgments of actions completed on the host. | 357 // will get acknowledgments of actions completed on the host. |
| 376 content::WebContents* client_web_content_; | 358 content::WebContents* client_web_content_; |
| 377 | 359 |
| 360 // Helper class to assist in performing and verifying remote operations. |
| 361 scoped_ptr<RemoteTestHelper> remote_test_helper_; |
| 362 |
| 378 // WebContent of the landing page in the chromoting app. | 363 // WebContent of the landing page in the chromoting app. |
| 379 content::WebContents* app_web_content_; | 364 content::WebContents* app_web_content_; |
| 380 | 365 |
| 381 bool no_cleanup_; | 366 bool no_cleanup_; |
| 382 bool no_install_; | 367 bool no_install_; |
| 383 const Extension* extension_; | 368 const Extension* extension_; |
| 384 base::FilePath webapp_crx_; | 369 base::FilePath webapp_crx_; |
| 385 base::FilePath webapp_unpacked_; | 370 base::FilePath webapp_unpacked_; |
| 386 std::string username_; | 371 std::string username_; |
| 387 std::string password_; | 372 std::string password_; |
| 388 std::string me2me_pin_; | 373 std::string me2me_pin_; |
| 389 std::string remote_host_name_; | 374 std::string remote_host_name_; |
| 390 std::string extension_name_; | 375 std::string extension_name_; |
| 391 std::string http_server_; | 376 std::string http_server_; |
| 392 }; | 377 }; |
| 393 | 378 |
| 394 } // namespace remoting | 379 } // namespace remoting |
| 395 | 380 |
| 396 #endif // CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ | 381 #endif // CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ |
| OLD | NEW |