Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <list> | 6 #include <list> |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 const AuthInfo& info = i->second; | 91 const AuthInfo& info = i->second; |
| 92 handler->SetAuth(base::UTF8ToUTF16(info.username_), | 92 handler->SetAuth(base::UTF8ToUTF16(info.username_), |
| 93 base::UTF8ToUTF16(info.password_)); | 93 base::UTF8ToUTF16(info.password_)); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 const char kPrefetchAuthPage[] = "/login/prefetch.html"; | 97 const char kPrefetchAuthPage[] = "/login/prefetch.html"; |
| 98 | 98 |
| 99 const char kMultiRealmTestPage[] = "/login/multi_realm.html"; | 99 const char kMultiRealmTestPage[] = "/login/multi_realm.html"; |
| 100 const int kMultiRealmTestRealmCount = 2; | 100 const int kMultiRealmTestRealmCount = 2; |
| 101 const int kMultiRealmTestAuthRequestsCount = 4; | |
| 101 | 102 |
| 102 const char kSingleRealmTestPage[] = "/login/single_realm.html"; | 103 const char kSingleRealmTestPage[] = "/login/single_realm.html"; |
| 103 | 104 |
| 104 const char kAuthBasicPage[] = "/auth-basic"; | 105 const char kAuthBasicPage[] = "/auth-basic"; |
| 105 const char kAuthDigestPage[] = "/auth-digest"; | 106 const char kAuthDigestPage[] = "/auth-digest"; |
| 106 | 107 |
| 107 // It does not matter what pages are selected as no-auth, as long as they exist. | 108 // It does not matter what pages are selected as no-auth, as long as they exist. |
| 108 // Navigating to non-existing pages caused flakes in the past | 109 // Navigating to non-existing pages caused flakes in the past |
| 109 // (https://crbug.com/636875). | 110 // (https://crbug.com/636875). |
| 110 const char kNoAuthPage1[] = "/simple.html"; | 111 const char kNoAuthPage1[] = "/simple.html"; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 ASSERT_TRUE(controller->CanGoForward()); | 454 ASSERT_TRUE(controller->CanGoForward()); |
| 454 controller->GoForward(); | 455 controller->GoForward(); |
| 455 auth_cancelled_waiter.Wait(); | 456 auth_cancelled_waiter.Wait(); |
| 456 load_stop_waiter.Wait(); | 457 load_stop_waiter.Wait(); |
| 457 EXPECT_TRUE(observer.handlers().empty()); | 458 EXPECT_TRUE(observer.handlers().empty()); |
| 458 } | 459 } |
| 459 | 460 |
| 460 // Test handling of resources that require authentication even though | 461 // Test handling of resources that require authentication even though |
| 461 // the page they are included on doesn't. In this case we should only | 462 // the page they are included on doesn't. In this case we should only |
| 462 // present the minimal number of prompts necessary for successfully | 463 // present the minimal number of prompts necessary for successfully |
| 463 // displaying the page. First we check whether cancelling works as | 464 // displaying the page. |
| 464 // expected. | 465 class MultiRealmLoginPromptBrowserTest : public LoginPromptBrowserTest { |
| 465 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { | 466 public: |
|
Alexander Semashko
2017/02/21 21:33:47
For easer review: the functional changes for these
| |
| 467 void TearDownOnMainThread() override { | |
| 468 login_prompt_observer_.UnregisterAll(); | |
| 469 LoginPromptBrowserTest::TearDownOnMainThread(); | |
| 470 } | |
| 471 | |
| 472 // Load the multi-realm test page, waits for LoginHandlers to be created, then | |
| 473 // calls |for_each_realm_func| once for each authentication realm, passing a | |
| 474 // LoginHandler for the realm as an argument. The page should stop loading | |
| 475 // after that. | |
| 476 template <class F> | |
| 477 void RunTest(const F& for_each_realm_func); | |
| 478 | |
| 479 NavigationController* GetNavigationController() { | |
| 480 return &browser() | |
| 481 ->tab_strip_model() | |
| 482 ->GetActiveWebContents() | |
| 483 ->GetController(); | |
| 484 } | |
| 485 | |
| 486 LoginPromptBrowserTestObserver* login_prompt_observer() { | |
| 487 return &login_prompt_observer_; | |
| 488 } | |
| 489 | |
| 490 private: | |
| 491 LoginPromptBrowserTestObserver login_prompt_observer_; | |
| 492 }; | |
| 493 | |
| 494 template <class F> | |
| 495 void MultiRealmLoginPromptBrowserTest::RunTest(const F& for_each_realm_func) { | |
| 466 ASSERT_TRUE(embedded_test_server()->Start()); | 496 ASSERT_TRUE(embedded_test_server()->Start()); |
| 467 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); | 497 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); |
| 468 | 498 |
| 469 content::WebContents* contents = | 499 NavigationController* controller = GetNavigationController(); |
| 470 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 471 NavigationController* controller = &contents->GetController(); | |
| 472 LoginPromptBrowserTestObserver observer; | |
| 473 | 500 |
| 474 observer.Register(content::Source<NavigationController>(controller)); | 501 login_prompt_observer_.Register( |
| 502 content::Source<NavigationController>(controller)); | |
| 475 | 503 |
| 476 WindowedLoadStopObserver load_stop_waiter(controller, 1); | 504 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
| 477 | 505 |
| 478 { | 506 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
| 479 WindowedAuthNeededObserver auth_needed_waiter(controller); | 507 WindowOpenDisposition::CURRENT_TAB, |
| 480 browser()->OpenURL(OpenURLParams(test_page, Referrer(), | 508 ui::PAGE_TRANSITION_TYPED, false)); |
| 481 WindowOpenDisposition::CURRENT_TAB, | |
| 482 ui::PAGE_TRANSITION_TYPED, false)); | |
| 483 auth_needed_waiter.Wait(); | |
| 484 } | |
| 485 | 509 |
| 486 int n_handlers = 0; | 510 // Need to have LoginHandlers created for all requests that need |
| 511 // authentication. | |
| 512 while (login_prompt_observer_.handlers().size() < | |
| 513 kMultiRealmTestAuthRequestsCount) | |
| 514 WindowedAuthNeededObserver(controller).Wait(); | |
| 487 | 515 |
| 488 while (n_handlers < kMultiRealmTestRealmCount) { | 516 // Now confirm or cancel auth once per realm. |
| 489 WindowedAuthNeededObserver auth_needed_waiter(controller); | 517 std::set<std::string> seen_realms; |
| 518 for (int i = 0; i < kMultiRealmTestRealmCount; ++i) { | |
| 519 auto it = std::find_if( | |
| 520 login_prompt_observer_.handlers().begin(), | |
| 521 login_prompt_observer_.handlers().end(), | |
| 522 [&seen_realms](LoginHandler* handler) { | |
| 523 return seen_realms.count(handler->auth_info()->realm) == 0; | |
| 524 }); | |
| 525 ASSERT_TRUE(it != login_prompt_observer_.handlers().end()); | |
| 526 seen_realms.insert((*it)->auth_info()->realm); | |
| 490 | 527 |
| 491 while (!observer.handlers().empty()) { | 528 for_each_realm_func(*it); |
| 492 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | |
| 493 LoginHandler* handler = *observer.handlers().begin(); | |
| 494 | |
| 495 ASSERT_TRUE(handler); | |
| 496 n_handlers++; | |
| 497 handler->CancelAuth(); | |
| 498 auth_cancelled_waiter.Wait(); | |
| 499 } | |
| 500 | |
| 501 if (n_handlers < kMultiRealmTestRealmCount) | |
| 502 auth_needed_waiter.Wait(); | |
| 503 } | 529 } |
| 504 | 530 |
| 505 load_stop_waiter.Wait(); | 531 load_stop_waiter.Wait(); |
| 506 | |
| 507 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); | |
| 508 EXPECT_EQ(0, observer.auth_supplied_count()); | |
| 509 EXPECT_LT(0, observer.auth_needed_count()); | |
| 510 EXPECT_LT(0, observer.auth_cancelled_count()); | |
| 511 } | 532 } |
| 512 | 533 |
| 513 // Similar to the MultipleRealmCancellation test above, but tests | 534 // Checks that cancelling works as expected. |
| 514 // whether supplying credentials work as exepcted. | 535 IN_PROC_BROWSER_TEST_F(MultiRealmLoginPromptBrowserTest, |
| 515 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { | 536 MultipleRealmCancellation) { |
| 516 ASSERT_TRUE(embedded_test_server()->Start()); | 537 RunTest([this](LoginHandler* handler) { |
| 517 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); | 538 WindowedAuthCancelledObserver waiter(GetNavigationController()); |
| 539 handler->CancelAuth(); | |
| 540 waiter.Wait(); | |
| 541 }); | |
| 518 | 542 |
| 519 content::WebContents* contents = | 543 EXPECT_EQ(0, login_prompt_observer()->auth_supplied_count()); |
| 520 browser()->tab_strip_model()->GetActiveWebContents(); | 544 EXPECT_LT(0, login_prompt_observer()->auth_needed_count()); |
| 521 NavigationController* controller = &contents->GetController(); | 545 EXPECT_LT(0, login_prompt_observer()->auth_cancelled_count()); |
| 522 LoginPromptBrowserTestObserver observer; | 546 } |
| 523 | 547 |
| 524 observer.Register(content::Source<NavigationController>(controller)); | 548 // Checks that supplying credentials works as exepcted. |
| 549 IN_PROC_BROWSER_TEST_F(MultiRealmLoginPromptBrowserTest, | |
| 550 MultipleRealmConfirmation) { | |
| 551 RunTest([this](LoginHandler* handler) { | |
| 552 WindowedAuthSuppliedObserver waiter(GetNavigationController()); | |
| 553 SetAuthFor(handler); | |
| 554 waiter.Wait(); | |
| 555 }); | |
| 525 | 556 |
| 526 WindowedLoadStopObserver load_stop_waiter(controller, 1); | 557 EXPECT_LT(0, login_prompt_observer()->auth_needed_count()); |
| 527 int n_handlers = 0; | 558 EXPECT_LT(0, login_prompt_observer()->auth_supplied_count()); |
| 528 | 559 EXPECT_EQ(0, login_prompt_observer()->auth_cancelled_count()); |
| 529 { | |
| 530 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 531 | |
| 532 browser()->OpenURL(OpenURLParams(test_page, Referrer(), | |
| 533 WindowOpenDisposition::CURRENT_TAB, | |
| 534 ui::PAGE_TRANSITION_TYPED, false)); | |
| 535 auth_needed_waiter.Wait(); | |
| 536 } | |
| 537 | |
| 538 while (n_handlers < kMultiRealmTestRealmCount) { | |
| 539 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 540 | |
| 541 while (!observer.handlers().empty()) { | |
| 542 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); | |
| 543 LoginHandler* handler = *observer.handlers().begin(); | |
| 544 | |
| 545 ASSERT_TRUE(handler); | |
| 546 n_handlers++; | |
| 547 SetAuthFor(handler); | |
| 548 auth_supplied_waiter.Wait(); | |
| 549 } | |
| 550 | |
| 551 if (n_handlers < kMultiRealmTestRealmCount) | |
| 552 auth_needed_waiter.Wait(); | |
| 553 } | |
| 554 | |
| 555 load_stop_waiter.Wait(); | |
| 556 | |
| 557 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); | |
| 558 EXPECT_LT(0, observer.auth_needed_count()); | |
| 559 EXPECT_LT(0, observer.auth_supplied_count()); | |
| 560 EXPECT_EQ(0, observer.auth_cancelled_count()); | |
| 561 } | 560 } |
| 562 | 561 |
| 563 // Testing for recovery from an incorrect password for the case where | 562 // Testing for recovery from an incorrect password for the case where |
| 564 // there are multiple authenticated resources. | 563 // there are multiple authenticated resources. |
| 565 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { | 564 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { |
| 566 ASSERT_TRUE(embedded_test_server()->Start()); | 565 ASSERT_TRUE(embedded_test_server()->Start()); |
| 567 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage); | 566 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage); |
| 568 | 567 |
| 569 content::WebContents* contents = | 568 content::WebContents* contents = |
| 570 browser()->tab_strip_model()->GetActiveWebContents(); | 569 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1495 // out. | 1494 // out. |
| 1496 EXPECT_TRUE( | 1495 EXPECT_TRUE( |
| 1497 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 1496 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 1498 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1497 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
| 1499 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | 1498 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
| 1500 ->GetDelegateForTesting() | 1499 ->GetDelegateForTesting() |
| 1501 ->GetTypeForTesting()); | 1500 ->GetTypeForTesting()); |
| 1502 } | 1501 } |
| 1503 | 1502 |
| 1504 } // namespace | 1503 } // namespace |
| OLD | NEW |