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 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 } | 978 } |
979 | 979 |
980 EXPECT_EQ(1, observer.auth_needed_count()); | 980 EXPECT_EQ(1, observer.auth_needed_count()); |
981 EXPECT_EQ(1, observer.auth_supplied_count()); | 981 EXPECT_EQ(1, observer.auth_supplied_count()); |
982 EXPECT_EQ(0, observer.auth_cancelled_count()); | 982 EXPECT_EQ(0, observer.auth_cancelled_count()); |
983 EXPECT_EQ(1, observer_incognito.auth_needed_count()); | 983 EXPECT_EQ(1, observer_incognito.auth_needed_count()); |
984 EXPECT_EQ(0, observer_incognito.auth_supplied_count()); | 984 EXPECT_EQ(0, observer_incognito.auth_supplied_count()); |
985 EXPECT_EQ(0, observer_incognito.auth_cancelled_count()); | 985 EXPECT_EQ(0, observer_incognito.auth_cancelled_count()); |
986 } | 986 } |
987 | 987 |
| 988 // If an XMLHttpRequest is made with incorrect credentials, there should be no |
| 989 // login prompt; instead the 401 status should be returned to the script. |
| 990 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, |
| 991 NoLoginPromptForXHRWithBadCredentials) { |
| 992 const char kXHRTestPage[] = "/login/xhr_with_credentials.html#incorrect"; |
| 993 |
| 994 ASSERT_TRUE(embedded_test_server()->Start()); |
| 995 |
| 996 content::WebContents* contents = |
| 997 browser()->tab_strip_model()->GetActiveWebContents(); |
| 998 NavigationController* controller = &contents->GetController(); |
| 999 LoginPromptBrowserTestObserver observer; |
| 1000 |
| 1001 observer.Register(content::Source<NavigationController>(controller)); |
| 1002 |
| 1003 // Load a page which makes a synchronous XMLHttpRequest for an authenticated |
| 1004 // resource with the wrong credentials. There should be no login prompt. |
| 1005 { |
| 1006 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage); |
| 1007 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
| 1008 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
| 1009 WindowOpenDisposition::CURRENT_TAB, |
| 1010 ui::PAGE_TRANSITION_TYPED, false)); |
| 1011 load_stop_waiter.Wait(); |
| 1012 } |
| 1013 |
| 1014 base::string16 expected_title(base::UTF8ToUTF16("status=401")); |
| 1015 |
| 1016 EXPECT_EQ(expected_title, contents->GetTitle()); |
| 1017 EXPECT_EQ(0, observer.auth_supplied_count()); |
| 1018 EXPECT_EQ(0, observer.auth_needed_count()); |
| 1019 EXPECT_EQ(0, observer.auth_cancelled_count()); |
| 1020 } |
| 1021 |
| 1022 // If an XMLHttpRequest is made with correct credentials, there should be no |
| 1023 // login prompt either. |
| 1024 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, |
| 1025 NoLoginPromptForXHRWithGoodCredentials) { |
| 1026 const char kXHRTestPage[] = "/login/xhr_with_credentials.html#secret"; |
| 1027 |
| 1028 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1029 |
| 1030 content::WebContents* contents = |
| 1031 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1032 NavigationController* controller = &contents->GetController(); |
| 1033 LoginPromptBrowserTestObserver observer; |
| 1034 |
| 1035 observer.Register(content::Source<NavigationController>(controller)); |
| 1036 |
| 1037 // Load a page which makes a synchronous XMLHttpRequest for an authenticated |
| 1038 // resource with the wrong credentials. There should be no login prompt. |
| 1039 { |
| 1040 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage); |
| 1041 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
| 1042 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
| 1043 WindowOpenDisposition::CURRENT_TAB, |
| 1044 ui::PAGE_TRANSITION_TYPED, false)); |
| 1045 load_stop_waiter.Wait(); |
| 1046 } |
| 1047 |
| 1048 base::string16 expected_title(base::UTF8ToUTF16("status=200")); |
| 1049 |
| 1050 EXPECT_EQ(expected_title, contents->GetTitle()); |
| 1051 EXPECT_EQ(0, observer.auth_supplied_count()); |
| 1052 EXPECT_EQ(0, observer.auth_needed_count()); |
| 1053 EXPECT_EQ(0, observer.auth_cancelled_count()); |
| 1054 } |
| 1055 |
988 // If an XMLHttpRequest is made without credentials, there should be a login | 1056 // If an XMLHttpRequest is made without credentials, there should be a login |
989 // prompt. | 1057 // prompt. |
990 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, | 1058 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, |
991 LoginPromptForXHRWithoutCredentials) { | 1059 LoginPromptForXHRWithoutCredentials) { |
992 const char kXHRTestPage[] = "/login/xhr_without_credentials.html"; | 1060 const char kXHRTestPage[] = "/login/xhr_without_credentials.html"; |
993 | 1061 |
994 ASSERT_TRUE(embedded_test_server()->Start()); | 1062 ASSERT_TRUE(embedded_test_server()->Start()); |
995 | 1063 |
996 content::WebContents* contents = | 1064 content::WebContents* contents = |
997 browser()->tab_strip_model()->GetActiveWebContents(); | 1065 browser()->tab_strip_model()->GetActiveWebContents(); |
998 NavigationController* controller = &contents->GetController(); | 1066 NavigationController* controller = &contents->GetController(); |
999 LoginPromptBrowserTestObserver observer; | 1067 LoginPromptBrowserTestObserver observer; |
1000 | 1068 |
1001 observer.Register(content::Source<NavigationController>(controller)); | 1069 observer.Register(content::Source<NavigationController>(controller)); |
1002 | 1070 |
1003 // Load a page which makes a synchronous XMLHttpRequest for an authenticated | 1071 // Load a page which makes a synchronous XMLHttpRequest for an authenticated |
1004 // resource without credentials. There should be a login prompt. | 1072 // resource with the wrong credentials. There should be no login prompt. |
1005 { | 1073 { |
1006 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage); | 1074 GURL test_page = embedded_test_server()->GetURL(kXHRTestPage); |
1007 WindowedAuthNeededObserver auth_needed_waiter(controller); | 1075 WindowedAuthNeededObserver auth_needed_waiter(controller); |
1008 browser()->OpenURL(OpenURLParams(test_page, Referrer(), | 1076 browser()->OpenURL(OpenURLParams(test_page, Referrer(), |
1009 WindowOpenDisposition::CURRENT_TAB, | 1077 WindowOpenDisposition::CURRENT_TAB, |
1010 ui::PAGE_TRANSITION_TYPED, false)); | 1078 ui::PAGE_TRANSITION_TYPED, false)); |
1011 auth_needed_waiter.Wait(); | 1079 auth_needed_waiter.Wait(); |
1012 } | 1080 } |
1013 | 1081 |
1014 ASSERT_FALSE(observer.handlers().empty()); | 1082 ASSERT_FALSE(observer.handlers().empty()); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 // out. | 1499 // out. |
1432 EXPECT_TRUE( | 1500 EXPECT_TRUE( |
1433 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 1501 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
1434 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1502 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
1435 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | 1503 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
1436 ->GetDelegateForTesting() | 1504 ->GetDelegateForTesting() |
1437 ->GetTypeForTesting()); | 1505 ->GetTypeForTesting()); |
1438 } | 1506 } |
1439 | 1507 |
1440 } // namespace | 1508 } // namespace |
OLD | NEW |