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

Side by Side Diff: chrome/browser/ui/login/login_handler_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698