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

Side by Side Diff: chrome/browser/chromeos/login/saml/saml_browsertest.cc

Issue 1004753004: cros: Port SAML support to webview sign-in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle loadabort to fix test Created 5 years, 9 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 | chrome/browser/resources/gaia_auth/channel.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <cstring> 5 #include <cstring>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/json/json_file_value_serializer.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/run_loop.h" 20 #include "base/run_loop.h"
20 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "base/values.h" 25 #include "base/values.h"
25 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/chromeos/login/existing_user_controller.h" 27 #include "chrome/browser/chromeos/login/existing_user_controller.h"
28 #include "chrome/browser/chromeos/login/startup_utils.h"
27 #include "chrome/browser/chromeos/login/test/https_forwarder.h" 29 #include "chrome/browser/chromeos/login/test/https_forwarder.h"
28 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" 30 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
29 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 31 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
30 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 32 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
31 #include "chrome/browser/chromeos/login/wizard_controller.h" 33 #include "chrome/browser/chromeos/login/wizard_controller.h"
32 #include "chrome/browser/chromeos/policy/device_policy_builder.h" 34 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
33 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 35 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
34 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 36 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
35 #include "chrome/browser/chromeos/profiles/profile_helper.h" 37 #include "chrome/browser/chromeos/profiles/profile_helper.h"
36 #include "chrome/browser/chromeos/settings/cros_settings.h" 38 #include "chrome/browser/chromeos/settings/cros_settings.h"
37 #include "chrome/browser/lifetime/application_lifetime.h" 39 #include "chrome/browser/lifetime/application_lifetime.h"
38 #include "chrome/browser/policy/test/local_policy_test_server.h" 40 #include "chrome/browser/policy/test/local_policy_test_server.h"
39 #include "chrome/browser/profiles/profile.h" 41 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 42 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
43 #include "chrome/common/chrome_constants.h"
41 #include "chrome/common/chrome_paths.h" 44 #include "chrome/common/chrome_paths.h"
42 #include "chrome/common/chrome_switches.h" 45 #include "chrome/common/chrome_switches.h"
46 #include "chrome/common/extensions/features/feature_channel.h"
47 #include "chrome/common/pref_names.h"
43 #include "chrome/grit/generated_resources.h" 48 #include "chrome/grit/generated_resources.h"
44 #include "chrome/test/base/in_process_browser_test.h" 49 #include "chrome/test/base/in_process_browser_test.h"
45 #include "chromeos/chromeos_switches.h" 50 #include "chromeos/chromeos_switches.h"
46 #include "chromeos/dbus/dbus_thread_manager.h" 51 #include "chromeos/dbus/dbus_thread_manager.h"
47 #include "chromeos/dbus/fake_session_manager_client.h" 52 #include "chromeos/dbus/fake_session_manager_client.h"
48 #include "chromeos/dbus/session_manager_client.h" 53 #include "chromeos/dbus/session_manager_client.h"
49 #include "chromeos/settings/cros_settings_names.h" 54 #include "chromeos/settings/cros_settings_names.h"
50 #include "components/policy/core/browser/browser_policy_connector.h" 55 #include "components/policy/core/browser/browser_policy_connector.h"
51 #include "components/policy/core/common/mock_configuration_policy_provider.h" 56 #include "components/policy/core/common/mock_configuration_policy_provider.h"
52 #include "components/policy/core/common/policy_map.h" 57 #include "components/policy/core/common/policy_map.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 252 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
248 http_response->set_code(net::HTTP_OK); 253 http_response->set_code(net::HTTP_OK);
249 http_response->set_content(response_html); 254 http_response->set_content(response_html);
250 http_response->set_content_type("text/html"); 255 http_response->set_content_type("text/html");
251 256
252 return http_response.Pass(); 257 return http_response.Pass();
253 } 258 }
254 259
255 } // namespace 260 } // namespace
256 261
257 class SamlTest : public InProcessBrowserTest { 262 class SamlTest : public InProcessBrowserTest,
263 public testing::WithParamInterface<bool> {
258 public: 264 public:
259 SamlTest() : gaia_frame_parent_("signin-frame"), saml_load_injected_(false) {} 265 SamlTest() : gaia_frame_parent_("signin-frame"), saml_load_injected_(false) {}
260 ~SamlTest() override {} 266 ~SamlTest() override {}
261 267
268 bool UseWebView() const {
269 return GetParam();
270 }
271
262 void SetUp() override { 272 void SetUp() override {
263 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 273 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
264 274
265 // Start the GAIA https wrapper here so that the GAIA URLs can be pointed at 275 // Start the GAIA https wrapper here so that the GAIA URLs can be pointed at
266 // it in SetUpCommandLine(). 276 // it in SetUpCommandLine().
267 gaia_https_forwarder_.reset( 277 gaia_https_forwarder_.reset(
268 new HTTPSForwarder(embedded_test_server()->base_url())); 278 new HTTPSForwarder(embedded_test_server()->base_url()));
269 ASSERT_TRUE(gaia_https_forwarder_->Start()); 279 ASSERT_TRUE(gaia_https_forwarder_->Start());
270 280
271 // Start the SAML IdP https wrapper here so that GAIA can be pointed at it 281 // Start the SAML IdP https wrapper here so that GAIA can be pointed at it
272 // in SetUpCommandLine(). 282 // in SetUpCommandLine().
273 saml_https_forwarder_.reset( 283 saml_https_forwarder_.reset(
274 new HTTPSForwarder(embedded_test_server()->base_url())); 284 new HTTPSForwarder(embedded_test_server()->base_url()));
275 ASSERT_TRUE(saml_https_forwarder_->Start()); 285 ASSERT_TRUE(saml_https_forwarder_->Start());
276 286
277 // Stop IO thread here because no threads are allowed while 287 // Stop IO thread here because no threads are allowed while
278 // spawning sandbox host process. See crbug.com/322732. 288 // spawning sandbox host process. See crbug.com/322732.
279 embedded_test_server()->StopThread(); 289 embedded_test_server()->StopThread();
280 290
281 InProcessBrowserTest::SetUp(); 291 InProcessBrowserTest::SetUp();
282 } 292 }
283 293
294 bool SetUpUserDataDirectory() override {
295 if (UseWebView()) {
296 // Enable webview signin.
297 scoped_channel_.reset(new extensions::ScopedCurrentChannel(
298 chrome::VersionInfo::CHANNEL_DEV));
299
300 base::DictionaryValue local_state_dict;
301 local_state_dict.SetBoolean(prefs::kWebviewSigninEnabled, true);
302 // OobeCompleted to skip controller-pairing-screen which still uses
303 // iframe and ends up in a JS error in oobe page init.
304 // See http://crbug.com/467147
305 local_state_dict.SetBoolean(prefs::kOobeComplete, true);
306
307 base::FilePath user_data_dir;
308 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
309 base::FilePath local_state_path =
310 user_data_dir.Append(chrome::kLocalStateFilename);
311 CHECK(JSONFileValueSerializer(local_state_path)
312 .Serialize(local_state_dict));
313 }
314
315 return InProcessBrowserTest::SetUpUserDataDirectory();
316 }
317
284 void SetUpInProcessBrowserTestFixture() override { 318 void SetUpInProcessBrowserTestFixture() override {
285 host_resolver()->AddRule("*", "127.0.0.1"); 319 host_resolver()->AddRule("*", "127.0.0.1");
286 } 320 }
287 321
288 void SetUpCommandLine(base::CommandLine* command_line) override { 322 void SetUpCommandLine(base::CommandLine* command_line) override {
289 command_line->AppendSwitch(switches::kLoginManager); 323 command_line->AppendSwitch(switches::kLoginManager);
290 command_line->AppendSwitch(switches::kForceLoginManagerInTests); 324 command_line->AppendSwitch(switches::kForceLoginManagerInTests);
325 command_line->AppendSwitch(switches::kOobeSkipPostLogin);
291 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); 326 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
292 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 327 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
293 328
329 if (UseWebView()) {
330 // Use ServiceLogin test html/js for MM.
331 command_line->AppendSwitchASCII(switches::kGaiaEndpointChromeOS,
332 "ServiceLogin");
333 }
334
294 const GURL gaia_url = gaia_https_forwarder_->GetURL(""); 335 const GURL gaia_url = gaia_https_forwarder_->GetURL("");
295 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); 336 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec());
296 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); 337 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec());
297 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, 338 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
298 gaia_url.spec()); 339 gaia_url.spec());
299 340
300 const GURL saml_idp_url = saml_https_forwarder_->GetURL("SAML"); 341 const GURL saml_idp_url = saml_https_forwarder_->GetURL("SAML");
301 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url); 342 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url);
302 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); 343 fake_gaia_.RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url);
303 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); 344 fake_gaia_.RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url);
304 fake_gaia_.RegisterSamlUser( 345 fake_gaia_.RegisterSamlUser(
305 kHTTPSAMLUserEmail, 346 kHTTPSAMLUserEmail,
306 embedded_test_server()->base_url().Resolve("/SAML")); 347 embedded_test_server()->base_url().Resolve("/SAML"));
307 fake_gaia_.RegisterSamlUser(kDifferentDomainSAMLUserEmail, saml_idp_url); 348 fake_gaia_.RegisterSamlUser(kDifferentDomainSAMLUserEmail, saml_idp_url);
308 349
309 fake_gaia_.Initialize(); 350 fake_gaia_.Initialize();
351 fake_gaia_.set_issue_oauth_code_cookie(UseWebView());
310 } 352 }
311 353
312 void SetUpOnMainThread() override { 354 void SetUpOnMainThread() override {
313 fake_gaia_.SetFakeMergeSessionParams(kFirstSAMLUserEmail, 355 fake_gaia_.SetFakeMergeSessionParams(kFirstSAMLUserEmail,
314 kTestAuthSIDCookie1, 356 kTestAuthSIDCookie1,
315 kTestAuthLSIDCookie1); 357 kTestAuthLSIDCookie1);
316 358
317 embedded_test_server()->RegisterRequestHandler( 359 embedded_test_server()->RegisterRequestHandler(
318 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); 360 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
319 embedded_test_server()->RegisterRequestHandler(base::Bind( 361 embedded_test_server()->RegisterRequestHandler(base::Bind(
(...skipping 20 matching lines...) Expand all
340 ExistingUserController* controller = 382 ExistingUserController* controller =
341 ExistingUserController::current_controller(); 383 ExistingUserController::current_controller();
342 CHECK(controller); 384 CHECK(controller);
343 return static_cast<WebUILoginDisplay*>(controller->login_display()); 385 return static_cast<WebUILoginDisplay*>(controller->login_display());
344 } 386 }
345 387
346 void WaitForSigninScreen() { 388 void WaitForSigninScreen() {
347 WizardController* wizard_controller = 389 WizardController* wizard_controller =
348 WizardController::default_controller(); 390 WizardController::default_controller();
349 if (wizard_controller) { 391 if (wizard_controller) {
350 WizardController::SkipPostLoginScreensForTesting();
351 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); 392 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
352 } 393 }
394 WizardController::SkipPostLoginScreensForTesting();
353 395
354 login_screen_load_observer_->Wait(); 396 login_screen_load_observer_->Wait();
355 } 397 }
356 398
357 virtual void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) { 399 virtual void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) {
358 WaitForSigninScreen(); 400 WaitForSigninScreen();
359 401
360 if (!saml_load_injected_) { 402 if (!saml_load_injected_) {
361 saml_load_injected_ = true; 403 saml_load_injected_ = true;
362 404
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_; 481 scoped_ptr<content::WindowedNotificationObserver> login_screen_load_observer_;
440 FakeGaia fake_gaia_; 482 FakeGaia fake_gaia_;
441 483
442 std::string gaia_frame_parent_; 484 std::string gaia_frame_parent_;
443 485
444 scoped_ptr<HTTPSForwarder> gaia_https_forwarder_; 486 scoped_ptr<HTTPSForwarder> gaia_https_forwarder_;
445 scoped_ptr<HTTPSForwarder> saml_https_forwarder_; 487 scoped_ptr<HTTPSForwarder> saml_https_forwarder_;
446 488
447 private: 489 private:
448 FakeSamlIdp fake_saml_idp_; 490 FakeSamlIdp fake_saml_idp_;
491 scoped_ptr<extensions::ScopedCurrentChannel> scoped_channel_;
449 492
450 bool saml_load_injected_; 493 bool saml_load_injected_;
451 494
452 DISALLOW_COPY_AND_ASSIGN(SamlTest); 495 DISALLOW_COPY_AND_ASSIGN(SamlTest);
453 }; 496 };
454 497
455 // Tests that signin frame should have 'saml' class and 'cancel' button is 498 // Tests that signin frame should have 'saml' class and 'cancel' button is
456 // visible when SAML IdP page is loaded. And 'cancel' button goes back to 499 // visible when SAML IdP page is loaded. And 'cancel' button goes back to
457 // gaia on clicking. 500 // gaia on clicking.
458 IN_PROC_BROWSER_TEST_F(SamlTest, SamlUI) { 501 IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) {
459 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 502 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
460 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 503 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
461 504
462 // Saml flow UI expectations. 505 // Saml flow UI expectations.
463 JsExpect("$('gaia-signin').classList.contains('full-width')"); 506 JsExpect("$('gaia-signin').classList.contains('full-width')");
464 JsExpect("!$('cancel-add-user-button').hidden"); 507 if (!UseWebView()) {
508 JsExpect("!$('cancel-add-user-button').hidden");
509 }
465 510
466 // Click on 'cancel'. 511 // Click on 'cancel'.
467 content::DOMMessageQueue message_queue; // Observe before 'cancel'. 512 content::DOMMessageQueue message_queue; // Observe before 'cancel'.
468 ASSERT_TRUE(content::ExecuteScript( 513 if (UseWebView()) {
469 GetLoginUI()->GetWebContents(), 514 ASSERT_TRUE(content::ExecuteScript(
470 "$('cancel-add-user-button').click();")); 515 GetLoginUI()->GetWebContents(),
516 "$('close-button-item').click();"));
517 } else {
518 ASSERT_TRUE(content::ExecuteScript(
519 GetLoginUI()->GetWebContents(),
520 "$('cancel-add-user-button').click();"));
521 }
471 522
472 // Auth flow should change back to Gaia. 523 // Auth flow should change back to Gaia.
473 std::string message; 524 std::string message;
474 do { 525 do {
475 ASSERT_TRUE(message_queue.WaitForMessage(&message)); 526 ASSERT_TRUE(message_queue.WaitForMessage(&message));
476 } while (message != "\"GaiaLoaded\""); 527 } while (message != "\"GaiaLoaded\"");
477 528
478 // Saml flow is gone. 529 // Saml flow is gone.
479 JsExpect("!$('gaia-signin').classList.contains('full-width')"); 530 JsExpect("!$('gaia-signin').classList.contains('full-width')");
480 } 531 }
481 532
482 // Tests the sign-in flow when the credentials passing API is used. 533 // Tests the sign-in flow when the credentials passing API is used.
483 IN_PROC_BROWSER_TEST_F(SamlTest, CredentialPassingAPI) { 534 IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) {
535 // Disabled for webview because the script is injected using
536 // webview.executeScript and there is no way to control the injection time.
537 // As a result, this test is flaky and fails about 20% of the time.
538 // TODO(xiyuan): Re-enable when webview.addContentScript API is ready.
539 if (UseWebView())
540 return;
541
484 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); 542 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html");
485 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); 543 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html");
486 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 544 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
487 545
546 content::WindowedNotificationObserver session_start_waiter(
547 chrome::NOTIFICATION_SESSION_STARTED,
548 content::NotificationService::AllSources());
549
488 // Fill-in the SAML IdP form and submit. 550 // Fill-in the SAML IdP form and submit.
489 SetSignFormField("Email", "fake_user"); 551 SetSignFormField("Email", "fake_user");
490 SetSignFormField("Password", "fake_password"); 552 SetSignFormField("Password", "fake_password");
491 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 553 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
492 554
493 // Login should finish login and a session should start. 555 // Login should finish login and a session should start.
494 content::WindowedNotificationObserver( 556 session_start_waiter.Wait();
495 chrome::NOTIFICATION_SESSION_STARTED,
496 content::NotificationService::AllSources()).Wait();
497 } 557 }
498 558
499 // Tests the single password scraped flow. 559 // Tests the single password scraped flow.
500 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedSingle) { 560 IN_PROC_BROWSER_TEST_P(SamlTest, ScrapedSingle) {
501 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 561 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
502 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 562 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
503 563
504 // Fill-in the SAML IdP form and submit. 564 // Fill-in the SAML IdP form and submit.
505 SetSignFormField("Email", "fake_user"); 565 SetSignFormField("Email", "fake_user");
506 SetSignFormField("Password", "fake_password"); 566 SetSignFormField("Password", "fake_password");
507 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 567 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
508 568
509 // Lands on confirm password screen. 569 // Lands on confirm password screen.
510 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 570 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
511 571
512 // Entering an unknown password should go back to the confirm password screen. 572 // Entering an unknown password should go back to the confirm password screen.
513 SendConfirmPassword("wrong_password"); 573 SendConfirmPassword("wrong_password");
514 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 574 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
515 575
516 // Entering a known password should finish login and start session. 576 // Entering a known password should finish login and start session.
577 content::WindowedNotificationObserver session_start_waiter(
578 chrome::NOTIFICATION_SESSION_STARTED,
579 content::NotificationService::AllSources());
517 SendConfirmPassword("fake_password"); 580 SendConfirmPassword("fake_password");
518 content::WindowedNotificationObserver( 581 session_start_waiter.Wait();
519 chrome::NOTIFICATION_SESSION_STARTED,
520 content::NotificationService::AllSources()).Wait();
521 } 582 }
522 583
523 // Tests password scraping from a dynamically created password field. 584 // Tests password scraping from a dynamically created password field.
524 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedDynamic) { 585 IN_PROC_BROWSER_TEST_P(SamlTest, ScrapedDynamic) {
525 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 586 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
526 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 587 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
527 588
528 ExecuteJsInSigninFrame( 589 ExecuteJsInSigninFrame(
529 "(function() {" 590 "(function() {"
530 "var newPassInput = document.createElement('input');" 591 "var newPassInput = document.createElement('input');"
531 "newPassInput.id = 'DynamicallyCreatedPassword';" 592 "newPassInput.id = 'DynamicallyCreatedPassword';"
532 "newPassInput.type = 'password';" 593 "newPassInput.type = 'password';"
533 "newPassInput.name = 'Password';" 594 "newPassInput.name = 'Password';"
534 "document.forms[0].appendChild(newPassInput);" 595 "document.forms[0].appendChild(newPassInput);"
535 "})();"); 596 "})();");
536 597
537 // Fill-in the SAML IdP form and submit. 598 // Fill-in the SAML IdP form and submit.
538 SetSignFormField("Email", "fake_user"); 599 SetSignFormField("Email", "fake_user");
539 SetSignFormField("DynamicallyCreatedPassword", "fake_password"); 600 SetSignFormField("DynamicallyCreatedPassword", "fake_password");
540 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 601 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
541 602
542 // Lands on confirm password screen. 603 // Lands on confirm password screen.
543 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 604 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
544 605
545 // Entering an unknown password should go back to the confirm password screen. 606 // Entering an unknown password should go back to the confirm password screen.
546 SendConfirmPassword("wrong_password"); 607 SendConfirmPassword("wrong_password");
547 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 608 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
548 609
549 // Entering a known password should finish login and start session. 610 // Entering a known password should finish login and start session.
611 content::WindowedNotificationObserver session_start_waiter(
612 chrome::NOTIFICATION_SESSION_STARTED,
613 content::NotificationService::AllSources());
550 SendConfirmPassword("fake_password"); 614 SendConfirmPassword("fake_password");
551 content::WindowedNotificationObserver( 615 session_start_waiter.Wait();
552 chrome::NOTIFICATION_SESSION_STARTED,
553 content::NotificationService::AllSources()).Wait();
554 } 616 }
555 617
556 // Tests the multiple password scraped flow. 618 // Tests the multiple password scraped flow.
557 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedMultiple) { 619 IN_PROC_BROWSER_TEST_P(SamlTest, ScrapedMultiple) {
558 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html"); 620 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_two_passwords.html");
559 621
560 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 622 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
561 623
562 SetSignFormField("Email", "fake_user"); 624 SetSignFormField("Email", "fake_user");
563 SetSignFormField("Password", "fake_password"); 625 SetSignFormField("Password", "fake_password");
564 SetSignFormField("Password1", "password1"); 626 SetSignFormField("Password1", "password1");
565 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 627 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
566 628
567 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 629 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
568 630
569 // Either scraped password should be able to sign-in. 631 // Either scraped password should be able to sign-in.
632 content::WindowedNotificationObserver session_start_waiter(
633 chrome::NOTIFICATION_SESSION_STARTED,
634 content::NotificationService::AllSources());
570 SendConfirmPassword("password1"); 635 SendConfirmPassword("password1");
571 content::WindowedNotificationObserver( 636 session_start_waiter.Wait();
572 chrome::NOTIFICATION_SESSION_STARTED,
573 content::NotificationService::AllSources()).Wait();
574 } 637 }
575 638
576 // Tests the no password scraped flow. 639 // Tests the no password scraped flow.
577 IN_PROC_BROWSER_TEST_F(SamlTest, ScrapedNone) { 640 IN_PROC_BROWSER_TEST_P(SamlTest, ScrapedNone) {
578 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html"); 641 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_no_passwords.html");
579 642
580 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 643 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
581 644
582 SetSignFormField("Email", "fake_user"); 645 SetSignFormField("Email", "fake_user");
583 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 646 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
584 647
585 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_PASSWORD), 648 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_PASSWORD),
586 WaitForAndGetFatalErrorMessage()); 649 WaitForAndGetFatalErrorMessage());
587 } 650 }
588 651
589 // Types |bob@example.com| into the GAIA login form but then authenticates as 652 // Types |bob@example.com| into the GAIA login form but then authenticates as
590 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly 653 // |alice@example.com| via SAML. Verifies that the logged-in user is correctly
591 // identified as Alice. 654 // identified as Alice.
592 IN_PROC_BROWSER_TEST_F(SamlTest, UseAutenticatedUserEmailAddress) { 655 IN_PROC_BROWSER_TEST_P(SamlTest, UseAutenticatedUserEmailAddress) {
593 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 656 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
594 // Type |bob@example.com| into the GAIA login form. 657 // Type |bob@example.com| into the GAIA login form.
595 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail); 658 StartSamlAndWaitForIdpPageLoad(kSecondSAMLUserEmail);
596 659
597 // Authenticate as alice@example.com via SAML (the |Email| provided here is 660 // Authenticate as alice@example.com via SAML (the |Email| provided here is
598 // irrelevant - the authenticated user's e-mail address that FakeGAIA 661 // irrelevant - the authenticated user's e-mail address that FakeGAIA
599 // reports was set via |SetFakeMergeSessionParams|. 662 // reports was set via |SetFakeMergeSessionParams|.
600 SetSignFormField("Email", "fake_user"); 663 SetSignFormField("Email", "fake_user");
601 SetSignFormField("Password", "fake_password"); 664 SetSignFormField("Password", "fake_password");
602 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 665 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
603 666
604 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 667 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
605 668
669 content::WindowedNotificationObserver session_start_waiter(
670 chrome::NOTIFICATION_SESSION_STARTED,
671 content::NotificationService::AllSources());
606 SendConfirmPassword("fake_password"); 672 SendConfirmPassword("fake_password");
607 content::WindowedNotificationObserver( 673 session_start_waiter.Wait();
608 chrome::NOTIFICATION_SESSION_STARTED,
609 content::NotificationService::AllSources()).Wait();
610 const user_manager::User* user = 674 const user_manager::User* user =
611 user_manager::UserManager::Get()->GetActiveUser(); 675 user_manager::UserManager::Get()->GetActiveUser();
612 ASSERT_TRUE(user); 676 ASSERT_TRUE(user);
613 EXPECT_EQ(kFirstSAMLUserEmail, user->email()); 677 EXPECT_EQ(kFirstSAMLUserEmail, user->email());
614 } 678 }
615 679
616 // Verifies that if the authenticated user's e-mail address cannot be retrieved, 680 // Verifies that if the authenticated user's e-mail address cannot be retrieved,
617 // an error message is shown. 681 // an error message is shown.
618 IN_PROC_BROWSER_TEST_F(SamlTest, FailToRetrieveAutenticatedUserEmailAddress) { 682 IN_PROC_BROWSER_TEST_P(SamlTest, FailToRetrieveAutenticatedUserEmailAddress) {
619 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 683 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
620 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 684 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
621 685
622 fake_gaia_.SetFakeMergeSessionParams( 686 fake_gaia_.SetFakeMergeSessionParams(
623 "", kTestAuthSIDCookie1, kTestAuthLSIDCookie1); 687 "", kTestAuthSIDCookie1, kTestAuthLSIDCookie1);
624 SetSignFormField("Email", "fake_user"); 688 SetSignFormField("Email", "fake_user");
625 SetSignFormField("Password", "fake_password"); 689 SetSignFormField("Password", "fake_password");
626 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 690 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
627 691
628 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_ACCOUNT_DETAILS), 692 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_NO_ACCOUNT_DETAILS),
629 WaitForAndGetFatalErrorMessage()); 693 WaitForAndGetFatalErrorMessage());
630 } 694 }
631 695
632 // Tests the password confirm flow: show error on the first failure and 696 // Tests the password confirm flow: show error on the first failure and
633 // fatal error on the second failure. 697 // fatal error on the second failure.
634 IN_PROC_BROWSER_TEST_F(SamlTest, PasswordConfirmFlow) { 698 IN_PROC_BROWSER_TEST_P(SamlTest, PasswordConfirmFlow) {
635 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 699 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
636 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 700 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
637 701
638 // Fill-in the SAML IdP form and submit. 702 // Fill-in the SAML IdP form and submit.
639 SetSignFormField("Email", "fake_user"); 703 SetSignFormField("Email", "fake_user");
640 SetSignFormField("Password", "fake_password"); 704 SetSignFormField("Password", "fake_password");
641 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 705 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
642 706
643 // Lands on confirm password screen with no error message. 707 // Lands on confirm password screen with no error message.
644 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 708 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
645 JsExpect("!$('confirm-password').classList.contains('error')"); 709 JsExpect("!$('confirm-password').classList.contains('error')");
646 710
647 // Enter an unknown password for the first time should go back to confirm 711 // Enter an unknown password for the first time should go back to confirm
648 // password screen with error message. 712 // password screen with error message.
649 SendConfirmPassword("wrong_password"); 713 SendConfirmPassword("wrong_password");
650 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 714 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
651 JsExpect("$('confirm-password').classList.contains('error')"); 715 JsExpect("$('confirm-password').classList.contains('error')");
652 716
653 // Enter an unknown password 2nd time should go back fatal error message. 717 // Enter an unknown password 2nd time should go back fatal error message.
654 SendConfirmPassword("wrong_password"); 718 SendConfirmPassword("wrong_password");
655 EXPECT_EQ( 719 EXPECT_EQ(
656 l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_PASSWORD_VERIFICATION), 720 l10n_util::GetStringUTF8(IDS_LOGIN_FATAL_ERROR_PASSWORD_VERIFICATION),
657 WaitForAndGetFatalErrorMessage()); 721 WaitForAndGetFatalErrorMessage());
658 } 722 }
659 723
660 // Verifies that when GAIA attempts to redirect to a SAML IdP served over http, 724 // Verifies that when GAIA attempts to redirect to a SAML IdP served over http,
661 // not https, the redirect is blocked and an error message is shown. 725 // not https, the redirect is blocked and an error message is shown.
662 IN_PROC_BROWSER_TEST_F(SamlTest, HTTPRedirectDisallowed) { 726 IN_PROC_BROWSER_TEST_P(SamlTest, HTTPRedirectDisallowed) {
663 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 727 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
664 728
665 WaitForSigninScreen(); 729 WaitForSigninScreen();
666 GetLoginDisplay()->ShowSigninScreenForCreds(kHTTPSAMLUserEmail, ""); 730 GetLoginDisplay()->ShowSigninScreenForCreds(kHTTPSAMLUserEmail, "");
667 731
668 const GURL url = embedded_test_server()->base_url().Resolve("/SAML"); 732 const GURL url = embedded_test_server()->base_url().Resolve("/SAML");
669 EXPECT_EQ(l10n_util::GetStringFUTF8( 733 EXPECT_EQ(l10n_util::GetStringFUTF8(
670 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL, 734 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL,
671 base::UTF8ToUTF16(url.spec())), 735 base::UTF8ToUTF16(url.spec())),
672 WaitForAndGetFatalErrorMessage()); 736 WaitForAndGetFatalErrorMessage());
673 } 737 }
674 738
675 // Verifies that when GAIA attempts to redirect to a page served over http, not 739 // Verifies that when GAIA attempts to redirect to a page served over http, not
676 // https, via an HTML meta refresh, the redirect is blocked and an error message 740 // https, via an HTML meta refresh, the redirect is blocked and an error message
677 // is shown. This guards against regressions of http://crbug.com/359515. 741 // is shown. This guards against regressions of http://crbug.com/359515.
678 IN_PROC_BROWSER_TEST_F(SamlTest, MetaRefreshToHTTPDisallowed) { 742 IN_PROC_BROWSER_TEST_P(SamlTest, MetaRefreshToHTTPDisallowed) {
679 const GURL url = embedded_test_server()->base_url().Resolve("/SSO"); 743 const GURL url = embedded_test_server()->base_url().Resolve("/SSO");
680 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_instant_meta_refresh.html"); 744 fake_saml_idp()->SetLoginHTMLTemplate("saml_login_instant_meta_refresh.html");
681 fake_saml_idp()->SetRefreshURL(url); 745 fake_saml_idp()->SetRefreshURL(url);
682 746
683 WaitForSigninScreen(); 747 WaitForSigninScreen();
684 GetLoginDisplay()->ShowSigninScreenForCreds(kFirstSAMLUserEmail, ""); 748 GetLoginDisplay()->ShowSigninScreenForCreds(kFirstSAMLUserEmail, "");
685 749
686 EXPECT_EQ(l10n_util::GetStringFUTF8( 750 EXPECT_EQ(l10n_util::GetStringFUTF8(
687 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL, 751 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL,
688 base::UTF8ToUTF16(url.spec())), 752 base::UTF8ToUTF16(url.spec())),
689 WaitForAndGetFatalErrorMessage()); 753 WaitForAndGetFatalErrorMessage());
690 } 754 }
691 755
756 INSTANTIATE_TEST_CASE_P(SamlSuite,
757 SamlTest,
758 testing::Bool());
759
692 class SAMLEnrollmentTest : public SamlTest, 760 class SAMLEnrollmentTest : public SamlTest,
693 public content::WebContentsObserver { 761 public content::WebContentsObserver {
694 public: 762 public:
695 SAMLEnrollmentTest(); 763 SAMLEnrollmentTest();
696 ~SAMLEnrollmentTest() override; 764 ~SAMLEnrollmentTest() override;
697 765
698 // SamlTest: 766 // SamlTest:
699 void SetUp() override; 767 void SetUp() override;
700 void SetUpCommandLine(base::CommandLine* command_line) override; 768 void SetUpCommandLine(base::CommandLine* command_line) override;
701 void SetUpOnMainThread() override; 769 void SetUpOnMainThread() override;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 " return true;" 889 " return true;"
822 "}" 890 "}"
823 "var observer = new MutationObserver(SendReplyIfEnrollmentDone);" 891 "var observer = new MutationObserver(SendReplyIfEnrollmentDone);"
824 "if (!SendReplyIfEnrollmentDone()) {" 892 "if (!SendReplyIfEnrollmentDone()) {"
825 " var options = { attributes: true, attributeFilter: [ 'class' ] };" 893 " var options = { attributes: true, attributeFilter: [ 'class' ] };"
826 " observer.observe(enrollmentScreen, options);" 894 " observer.observe(enrollmentScreen, options);"
827 "}", 895 "}",
828 &done)); 896 &done));
829 } 897 }
830 898
831 IN_PROC_BROWSER_TEST_F(SAMLEnrollmentTest, WithoutCredentialsPassingAPI) { 899 IN_PROC_BROWSER_TEST_P(SAMLEnrollmentTest, WithoutCredentialsPassingAPI) {
832 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 900 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
833 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 901 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
834 902
835 // Fill-in the SAML IdP form and submit. 903 // Fill-in the SAML IdP form and submit.
836 SetSignFormField("Email", "fake_user"); 904 SetSignFormField("Email", "fake_user");
837 SetSignFormField("Password", "fake_password"); 905 SetSignFormField("Password", "fake_password");
838 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 906 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
839 907
840 WaitForEnrollmentSuccess(); 908 WaitForEnrollmentSuccess();
841 } 909 }
842 910
843 IN_PROC_BROWSER_TEST_F(SAMLEnrollmentTest, WithCredentialsPassingAPI) { 911 IN_PROC_BROWSER_TEST_P(SAMLEnrollmentTest, WithCredentialsPassingAPI) {
844 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); 912 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html");
845 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); 913 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html");
846 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); 914 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail);
847 915
848 // Fill-in the SAML IdP form and submit. 916 // Fill-in the SAML IdP form and submit.
849 SetSignFormField("Email", "fake_user"); 917 SetSignFormField("Email", "fake_user");
850 SetSignFormField("Password", "fake_password"); 918 SetSignFormField("Password", "fake_password");
851 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 919 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
852 920
853 WaitForEnrollmentSuccess(); 921 WaitForEnrollmentSuccess();
854 } 922 }
855 923
924 // TODO(xiyuan): Update once webview flow is implemented.
925 INSTANTIATE_TEST_CASE_P(SamlSuite,
926 SAMLEnrollmentTest,
927 testing::Values(false));
928
856 class SAMLPolicyTest : public SamlTest { 929 class SAMLPolicyTest : public SamlTest {
857 public: 930 public:
858 SAMLPolicyTest(); 931 SAMLPolicyTest();
859 ~SAMLPolicyTest() override; 932 ~SAMLPolicyTest() override;
860 933
861 // SamlTest: 934 // SamlTest:
862 void SetUpInProcessBrowserTestFixture() override; 935 void SetUpInProcessBrowserTestFixture() override;
863 void SetUpOnMainThread() override; 936 void SetUpOnMainThread() override;
864 937
865 void SetSAMLOfflineSigninTimeLimitPolicy(int limit); 938 void SetSAMLOfflineSigninTimeLimitPolicy(int limit);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 StartSamlAndWaitForIdpPageLoad(user_id); 1058 StartSamlAndWaitForIdpPageLoad(user_id);
986 1059
987 fake_gaia_.SetFakeMergeSessionParams( 1060 fake_gaia_.SetFakeMergeSessionParams(
988 user_id, auth_sid_cookie, auth_lsid_cookie); 1061 user_id, auth_sid_cookie, auth_lsid_cookie);
989 SetSignFormField("Email", "fake_user"); 1062 SetSignFormField("Email", "fake_user");
990 SetSignFormField("Password", "fake_password"); 1063 SetSignFormField("Password", "fake_password");
991 ExecuteJsInSigninFrame("document.getElementById('Submit').click();"); 1064 ExecuteJsInSigninFrame("document.getElementById('Submit').click();");
992 1065
993 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait(); 1066 OobeScreenWaiter(OobeDisplay::SCREEN_CONFIRM_PASSWORD).Wait();
994 1067
1068 content::WindowedNotificationObserver session_start_waiter(
1069 chrome::NOTIFICATION_SESSION_STARTED,
1070 content::NotificationService::AllSources());
995 SendConfirmPassword("fake_password"); 1071 SendConfirmPassword("fake_password");
996 content::WindowedNotificationObserver( 1072 session_start_waiter.Wait();
997 chrome::NOTIFICATION_SESSION_STARTED,
998 content::NotificationService::AllSources()).Wait();
999 } 1073 }
1000 1074
1001 std::string SAMLPolicyTest::GetCookieValue(const std::string& name) { 1075 std::string SAMLPolicyTest::GetCookieValue(const std::string& name) {
1002 for (net::CookieList::const_iterator it = cookie_list_.begin(); 1076 for (net::CookieList::const_iterator it = cookie_list_.begin();
1003 it != cookie_list_.end(); ++it) { 1077 it != cookie_list_.end(); ++it) {
1004 if (it->Name() == name) 1078 if (it->Name() == name)
1005 return it->Value(); 1079 return it->Value();
1006 } 1080 }
1007 return std::string(); 1081 return std::string();
1008 } 1082 }
(...skipping 26 matching lines...) Expand all
1035 1109
1036 void SAMLPolicyTest::StoreCookieList( 1110 void SAMLPolicyTest::StoreCookieList(
1037 const base::Closure& callback, 1111 const base::Closure& callback,
1038 const net::CookieList& cookie_list) { 1112 const net::CookieList& cookie_list) {
1039 cookie_list_ = cookie_list; 1113 cookie_list_ = cookie_list;
1040 content::BrowserThread::PostTask(content::BrowserThread::UI, 1114 content::BrowserThread::PostTask(content::BrowserThread::UI,
1041 FROM_HERE, 1115 FROM_HERE,
1042 callback); 1116 callback);
1043 } 1117 }
1044 1118
1045 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_NoSAML) { 1119 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_NoSAML) {
1046 // Set the offline login time limit for SAML users to zero. 1120 // Set the offline login time limit for SAML users to zero.
1047 SetSAMLOfflineSigninTimeLimitPolicy(0); 1121 SetSAMLOfflineSigninTimeLimitPolicy(0);
1048 1122
1049 WaitForSigninScreen(); 1123 WaitForSigninScreen();
1050 1124
1051 // Log in without SAML. 1125 // Log in without SAML.
1052 GetLoginDisplay()->ShowSigninScreenForCreds(kNonSAMLUserEmail, "password"); 1126 GetLoginDisplay()->ShowSigninScreenForCreds(kNonSAMLUserEmail, "password");
1053 1127
1054 content::WindowedNotificationObserver( 1128 content::WindowedNotificationObserver(
1055 chrome::NOTIFICATION_SESSION_STARTED, 1129 chrome::NOTIFICATION_SESSION_STARTED,
1056 content::NotificationService::AllSources()).Wait(); 1130 content::NotificationService::AllSources()).Wait();
1057 } 1131 }
1058 1132
1059 // Verifies that the offline login time limit does not affect a user who 1133 // Verifies that the offline login time limit does not affect a user who
1060 // authenticated without SAML. 1134 // authenticated without SAML.
1061 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, NoSAML) { 1135 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, NoSAML) {
1062 login_screen_load_observer_->Wait(); 1136 login_screen_load_observer_->Wait();
1063 // Verify that offline login is allowed. 1137 // Verify that offline login is allowed.
1064 JsExpect("window.getComputedStyle(document.querySelector(" 1138 JsExpect("window.getComputedStyle(document.querySelector("
1065 " '#pod-row .signin-button-container')).display == 'none'"); 1139 " '#pod-row .signin-button-container')).display == 'none'");
1066 } 1140 }
1067 1141
1068 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLNoLimit) { 1142 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_SAMLNoLimit) {
1069 // Remove the offline login time limit for SAML users. 1143 // Remove the offline login time limit for SAML users.
1070 SetSAMLOfflineSigninTimeLimitPolicy(-1); 1144 SetSAMLOfflineSigninTimeLimitPolicy(-1);
1071 1145
1072 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); 1146 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1);
1073 } 1147 }
1074 1148
1075 // Verifies that when no offline login time limit is set, a user who 1149 // Verifies that when no offline login time limit is set, a user who
1076 // authenticated with SAML is allowed to log in offline. 1150 // authenticated with SAML is allowed to log in offline.
1077 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLNoLimit) { 1151 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, SAMLNoLimit) {
1078 login_screen_load_observer_->Wait(); 1152 login_screen_load_observer_->Wait();
1079 // Verify that offline login is allowed. 1153 // Verify that offline login is allowed.
1080 JsExpect("window.getComputedStyle(document.querySelector(" 1154 JsExpect("window.getComputedStyle(document.querySelector("
1081 " '#pod-row .signin-button-container')).display == 'none'"); 1155 " '#pod-row .signin-button-container')).display == 'none'");
1082 } 1156 }
1083 1157
1084 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_SAMLZeroLimit) { 1158 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_SAMLZeroLimit) {
1085 // Set the offline login time limit for SAML users to zero. 1159 // Set the offline login time limit for SAML users to zero.
1086 SetSAMLOfflineSigninTimeLimitPolicy(0); 1160 SetSAMLOfflineSigninTimeLimitPolicy(0);
1087 1161
1088 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); 1162 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1);
1089 } 1163 }
1090 1164
1091 // Verifies that when the offline login time limit is exceeded for a user who 1165 // Verifies that when the offline login time limit is exceeded for a user who
1092 // authenticated via SAML, that user is forced to log in online the next time. 1166 // authenticated via SAML, that user is forced to log in online the next time.
1093 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, SAMLZeroLimit) { 1167 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, SAMLZeroLimit) {
1094 login_screen_load_observer_->Wait(); 1168 login_screen_load_observer_->Wait();
1095 // Verify that offline login is not allowed. 1169 // Verify that offline login is not allowed.
1096 JsExpect("window.getComputedStyle(document.querySelector(" 1170 JsExpect("window.getComputedStyle(document.querySelector("
1097 " '#pod-row .signin-button-container')).display != 'none'"); 1171 " '#pod-row .signin-button-container')).display != 'none'");
1098 } 1172 }
1099 1173
1100 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_PRE_TransferCookiesAffiliated) { 1174 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_PRE_TransferCookiesAffiliated) {
1101 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue1); 1175 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue1);
1102 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); 1176 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1);
1103 1177
1104 GetCookies(); 1178 GetCookies();
1105 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); 1179 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName));
1106 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); 1180 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName));
1107 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); 1181 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName));
1108 } 1182 }
1109 1183
1110 // Verifies that when the DeviceTransferSAMLCookies policy is not enabled, SAML 1184 // Verifies that when the DeviceTransferSAMLCookies policy is not enabled, SAML
1111 // IdP cookies are not transferred to a user's profile on subsequent login, even 1185 // IdP cookies are not transferred to a user's profile on subsequent login, even
1112 // if the user belongs to the domain that the device is enrolled into. Also 1186 // if the user belongs to the domain that the device is enrolled into. Also
1113 // verifies that GAIA cookies are not transferred. 1187 // verifies that GAIA cookies are not transferred.
1114 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_TransferCookiesAffiliated) { 1188 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_TransferCookiesAffiliated) {
1115 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2); 1189 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2);
1116 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 1190 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
1117 ShowGAIALoginForm(); 1191 ShowGAIALoginForm();
1118 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie2, kTestAuthLSIDCookie2); 1192 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie2, kTestAuthLSIDCookie2);
1119 1193
1120 GetCookies(); 1194 GetCookies();
1121 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); 1195 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName));
1122 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); 1196 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName));
1123 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); 1197 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName));
1124 } 1198 }
1125 1199
1126 // Verifies that when the DeviceTransferSAMLCookies policy is enabled, SAML IdP 1200 // Verifies that when the DeviceTransferSAMLCookies policy is enabled, SAML IdP
1127 // cookies are transferred to a user's profile on subsequent login when the user 1201 // cookies are transferred to a user's profile on subsequent login when the user
1128 // belongs to the domain that the device is enrolled into. Also verifies that 1202 // belongs to the domain that the device is enrolled into. Also verifies that
1129 // GAIA cookies are not transferred. 1203 // GAIA cookies are not transferred.
1130 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, TransferCookiesAffiliated) { 1204 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, TransferCookiesAffiliated) {
1131 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2); 1205 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2);
1132 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 1206 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
1133 ShowGAIALoginForm(); 1207 ShowGAIALoginForm();
1134 1208
1135 EnableTransferSAMLCookiesPolicy(); 1209 EnableTransferSAMLCookiesPolicy();
1136 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie2, kTestAuthLSIDCookie2); 1210 LogInWithSAML(kFirstSAMLUserEmail, kTestAuthSIDCookie2, kTestAuthLSIDCookie2);
1137 1211
1138 GetCookies(); 1212 GetCookies();
1139 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); 1213 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName));
1140 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); 1214 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName));
1141 EXPECT_EQ(kSAMLIdPCookieValue2, GetCookieValue(kSAMLIdPCookieName)); 1215 EXPECT_EQ(kSAMLIdPCookieValue2, GetCookieValue(kSAMLIdPCookieName));
1142 } 1216 }
1143 1217
1144 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, PRE_TransferCookiesUnaffiliated) { 1218 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, PRE_TransferCookiesUnaffiliated) {
1145 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue1); 1219 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue1);
1146 LogInWithSAML(kDifferentDomainSAMLUserEmail, 1220 LogInWithSAML(kDifferentDomainSAMLUserEmail,
1147 kTestAuthSIDCookie1, 1221 kTestAuthSIDCookie1,
1148 kTestAuthLSIDCookie1); 1222 kTestAuthLSIDCookie1);
1149 1223
1150 GetCookies(); 1224 GetCookies();
1151 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); 1225 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName));
1152 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); 1226 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName));
1153 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); 1227 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName));
1154 } 1228 }
1155 1229
1156 // Verifies that even if the DeviceTransferSAMLCookies policy is enabled, SAML 1230 // Verifies that even if the DeviceTransferSAMLCookies policy is enabled, SAML
1157 // IdP are not transferred to a user's profile on subsequent login if the user 1231 // IdP are not transferred to a user's profile on subsequent login if the user
1158 // does not belong to the domain that the device is enrolled into. Also verifies 1232 // does not belong to the domain that the device is enrolled into. Also verifies
1159 // that GAIA cookies are not transferred. 1233 // that GAIA cookies are not transferred.
1160 IN_PROC_BROWSER_TEST_F(SAMLPolicyTest, TransferCookiesUnaffiliated) { 1234 IN_PROC_BROWSER_TEST_P(SAMLPolicyTest, TransferCookiesUnaffiliated) {
1161 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2); 1235 fake_saml_idp()->SetCookieValue(kSAMLIdPCookieValue2);
1162 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); 1236 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html");
1163 ShowGAIALoginForm(); 1237 ShowGAIALoginForm();
1164 1238
1165 EnableTransferSAMLCookiesPolicy(); 1239 EnableTransferSAMLCookiesPolicy();
1166 LogInWithSAML(kDifferentDomainSAMLUserEmail, 1240 LogInWithSAML(kDifferentDomainSAMLUserEmail,
1167 kTestAuthSIDCookie1, 1241 kTestAuthSIDCookie1,
1168 kTestAuthLSIDCookie1); 1242 kTestAuthLSIDCookie1);
1169 1243
1170 GetCookies(); 1244 GetCookies();
1171 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); 1245 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName));
1172 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); 1246 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName));
1173 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); 1247 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName));
1174 } 1248 }
1175 1249
1250 // TODO(xiyuan): Update once cookies are properly handled.
1251 INSTANTIATE_TEST_CASE_P(SamlSuite,
1252 SAMLPolicyTest,
1253 testing::Values(false));
1254
1176 } // namespace chromeos 1255 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/gaia_auth/channel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698