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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/unpacked_installer.h" | 10 #include "chrome/browser/extensions/unpacked_installer.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
29 | 29 |
30 using extensions::Extension; | 30 using extensions::Extension; |
31 | 31 |
32 namespace { | 32 namespace { |
33 // Command line arguments specific to the chromoting browser tests. | 33 // Command line arguments specific to the chromoting browser tests. |
34 const char kOverrideUserDataDir[] = "override-user-data-dir"; | 34 const char kOverrideUserDataDir[] = "override-user-data-dir"; |
35 const char kNoCleanup[] = "no-cleanup"; | 35 const char kNoCleanup[] = "no-cleanup"; |
36 const char kNoInstall[] = "no-install"; | 36 const char kNoInstall[] = "no-install"; |
37 const char kWebAppCrx[] = "webapp-crx"; | 37 const char kWebAppCrx[] = "webapp-crx"; |
38 const char kUsername[] = "username"; | |
39 const char kPassword[] = "password"; | |
38 } | 40 } |
39 | 41 |
40 namespace remoting { | 42 namespace remoting { |
41 | 43 |
42 class RemoteDesktopBrowserTest : public ExtensionBrowserTest { | 44 class RemoteDesktopBrowserTest : public ExtensionBrowserTest { |
43 public: | 45 public: |
44 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
45 ParseCommandLine(); | 47 ParseCommandLine(); |
46 ExtensionBrowserTest::SetUp(); | 48 ExtensionBrowserTest::SetUp(); |
47 } | 49 } |
(...skipping 22 matching lines...) Expand all Loading... | |
70 void VerifyChromotingLoaded(bool expected); | 72 void VerifyChromotingLoaded(bool expected); |
71 | 73 |
72 // Launch the chromoting app. | 74 // Launch the chromoting app. |
73 void LaunchChromotingApp(); | 75 void LaunchChromotingApp(); |
74 | 76 |
75 // Verify the test has access to the internet (specifically google.com) | 77 // Verify the test has access to the internet (specifically google.com) |
76 void VerifyInternetAccess(); | 78 void VerifyInternetAccess(); |
77 | 79 |
78 void Authorize(); | 80 void Authorize(); |
79 | 81 |
82 void Authenticate(); | |
83 | |
80 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). | 84 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). |
81 // This is useful for diagnostic purposes. | 85 // This is useful for diagnostic purposes. |
82 bool NoCleanup() { return no_cleanup_; } | 86 bool NoCleanup() { return no_cleanup_; } |
83 | 87 |
84 // Whether to install the chromoting extension before running the test cases. | 88 // Whether to install the chromoting extension before running the test cases. |
85 // This is useful for diagnostic purposes. | 89 // This is useful for diagnostic purposes. |
86 bool NoInstall() { return no_install_; } | 90 bool NoInstall() { return no_install_; } |
87 | 91 |
88 private: | 92 private: |
89 void ParseCommandLine(); | 93 void ParseCommandLine(); |
(...skipping 19 matching lines...) Expand all Loading... | |
109 | 113 |
110 // This test needs to make live DNS requests for access to | 114 // This test needs to make live DNS requests for access to |
111 // GAIA and sync server URLs under google.com. We use a scoped version | 115 // GAIA and sync server URLs under google.com. We use a scoped version |
112 // to override the default resolver while the test is active. | 116 // to override the default resolver while the test is active. |
113 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; | 117 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; |
114 | 118 |
115 bool no_cleanup_; | 119 bool no_cleanup_; |
116 bool no_install_; | 120 bool no_install_; |
117 std::string chromoting_id_; | 121 std::string chromoting_id_; |
118 base::FilePath webapp_crx_; | 122 base::FilePath webapp_crx_; |
123 std::string username_; | |
124 std::string password_; | |
119 }; | 125 }; |
120 | 126 |
121 void RemoteDesktopBrowserTest::ParseCommandLine() { | 127 void RemoteDesktopBrowserTest::ParseCommandLine() { |
122 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 128 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
123 | 129 |
124 // The test framework overrides any command line user-data-dir | 130 // The test framework overrides any command line user-data-dir |
125 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory. | 131 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory. |
126 // That happens in the ChromeTestLauncherDelegate, and affects | 132 // That happens in the ChromeTestLauncherDelegate, and affects |
127 // all unit tests (no opt out available). It intentionally erases | 133 // all unit tests (no opt out available). It intentionally erases |
128 // any --user-data-dir switch if present and appends a new one. | 134 // any --user-data-dir switch if present and appends a new one. |
129 // Re-override the default data dir if override-user-data-dir | 135 // Re-override the default data dir if override-user-data-dir |
130 // is specified. | 136 // is specified. |
131 if (command_line->HasSwitch(kOverrideUserDataDir)) { | 137 if (command_line->HasSwitch(kOverrideUserDataDir)) { |
132 const base::FilePath& override_user_data_dir = | 138 const base::FilePath& override_user_data_dir = |
133 command_line->GetSwitchValuePath(kOverrideUserDataDir); | 139 command_line->GetSwitchValuePath(kOverrideUserDataDir); |
134 | 140 |
135 ASSERT_FALSE(override_user_data_dir.empty()); | 141 ASSERT_FALSE(override_user_data_dir.empty()); |
136 | 142 |
137 command_line->AppendSwitchPath(switches::kUserDataDir, | 143 command_line->AppendSwitchPath(switches::kUserDataDir, |
138 override_user_data_dir); | 144 override_user_data_dir); |
139 } | 145 } |
140 | 146 |
147 username_ = command_line->GetSwitchValueNative(kUsername); | |
148 password_ = command_line->GetSwitchValueNative(kPassword); | |
149 | |
141 no_cleanup_ = command_line->HasSwitch(kNoCleanup); | 150 no_cleanup_ = command_line->HasSwitch(kNoCleanup); |
142 no_install_ = command_line->HasSwitch(kNoInstall); | 151 no_install_ = command_line->HasSwitch(kNoInstall); |
143 | 152 |
144 if (!no_install_) { | 153 if (!no_install_) { |
145 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); | 154 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); |
146 ASSERT_FALSE(webapp_crx_.empty()); | 155 ASSERT_FALSE(webapp_crx_.empty()); |
147 } | 156 } |
148 } | 157 } |
149 | 158 |
150 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest( | 159 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 EXPECT_TRUE(result); | 289 EXPECT_TRUE(result); |
281 | 290 |
282 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 291 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
283 browser()->tab_strip_model()->GetActiveWebContents(), | 292 browser()->tab_strip_model()->GetActiveWebContents(), |
284 "window.domAutomationController.send(" | 293 "window.domAutomationController.send(" |
285 "document.getElementById(\"Passwd\") != null);", | 294 "document.getElementById(\"Passwd\") != null);", |
286 &result)); | 295 &result)); |
287 EXPECT_TRUE(result); | 296 EXPECT_TRUE(result); |
288 } | 297 } |
289 | 298 |
299 void RemoteDesktopBrowserTest::Authenticate() { | |
300 // The chromoting extension should be installed. | |
301 ASSERT_FALSE(ChromotingID().empty()); | |
302 | |
303 // The active tab should have the "Google Accounts" login page loaded. | |
304 ASSERT_EQ(GetCurrentURL().host(), "accounts.google.com"); | |
305 | |
306 bool result; | |
307 | |
308 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
309 browser()->tab_strip_model()->GetActiveWebContents(), | |
310 "window.domAutomationController.send(" | |
311 "document.getElementById(\"Email\") != null);", | |
312 &result)); | |
313 ASSERT_TRUE(result); | |
314 | |
315 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
316 browser()->tab_strip_model()->GetActiveWebContents(), | |
317 "window.domAutomationController.send(" | |
318 "document.getElementById(\"Passwd\") != null);", | |
319 &result)); | |
garykac
2013/08/07 17:52:18
Have you tried extracting this pattern:
ASSERT_TR
| |
320 ASSERT_TRUE(result); | |
321 | |
322 content::WindowedNotificationObserver observer( | |
323 content::NOTIFICATION_LOAD_STOP, | |
324 content::Source<content::NavigationController>( | |
325 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
326 GetController())); | |
327 | |
328 // Now log in using the username and password passed in from the command line. | |
329 ASSERT_TRUE(content::ExecuteScript( | |
330 browser()->tab_strip_model()->GetActiveWebContents(), | |
331 "document.getElementById(\"Email\").value = \"" + username_ + "\";" + | |
332 "document.getElementById(\"Passwd\").value = \"" + password_ +"\";" + | |
333 "document.forms[\"gaia_loginform\"].submit();")); | |
334 observer.Wait(); | |
335 | |
336 EXPECT_EQ(GetCurrentURL().host(), "accounts.google.com"); | |
337 | |
338 // Is there a better way to verify we are on the "Request for Permission" | |
339 // page? | |
340 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
341 browser()->tab_strip_model()->GetActiveWebContents(), | |
342 "window.domAutomationController.send(" | |
343 "document.getElementById(\"submit_approve_access\") != null);", | |
344 &result)); | |
345 EXPECT_TRUE(result); | |
346 } | |
347 | |
290 IN_PROC_BROWSER_TEST_F(RemoteDesktopBrowserTest, MANUAL_Launch) { | 348 IN_PROC_BROWSER_TEST_F(RemoteDesktopBrowserTest, MANUAL_Launch) { |
291 VerifyInternetAccess(); | 349 VerifyInternetAccess(); |
292 | 350 |
293 if (!NoInstall()) { | 351 if (!NoInstall()) { |
294 VerifyChromotingLoaded(false); | 352 VerifyChromotingLoaded(false); |
295 InstallChromotingApp(); | 353 InstallChromotingApp(); |
296 } | 354 } |
297 | 355 |
298 VerifyChromotingLoaded(true); | 356 VerifyChromotingLoaded(true); |
299 | 357 |
(...skipping 18 matching lines...) Expand all Loading... | |
318 VerifyChromotingLoaded(false); | 376 VerifyChromotingLoaded(false); |
319 InstallChromotingApp(); | 377 InstallChromotingApp(); |
320 } | 378 } |
321 | 379 |
322 VerifyChromotingLoaded(true); | 380 VerifyChromotingLoaded(true); |
323 | 381 |
324 LaunchChromotingApp(); | 382 LaunchChromotingApp(); |
325 | 383 |
326 Authorize(); | 384 Authorize(); |
327 | 385 |
386 Authenticate(); | |
387 | |
328 if (!NoCleanup()) { | 388 if (!NoCleanup()) { |
329 UninstallChromotingApp(); | 389 UninstallChromotingApp(); |
330 VerifyChromotingLoaded(false); | 390 VerifyChromotingLoaded(false); |
331 } | 391 } |
332 } | 392 } |
333 | 393 |
334 } // namespace remoting | 394 } // namespace remoting |
OLD | NEW |