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

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

Issue 2715733003: Revert of Switch WindowedNotificationObserver to use base::RunLoop. (Closed)
Patch Set: Created 3 years, 10 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
102 101
103 const char kSingleRealmTestPage[] = "/login/single_realm.html"; 102 const char kSingleRealmTestPage[] = "/login/single_realm.html";
104 103
105 const char kAuthBasicPage[] = "/auth-basic"; 104 const char kAuthBasicPage[] = "/auth-basic";
106 const char kAuthDigestPage[] = "/auth-digest"; 105 const char kAuthDigestPage[] = "/auth-digest";
107 106
108 // It does not matter what pages are selected as no-auth, as long as they exist. 107 // 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 108 // Navigating to non-existing pages caused flakes in the past
110 // (https://crbug.com/636875). 109 // (https://crbug.com/636875).
111 const char kNoAuthPage1[] = "/simple.html"; 110 const char kNoAuthPage1[] = "/simple.html";
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 ASSERT_TRUE(controller->CanGoForward()); 453 ASSERT_TRUE(controller->CanGoForward());
455 controller->GoForward(); 454 controller->GoForward();
456 auth_cancelled_waiter.Wait(); 455 auth_cancelled_waiter.Wait();
457 load_stop_waiter.Wait(); 456 load_stop_waiter.Wait();
458 EXPECT_TRUE(observer.handlers().empty()); 457 EXPECT_TRUE(observer.handlers().empty());
459 } 458 }
460 459
461 // Test handling of resources that require authentication even though 460 // Test handling of resources that require authentication even though
462 // the page they are included on doesn't. In this case we should only 461 // the page they are included on doesn't. In this case we should only
463 // present the minimal number of prompts necessary for successfully 462 // present the minimal number of prompts necessary for successfully
464 // displaying the page. 463 // displaying the page. First we check whether cancelling works as
465 class MultiRealmLoginPromptBrowserTest : public LoginPromptBrowserTest { 464 // expected.
466 public: 465 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
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) {
496 ASSERT_TRUE(embedded_test_server()->Start()); 466 ASSERT_TRUE(embedded_test_server()->Start());
497 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); 467 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage);
498 468
499 NavigationController* controller = GetNavigationController(); 469 content::WebContents* contents =
470 browser()->tab_strip_model()->GetActiveWebContents();
471 NavigationController* controller = &contents->GetController();
472 LoginPromptBrowserTestObserver observer;
500 473
501 login_prompt_observer_.Register( 474 observer.Register(content::Source<NavigationController>(controller));
502 content::Source<NavigationController>(controller));
503 475
504 WindowedLoadStopObserver load_stop_waiter(controller, 1); 476 WindowedLoadStopObserver load_stop_waiter(controller, 1);
505 477
506 browser()->OpenURL(OpenURLParams(test_page, Referrer(), 478 {
507 WindowOpenDisposition::CURRENT_TAB, 479 WindowedAuthNeededObserver auth_needed_waiter(controller);
508 ui::PAGE_TRANSITION_TYPED, false)); 480 browser()->OpenURL(OpenURLParams(test_page, Referrer(),
481 WindowOpenDisposition::CURRENT_TAB,
482 ui::PAGE_TRANSITION_TYPED, false));
483 auth_needed_waiter.Wait();
484 }
509 485
510 // Need to have LoginHandlers created for all requests that need 486 int n_handlers = 0;
511 // authentication.
512 while (login_prompt_observer_.handlers().size() <
513 kMultiRealmTestAuthRequestsCount)
514 WindowedAuthNeededObserver(controller).Wait();
515 487
516 // Now confirm or cancel auth once per realm. 488 while (n_handlers < kMultiRealmTestRealmCount) {
517 std::set<std::string> seen_realms; 489 WindowedAuthNeededObserver auth_needed_waiter(controller);
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);
527 490
528 for_each_realm_func(*it); 491 while (!observer.handlers().empty()) {
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();
529 } 503 }
530 504
531 load_stop_waiter.Wait(); 505 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());
532 } 511 }
533 512
534 // Checks that cancelling works as expected. 513 // Similar to the MultipleRealmCancellation test above, but tests
535 IN_PROC_BROWSER_TEST_F(MultiRealmLoginPromptBrowserTest, 514 // whether supplying credentials work as exepcted.
536 MultipleRealmCancellation) { 515 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) {
537 RunTest([this](LoginHandler* handler) { 516 ASSERT_TRUE(embedded_test_server()->Start());
538 WindowedAuthCancelledObserver waiter(GetNavigationController()); 517 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage);
539 handler->CancelAuth();
540 waiter.Wait();
541 });
542 518
543 EXPECT_EQ(0, login_prompt_observer()->auth_supplied_count()); 519 content::WebContents* contents =
544 EXPECT_LT(0, login_prompt_observer()->auth_needed_count()); 520 browser()->tab_strip_model()->GetActiveWebContents();
545 EXPECT_LT(0, login_prompt_observer()->auth_cancelled_count()); 521 NavigationController* controller = &contents->GetController();
546 } 522 LoginPromptBrowserTestObserver observer;
547 523
548 // Checks that supplying credentials works as exepcted. 524 observer.Register(content::Source<NavigationController>(controller));
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 });
556 525
557 EXPECT_LT(0, login_prompt_observer()->auth_needed_count()); 526 WindowedLoadStopObserver load_stop_waiter(controller, 1);
558 EXPECT_LT(0, login_prompt_observer()->auth_supplied_count()); 527 int n_handlers = 0;
559 EXPECT_EQ(0, login_prompt_observer()->auth_cancelled_count()); 528
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());
560 } 561 }
561 562
562 // Testing for recovery from an incorrect password for the case where 563 // Testing for recovery from an incorrect password for the case where
563 // there are multiple authenticated resources. 564 // there are multiple authenticated resources.
564 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { 565 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) {
565 ASSERT_TRUE(embedded_test_server()->Start()); 566 ASSERT_TRUE(embedded_test_server()->Start());
566 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage); 567 GURL test_page = embedded_test_server()->GetURL(kSingleRealmTestPage);
567 568
568 content::WebContents* contents = 569 content::WebContents* contents =
569 browser()->tab_strip_model()->GetActiveWebContents(); 570 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 // out. 1495 // out.
1495 EXPECT_TRUE( 1496 EXPECT_TRUE(
1496 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); 1497 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()));
1497 EXPECT_TRUE(contents->ShowingInterstitialPage()); 1498 EXPECT_TRUE(contents->ShowingInterstitialPage());
1498 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() 1499 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage()
1499 ->GetDelegateForTesting() 1500 ->GetDelegateForTesting()
1500 ->GetTypeForTesting()); 1501 ->GetTypeForTesting());
1501 } 1502 }
1502 1503
1503 } // namespace 1504 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698