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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 469 |
469 content::WebContents* contents = | 470 content::WebContents* contents = |
470 browser()->tab_strip_model()->GetActiveWebContents(); | 471 browser()->tab_strip_model()->GetActiveWebContents(); |
471 NavigationController* controller = &contents->GetController(); | 472 NavigationController* controller = &contents->GetController(); |
472 LoginPromptBrowserTestObserver observer; | 473 LoginPromptBrowserTestObserver observer; |
473 | 474 |
474 observer.Register(content::Source<NavigationController>(controller)); | 475 observer.Register(content::Source<NavigationController>(controller)); |
475 | 476 |
476 WindowedLoadStopObserver load_stop_waiter(controller, 1); | 477 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
477 | 478 |
478 { | 479 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
479 WindowedAuthNeededObserver auth_needed_waiter(controller); | 480 WindowOpenDisposition::CURRENT_TAB, |
480 browser()->OpenURL(OpenURLParams(test_page, Referrer(), | 481 ui::PAGE_TRANSITION_TYPED, false)); |
481 WindowOpenDisposition::CURRENT_TAB, | |
482 ui::PAGE_TRANSITION_TYPED, false)); | |
483 auth_needed_waiter.Wait(); | |
484 } | |
485 | 482 |
486 int n_handlers = 0; | 483 // Need to have LoginHandlers created for all requests that need |
| 484 // authentication. |
| 485 while (observer.handlers().size() < kMultiRealmTestAuthRequestsCount) |
| 486 WindowedAuthNeededObserver(controller).Wait(); |
487 | 487 |
488 while (n_handlers < kMultiRealmTestRealmCount) { | 488 // Now cancel auth once per realm. This should be sufficient to cancel all |
489 WindowedAuthNeededObserver auth_needed_waiter(controller); | 489 // auth requests. |
| 490 std::set<std::string> seen_realms; |
| 491 for (int i = 0; i < kMultiRealmTestRealmCount; ++i) { |
| 492 auto it = std::find_if( |
| 493 observer.handlers().begin(), observer.handlers().end(), |
| 494 [&seen_realms](LoginHandler* handler) { |
| 495 return seen_realms.count(handler->auth_info()->realm) == 0; |
| 496 }); |
| 497 ASSERT_TRUE(it != observer.handlers().end()); |
| 498 seen_realms.insert((*it)->auth_info()->realm); |
490 | 499 |
491 while (!observer.handlers().empty()) { | 500 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
492 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 501 (*it)->CancelAuth(); |
493 LoginHandler* handler = *observer.handlers().begin(); | 502 auth_cancelled_waiter.Wait(); |
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 } | 503 } |
504 | 504 |
505 load_stop_waiter.Wait(); | 505 load_stop_waiter.Wait(); |
506 | 506 |
507 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); | |
508 EXPECT_EQ(0, observer.auth_supplied_count()); | 507 EXPECT_EQ(0, observer.auth_supplied_count()); |
509 EXPECT_LT(0, observer.auth_needed_count()); | 508 EXPECT_LT(0, observer.auth_needed_count()); |
510 EXPECT_LT(0, observer.auth_cancelled_count()); | 509 EXPECT_LT(0, observer.auth_cancelled_count()); |
511 } | 510 } |
512 | 511 |
513 // Similar to the MultipleRealmCancellation test above, but tests | 512 // Similar to the MultipleRealmCancellation test above, but tests |
514 // whether supplying credentials work as exepcted. | 513 // whether supplying credentials work as exepcted. |
515 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { | 514 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) { |
516 ASSERT_TRUE(embedded_test_server()->Start()); | 515 ASSERT_TRUE(embedded_test_server()->Start()); |
517 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); | 516 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); |
518 | 517 |
519 content::WebContents* contents = | 518 content::WebContents* contents = |
520 browser()->tab_strip_model()->GetActiveWebContents(); | 519 browser()->tab_strip_model()->GetActiveWebContents(); |
521 NavigationController* controller = &contents->GetController(); | 520 NavigationController* controller = &contents->GetController(); |
522 LoginPromptBrowserTestObserver observer; | 521 LoginPromptBrowserTestObserver observer; |
523 | 522 |
524 observer.Register(content::Source<NavigationController>(controller)); | 523 observer.Register(content::Source<NavigationController>(controller)); |
525 | 524 |
526 WindowedLoadStopObserver load_stop_waiter(controller, 1); | 525 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
527 int n_handlers = 0; | |
528 | 526 |
529 { | 527 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
530 WindowedAuthNeededObserver auth_needed_waiter(controller); | 528 WindowOpenDisposition::CURRENT_TAB, |
| 529 ui::PAGE_TRANSITION_TYPED, false)); |
531 | 530 |
532 browser()->OpenURL(OpenURLParams(test_page, Referrer(), | 531 // Need to have LoginHandlers created for all requests that need |
533 WindowOpenDisposition::CURRENT_TAB, | 532 // authentication. |
534 ui::PAGE_TRANSITION_TYPED, false)); | 533 while (observer.handlers().size() < kMultiRealmTestAuthRequestsCount) |
535 auth_needed_waiter.Wait(); | 534 WindowedAuthNeededObserver(controller).Wait(); |
536 } | |
537 | 535 |
538 while (n_handlers < kMultiRealmTestRealmCount) { | 536 // Now supply auth once per realm. This should be sufficient to confirm all |
539 WindowedAuthNeededObserver auth_needed_waiter(controller); | 537 // auth requests. |
| 538 std::set<std::string> seen_realms; |
| 539 for (int i = 0; i < kMultiRealmTestRealmCount; ++i) { |
| 540 auto it = std::find_if( |
| 541 observer.handlers().begin(), observer.handlers().end(), |
| 542 [&seen_realms](LoginHandler* handler) { |
| 543 return seen_realms.count(handler->auth_info()->realm) == 0; |
| 544 }); |
| 545 ASSERT_TRUE(it != observer.handlers().end()); |
| 546 seen_realms.insert((*it)->auth_info()->realm); |
540 | 547 |
541 while (!observer.handlers().empty()) { | 548 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); |
542 WindowedAuthSuppliedObserver auth_supplied_waiter(controller); | 549 SetAuthFor(*it); |
543 LoginHandler* handler = *observer.handlers().begin(); | 550 auth_supplied_waiter.Wait(); |
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 } | 551 } |
554 | 552 |
555 load_stop_waiter.Wait(); | 553 load_stop_waiter.Wait(); |
556 | 554 |
557 EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers); | |
558 EXPECT_LT(0, observer.auth_needed_count()); | 555 EXPECT_LT(0, observer.auth_needed_count()); |
559 EXPECT_LT(0, observer.auth_supplied_count()); | 556 EXPECT_LT(0, observer.auth_supplied_count()); |
560 EXPECT_EQ(0, observer.auth_cancelled_count()); | 557 EXPECT_EQ(0, observer.auth_cancelled_count()); |
561 } | 558 } |
562 | 559 |
563 // Testing for recovery from an incorrect password for the case where | 560 // Testing for recovery from an incorrect password for the case where |
564 // there are multiple authenticated resources. | 561 // there are multiple authenticated resources. |
565 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { | 562 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { |
566 ASSERT_TRUE(embedded_test_server()->Start()); | 563 ASSERT_TRUE(embedded_test_server()->Start()); |
567 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage); | 564 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage); |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 // out. | 1492 // out. |
1496 EXPECT_TRUE( | 1493 EXPECT_TRUE( |
1497 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 1494 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
1498 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1495 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
1499 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | 1496 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
1500 ->GetDelegateForTesting() | 1497 ->GetDelegateForTesting() |
1501 ->GetTypeForTesting()); | 1498 ->GetTypeForTesting()); |
1502 } | 1499 } |
1503 | 1500 |
1504 } // namespace | 1501 } // namespace |
OLD | NEW |