| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 REMOTE_DESKTOP_BROWSER_TEST_H_ | 5 #ifndef REMOTE_DESKTOP_BROWSER_TEST_H_ |
| 6 #define REMOTE_DESKTOP_BROWSER_TEST_H_ | 6 #define REMOTE_DESKTOP_BROWSER_TEST_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace remoting { | 33 namespace remoting { |
| 34 | 34 |
| 35 class RemoteDesktopBrowserTest : public ExtensionBrowserTest { | 35 class RemoteDesktopBrowserTest : public ExtensionBrowserTest { |
| 36 public: | 36 public: |
| 37 RemoteDesktopBrowserTest(); | 37 RemoteDesktopBrowserTest(); |
| 38 virtual ~RemoteDesktopBrowserTest(); | 38 virtual ~RemoteDesktopBrowserTest(); |
| 39 | 39 |
| 40 // InProcessBrowserTest Overrides |
| 40 virtual void SetUp() OVERRIDE; | 41 virtual void SetUp() OVERRIDE; |
| 41 | 42 |
| 42 protected: | 43 protected: |
| 44 // InProcessBrowserTest Overrides |
| 43 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | 45 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; |
| 46 |
| 47 // InProcessBrowserTest Overrides |
| 44 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; | 48 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; |
| 45 | 49 |
| 50 |
| 51 /* */ |
| 52 /* The following helpers each perform a simple task. */ |
| 53 /* */ |
| 54 |
| 55 // Verify the test has access to the internet (specifically google.com) |
| 56 void VerifyInternetAccess(); |
| 57 |
| 46 // Install the chromoting extension from a crx file. | 58 // Install the chromoting extension from a crx file. |
| 47 void InstallChromotingApp(); | 59 void InstallChromotingApp(); |
| 48 | 60 |
| 49 // Uninstall the chromoting extension. | 61 // Uninstall the chromoting extension. |
| 50 void UninstallChromotingApp(); | 62 void UninstallChromotingApp(); |
| 51 | 63 |
| 52 // Test whether the chromoting extension is installed. | 64 // Test whether the chromoting extension is installed. |
| 53 void VerifyChromotingLoaded(bool expected); | 65 void VerifyChromotingLoaded(bool expected); |
| 54 | 66 |
| 55 // Launch the chromoting app. | 67 // Launch the chromoting app. |
| 56 void LaunchChromotingApp(); | 68 void LaunchChromotingApp(); |
| 57 | 69 |
| 58 // Verify the test has access to the internet (specifically google.com) | |
| 59 void VerifyInternetAccess(); | |
| 60 | |
| 61 // Authorize: grant extended access permission to the user's computer. | 70 // Authorize: grant extended access permission to the user's computer. |
| 62 void Authorize(); | 71 void Authorize(); |
| 63 | 72 |
| 64 // Authenticate: sign in to google using the credentials provided. | 73 // Authenticate: sign in to google using the credentials provided. |
| 65 void Authenticate(); | 74 void Authenticate(); |
| 66 | 75 |
| 67 // Approve: grant the chromoting app necessary permissions. | 76 // Approve: grant the chromoting app necessary permissions. |
| 68 void Approve(); | 77 void Approve(); |
| 69 | 78 |
| 70 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). | |
| 71 // This is useful for diagnostic purposes. | |
| 72 bool NoCleanup() { return no_cleanup_; } | |
| 73 | 79 |
| 74 // Whether to install the chromoting extension before running the test cases. | 80 /* */ |
| 75 // This is useful for diagnostic purposes. | 81 /* The following helpers each perform a composite task. */ |
| 76 bool NoInstall() { return no_install_; } | 82 /* */ |
| 83 |
| 84 // Install the chromoting extension |
| 85 void Install(); |
| 86 |
| 87 // Clean up after the test. |
| 88 void Cleanup(); |
| 89 |
| 90 // Perform all the auth steps: authorization, authenticattion, etc. |
| 91 // It starts from the chromoting main page unauthenticated and ends up back |
| 92 // on the chromoting main page authenticated and ready to go. |
| 93 void Auth(); |
| 77 | 94 |
| 78 private: | 95 private: |
| 79 void ParseCommandLine(); | |
| 80 | |
| 81 // Change behavior of the default host resolver to allow DNS lookup | 96 // Change behavior of the default host resolver to allow DNS lookup |
| 82 // to proceed instead of being blocked by the test infrastructure. | 97 // to proceed instead of being blocked by the test infrastructure. |
| 83 void EnableDNSLookupForThisTest( | 98 void EnableDNSLookupForThisTest( |
| 84 net::RuleBasedHostResolverProc* host_resolver); | 99 net::RuleBasedHostResolverProc* host_resolver); |
| 85 | 100 |
| 86 // We need to reset the DNS lookup when we finish, or the test will fail. | 101 // We need to reset the DNS lookup when we finish, or the test will fail. |
| 87 void DisableDNSLookupForThisTest(); | 102 void DisableDNSLookupForThisTest(); |
| 88 | 103 |
| 104 void ParseCommandLine(); |
| 105 |
| 106 |
| 107 /* */ |
| 108 /* Accessor methods. */ |
| 109 /* */ |
| 110 |
| 89 // Helper to get the path to the crx file of the webapp to be tested. | 111 // Helper to get the path to the crx file of the webapp to be tested. |
| 90 base::FilePath WebAppCrxPath() { return webapp_crx_; } | 112 base::FilePath WebAppCrxPath() { return webapp_crx_; } |
| 91 | 113 |
| 92 // Helper to get the extension ID of the installed chromoting webapp. | 114 // Helper to get the extension ID of the installed chromoting webapp. |
| 93 std::string ChromotingID() { return chromoting_id_; } | 115 std::string ChromotingID() { return chromoting_id_; } |
| 94 | 116 |
| 117 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). |
| 118 // This is useful for diagnostic purposes. |
| 119 bool NoCleanup() { return no_cleanup_; } |
| 120 |
| 121 // Whether to install the chromoting extension before running the test cases. |
| 122 // This is useful for diagnostic purposes. |
| 123 bool NoInstall() { return no_install_; } |
| 124 |
| 95 // Helper to construct the starting URL of the installed chromoting webapp. | 125 // Helper to construct the starting URL of the installed chromoting webapp. |
| 96 GURL Chromoting_Main_URL() { | 126 GURL Chromoting_Main_URL() { |
| 97 return GURL("chrome-extension://" + ChromotingID() + "/main.html"); | 127 return GURL("chrome-extension://" + ChromotingID() + "/main.html"); |
| 98 } | 128 } |
| 99 | 129 |
| 100 // Helper to retrieve the current URL of the active tab in the browser. | 130 // Helper to retrieve the current URL of the active tab in the browser. |
| 101 GURL GetCurrentURL() { | 131 GURL GetCurrentURL() { |
| 102 return browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); | 132 return browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); |
| 103 } | 133 } |
| 104 | 134 |
| 135 |
| 136 /* */ |
| 137 /* Helpers to execute javascript code on a web page. */ |
| 138 /* */ |
| 139 |
| 105 // Helper to execute a javascript code snippet on the current page. | 140 // Helper to execute a javascript code snippet on the current page. |
| 106 void ExecuteScript(const std::string& script) { | 141 void ExecuteScript(const std::string& script); |
| 107 ASSERT_TRUE(content::ExecuteScript( | |
| 108 browser()->tab_strip_model()->GetActiveWebContents(), script)); | |
| 109 } | |
| 110 | 142 |
| 111 // Helper to execute a javascript code snippet on the current page and | 143 // Helper to execute a javascript code snippet on the current page and |
| 112 // wait for page load to complete. | 144 // wait for page load to complete. |
| 113 void ExecuteScriptAndWait(const std::string& script) { | 145 void ExecuteScriptAndWait(const std::string& script); |
| 114 content::WindowedNotificationObserver observer( | |
| 115 content::NOTIFICATION_LOAD_STOP, | |
| 116 content::Source<content::NavigationController>( | |
| 117 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 118 GetController())); | |
| 119 | |
| 120 ExecuteScript(script); | |
| 121 | |
| 122 observer.Wait(); | |
| 123 } | |
| 124 | 146 |
| 125 // Helper to execute a javascript code snippet on the current page and | 147 // Helper to execute a javascript code snippet on the current page and |
| 126 // wait until the target url is loaded. This is used when the target page | 148 // wait until the target url is loaded. This is used when the target page |
| 127 // is loaded after multiple redirections. | 149 // is loaded after multiple redirections. |
| 128 void ExecuteScriptAndWaitUntil( | 150 void ExecuteScriptAndWaitUntil(const std::string& script, const GURL& target); |
| 129 const std::string& script, const GURL& target) { | |
| 130 content::WindowedNotificationObserver observer( | |
| 131 content::NOTIFICATION_LOAD_STOP, | |
| 132 content::Source<content::NavigationController>( | |
| 133 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 134 GetController())); | |
| 135 | |
| 136 ExecuteScript(script); | |
| 137 | |
| 138 observer.Wait(); | |
| 139 | |
| 140 // TODO: is there a better way to wait for all the redirections to complete? | |
| 141 while (GetCurrentURL() != target) { | |
| 142 content::WindowedNotificationObserver( | |
| 143 content::NOTIFICATION_LOAD_STOP, | |
| 144 content::Source<content::NavigationController>( | |
| 145 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 146 GetController())).Wait(); | |
| 147 } | |
| 148 } | |
| 149 | 151 |
| 150 // Helper to execute a javascript code snippet on the current page and | 152 // Helper to execute a javascript code snippet on the current page and |
| 151 // extract the boolean result. | 153 // extract the boolean result. |
| 152 bool ExecuteScriptAndExtractBool(const std::string& script) { | 154 bool ExecuteScriptAndExtractBool(const std::string& script); |
| 153 bool result; | |
| 154 // Using a private assert function because ASSERT_TRUE can only be used in | |
| 155 // void returning functions. | |
| 156 _ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 157 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 158 "window.domAutomationController.send(" + script + ");", | |
| 159 &result)); | |
| 160 | 155 |
| 161 return result; | 156 // Helper to navigate to a given url. |
| 162 } | 157 void NavigateToURLAndWait(const GURL& url); |
| 163 | 158 |
| 164 // Helper to check whether a html element with the given name exists on | 159 // Helper to check whether a html element with the given name exists on |
| 165 // the current page. | 160 // the current page. |
| 166 bool HtmlElementExists(const std::string& name) { | 161 bool HtmlElementExists(const std::string& name) { |
| 167 return ExecuteScriptAndExtractBool( | 162 return ExecuteScriptAndExtractBool( |
| 168 "document.getElementById(\"" + name + "\") != null"); | 163 "document.getElementById(\"" + name + "\") != null"); |
| 169 } | 164 } |
| 170 | 165 |
| 171 // Helper to navigate to a given url. | |
| 172 void NavigateToURLAndWait(const GURL& url) { | |
| 173 content::WindowedNotificationObserver observer( | |
| 174 content::NOTIFICATION_LOAD_STOP, | |
| 175 content::Source<content::NavigationController>( | |
| 176 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 177 GetController())); | |
| 178 | 166 |
| 179 ui_test_utils::NavigateToURL(browser(), url); | 167 /* */ |
| 180 observer.Wait(); | 168 /* Fields */ |
| 181 } | 169 /* */ |
| 182 | 170 |
| 183 // This test needs to make live DNS requests for access to | 171 // This test needs to make live DNS requests for access to |
| 184 // GAIA and sync server URLs under google.com. We use a scoped version | 172 // GAIA and sync server URLs under google.com. We use a scoped version |
| 185 // to override the default resolver while the test is active. | 173 // to override the default resolver while the test is active. |
| 186 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; | 174 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; |
| 187 | 175 |
| 188 bool no_cleanup_; | 176 bool no_cleanup_; |
| 189 bool no_install_; | 177 bool no_install_; |
| 190 std::string chromoting_id_; | 178 std::string chromoting_id_; |
| 191 base::FilePath webapp_crx_; | 179 base::FilePath webapp_crx_; |
| 192 std::string username_; | 180 std::string username_; |
| 193 std::string password_; | 181 std::string password_; |
| 194 }; | 182 }; |
| 195 | 183 |
| 196 } // namespace remoting | 184 } // namespace remoting |
| 197 | 185 |
| 198 #endif // REMOTE_DESKTOP_BROWSER_TEST_H_ | 186 #endif // REMOTE_DESKTOP_BROWSER_TEST_H_ |
| OLD | NEW |