Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: remoting/test/remote_desktop_browsertest.cc

Issue 22274016: Adding the "Authenticate" step to the "MANUAL_Auth" test case. Also added the username and password… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_tests_v2
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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";
40
41 // ASSERT_TRUE can only be used in void returning functions.
42 void _ASSERT_TRUE(bool condition) {
43 ASSERT_TRUE(condition);
44 return;
45 }
46
38 } 47 }
39 48
40 namespace remoting { 49 namespace remoting {
41 50
42 class RemoteDesktopBrowserTest : public ExtensionBrowserTest { 51 class RemoteDesktopBrowserTest : public ExtensionBrowserTest {
43 public: 52 public:
44 virtual void SetUp() OVERRIDE { 53 virtual void SetUp() OVERRIDE {
45 ParseCommandLine(); 54 ParseCommandLine();
46 ExtensionBrowserTest::SetUp(); 55 ExtensionBrowserTest::SetUp();
47 } 56 }
(...skipping 22 matching lines...) Expand all
70 void VerifyChromotingLoaded(bool expected); 79 void VerifyChromotingLoaded(bool expected);
71 80
72 // Launch the chromoting app. 81 // Launch the chromoting app.
73 void LaunchChromotingApp(); 82 void LaunchChromotingApp();
74 83
75 // Verify the test has access to the internet (specifically google.com) 84 // Verify the test has access to the internet (specifically google.com)
76 void VerifyInternetAccess(); 85 void VerifyInternetAccess();
77 86
78 void Authorize(); 87 void Authorize();
79 88
89 void Authenticate();
90
80 // Whether to perform the cleanup tasks (uninstalling chromoting, etc). 91 // Whether to perform the cleanup tasks (uninstalling chromoting, etc).
81 // This is useful for diagnostic purposes. 92 // This is useful for diagnostic purposes.
82 bool NoCleanup() { return no_cleanup_; } 93 bool NoCleanup() { return no_cleanup_; }
83 94
84 // Whether to install the chromoting extension before running the test cases. 95 // Whether to install the chromoting extension before running the test cases.
85 // This is useful for diagnostic purposes. 96 // This is useful for diagnostic purposes.
86 bool NoInstall() { return no_install_; } 97 bool NoInstall() { return no_install_; }
87 98
88 private: 99 private:
89 void ParseCommandLine(); 100 void ParseCommandLine();
(...skipping 10 matching lines...) Expand all
100 base::FilePath WebAppCrxPath() { return webapp_crx_; } 111 base::FilePath WebAppCrxPath() { return webapp_crx_; }
101 112
102 // Helper to get the extension ID of the installed chromoting webapp. 113 // Helper to get the extension ID of the installed chromoting webapp.
103 std::string ChromotingID() { return chromoting_id_; } 114 std::string ChromotingID() { return chromoting_id_; }
104 115
105 // Helper to retrieve the current URL of the active tab in the browser. 116 // Helper to retrieve the current URL of the active tab in the browser.
106 GURL GetCurrentURL() { 117 GURL GetCurrentURL() {
107 return browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); 118 return browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
108 } 119 }
109 120
121 // Helper to execute a javascript code snippet on the current page.
122 void ExecuteScript(const std::string& script) {
123 ASSERT_TRUE(content::ExecuteScript(
124 browser()->tab_strip_model()->GetActiveWebContents(), script));
125 }
126
127 // Helper to execute a javascript code snippet on the current page and
128 // wait for page load to complete.
129 void ExecuteScriptAndWait(const std::string& script) {
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
141 // Helper to execute a javascript code snippet on the current page and
142 // extract the boolean result.
143 bool ExecuteScriptAndExtractBool(const std::string& script) {
144 bool result;
145 // Using a private assert function because ASSERT_TRUE can only be used in
146 // void returning functions.
147 _ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
148 browser()->tab_strip_model()->GetActiveWebContents(),
149 "window.domAutomationController.send(" + script + ");",
150 &result));
151
152 return result;
153 }
154
155 // Helper to check whether a html element with the given name exists on
156 // the current page.
157 bool HtmlElementExists(const std::string& name) {
158 return ExecuteScriptAndExtractBool(
159 "document.getElementById(\"" + name + "\") != null");
160 }
161
162 // Helper to navigate to a given url.
163 void NavigateToURLAndWait(const GURL& url) {
164 content::WindowedNotificationObserver observer(
165 content::NOTIFICATION_LOAD_STOP,
166 content::Source<content::NavigationController>(
167 &browser()->tab_strip_model()->GetActiveWebContents()->
168 GetController()));
169
170 ui_test_utils::NavigateToURL(browser(), url);
171 observer.Wait();
172 }
173
110 // This test needs to make live DNS requests for access to 174 // 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 175 // GAIA and sync server URLs under google.com. We use a scoped version
112 // to override the default resolver while the test is active. 176 // to override the default resolver while the test is active.
113 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; 177 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_;
114 178
115 bool no_cleanup_; 179 bool no_cleanup_;
116 bool no_install_; 180 bool no_install_;
117 std::string chromoting_id_; 181 std::string chromoting_id_;
118 base::FilePath webapp_crx_; 182 base::FilePath webapp_crx_;
183 std::string username_;
184 std::string password_;
119 }; 185 };
120 186
121 void RemoteDesktopBrowserTest::ParseCommandLine() { 187 void RemoteDesktopBrowserTest::ParseCommandLine() {
122 CommandLine* command_line = CommandLine::ForCurrentProcess(); 188 CommandLine* command_line = CommandLine::ForCurrentProcess();
123 189
124 // The test framework overrides any command line user-data-dir 190 // The test framework overrides any command line user-data-dir
125 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory. 191 // argument with a /tmp/.org.chromium.Chromium.XXXXXX directory.
126 // That happens in the ChromeTestLauncherDelegate, and affects 192 // That happens in the ChromeTestLauncherDelegate, and affects
127 // all unit tests (no opt out available). It intentionally erases 193 // all unit tests (no opt out available). It intentionally erases
128 // any --user-data-dir switch if present and appends a new one. 194 // any --user-data-dir switch if present and appends a new one.
129 // Re-override the default data dir if override-user-data-dir 195 // Re-override the default data dir if override-user-data-dir
130 // is specified. 196 // is specified.
131 if (command_line->HasSwitch(kOverrideUserDataDir)) { 197 if (command_line->HasSwitch(kOverrideUserDataDir)) {
132 const base::FilePath& override_user_data_dir = 198 const base::FilePath& override_user_data_dir =
133 command_line->GetSwitchValuePath(kOverrideUserDataDir); 199 command_line->GetSwitchValuePath(kOverrideUserDataDir);
134 200
135 ASSERT_FALSE(override_user_data_dir.empty()); 201 ASSERT_FALSE(override_user_data_dir.empty());
136 202
137 command_line->AppendSwitchPath(switches::kUserDataDir, 203 command_line->AppendSwitchPath(switches::kUserDataDir,
138 override_user_data_dir); 204 override_user_data_dir);
139 } 205 }
140 206
207 username_ = command_line->GetSwitchValueNative(kUsername);
208 password_ = command_line->GetSwitchValueNative(kPassword);
209
141 no_cleanup_ = command_line->HasSwitch(kNoCleanup); 210 no_cleanup_ = command_line->HasSwitch(kNoCleanup);
142 no_install_ = command_line->HasSwitch(kNoInstall); 211 no_install_ = command_line->HasSwitch(kNoInstall);
143 212
144 if (!no_install_) { 213 if (!no_install_) {
145 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); 214 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx);
146 ASSERT_FALSE(webapp_crx_.empty()); 215 ASSERT_FALSE(webapp_crx_.empty());
147 } 216 }
148 } 217 }
149 218
150 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest( 219 void RemoteDesktopBrowserTest::EnableDNSLookupForThisTest(
(...skipping 11 matching lines...) Expand all
162 resolver->AllowDirectLookup("*.googleapis.com"); 231 resolver->AllowDirectLookup("*.googleapis.com");
163 mock_host_resolver_override_.reset( 232 mock_host_resolver_override_.reset(
164 new net::ScopedDefaultHostResolverProc(resolver.get())); 233 new net::ScopedDefaultHostResolverProc(resolver.get()));
165 } 234 }
166 235
167 void RemoteDesktopBrowserTest::DisableDNSLookupForThisTest() { 236 void RemoteDesktopBrowserTest::DisableDNSLookupForThisTest() {
168 mock_host_resolver_override_.reset(); 237 mock_host_resolver_override_.reset();
169 } 238 }
170 239
171 void RemoteDesktopBrowserTest::VerifyInternetAccess() { 240 void RemoteDesktopBrowserTest::VerifyInternetAccess() {
172 content::WindowedNotificationObserver observer(
173 content::NOTIFICATION_LOAD_STOP,
174 content::Source<content::NavigationController>(
175 &browser()->tab_strip_model()->GetActiveWebContents()->
176 GetController()));
177
178 GURL google_url("http://www.google.com"); 241 GURL google_url("http://www.google.com");
179 ui_test_utils::NavigateToURL(browser(), google_url); 242 NavigateToURLAndWait(google_url);
180 observer.Wait();
181 243
182 EXPECT_EQ(GetCurrentURL().host(), "www.google.com"); 244 EXPECT_EQ(GetCurrentURL().host(), "www.google.com");
183 } 245 }
184 246
185 void RemoteDesktopBrowserTest::InstallChromotingApp() { 247 void RemoteDesktopBrowserTest::InstallChromotingApp() {
186 base::FilePath install_dir(WebAppCrxPath()); 248 base::FilePath install_dir(WebAppCrxPath());
187 scoped_refptr<const Extension> extension(InstallExtensionWithUIAutoConfirm( 249 scoped_refptr<const Extension> extension(InstallExtensionWithUIAutoConfirm(
188 install_dir, 1, browser())); 250 install_dir, 1, browser()));
189 251
190 EXPECT_FALSE(extension.get() == NULL); 252 EXPECT_FALSE(extension.get() == NULL);
191 } 253 }
192 254
193 void RemoteDesktopBrowserTest::UninstallChromotingApp() { 255 void RemoteDesktopBrowserTest::UninstallChromotingApp() {
194 UninstallExtension(ChromotingID()); 256 UninstallExtension(ChromotingID());
195 chromoting_id_.clear(); 257 chromoting_id_.clear();
196 } 258 }
197 259
198 void RemoteDesktopBrowserTest::LaunchChromotingApp() { 260 void RemoteDesktopBrowserTest::LaunchChromotingApp() {
199 ASSERT_FALSE(ChromotingID().empty()); 261 ASSERT_FALSE(ChromotingID().empty());
262
200 std::string url = "chrome-extension://" + ChromotingID() + "/main.html"; 263 std::string url = "chrome-extension://" + ChromotingID() + "/main.html";
201 const GURL chromoting_main(url); 264 const GURL chromoting_main(url);
202 265 NavigateToURLAndWait(chromoting_main);
203 content::WindowedNotificationObserver observer(
204 content::NOTIFICATION_LOAD_STOP,
205 content::Source<content::NavigationController>(
206 &browser()->tab_strip_model()->GetActiveWebContents()->
207 GetController()));
208
209 ui_test_utils::NavigateToURL(browser(), chromoting_main);
210 observer.Wait();
211 266
212 EXPECT_EQ(GetCurrentURL(), chromoting_main); 267 EXPECT_EQ(GetCurrentURL(), chromoting_main);
213 } 268 }
214 269
215 void RemoteDesktopBrowserTest::VerifyChromotingLoaded(bool expected) { 270 void RemoteDesktopBrowserTest::VerifyChromotingLoaded(bool expected) {
216 const ExtensionSet* extensions = extension_service()->extensions(); 271 const ExtensionSet* extensions = extension_service()->extensions();
217 scoped_refptr<const extensions::Extension> extension; 272 scoped_refptr<const extensions::Extension> extension;
218 ExtensionSet::const_iterator iter; 273 ExtensionSet::const_iterator iter;
219 bool installed = false; 274 bool installed = false;
220 275
(...skipping 21 matching lines...) Expand all
242 } 297 }
243 298
244 void RemoteDesktopBrowserTest::Authorize() { 299 void RemoteDesktopBrowserTest::Authorize() {
245 // The chromoting extension should be installed. 300 // The chromoting extension should be installed.
246 ASSERT_FALSE(ChromotingID().empty()); 301 ASSERT_FALSE(ChromotingID().empty());
247 302
248 // The chromoting main page should be loaded in the current tab 303 // The chromoting main page should be loaded in the current tab
249 // and isAuthenticated() should be false (auth dialog visible). 304 // and isAuthenticated() should be false (auth dialog visible).
250 std::string url = "chrome-extension://" + ChromotingID() + "/main.html"; 305 std::string url = "chrome-extension://" + ChromotingID() + "/main.html";
251 ASSERT_EQ(GetCurrentURL().spec(), url); 306 ASSERT_EQ(GetCurrentURL().spec(), url);
307 ASSERT_FALSE(ExecuteScriptAndExtractBool(
308 "remoting.OAuth2.prototype.isAuthenticated()"));
252 309
253 bool result; 310 ExecuteScriptAndWait("remoting.OAuth2.prototype.doAuthRedirect();");
254 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
255 browser()->tab_strip_model()->GetActiveWebContents(),
256 "window.domAutomationController.send("
257 "remoting.OAuth2.prototype.isAuthenticated());",
258 &result));
259 EXPECT_FALSE(result);
260
261 content::WindowedNotificationObserver observer(
262 content::NOTIFICATION_LOAD_STOP,
263 content::Source<content::NavigationController>(
264 &browser()->tab_strip_model()->GetActiveWebContents()->
265 GetController()));
266
267 ASSERT_TRUE(content::ExecuteScript(
268 browser()->tab_strip_model()->GetActiveWebContents(),
269 "remoting.OAuth2.prototype.doAuthRedirect()"));
270 observer.Wait();
271 311
272 // Verify the active tab is at the "Google Accounts" login page. 312 // Verify the active tab is at the "Google Accounts" login page.
273 EXPECT_EQ(GetCurrentURL().host(), "accounts.google.com"); 313 EXPECT_EQ(GetCurrentURL().host(), "accounts.google.com");
314 EXPECT_TRUE(HtmlElementExists("Email"));
315 EXPECT_TRUE(HtmlElementExists("Passwd"));
316 }
274 317
275 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 318 void RemoteDesktopBrowserTest::Authenticate() {
276 browser()->tab_strip_model()->GetActiveWebContents(), 319 // The chromoting extension should be installed.
277 "window.domAutomationController.send(" 320 ASSERT_FALSE(ChromotingID().empty());
278 "document.getElementById(\"Email\") != null);",
279 &result));
280 EXPECT_TRUE(result);
281 321
282 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 322 // The active tab should have the "Google Accounts" login page loaded.
283 browser()->tab_strip_model()->GetActiveWebContents(), 323 ASSERT_EQ(GetCurrentURL().host(), "accounts.google.com");
284 "window.domAutomationController.send(" 324 ASSERT_TRUE(HtmlElementExists("Email"));
285 "document.getElementById(\"Passwd\") != null);", 325 ASSERT_TRUE(HtmlElementExists("Passwd"));
286 &result)); 326
287 EXPECT_TRUE(result); 327 // Now log in using the username and password passed in from the command line.
328 ExecuteScriptAndWait(
329 "document.getElementById(\"Email\").value = \"" + username_ + "\";" +
330 "document.getElementById(\"Passwd\").value = \"" + password_ +"\";" +
331 "document.forms[\"gaia_loginform\"].submit();");
332
333 EXPECT_EQ(GetCurrentURL().host(), "accounts.google.com");
334
335 // Is there a better way to verify we are on the "Request for Permission"
garykac 2013/08/09 17:29:05 This sounds like it should have a TODO at the star
336 // page?
337 EXPECT_TRUE(HtmlElementExists("submit_approve_access"));
288 } 338 }
289 339
290 IN_PROC_BROWSER_TEST_F(RemoteDesktopBrowserTest, MANUAL_Launch) { 340 IN_PROC_BROWSER_TEST_F(RemoteDesktopBrowserTest, MANUAL_Launch) {
291 VerifyInternetAccess(); 341 VerifyInternetAccess();
292 342
293 if (!NoInstall()) { 343 if (!NoInstall()) {
294 VerifyChromotingLoaded(false); 344 VerifyChromotingLoaded(false);
295 InstallChromotingApp(); 345 InstallChromotingApp();
296 } 346 }
297 347
(...skipping 20 matching lines...) Expand all
318 VerifyChromotingLoaded(false); 368 VerifyChromotingLoaded(false);
319 InstallChromotingApp(); 369 InstallChromotingApp();
320 } 370 }
321 371
322 VerifyChromotingLoaded(true); 372 VerifyChromotingLoaded(true);
323 373
324 LaunchChromotingApp(); 374 LaunchChromotingApp();
325 375
326 Authorize(); 376 Authorize();
327 377
378 Authenticate();
379
328 if (!NoCleanup()) { 380 if (!NoCleanup()) {
329 UninstallChromotingApp(); 381 UninstallChromotingApp();
330 VerifyChromotingLoaded(false); 382 VerifyChromotingLoaded(false);
331 } 383 }
332 } 384 }
333 385
334 } // namespace remoting 386 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698