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 #include "remote_desktop_browsertest.h" | 5 #include "remote_desktop_browsertest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 void RemoteDesktopBrowserTest::SetUpInProcessBrowserTestFixture() { | 29 void RemoteDesktopBrowserTest::SetUpInProcessBrowserTestFixture() { |
30 // The resolver object lifetime is managed by sync_test_setup, not here. | 30 // The resolver object lifetime is managed by sync_test_setup, not here. |
31 EnableDNSLookupForThisTest( | 31 EnableDNSLookupForThisTest( |
32 new net::RuleBasedHostResolverProc(host_resolver())); | 32 new net::RuleBasedHostResolverProc(host_resolver())); |
33 } | 33 } |
34 | 34 |
35 void RemoteDesktopBrowserTest::TearDownInProcessBrowserTestFixture() { | 35 void RemoteDesktopBrowserTest::TearDownInProcessBrowserTestFixture() { |
36 DisableDNSLookupForThisTest(); | 36 DisableDNSLookupForThisTest(); |
37 } | 37 } |
38 | 38 |
39 void RemoteDesktopBrowserTest::ParseCommandLine() { | |
40 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
41 | |
42 // The test framework overrides any command line user-data-dir | |
43 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory. | |
44 // That happens in the ChromeTestLauncherDelegate, and affects | |
45 // all unit tests (no opt out available). It intentionally erases | |
46 // any --user-data-dir switch if present and appends a new one. | |
47 // Re-override the default data dir if override-user-data-dir | |
48 // is specified. | |
49 if (command_line->HasSwitch(kOverrideUserDataDir)) { | |
50 const base::FilePath& override_user_data_dir = | |
51 command_line->GetSwitchValuePath(kOverrideUserDataDir); | |
52 | |
53 ASSERT_FALSE(override_user_data_dir.empty()); | |
54 | |
55 command_line->AppendSwitchPath(switches::kUserDataDir, | |
56 override_user_data_dir); | |
57 } | |
58 | |
59 username_ = command_line->GetSwitchValueASCII(kUsername); | |
60 password_ = command_line->GetSwitchValueASCII(kkPassword); | |
61 | |
62 no_cleanup_ = command_line->HasSwitch(kNoCleanup); | |
63 no_install_ = command_line->HasSwitch(kNoInstall); | |
64 | |
65 if (!no_install_) { | |
66 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); | |
67 ASSERT_FALSE(webapp_crx_.empty()); | |
68 } | |
69 } | |
70 | |
71 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest( | |
72 net::RuleBasedHostResolverProc* host_resolver) { | |
73 // mock_host_resolver_override_ takes ownership of the resolver. | |
74 scoped_refptr<net::RuleBasedHostResolverProc> resolver = | |
75 new net::RuleBasedHostResolverProc(host_resolver); | |
76 resolver->AllowDirectLookup("*.google.com"); | |
77 // On Linux, we use Chromium's NSS implementation which uses the following | |
78 // hosts for certificate verification. Without these overrides, running the | |
79 // integration tests on Linux causes errors as we make external DNS lookups. | |
80 resolver->AllowDirectLookup("*.thawte.com"); | |
81 resolver->AllowDirectLookup("*.geotrust.com"); | |
82 resolver->AllowDirectLookup("*.gstatic.com"); | |
83 resolver->AllowDirectLookup("*.googleapis.com"); | |
84 mock_host_resolver_override_.reset( | |
85 new net::ScopedDefaultHostResolverProc(resolver.get())); | |
86 } | |
87 | |
88 void RemoteDesktopBrowserTest::DisableDNSLookupForThisTest() { | |
89 mock_host_resolver_override_.reset(); | |
90 } | |
91 | |
92 void RemoteDesktopBrowserTest::VerifyInternetAccess() { | 39 void RemoteDesktopBrowserTest::VerifyInternetAccess() { |
93 GURL google_url("http://www.google.com"); | 40 GURL google_url("http://www.google.com"); |
94 NavigateToURLAndWait(google_url); | 41 NavigateToURLAndWait(google_url); |
95 | 42 |
96 EXPECT_EQ(GetCurrentURL().host(), "www.google.com"); | 43 EXPECT_EQ(GetCurrentURL().host(), "www.google.com"); |
97 } | 44 } |
98 | 45 |
99 void RemoteDesktopBrowserTest::InstallChromotingApp() { | 46 void RemoteDesktopBrowserTest::InstallChromotingApp() { |
100 base::FilePath install_dir(WebAppCrxPath()); | 47 base::FilePath install_dir(WebAppCrxPath()); |
101 scoped_refptr<const Extension> extension(InstallExtensionWithUIAutoConfirm( | 48 scoped_refptr<const Extension> extension(InstallExtensionWithUIAutoConfirm( |
102 install_dir, 1, browser())); | 49 install_dir, 1, browser())); |
103 | 50 |
104 EXPECT_FALSE(extension.get() == NULL); | 51 EXPECT_FALSE(extension.get() == NULL); |
105 } | 52 } |
106 | 53 |
107 void RemoteDesktopBrowserTest::UninstallChromotingApp() { | 54 void RemoteDesktopBrowserTest::UninstallChromotingApp() { |
108 UninstallExtension(ChromotingID()); | 55 UninstallExtension(ChromotingID()); |
109 chromoting_id_.clear(); | 56 chromoting_id_.clear(); |
110 } | 57 } |
111 | 58 |
112 void RemoteDesktopBrowserTest::LaunchChromotingApp() { | |
113 ASSERT_FALSE(ChromotingID().empty()); | |
114 | |
115 const GURL chromoting_main = Chromoting_Main_URL(); | |
116 NavigateToURLAndWait(chromoting_main); | |
117 | |
118 EXPECT_EQ(GetCurrentURL(), chromoting_main); | |
119 } | |
120 | |
121 void RemoteDesktopBrowserTest::VerifyChromotingLoaded(bool expected) { | 59 void RemoteDesktopBrowserTest::VerifyChromotingLoaded(bool expected) { |
122 const ExtensionSet* extensions = extension_service()->extensions(); | 60 const ExtensionSet* extensions = extension_service()->extensions(); |
123 scoped_refptr<const extensions::Extension> extension; | 61 scoped_refptr<const extensions::Extension> extension; |
124 ExtensionSet::const_iterator iter; | 62 ExtensionSet::const_iterator iter; |
125 bool installed = false; | 63 bool installed = false; |
126 | 64 |
127 for (iter = extensions->begin(); iter != extensions->end(); ++iter) { | 65 for (iter = extensions->begin(); iter != extensions->end(); ++iter) { |
128 extension = *iter; | 66 extension = *iter; |
129 // Is there a better way to recognize the chromoting extension | 67 // Is there a better way to recognize the chromoting extension |
130 // than name comparison? | 68 // than name comparison? |
131 if (extension->name() == "Chromoting" || | 69 if (extension->name() == "Chromoting" || |
132 extension->name() == "Chrome Remote Desktop") { | 70 extension->name() == "Chrome Remote Desktop") { |
133 installed = true; | 71 installed = true; |
134 break; | 72 break; |
135 } | 73 } |
136 } | 74 } |
137 | 75 |
138 if (installed) { | 76 if (installed) { |
139 chromoting_id_ = extension->id(); | 77 chromoting_id_ = extension->id(); |
140 | 78 |
141 EXPECT_EQ(extension->GetType(), | 79 EXPECT_EQ(extension->GetType(), |
142 extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); | 80 extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); |
143 | 81 |
144 EXPECT_TRUE(extension->ShouldDisplayInAppLauncher()); | 82 EXPECT_TRUE(extension->ShouldDisplayInAppLauncher()); |
145 } | 83 } |
146 | 84 |
147 EXPECT_EQ(installed, expected); | 85 EXPECT_EQ(installed, expected); |
148 } | 86 } |
149 | 87 |
| 88 void RemoteDesktopBrowserTest::LaunchChromotingApp() { |
| 89 ASSERT_FALSE(ChromotingID().empty()); |
| 90 |
| 91 const GURL chromoting_main = Chromoting_Main_URL(); |
| 92 NavigateToURLAndWait(chromoting_main); |
| 93 |
| 94 EXPECT_EQ(GetCurrentURL(), chromoting_main); |
| 95 } |
| 96 |
150 void RemoteDesktopBrowserTest::Authorize() { | 97 void RemoteDesktopBrowserTest::Authorize() { |
151 // The chromoting extension should be installed. | 98 // The chromoting extension should be installed. |
152 ASSERT_FALSE(ChromotingID().empty()); | 99 ASSERT_FALSE(ChromotingID().empty()); |
153 | 100 |
154 // The chromoting main page should be loaded in the current tab | 101 // The chromoting main page should be loaded in the current tab |
155 // and isAuthenticated() should be false (auth dialog visible). | 102 // and isAuthenticated() should be false (auth dialog visible). |
156 ASSERT_EQ(GetCurrentURL(), Chromoting_Main_URL()); | 103 ASSERT_EQ(GetCurrentURL(), Chromoting_Main_URL()); |
157 ASSERT_FALSE(ExecuteScriptAndExtractBool( | 104 ASSERT_FALSE(ExecuteScriptAndExtractBool( |
158 "remoting.OAuth2.prototype.isAuthenticated()")); | 105 "remoting.OAuth2.prototype.isAuthenticated()")); |
159 | 106 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 "lso.approveButtonAction();" | 150 "lso.approveButtonAction();" |
204 "document.forms[\"connect-approve\"].submit();", | 151 "document.forms[\"connect-approve\"].submit();", |
205 chromoting_main); | 152 chromoting_main); |
206 | 153 |
207 ASSERT_TRUE(GetCurrentURL() == chromoting_main); | 154 ASSERT_TRUE(GetCurrentURL() == chromoting_main); |
208 | 155 |
209 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 156 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
210 "remoting.OAuth2.prototype.isAuthenticated()")); | 157 "remoting.OAuth2.prototype.isAuthenticated()")); |
211 } | 158 } |
212 | 159 |
| 160 void RemoteDesktopBrowserTest::Install() { |
| 161 // TODO: add support for installing unpacked extension (the v2 app needs it). |
| 162 if (!NoInstall()) { |
| 163 VerifyChromotingLoaded(false); |
| 164 InstallChromotingApp(); |
| 165 } |
| 166 |
| 167 VerifyChromotingLoaded(true); |
| 168 } |
| 169 |
| 170 void RemoteDesktopBrowserTest::Cleanup() { |
| 171 // TODO: Remove this hack by blocking on the appropriate notification. |
| 172 // The browser may still be loading images embedded in the webapp. If we |
| 173 // uinstall it now those load will fail. Navigating away to avoid the load |
| 174 // failures. |
| 175 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 176 |
| 177 if (!NoCleanup()) { |
| 178 UninstallChromotingApp(); |
| 179 VerifyChromotingLoaded(false); |
| 180 } |
| 181 } |
| 182 |
| 183 void RemoteDesktopBrowserTest::Auth() { |
| 184 Authorize(); |
| 185 Authenticate(); |
| 186 Approve(); |
| 187 } |
| 188 |
| 189 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest( |
| 190 net::RuleBasedHostResolverProc* host_resolver) { |
| 191 // mock_host_resolver_override_ takes ownership of the resolver. |
| 192 scoped_refptr<net::RuleBasedHostResolverProc> resolver = |
| 193 new net::RuleBasedHostResolverProc(host_resolver); |
| 194 resolver->AllowDirectLookup("*.google.com"); |
| 195 // On Linux, we use Chromium's NSS implementation which uses the following |
| 196 // hosts for certificate verification. Without these overrides, running the |
| 197 // integration tests on Linux causes errors as we make external DNS lookups. |
| 198 resolver->AllowDirectLookup("*.thawte.com"); |
| 199 resolver->AllowDirectLookup("*.geotrust.com"); |
| 200 resolver->AllowDirectLookup("*.gstatic.com"); |
| 201 resolver->AllowDirectLookup("*.googleapis.com"); |
| 202 mock_host_resolver_override_.reset( |
| 203 new net::ScopedDefaultHostResolverProc(resolver.get())); |
| 204 } |
| 205 |
| 206 void RemoteDesktopBrowserTest::DisableDNSLookupForThisTest() { |
| 207 mock_host_resolver_override_.reset(); |
| 208 } |
| 209 |
| 210 void RemoteDesktopBrowserTest::ParseCommandLine() { |
| 211 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 212 |
| 213 // The test framework overrides any command line user-data-dir |
| 214 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory. |
| 215 // That happens in the ChromeTestLauncherDelegate, and affects |
| 216 // all unit tests (no opt out available). It intentionally erases |
| 217 // any --user-data-dir switch if present and appends a new one. |
| 218 // Re-override the default data dir if override-user-data-dir |
| 219 // is specified. |
| 220 if (command_line->HasSwitch(kOverrideUserDataDir)) { |
| 221 const base::FilePath& override_user_data_dir = |
| 222 command_line->GetSwitchValuePath(kOverrideUserDataDir); |
| 223 |
| 224 ASSERT_FALSE(override_user_data_dir.empty()); |
| 225 |
| 226 command_line->AppendSwitchPath(switches::kUserDataDir, |
| 227 override_user_data_dir); |
| 228 } |
| 229 |
| 230 username_ = command_line->GetSwitchValueASCII(kUsername); |
| 231 password_ = command_line->GetSwitchValueASCII(kkPassword); |
| 232 |
| 233 no_cleanup_ = command_line->HasSwitch(kNoCleanup); |
| 234 no_install_ = command_line->HasSwitch(kNoInstall); |
| 235 |
| 236 if (!no_install_) { |
| 237 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); |
| 238 ASSERT_FALSE(webapp_crx_.empty()); |
| 239 } |
| 240 } |
| 241 |
| 242 void RemoteDesktopBrowserTest::ExecuteScript(const std::string& script) { |
| 243 ASSERT_TRUE(content::ExecuteScript( |
| 244 browser()->tab_strip_model()->GetActiveWebContents(), script)); |
| 245 } |
| 246 |
| 247 void RemoteDesktopBrowserTest::ExecuteScriptAndWait(const std::string& script) { |
| 248 content::WindowedNotificationObserver observer( |
| 249 content::NOTIFICATION_LOAD_STOP, |
| 250 content::Source<content::NavigationController>( |
| 251 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 252 GetController())); |
| 253 |
| 254 ExecuteScript(script); |
| 255 |
| 256 observer.Wait(); |
| 257 } |
| 258 |
| 259 void RemoteDesktopBrowserTest::ExecuteScriptAndWaitUntil( |
| 260 const std::string& script, |
| 261 const GURL& target) { |
| 262 content::WindowedNotificationObserver observer( |
| 263 content::NOTIFICATION_LOAD_STOP, |
| 264 content::Source<content::NavigationController>( |
| 265 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 266 GetController())); |
| 267 |
| 268 ExecuteScript(script); |
| 269 |
| 270 observer.Wait(); |
| 271 |
| 272 // TODO: is there a better way to wait for all the redirections to complete? |
| 273 while (GetCurrentURL() != target) { |
| 274 content::WindowedNotificationObserver( |
| 275 content::NOTIFICATION_LOAD_STOP, |
| 276 content::Source<content::NavigationController>( |
| 277 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 278 GetController())).Wait(); |
| 279 } |
| 280 } |
| 281 |
| 282 bool RemoteDesktopBrowserTest::ExecuteScriptAndExtractBool( |
| 283 const std::string& script) { |
| 284 bool result; |
| 285 // Using a private assert function because ASSERT_TRUE can only be used in |
| 286 // void returning functions. |
| 287 _ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 288 browser()->tab_strip_model()->GetActiveWebContents(), |
| 289 "window.domAutomationController.send(" + script + ");", |
| 290 &result)); |
| 291 |
| 292 return result; |
| 293 } |
| 294 |
| 295 // Helper to navigate to a given url. |
| 296 void RemoteDesktopBrowserTest::NavigateToURLAndWait(const GURL& url) { |
| 297 content::WindowedNotificationObserver observer( |
| 298 content::NOTIFICATION_LOAD_STOP, |
| 299 content::Source<content::NavigationController>( |
| 300 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 301 GetController())); |
| 302 |
| 303 ui_test_utils::NavigateToURL(browser(), url); |
| 304 observer.Wait(); |
| 305 } |
| 306 |
213 } // namespace remoting | 307 } // namespace remoting |
OLD | NEW |