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