| OLD | NEW |
| 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" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 FakeSamlIdp::~FakeSamlIdp() { | 165 FakeSamlIdp::~FakeSamlIdp() { |
| 166 } | 166 } |
| 167 | 167 |
| 168 void FakeSamlIdp::SetUp(const std::string& base_path, const GURL& gaia_url) { | 168 void FakeSamlIdp::SetUp(const std::string& base_path, const GURL& gaia_url) { |
| 169 base::FilePath test_data_dir; | 169 base::FilePath test_data_dir; |
| 170 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 170 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
| 171 html_template_dir_ = test_data_dir.Append("login"); | 171 html_template_dir_ = test_data_dir.Append("login"); |
| 172 | 172 |
| 173 login_path_= base_path; | 173 login_path_ = base_path; |
| 174 login_auth_path_ = base_path + "Auth"; | 174 login_auth_path_ = base_path + "Auth"; |
| 175 gaia_assertion_url_ = gaia_url.Resolve("/SSO"); | 175 gaia_assertion_url_ = gaia_url.Resolve("/SSO"); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void FakeSamlIdp::SetLoginHTMLTemplate(const std::string& template_file) { | 178 void FakeSamlIdp::SetLoginHTMLTemplate(const std::string& template_file) { |
| 179 EXPECT_TRUE(base::ReadFileToString( | 179 EXPECT_TRUE(base::ReadFileToString( |
| 180 html_template_dir_.Append(template_file), | 180 html_template_dir_.Append(template_file), |
| 181 &login_html_template_)); | 181 &login_html_template_)); |
| 182 } | 182 } |
| 183 | 183 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 252 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 253 http_response->set_code(net::HTTP_OK); | 253 http_response->set_code(net::HTTP_OK); |
| 254 http_response->set_content(response_html); | 254 http_response->set_content(response_html); |
| 255 http_response->set_content_type("text/html"); | 255 http_response->set_content_type("text/html"); |
| 256 | 256 |
| 257 return http_response.Pass(); | 257 return http_response.Pass(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace | 260 } // namespace |
| 261 | 261 |
| 262 // Boolean parameter is used to run this test for webview (true) and for |
| 263 // iframe (false) GAIA sign in. |
| 262 class SamlTest : public OobeBaseTest, public testing::WithParamInterface<bool> { | 264 class SamlTest : public OobeBaseTest, public testing::WithParamInterface<bool> { |
| 263 public: | 265 public: |
| 264 SamlTest() : saml_load_injected_(false) { use_webview_ = GetParam(); } | 266 SamlTest() : saml_load_injected_(false) { |
| 267 set_use_webview(GetParam()); |
| 268 set_initialize_fake_merge_session(false); |
| 269 } |
| 265 ~SamlTest() override {} | 270 ~SamlTest() override {} |
| 266 | 271 |
| 267 void SetUpCommandLine(base::CommandLine* command_line) override { | 272 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 268 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | 273 command_line->AppendSwitch(switches::kOobeSkipPostLogin); |
| 269 | 274 |
| 270 const GURL gaia_url = gaia_https_forwarder_->GetURL(""); | 275 const GURL gaia_url = gaia_https_forwarder_->GetURL(""); |
| 271 const GURL saml_idp_url = saml_https_forwarder_->GetURL("SAML"); | 276 const GURL saml_idp_url = saml_https_forwarder_->GetURL("SAML"); |
| 272 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url); | 277 fake_saml_idp_.SetUp(saml_idp_url.path(), gaia_url); |
| 273 fake_gaia_->RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); | 278 fake_gaia_->RegisterSamlUser(kFirstSAMLUserEmail, saml_idp_url); |
| 274 fake_gaia_->RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); | 279 fake_gaia_->RegisterSamlUser(kSecondSAMLUserEmail, saml_idp_url); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 363 |
| 359 // Tests that signin frame should have 'saml' class and 'cancel' button is | 364 // Tests that signin frame should have 'saml' class and 'cancel' button is |
| 360 // visible when SAML IdP page is loaded. And 'cancel' button goes back to | 365 // visible when SAML IdP page is loaded. And 'cancel' button goes back to |
| 361 // gaia on clicking. | 366 // gaia on clicking. |
| 362 IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) { | 367 IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) { |
| 363 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); | 368 fake_saml_idp()->SetLoginHTMLTemplate("saml_login.html"); |
| 364 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); | 369 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 365 | 370 |
| 366 // Saml flow UI expectations. | 371 // Saml flow UI expectations. |
| 367 JsExpect("$('gaia-signin').classList.contains('full-width')"); | 372 JsExpect("$('gaia-signin').classList.contains('full-width')"); |
| 368 if (!use_webview_) { | 373 if (!use_webview()) { |
| 369 JsExpect("!$('cancel-add-user-button').hidden"); | 374 JsExpect("!$('cancel-add-user-button').hidden"); |
| 370 } | 375 } |
| 371 | 376 |
| 372 // Click on 'cancel'. | 377 // Click on 'cancel'. |
| 373 content::DOMMessageQueue message_queue; // Observe before 'cancel'. | 378 content::DOMMessageQueue message_queue; // Observe before 'cancel'. |
| 374 if (use_webview_) { | 379 if (use_webview()) { |
| 375 ASSERT_TRUE(content::ExecuteScript( | 380 ASSERT_TRUE(content::ExecuteScript( |
| 376 GetLoginUI()->GetWebContents(), | 381 GetLoginUI()->GetWebContents(), |
| 377 "$('close-button-item').click();")); | 382 "$('close-button-item').click();")); |
| 378 } else { | 383 } else { |
| 379 ASSERT_TRUE(content::ExecuteScript( | 384 ASSERT_TRUE(content::ExecuteScript( |
| 380 GetLoginUI()->GetWebContents(), | 385 GetLoginUI()->GetWebContents(), |
| 381 "$('cancel-add-user-button').click();")); | 386 "$('cancel-add-user-button').click();")); |
| 382 } | 387 } |
| 383 | 388 |
| 384 // Auth flow should change back to Gaia. | 389 // Auth flow should change back to Gaia. |
| 385 std::string message; | 390 std::string message; |
| 386 do { | 391 do { |
| 387 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 392 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 388 } while (message != "\"GaiaLoaded\""); | 393 } while (message != "\"GaiaLoaded\""); |
| 389 | 394 |
| 390 // Saml flow is gone. | 395 // Saml flow is gone. |
| 391 JsExpect("!$('gaia-signin').classList.contains('full-width')"); | 396 JsExpect("!$('gaia-signin').classList.contains('full-width')"); |
| 392 } | 397 } |
| 393 | 398 |
| 394 // Tests the sign-in flow when the credentials passing API is used. | 399 // Tests the sign-in flow when the credentials passing API is used. |
| 395 IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) { | 400 IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) { |
| 396 // Disabled for webview because the script is injected using | 401 // Disabled for webview because the script is injected using |
| 397 // webview.executeScript and there is no way to control the injection time. | 402 // webview.executeScript and there is no way to control the injection time. |
| 398 // As a result, this test is flaky and fails about 20% of the time. | 403 // As a result, this test is flaky and fails about 20% of the time. |
| 399 // TODO(xiyuan): Re-enable when webview.addContentScript API is ready. | 404 // TODO(xiyuan): Re-enable when webview.addContentScript API is ready. |
| 400 if (use_webview_) | 405 if (use_webview()) |
| 401 return; | 406 return; |
| 402 | 407 |
| 403 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); | 408 fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); |
| 404 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); | 409 fake_saml_idp()->SetLoginAuthHTMLTemplate("saml_api_login_auth.html"); |
| 405 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); | 410 StartSamlAndWaitForIdpPageLoad(kFirstSAMLUserEmail); |
| 406 | 411 |
| 407 content::WindowedNotificationObserver session_start_waiter( | 412 content::WindowedNotificationObserver session_start_waiter( |
| 408 chrome::NOTIFICATION_SESSION_STARTED, | 413 chrome::NOTIFICATION_SESSION_STARTED, |
| 409 content::NotificationService::AllSources()); | 414 content::NotificationService::AllSources()); |
| 410 | 415 |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); | 1111 EXPECT_EQ(kTestAuthSIDCookie1, GetCookieValue(kGAIASIDCookieName)); |
| 1107 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); | 1112 EXPECT_EQ(kTestAuthLSIDCookie1, GetCookieValue(kGAIALSIDCookieName)); |
| 1108 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); | 1113 EXPECT_EQ(kSAMLIdPCookieValue1, GetCookieValue(kSAMLIdPCookieName)); |
| 1109 } | 1114 } |
| 1110 | 1115 |
| 1111 INSTANTIATE_TEST_CASE_P(SamlSuite, | 1116 INSTANTIATE_TEST_CASE_P(SamlSuite, |
| 1112 SAMLPolicyTest, | 1117 SAMLPolicyTest, |
| 1113 testing::Bool()); | 1118 testing::Bool()); |
| 1114 | 1119 |
| 1115 } // namespace chromeos | 1120 } // namespace chromeos |
| OLD | NEW |