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

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

Issue 889463003: GURL::Replacements methods accept a StringPiece instead of std::string&. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (fixed some merge conflicts). Created 5 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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 observer.Register(content::Source<NavigationController>(controller)); 654 observer.Register(content::Source<NavigationController>(controller));
655 655
656 // Load a page that has a cross-domain sub-resource authentication. 656 // Load a page that has a cross-domain sub-resource authentication.
657 // There should be no login prompt. 657 // There should be no login prompt.
658 { 658 {
659 GURL test_page = test_server()->GetURL(kTestPage); 659 GURL test_page = test_server()->GetURL(kTestPage);
660 ASSERT_EQ("127.0.0.1", test_page.host()); 660 ASSERT_EQ("127.0.0.1", test_page.host());
661 661
662 // Change the host from 127.0.0.1 to www.a.com so that when the 662 // Change the host from 127.0.0.1 to www.a.com so that when the
663 // page tries to load from b, it will be cross-origin. 663 // page tries to load from b, it will be cross-origin.
664 std::string new_host("www.a.com");
665 GURL::Replacements replacements; 664 GURL::Replacements replacements;
666 replacements.SetHostStr(new_host); 665 replacements.SetHostStr("www.a.com");
667 test_page = test_page.ReplaceComponents(replacements); 666 test_page = test_page.ReplaceComponents(replacements);
668 667
669 WindowedLoadStopObserver load_stop_waiter(controller, 1); 668 WindowedLoadStopObserver load_stop_waiter(controller, 1);
670 browser()->OpenURL(OpenURLParams( 669 browser()->OpenURL(OpenURLParams(
671 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 670 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
672 false)); 671 false));
673 load_stop_waiter.Wait(); 672 load_stop_waiter.Wait();
674 } 673 }
675 674
676 EXPECT_EQ(0, observer.auth_needed_count()); 675 EXPECT_EQ(0, observer.auth_needed_count());
677 676
678 // Now request the same page, but from the same origin. 677 // Now request the same page, but from the same origin.
679 // There should be one login prompt. 678 // There should be one login prompt.
680 { 679 {
681 GURL test_page = test_server()->GetURL(kTestPage); 680 GURL test_page = test_server()->GetURL(kTestPage);
682 ASSERT_EQ("127.0.0.1", test_page.host()); 681 ASSERT_EQ("127.0.0.1", test_page.host());
683 682
684 // Change the host from 127.0.0.1 to www.b.com so that when the 683 // Change the host from 127.0.0.1 to www.b.com so that when the
685 // page tries to load from b, it will be same-origin. 684 // page tries to load from b, it will be same-origin.
686 std::string new_host("www.b.com");
687 GURL::Replacements replacements; 685 GURL::Replacements replacements;
688 replacements.SetHostStr(new_host); 686 replacements.SetHostStr("www.b.com");
689 test_page = test_page.ReplaceComponents(replacements); 687 test_page = test_page.ReplaceComponents(replacements);
690 688
691 WindowedAuthNeededObserver auth_needed_waiter(controller); 689 WindowedAuthNeededObserver auth_needed_waiter(controller);
692 browser()->OpenURL(OpenURLParams( 690 browser()->OpenURL(OpenURLParams(
693 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 691 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
694 false)); 692 false));
695 auth_needed_waiter.Wait(); 693 auth_needed_waiter.Wait();
696 ASSERT_EQ(1u, observer.handlers().size()); 694 ASSERT_EQ(1u, observer.handlers().size());
697 695
698 while (!observer.handlers().empty()) { 696 while (!observer.handlers().empty()) {
(...skipping 25 matching lines...) Expand all
724 LoginPromptBrowserTestObserver observer; 722 LoginPromptBrowserTestObserver observer;
725 observer.Register(content::Source<NavigationController>(controller)); 723 observer.Register(content::Source<NavigationController>(controller));
726 724
727 // Load a page that has a cross-domain iframe authentication. 725 // Load a page that has a cross-domain iframe authentication.
728 { 726 {
729 GURL test_page = test_server()->GetURL(kTestPage); 727 GURL test_page = test_server()->GetURL(kTestPage);
730 ASSERT_EQ("127.0.0.1", test_page.host()); 728 ASSERT_EQ("127.0.0.1", test_page.host());
731 729
732 // Change the host from 127.0.0.1 to www.a.com so that when the 730 // Change the host from 127.0.0.1 to www.a.com so that when the
733 // page tries to load from b, it will be cross-origin. 731 // page tries to load from b, it will be cross-origin.
734 std::string new_host("www.a.com"); 732 static const char kNewHost[] = "www.a.com";
735 GURL::Replacements replacements; 733 GURL::Replacements replacements;
736 replacements.SetHostStr(new_host); 734 replacements.SetHostStr(kNewHost);
737 test_page = test_page.ReplaceComponents(replacements); 735 test_page = test_page.ReplaceComponents(replacements);
738 736
739 WindowedAuthNeededObserver auth_needed_waiter(controller); 737 WindowedAuthNeededObserver auth_needed_waiter(controller);
740 browser()->OpenURL(OpenURLParams( 738 browser()->OpenURL(OpenURLParams(
741 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 739 test_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
742 false)); 740 false));
743 auth_needed_waiter.Wait(); 741 auth_needed_waiter.Wait();
744 ASSERT_EQ(1u, observer.handlers().size()); 742 ASSERT_EQ(1u, observer.handlers().size());
745 743
746 while (!observer.handlers().empty()) { 744 while (!observer.handlers().empty()) {
747 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 745 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
748 LoginHandler* handler = *observer.handlers().begin(); 746 LoginHandler* handler = *observer.handlers().begin();
749 747
750 ASSERT_TRUE(handler); 748 ASSERT_TRUE(handler);
751 // When a cross origin iframe displays a login prompt, the blank 749 // When a cross origin iframe displays a login prompt, the blank
752 // interstitial shouldn't be displayed and the omnibox should show the 750 // interstitial shouldn't be displayed and the omnibox should show the
753 // main frame's url, not the iframe's. 751 // main frame's url, not the iframe's.
754 EXPECT_EQ(new_host, contents->GetVisibleURL().host()); 752 EXPECT_EQ(kNewHost, contents->GetVisibleURL().host());
755 753
756 handler->CancelAuth(); 754 handler->CancelAuth();
757 auth_cancelled_waiter.Wait(); 755 auth_cancelled_waiter.Wait();
758 } 756 }
759 } 757 }
760 758
761 // Should stay on the main frame's url once the prompt the iframe is closed. 759 // Should stay on the main frame's url once the prompt the iframe is closed.
762 EXPECT_EQ("www.a.com", contents->GetVisibleURL().host()); 760 EXPECT_EQ("www.a.com", contents->GetVisibleURL().host());
763 761
764 EXPECT_EQ(1, observer.auth_needed_count()); 762 EXPECT_EQ(1, observer.auth_needed_count());
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 LoginHandler* handler = *observer.handlers().begin(); 1253 LoginHandler* handler = *observer.handlers().begin();
1256 content::RunTaskAndWaitForInterstitialDetach( 1254 content::RunTaskAndWaitForInterstitialDetach(
1257 contents, base::Bind(&LoginHandler::CancelAuth, handler)); 1255 contents, base::Bind(&LoginHandler::CancelAuth, handler));
1258 1256
1259 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host()); 1257 EXPECT_EQ("127.0.0.1", contents->GetVisibleURL().host());
1260 EXPECT_FALSE(contents->ShowingInterstitialPage()); 1258 EXPECT_FALSE(contents->ShowingInterstitialPage());
1261 } 1259 }
1262 } 1260 }
1263 1261
1264 } // namespace 1262 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698