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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/captive_portal/captive_portal_service.h" | 16 #include "chrome/browser/captive_portal/captive_portal_service.h" |
17 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 17 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
18 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 18 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
19 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 19 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
20 #include "chrome/browser/net/url_request_mock_util.h" | 20 #include "chrome/browser/net/url_request_mock_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_navigator.h" | 26 #include "chrome/browser/ui/browser_navigator.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
29 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 } | 910 } |
910 | 911 |
911 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( | 912 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( |
912 TabContents* tab_contents) const { | 913 TabContents* tab_contents) const { |
913 return GetTabReloader(tab_contents)->state(); | 914 return GetTabReloader(tab_contents)->state(); |
914 } | 915 } |
915 | 916 |
916 CaptivePortalTabReloader::State | 917 CaptivePortalTabReloader::State |
917 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, | 918 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, |
918 int index) const { | 919 int index) const { |
919 return GetStateOfTabReloader(browser->GetTabContentsAt(index)); | 920 return GetStateOfTabReloader(chrome::GetTabContentsAt(browser, index)); |
920 } | 921 } |
921 | 922 |
922 int CaptivePortalBrowserTest::NumTabsWithState( | 923 int CaptivePortalBrowserTest::NumTabsWithState( |
923 CaptivePortalTabReloader::State state) const { | 924 CaptivePortalTabReloader::State state) const { |
924 int num_tabs = 0; | 925 int num_tabs = 0; |
925 for (TabContentsIterator tab_contents_it; | 926 for (TabContentsIterator tab_contents_it; |
926 !tab_contents_it.done(); | 927 !tab_contents_it.done(); |
927 ++tab_contents_it) { | 928 ++tab_contents_it) { |
928 if (GetStateOfTabReloader(*tab_contents_it) == state) | 929 if (GetStateOfTabReloader(*tab_contents_it) == state) |
929 ++num_tabs; | 930 ++num_tabs; |
(...skipping 24 matching lines...) Expand all Loading... |
954 EXPECT_EQ(0, portal_observer.num_results_received()); | 955 EXPECT_EQ(0, portal_observer.num_results_received()); |
955 EXPECT_FALSE(CheckPending(browser)); | 956 EXPECT_FALSE(CheckPending(browser)); |
956 EXPECT_EQ(1, browser->tab_count()); | 957 EXPECT_EQ(1, browser->tab_count()); |
957 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations()); | 958 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations()); |
958 EXPECT_EQ(0, NumLoadingTabs()); | 959 EXPECT_EQ(0, NumLoadingTabs()); |
959 } | 960 } |
960 | 961 |
961 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal( | 962 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal( |
962 Browser* browser, Result expected_result) { | 963 Browser* browser, Result expected_result) { |
963 CaptivePortalTabReloader* tab_reloader = | 964 CaptivePortalTabReloader* tab_reloader = |
964 GetTabReloader(browser->GetActiveTabContents()); | 965 GetTabReloader(chrome::GetActiveTabContents(browser)); |
965 ASSERT_TRUE(tab_reloader); | 966 ASSERT_TRUE(tab_reloader); |
966 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); | 967 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); |
967 | 968 |
968 MultiNavigationObserver navigation_observer; | 969 MultiNavigationObserver navigation_observer; |
969 CaptivePortalObserver portal_observer(browser->profile()); | 970 CaptivePortalObserver portal_observer(browser->profile()); |
970 ui_test_utils::NavigateToURLWithDisposition(browser, | 971 ui_test_utils::NavigateToURLWithDisposition(browser, |
971 GURL(kMockHttpsUrl), | 972 GURL(kMockHttpsUrl), |
972 CURRENT_TAB, | 973 CURRENT_TAB, |
973 ui_test_utils::BROWSER_TEST_NONE); | 974 ui_test_utils::BROWSER_TEST_NONE); |
974 | 975 |
(...skipping 22 matching lines...) Expand all Loading... |
997 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); | 998 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); |
998 } | 999 } |
999 | 1000 |
1000 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal( | 1001 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal( |
1001 Browser* browser, Result expected_result) { | 1002 Browser* browser, Result expected_result) { |
1002 ASSERT_NE(expected_result, RESULT_BEHIND_CAPTIVE_PORTAL); | 1003 ASSERT_NE(expected_result, RESULT_BEHIND_CAPTIVE_PORTAL); |
1003 | 1004 |
1004 // Set the load time to be large, so the timer won't trigger. The value is | 1005 // Set the load time to be large, so the timer won't trigger. The value is |
1005 // not restored at the end of the function. | 1006 // not restored at the end of the function. |
1006 CaptivePortalTabReloader* tab_reloader = | 1007 CaptivePortalTabReloader* tab_reloader = |
1007 GetTabReloader(browser->GetActiveTabContents()); | 1008 GetTabReloader(chrome::GetActiveTabContents(browser)); |
1008 ASSERT_TRUE(tab_reloader); | 1009 ASSERT_TRUE(tab_reloader); |
1009 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1010 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1010 | 1011 |
1011 MultiNavigationObserver navigation_observer; | 1012 MultiNavigationObserver navigation_observer; |
1012 CaptivePortalObserver portal_observer(browser->profile()); | 1013 CaptivePortalObserver portal_observer(browser->profile()); |
1013 | 1014 |
1014 // Neither of these should be changed by the navigation. | 1015 // Neither of these should be changed by the navigation. |
1015 int active_index = browser->active_index(); | 1016 int active_index = browser->active_index(); |
1016 int expected_tab_count = browser->tab_count(); | 1017 int expected_tab_count = browser->tab_count(); |
1017 | 1018 |
1018 ui_test_utils::NavigateToURL( | 1019 ui_test_utils::NavigateToURL( |
1019 browser, | 1020 browser, |
1020 URLRequestFailedJob::GetMockHttpsUrl(net::ERR_CONNECTION_TIMED_OUT)); | 1021 URLRequestFailedJob::GetMockHttpsUrl(net::ERR_CONNECTION_TIMED_OUT)); |
1021 | 1022 |
1022 // An attempt to detect a captive portal should have started by now. If not, | 1023 // An attempt to detect a captive portal should have started by now. If not, |
1023 // abort early to prevent hanging. | 1024 // abort early to prevent hanging. |
1024 ASSERT_TRUE(portal_observer.num_results_received() > 0 || | 1025 ASSERT_TRUE(portal_observer.num_results_received() > 0 || |
1025 CheckPending(browser)); | 1026 CheckPending(browser)); |
1026 | 1027 |
1027 portal_observer.WaitForResults(1); | 1028 portal_observer.WaitForResults(1); |
1028 navigation_observer.WaitForNavigations(1); | 1029 navigation_observer.WaitForNavigations(1); |
1029 | 1030 |
1030 // Check the result. | 1031 // Check the result. |
1031 EXPECT_EQ(1, portal_observer.num_results_received()); | 1032 EXPECT_EQ(1, portal_observer.num_results_received()); |
1032 EXPECT_EQ(expected_result, portal_observer.captive_portal_result()); | 1033 EXPECT_EQ(expected_result, portal_observer.captive_portal_result()); |
1033 | 1034 |
1034 // Check that the right tab was navigated, and there were no extra | 1035 // Check that the right tab was navigated, and there were no extra |
1035 // navigations. | 1036 // navigations. |
1036 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1037 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1037 browser->GetWebContentsAt(active_index))); | 1038 chrome::GetWebContentsAt(browser, active_index))); |
1038 EXPECT_EQ(0, NumLoadingTabs()); | 1039 EXPECT_EQ(0, NumLoadingTabs()); |
1039 | 1040 |
1040 // Check the tab's state, and verify no captive portal check is pending. | 1041 // Check the tab's state, and verify no captive portal check is pending. |
1041 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1042 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1042 GetStateOfTabReloaderAt(browser, 0)); | 1043 GetStateOfTabReloaderAt(browser, 0)); |
1043 EXPECT_FALSE(CheckPending(browser)); | 1044 EXPECT_FALSE(CheckPending(browser)); |
1044 | 1045 |
1045 // Make sure no login tab was opened. | 1046 // Make sure no login tab was opened. |
1046 EXPECT_EQ(expected_tab_count, browser->tab_count()); | 1047 EXPECT_EQ(expected_tab_count, browser->tab_count()); |
1047 } | 1048 } |
1048 | 1049 |
1049 void CaptivePortalBrowserTest::SlowLoadBehindCaptivePortal( | 1050 void CaptivePortalBrowserTest::SlowLoadBehindCaptivePortal( |
1050 Browser* browser, | 1051 Browser* browser, |
1051 bool expect_open_login_tab) { | 1052 bool expect_open_login_tab) { |
1052 // Calling this on a tab that's waiting for a load to manually be timed out | 1053 // Calling this on a tab that's waiting for a load to manually be timed out |
1053 // will result in a hang. | 1054 // will result in a hang. |
1054 ASSERT_FALSE(browser->GetActiveWebContents()->IsLoading()); | 1055 ASSERT_FALSE(chrome::GetActiveWebContents(browser)->IsLoading()); |
1055 | 1056 |
1056 // Trigger a captive portal check quickly. | 1057 // Trigger a captive portal check quickly. |
1057 CaptivePortalTabReloader* tab_reloader = | 1058 CaptivePortalTabReloader* tab_reloader = |
1058 GetTabReloader(browser->GetActiveTabContents()); | 1059 GetTabReloader(chrome::GetActiveTabContents(browser)); |
1059 ASSERT_TRUE(tab_reloader); | 1060 ASSERT_TRUE(tab_reloader); |
1060 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); | 1061 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); |
1061 | 1062 |
1062 // Number of tabs expected to be open after the captive portal checks | 1063 // Number of tabs expected to be open after the captive portal checks |
1063 // have completed. | 1064 // have completed. |
1064 int initial_tab_count = browser->tab_count(); | 1065 int initial_tab_count = browser->tab_count(); |
1065 int initial_active_index = browser->active_index(); | 1066 int initial_active_index = browser->active_index(); |
1066 int initial_loading_tabs = NumLoadingTabs(); | 1067 int initial_loading_tabs = NumLoadingTabs(); |
1067 int expected_broken_tabs = NumBrokenTabs(); | 1068 int expected_broken_tabs = NumBrokenTabs(); |
1068 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != | 1069 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != |
1069 GetStateOfTabReloader(browser->GetActiveTabContents())) { | 1070 GetStateOfTabReloader(chrome::GetActiveTabContents(browser))) { |
1070 ++expected_broken_tabs; | 1071 ++expected_broken_tabs; |
1071 } | 1072 } |
1072 | 1073 |
1073 MultiNavigationObserver navigation_observer; | 1074 MultiNavigationObserver navigation_observer; |
1074 CaptivePortalObserver portal_observer(browser->profile()); | 1075 CaptivePortalObserver portal_observer(browser->profile()); |
1075 ui_test_utils::NavigateToURLWithDisposition(browser, | 1076 ui_test_utils::NavigateToURLWithDisposition(browser, |
1076 GURL(kMockHttpsUrl), | 1077 GURL(kMockHttpsUrl), |
1077 CURRENT_TAB, | 1078 CURRENT_TAB, |
1078 ui_test_utils::BROWSER_TEST_NONE); | 1079 ui_test_utils::BROWSER_TEST_NONE); |
1079 | 1080 |
1080 if (expect_open_login_tab) { | 1081 if (expect_open_login_tab) { |
1081 portal_observer.WaitForResults(2); | 1082 portal_observer.WaitForResults(2); |
1082 navigation_observer.WaitForNavigations(1); | 1083 navigation_observer.WaitForNavigations(1); |
1083 EXPECT_EQ(2, portal_observer.num_results_received()); | 1084 EXPECT_EQ(2, portal_observer.num_results_received()); |
1084 | 1085 |
1085 ASSERT_EQ(initial_tab_count + 1, browser->tab_count()); | 1086 ASSERT_EQ(initial_tab_count + 1, browser->tab_count()); |
1086 EXPECT_EQ(initial_tab_count, browser->active_index()); | 1087 EXPECT_EQ(initial_tab_count, browser->active_index()); |
1087 | 1088 |
1088 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1089 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1089 browser->GetWebContentsAt(initial_tab_count))); | 1090 chrome::GetWebContentsAt(browser, initial_tab_count))); |
1090 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1091 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1091 GetStateOfTabReloader(browser->GetTabContentsAt(1))); | 1092 GetStateOfTabReloader(chrome::GetTabContentsAt(browser, 1))); |
1092 EXPECT_TRUE(IsLoginTab(browser->GetTabContentsAt(1))); | 1093 EXPECT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser, 1))); |
1093 } else { | 1094 } else { |
1094 portal_observer.WaitForResults(1); | 1095 portal_observer.WaitForResults(1); |
1095 EXPECT_EQ(0, navigation_observer.num_navigations()); | 1096 EXPECT_EQ(0, navigation_observer.num_navigations()); |
1096 EXPECT_EQ(initial_active_index, browser->active_index()); | 1097 EXPECT_EQ(initial_active_index, browser->active_index()); |
1097 ASSERT_EQ(initial_tab_count, browser->tab_count()); | 1098 ASSERT_EQ(initial_tab_count, browser->tab_count()); |
1098 EXPECT_EQ(initial_active_index, browser->active_index()); | 1099 EXPECT_EQ(initial_active_index, browser->active_index()); |
1099 } | 1100 } |
1100 | 1101 |
1101 // Wait for all the expect resource loads to actually start, so subsequent | 1102 // Wait for all the expect resource loads to actually start, so subsequent |
1102 // functions can rely on them having started. | 1103 // functions can rely on them having started. |
1103 URLRequestTimeoutOnDemandJob::WaitForJobs(initial_loading_tabs + 1); | 1104 URLRequestTimeoutOnDemandJob::WaitForJobs(initial_loading_tabs + 1); |
1104 | 1105 |
1105 EXPECT_EQ(initial_loading_tabs + 1, NumLoadingTabs()); | 1106 EXPECT_EQ(initial_loading_tabs + 1, NumLoadingTabs()); |
1106 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); | 1107 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); |
1107 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1108 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1108 portal_observer.captive_portal_result()); | 1109 portal_observer.captive_portal_result()); |
1109 EXPECT_FALSE(CheckPending(browser)); | 1110 EXPECT_FALSE(CheckPending(browser)); |
1110 | 1111 |
1111 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1112 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1112 GetStateOfTabReloader( | 1113 GetStateOfTabReloader( |
1113 browser->GetTabContentsAt(initial_active_index))); | 1114 chrome::GetTabContentsAt(browser, initial_active_index))); |
1114 | 1115 |
1115 // Reset the load time to be large, so the timer won't trigger on a reload. | 1116 // Reset the load time to be large, so the timer won't trigger on a reload. |
1116 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1117 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1117 } | 1118 } |
1118 | 1119 |
1119 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( | 1120 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( |
1120 Browser* browser, | 1121 Browser* browser, |
1121 bool expect_open_login_tab) { | 1122 bool expect_open_login_tab) { |
1122 // Calling this on a tab that's waiting for a load to manually be timed out | 1123 // Calling this on a tab that's waiting for a load to manually be timed out |
1123 // will result in a hang. | 1124 // will result in a hang. |
1124 ASSERT_FALSE(browser->GetActiveWebContents()->IsLoading()); | 1125 ASSERT_FALSE(chrome::GetActiveWebContents(browser)->IsLoading()); |
1125 | 1126 |
1126 // Set the load time to be large, so the timer won't trigger. The value is | 1127 // Set the load time to be large, so the timer won't trigger. The value is |
1127 // not restored at the end of the function. | 1128 // not restored at the end of the function. |
1128 CaptivePortalTabReloader* tab_reloader = | 1129 CaptivePortalTabReloader* tab_reloader = |
1129 GetTabReloader(browser->GetActiveTabContents()); | 1130 GetTabReloader(chrome::GetActiveTabContents(browser)); |
1130 ASSERT_TRUE(tab_reloader); | 1131 ASSERT_TRUE(tab_reloader); |
1131 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1132 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1132 | 1133 |
1133 // Number of tabs expected to be open after the captive portal checks | 1134 // Number of tabs expected to be open after the captive portal checks |
1134 // have completed. | 1135 // have completed. |
1135 int initial_tab_count = browser->tab_count(); | 1136 int initial_tab_count = browser->tab_count(); |
1136 int initial_active_index = browser->active_index(); | 1137 int initial_active_index = browser->active_index(); |
1137 int initial_loading_tabs = NumLoadingTabs(); | 1138 int initial_loading_tabs = NumLoadingTabs(); |
1138 int expected_broken_tabs = NumBrokenTabs(); | 1139 int expected_broken_tabs = NumBrokenTabs(); |
1139 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != | 1140 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != |
1140 GetStateOfTabReloader(browser->GetActiveTabContents())) { | 1141 GetStateOfTabReloader(chrome::GetActiveTabContents(browser))) { |
1141 ++expected_broken_tabs; | 1142 ++expected_broken_tabs; |
1142 } | 1143 } |
1143 | 1144 |
1144 MultiNavigationObserver navigation_observer; | 1145 MultiNavigationObserver navigation_observer; |
1145 CaptivePortalObserver portal_observer(browser->profile()); | 1146 CaptivePortalObserver portal_observer(browser->profile()); |
1146 ui_test_utils::NavigateToURLWithDisposition(browser, | 1147 ui_test_utils::NavigateToURLWithDisposition(browser, |
1147 GURL(kMockHttpsQuickTimeoutUrl), | 1148 GURL(kMockHttpsQuickTimeoutUrl), |
1148 CURRENT_TAB, | 1149 CURRENT_TAB, |
1149 ui_test_utils::BROWSER_TEST_NONE); | 1150 ui_test_utils::BROWSER_TEST_NONE); |
1150 | 1151 |
1151 if (expect_open_login_tab) { | 1152 if (expect_open_login_tab) { |
1152 portal_observer.WaitForResults(2); | 1153 portal_observer.WaitForResults(2); |
1153 navigation_observer.WaitForNavigations(2); | 1154 navigation_observer.WaitForNavigations(2); |
1154 EXPECT_EQ(2, portal_observer.num_results_received()); | 1155 EXPECT_EQ(2, portal_observer.num_results_received()); |
1155 | 1156 |
1156 ASSERT_EQ(initial_tab_count + 1, browser->tab_count()); | 1157 ASSERT_EQ(initial_tab_count + 1, browser->tab_count()); |
1157 EXPECT_EQ(initial_tab_count, browser->active_index()); | 1158 EXPECT_EQ(initial_tab_count, browser->active_index()); |
1158 // Make sure that the originally active tab and the captive portal tab have | 1159 // Make sure that the originally active tab and the captive portal tab have |
1159 // each loaded once. | 1160 // each loaded once. |
1160 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1161 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1161 browser->GetWebContentsAt(initial_active_index))); | 1162 chrome::GetWebContentsAt(browser, initial_active_index))); |
1162 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1163 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1163 browser->GetWebContentsAt(initial_tab_count))); | 1164 chrome::GetWebContentsAt(browser, initial_tab_count))); |
1164 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1165 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1165 GetStateOfTabReloader(browser->GetTabContentsAt(1))); | 1166 GetStateOfTabReloader(chrome::GetTabContentsAt(browser, 1))); |
1166 EXPECT_TRUE(IsLoginTab(browser->GetTabContentsAt(1))); | 1167 EXPECT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser, 1))); |
1167 } else { | 1168 } else { |
1168 portal_observer.WaitForResults(1); | 1169 portal_observer.WaitForResults(1); |
1169 navigation_observer.WaitForNavigations(1); | 1170 navigation_observer.WaitForNavigations(1); |
1170 EXPECT_EQ(1, portal_observer.num_results_received()); | 1171 EXPECT_EQ(1, portal_observer.num_results_received()); |
1171 | 1172 |
1172 EXPECT_EQ(initial_active_index, browser->active_index()); | 1173 EXPECT_EQ(initial_active_index, browser->active_index()); |
1173 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1174 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1174 browser->GetWebContentsAt(initial_active_index))); | 1175 chrome::GetWebContentsAt(browser, initial_active_index))); |
1175 ASSERT_EQ(initial_tab_count, browser->tab_count()); | 1176 ASSERT_EQ(initial_tab_count, browser->tab_count()); |
1176 EXPECT_EQ(initial_active_index, browser->active_index()); | 1177 EXPECT_EQ(initial_active_index, browser->active_index()); |
1177 } | 1178 } |
1178 | 1179 |
1179 EXPECT_EQ(initial_loading_tabs, NumLoadingTabs()); | 1180 EXPECT_EQ(initial_loading_tabs, NumLoadingTabs()); |
1180 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); | 1181 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); |
1181 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1182 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1182 portal_observer.captive_portal_result()); | 1183 portal_observer.captive_portal_result()); |
1183 EXPECT_FALSE(CheckPending(browser)); | 1184 EXPECT_FALSE(CheckPending(browser)); |
1184 | 1185 |
1185 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1186 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1186 GetStateOfTabReloader( | 1187 GetStateOfTabReloader( |
1187 browser->GetTabContentsAt(initial_active_index))); | 1188 chrome::GetTabContentsAt(browser, initial_active_index))); |
1188 } | 1189 } |
1189 | 1190 |
1190 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, | 1191 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, |
1191 int num_loading_tabs, | 1192 int num_loading_tabs, |
1192 int num_timed_out_tabs) { | 1193 int num_timed_out_tabs) { |
1193 MultiNavigationObserver navigation_observer; | 1194 MultiNavigationObserver navigation_observer; |
1194 CaptivePortalObserver portal_observer(browser->profile()); | 1195 CaptivePortalObserver portal_observer(browser->profile()); |
1195 | 1196 |
1196 int initial_tab_count = browser->tab_count(); | 1197 int initial_tab_count = browser->tab_count(); |
1197 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1198 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1198 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1199 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); |
1199 | 1200 |
1200 int login_tab_index = browser->active_index(); | 1201 int login_tab_index = browser->active_index(); |
1201 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1202 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1202 GetStateOfTabReloader(browser->GetActiveTabContents())); | 1203 GetStateOfTabReloader(chrome::GetActiveTabContents(browser))); |
1203 ASSERT_TRUE(IsLoginTab(browser->GetActiveTabContents())); | 1204 ASSERT_TRUE(IsLoginTab(chrome::GetActiveTabContents(browser))); |
1204 | 1205 |
1205 // Do the navigation. | 1206 // Do the navigation. |
1206 content::RenderViewHost* render_view_host = | 1207 content::RenderViewHost* render_view_host = |
1207 browser->GetActiveWebContents()->GetRenderViewHost(); | 1208 chrome::GetActiveWebContents(browser)->GetRenderViewHost(); |
1208 render_view_host->ExecuteJavascriptInWebFrame( | 1209 render_view_host->ExecuteJavascriptInWebFrame( |
1209 string16(), | 1210 string16(), |
1210 ASCIIToUTF16("submitForm()")); | 1211 ASCIIToUTF16("submitForm()")); |
1211 | 1212 |
1212 portal_observer.WaitForResults(1); | 1213 portal_observer.WaitForResults(1); |
1213 navigation_observer.WaitForNavigations(1); | 1214 navigation_observer.WaitForNavigations(1); |
1214 | 1215 |
1215 // Check the captive portal result. | 1216 // Check the captive portal result. |
1216 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1217 EXPECT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1217 portal_observer.captive_portal_result()); | 1218 portal_observer.captive_portal_result()); |
1218 EXPECT_EQ(1, portal_observer.num_results_received()); | 1219 EXPECT_EQ(1, portal_observer.num_results_received()); |
1219 EXPECT_FALSE(CheckPending(browser)); | 1220 EXPECT_FALSE(CheckPending(browser)); |
1220 | 1221 |
1221 // Make sure not much has changed. | 1222 // Make sure not much has changed. |
1222 EXPECT_EQ(initial_tab_count, browser->tab_count()); | 1223 EXPECT_EQ(initial_tab_count, browser->tab_count()); |
1223 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1224 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1224 EXPECT_EQ(num_loading_tabs + num_timed_out_tabs, NumBrokenTabs()); | 1225 EXPECT_EQ(num_loading_tabs + num_timed_out_tabs, NumBrokenTabs()); |
1225 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1226 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1226 GetStateOfTabReloader(browser->GetTabContentsAt(login_tab_index))); | 1227 GetStateOfTabReloader(chrome::GetTabContentsAt(browser, |
1227 EXPECT_TRUE(IsLoginTab(browser->GetTabContentsAt(login_tab_index))); | 1228 login_tab_index))); |
| 1229 EXPECT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser, login_tab_index))); |
1228 | 1230 |
1229 // Make sure there were no unexpected navigations. | 1231 // Make sure there were no unexpected navigations. |
1230 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1232 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1231 browser->GetWebContentsAt(login_tab_index))); | 1233 chrome::GetWebContentsAt(browser, login_tab_index))); |
1232 } | 1234 } |
1233 | 1235 |
1234 void CaptivePortalBrowserTest::Login(Browser* browser, | 1236 void CaptivePortalBrowserTest::Login(Browser* browser, |
1235 int num_loading_tabs, | 1237 int num_loading_tabs, |
1236 int num_timed_out_tabs) { | 1238 int num_timed_out_tabs) { |
1237 // Simulate logging in. | 1239 // Simulate logging in. |
1238 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | 1240 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); |
1239 | 1241 |
1240 MultiNavigationObserver navigation_observer; | 1242 MultiNavigationObserver navigation_observer; |
1241 CaptivePortalObserver portal_observer(browser->profile()); | 1243 CaptivePortalObserver portal_observer(browser->profile()); |
1242 | 1244 |
1243 int initial_tab_count = browser->tab_count(); | 1245 int initial_tab_count = browser->tab_count(); |
1244 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1246 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1245 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1247 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); |
1246 | 1248 |
1247 // Verify that the login page is on top. | 1249 // Verify that the login page is on top. |
1248 int login_tab_index = browser->active_index(); | 1250 int login_tab_index = browser->active_index(); |
1249 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1251 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1250 GetStateOfTabReloader(browser->GetTabContentsAt(login_tab_index))); | 1252 GetStateOfTabReloader(chrome::GetTabContentsAt(browser, |
1251 ASSERT_TRUE(IsLoginTab(browser->GetTabContentsAt(login_tab_index))); | 1253 login_tab_index))); |
| 1254 ASSERT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser, login_tab_index))); |
1252 | 1255 |
1253 // Trigger a navigation. | 1256 // Trigger a navigation. |
1254 content::RenderViewHost* render_view_host = | 1257 content::RenderViewHost* render_view_host = |
1255 browser->GetActiveWebContents()->GetRenderViewHost(); | 1258 chrome::GetActiveWebContents(browser)->GetRenderViewHost(); |
1256 render_view_host->ExecuteJavascriptInWebFrame( | 1259 render_view_host->ExecuteJavascriptInWebFrame( |
1257 string16(), | 1260 string16(), |
1258 ASCIIToUTF16("submitForm()")); | 1261 ASCIIToUTF16("submitForm()")); |
1259 | 1262 |
1260 portal_observer.WaitForResults(1); | 1263 portal_observer.WaitForResults(1); |
1261 | 1264 |
1262 // Wait for all the timed out tabs to reload. | 1265 // Wait for all the timed out tabs to reload. |
1263 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs); | 1266 navigation_observer.WaitForNavigations(1 + num_timed_out_tabs); |
1264 EXPECT_EQ(1, portal_observer.num_results_received()); | 1267 EXPECT_EQ(1, portal_observer.num_results_received()); |
1265 | 1268 |
1266 // The tabs that were loading before should still be loading, and now be in | 1269 // The tabs that were loading before should still be loading, and now be in |
1267 // STATE_NEEDS_RELOAD. | 1270 // STATE_NEEDS_RELOAD. |
1268 EXPECT_EQ(0, NumBrokenTabs()); | 1271 EXPECT_EQ(0, NumBrokenTabs()); |
1269 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1272 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1270 EXPECT_EQ(num_loading_tabs, NumNeedReloadTabs()); | 1273 EXPECT_EQ(num_loading_tabs, NumNeedReloadTabs()); |
1271 | 1274 |
1272 // Make sure that the broken tabs have reloaded, and there's no more | 1275 // Make sure that the broken tabs have reloaded, and there's no more |
1273 // captive portal tab. | 1276 // captive portal tab. |
1274 EXPECT_EQ(initial_tab_count, browser->tab_count()); | 1277 EXPECT_EQ(initial_tab_count, browser->tab_count()); |
1275 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1278 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1276 GetStateOfTabReloaderAt(browser, login_tab_index)); | 1279 GetStateOfTabReloaderAt(browser, login_tab_index)); |
1277 EXPECT_FALSE(IsLoginTab(browser->GetTabContentsAt(login_tab_index))); | 1280 EXPECT_FALSE(IsLoginTab(chrome::GetTabContentsAt(browser, login_tab_index))); |
1278 | 1281 |
1279 // Make sure there were no unexpected navigations of the login tab. | 1282 // Make sure there were no unexpected navigations of the login tab. |
1280 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1283 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1281 browser->GetWebContentsAt(login_tab_index))); | 1284 chrome::GetWebContentsAt(browser, login_tab_index))); |
1282 } | 1285 } |
1283 | 1286 |
1284 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, | 1287 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, |
1285 int num_loading_tabs) { | 1288 int num_loading_tabs) { |
1286 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1289 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1287 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); | 1290 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); |
1288 EXPECT_EQ(0, NumBrokenTabs()); | 1291 EXPECT_EQ(0, NumBrokenTabs()); |
1289 | 1292 |
1290 int initial_num_tabs = browser->tab_count(); | 1293 int initial_num_tabs = browser->tab_count(); |
1291 int initial_active_tab = browser->active_index(); | 1294 int initial_active_tab = browser->active_index(); |
(...skipping 21 matching lines...) Expand all Loading... |
1313 | 1316 |
1314 void CaptivePortalBrowserTest::FailLoadsWithoutLogin(Browser* browser, | 1317 void CaptivePortalBrowserTest::FailLoadsWithoutLogin(Browser* browser, |
1315 int num_loading_tabs) { | 1318 int num_loading_tabs) { |
1316 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1319 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1317 ASSERT_EQ(0, NumNeedReloadTabs()); | 1320 ASSERT_EQ(0, NumNeedReloadTabs()); |
1318 EXPECT_EQ(num_loading_tabs, NumBrokenTabs()); | 1321 EXPECT_EQ(num_loading_tabs, NumBrokenTabs()); |
1319 | 1322 |
1320 int initial_num_tabs = browser->tab_count(); | 1323 int initial_num_tabs = browser->tab_count(); |
1321 int login_tab = browser->active_index(); | 1324 int login_tab = browser->active_index(); |
1322 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1325 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1323 GetStateOfTabReloader(browser->GetActiveTabContents())); | 1326 GetStateOfTabReloader(chrome::GetActiveTabContents(browser))); |
1324 ASSERT_TRUE(IsLoginTab(browser->GetActiveTabContents())); | 1327 ASSERT_TRUE(IsLoginTab(chrome::GetActiveTabContents(browser))); |
1325 | 1328 |
1326 CaptivePortalObserver portal_observer(browser->profile()); | 1329 CaptivePortalObserver portal_observer(browser->profile()); |
1327 MultiNavigationObserver navigation_observer; | 1330 MultiNavigationObserver navigation_observer; |
1328 // Connection(s) finally time out. There should have already been a call | 1331 // Connection(s) finally time out. There should have already been a call |
1329 // to wait for the requests to be issued. | 1332 // to wait for the requests to be issued. |
1330 URLRequestTimeoutOnDemandJob::FailJobs(num_loading_tabs); | 1333 URLRequestTimeoutOnDemandJob::FailJobs(num_loading_tabs); |
1331 | 1334 |
1332 navigation_observer.WaitForNavigations(num_loading_tabs); | 1335 navigation_observer.WaitForNavigations(num_loading_tabs); |
1333 | 1336 |
1334 // No captive portal checks should have ocurred or be pending, and there | 1337 // No captive portal checks should have ocurred or be pending, and there |
1335 // should be no new tabs. | 1338 // should be no new tabs. |
1336 EXPECT_EQ(0, portal_observer.num_results_received()); | 1339 EXPECT_EQ(0, portal_observer.num_results_received()); |
1337 EXPECT_FALSE(CheckPending(browser)); | 1340 EXPECT_FALSE(CheckPending(browser)); |
1338 EXPECT_EQ(initial_num_tabs, browser->tab_count()); | 1341 EXPECT_EQ(initial_num_tabs, browser->tab_count()); |
1339 | 1342 |
1340 EXPECT_EQ(0, NumNeedReloadTabs()); | 1343 EXPECT_EQ(0, NumNeedReloadTabs()); |
1341 EXPECT_EQ(0, NumLoadingTabs()); | 1344 EXPECT_EQ(0, NumLoadingTabs()); |
1342 EXPECT_EQ(num_loading_tabs, NumBrokenTabs()); | 1345 EXPECT_EQ(num_loading_tabs, NumBrokenTabs()); |
1343 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1346 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1344 GetStateOfTabReloader(browser->GetActiveTabContents())); | 1347 GetStateOfTabReloader(chrome::GetActiveTabContents(browser))); |
1345 EXPECT_TRUE(IsLoginTab(browser->GetActiveTabContents())); | 1348 EXPECT_TRUE(IsLoginTab(chrome::GetActiveTabContents(browser))); |
1346 EXPECT_EQ(login_tab, browser->active_index()); | 1349 EXPECT_EQ(login_tab, browser->active_index()); |
1347 | 1350 |
1348 EXPECT_EQ(0, navigation_observer.NumNavigationsForTab( | 1351 EXPECT_EQ(0, navigation_observer.NumNavigationsForTab( |
1349 browser->GetWebContentsAt(login_tab))); | 1352 chrome::GetWebContentsAt(browser, login_tab))); |
1350 } | 1353 } |
1351 | 1354 |
1352 void CaptivePortalBrowserTest::SetSlowSSLLoadTime( | 1355 void CaptivePortalBrowserTest::SetSlowSSLLoadTime( |
1353 CaptivePortalTabReloader* tab_reloader, | 1356 CaptivePortalTabReloader* tab_reloader, |
1354 base::TimeDelta slow_ssl_load_time) { | 1357 base::TimeDelta slow_ssl_load_time) { |
1355 tab_reloader->set_slow_ssl_load_time(slow_ssl_load_time); | 1358 tab_reloader->set_slow_ssl_load_time(slow_ssl_load_time); |
1356 } | 1359 } |
1357 | 1360 |
1358 CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader( | 1361 CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader( |
1359 TabContents* tab_contents) const { | 1362 TabContents* tab_contents) const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 GetStateOfTabReloaderAt(browser(), 0)); | 1487 GetStateOfTabReloaderAt(browser(), 0)); |
1485 | 1488 |
1486 Login(incognito_browser, 1, 0); | 1489 Login(incognito_browser, 1, 0); |
1487 FailLoadsAfterLogin(incognito_browser, 1); | 1490 FailLoadsAfterLogin(incognito_browser, 1); |
1488 | 1491 |
1489 EXPECT_EQ(1, browser()->tab_count()); | 1492 EXPECT_EQ(1, browser()->tab_count()); |
1490 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1493 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1491 GetStateOfTabReloaderAt(browser(), 0)); | 1494 GetStateOfTabReloaderAt(browser(), 0)); |
1492 | 1495 |
1493 EXPECT_EQ(0, navigation_observer.NumNavigationsForTab( | 1496 EXPECT_EQ(0, navigation_observer.NumNavigationsForTab( |
1494 browser()->GetWebContentsAt(0))); | 1497 chrome::GetWebContentsAt(browser(), 0))); |
1495 EXPECT_EQ(0, non_incognito_portal_observer.num_results_received()); | 1498 EXPECT_EQ(0, non_incognito_portal_observer.num_results_received()); |
1496 } | 1499 } |
1497 | 1500 |
1498 // The captive portal page is opened before the SSL page times out, | 1501 // The captive portal page is opened before the SSL page times out, |
1499 // but the user logs in only after the page times out. | 1502 // but the user logs in only after the page times out. |
1500 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginSlow) { | 1503 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginSlow) { |
1501 SlowLoadBehindCaptivePortal(browser(), true); | 1504 SlowLoadBehindCaptivePortal(browser(), true); |
1502 FailLoadsWithoutLogin(browser(), 1); | 1505 FailLoadsWithoutLogin(browser(), 1); |
1503 Login(browser(), 0, 1); | 1506 Login(browser(), 0, 1); |
1504 } | 1507 } |
1505 | 1508 |
1506 // Checks the unlikely case that the tab times out before the timer triggers. | 1509 // Checks the unlikely case that the tab times out before the timer triggers. |
1507 // This most likely won't happen, but should still work: | 1510 // This most likely won't happen, but should still work: |
1508 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { | 1511 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { |
1509 FastTimeoutBehindCaptivePortal(browser(), true); | 1512 FastTimeoutBehindCaptivePortal(browser(), true); |
1510 Login(browser(), 0, 1); | 1513 Login(browser(), 0, 1); |
1511 } | 1514 } |
1512 | 1515 |
1513 // Tries navigating both the tab that encounters an SSL timeout and the | 1516 // Tries navigating both the tab that encounters an SSL timeout and the |
1514 // login tab twice, only logging in the second time. | 1517 // login tab twice, only logging in the second time. |
1515 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { | 1518 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { |
1516 FastTimeoutBehindCaptivePortal(browser(), true); | 1519 FastTimeoutBehindCaptivePortal(browser(), true); |
1517 | 1520 |
1518 // Activate the timed out tab and navigate it to a timeout again. | 1521 // Activate the timed out tab and navigate it to a timeout again. |
1519 browser()->ActivateTabAt(0, true); | 1522 chrome::ActivateTabAt(browser(), 0, true); |
1520 FastTimeoutBehindCaptivePortal(browser(), false); | 1523 FastTimeoutBehindCaptivePortal(browser(), false); |
1521 | 1524 |
1522 // Activate and navigate the captive portal tab. This should not trigger a | 1525 // Activate and navigate the captive portal tab. This should not trigger a |
1523 // reload of the tab with the error. | 1526 // reload of the tab with the error. |
1524 browser()->ActivateTabAt(1, true); | 1527 chrome::ActivateTabAt(browser(), 1, true); |
1525 NavigateLoginTab(browser(), 0, 1); | 1528 NavigateLoginTab(browser(), 0, 1); |
1526 | 1529 |
1527 // Simulate logging in. | 1530 // Simulate logging in. |
1528 Login(browser(), 0, 1); | 1531 Login(browser(), 0, 1); |
1529 } | 1532 } |
1530 | 1533 |
1531 // After the first SSL timeout, closes the login tab and makes sure it's opened | 1534 // After the first SSL timeout, closes the login tab and makes sure it's opened |
1532 // it again on a second timeout. | 1535 // it again on a second timeout. |
1533 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, CloseLoginTab) { | 1536 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, CloseLoginTab) { |
1534 // First load starts, opens a login tab, and then times out. | 1537 // First load starts, opens a login tab, and then times out. |
(...skipping 25 matching lines...) Expand all Loading... |
1560 FilePath(FILE_PATH_LITERAL("title2.html"))), | 1563 FilePath(FILE_PATH_LITERAL("title2.html"))), |
1561 NEW_FOREGROUND_TAB, | 1564 NEW_FOREGROUND_TAB, |
1562 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1565 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1563 | 1566 |
1564 ASSERT_EQ(3, browser()->tab_count()); | 1567 ASSERT_EQ(3, browser()->tab_count()); |
1565 EXPECT_FALSE(CheckPending(browser())); | 1568 EXPECT_FALSE(CheckPending(browser())); |
1566 EXPECT_EQ(0, portal_observer.num_results_received()); | 1569 EXPECT_EQ(0, portal_observer.num_results_received()); |
1567 EXPECT_EQ(1, NumLoadingTabs()); | 1570 EXPECT_EQ(1, NumLoadingTabs()); |
1568 EXPECT_EQ(1, navigation_observer.num_navigations()); | 1571 EXPECT_EQ(1, navigation_observer.num_navigations()); |
1569 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1572 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1570 browser()->GetWebContentsAt(2))); | 1573 chrome::GetWebContentsAt(browser(), 2))); |
1571 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1574 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1572 GetStateOfTabReloaderAt(browser(), 0)); | 1575 GetStateOfTabReloaderAt(browser(), 0)); |
1573 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1576 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1574 GetStateOfTabReloader(browser()->GetTabContentsAt(1))); | 1577 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 1))); |
1575 ASSERT_TRUE(IsLoginTab(browser()->GetTabContentsAt(1))); | 1578 ASSERT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser(), 1))); |
1576 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1579 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1577 GetStateOfTabReloaderAt(browser(), 2)); | 1580 GetStateOfTabReloaderAt(browser(), 2)); |
1578 ASSERT_EQ(2, browser()->active_index()); | 1581 ASSERT_EQ(2, browser()->active_index()); |
1579 | 1582 |
1580 SlowLoadBehindCaptivePortal(browser(), false); | 1583 SlowLoadBehindCaptivePortal(browser(), false); |
1581 | 1584 |
1582 browser()->ActivateTabAt(1, true); | 1585 chrome::ActivateTabAt(browser(), 1, true); |
1583 Login(browser(), 2, 0); | 1586 Login(browser(), 2, 0); |
1584 FailLoadsAfterLogin(browser(), 2); | 1587 FailLoadsAfterLogin(browser(), 2); |
1585 } | 1588 } |
1586 | 1589 |
1587 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, AbortLoad) { | 1590 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, AbortLoad) { |
1588 SlowLoadBehindCaptivePortal(browser(), true); | 1591 SlowLoadBehindCaptivePortal(browser(), true); |
1589 | 1592 |
1590 // Abandon the request. | 1593 // Abandon the request. |
1591 URLRequestTimeoutOnDemandJob::WaitForJobs(1); | 1594 URLRequestTimeoutOnDemandJob::WaitForJobs(1); |
1592 URLRequestTimeoutOnDemandJob::AbandonJobs(1); | 1595 URLRequestTimeoutOnDemandJob::AbandonJobs(1); |
1593 | 1596 |
1594 CaptivePortalObserver portal_observer(browser()->profile()); | 1597 CaptivePortalObserver portal_observer(browser()->profile()); |
1595 MultiNavigationObserver navigation_observer; | 1598 MultiNavigationObserver navigation_observer; |
1596 | 1599 |
1597 // Switch back to the hung tab from the login tab, and abort the navigation. | 1600 // Switch back to the hung tab from the login tab, and abort the navigation. |
1598 browser()->ActivateTabAt(0, true); | 1601 chrome::ActivateTabAt(browser(), 0, true); |
1599 chrome::Stop(browser()); | 1602 chrome::Stop(browser()); |
1600 navigation_observer.WaitForNavigations(1); | 1603 navigation_observer.WaitForNavigations(1); |
1601 | 1604 |
1602 EXPECT_EQ(0, NumBrokenTabs()); | 1605 EXPECT_EQ(0, NumBrokenTabs()); |
1603 EXPECT_EQ(0, portal_observer.num_results_received()); | 1606 EXPECT_EQ(0, portal_observer.num_results_received()); |
1604 EXPECT_FALSE(CheckPending(browser())); | 1607 EXPECT_FALSE(CheckPending(browser())); |
1605 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1608 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1606 GetStateOfTabReloaderAt(browser(), 0)); | 1609 GetStateOfTabReloaderAt(browser(), 0)); |
1607 | 1610 |
1608 browser()->ActivateTabAt(1, true); | 1611 chrome::ActivateTabAt(browser(), 1, true); |
1609 Login(browser(), 0, 0); | 1612 Login(browser(), 0, 0); |
1610 } | 1613 } |
1611 | 1614 |
1612 // Checks the case where the timed out tab is successfully navigated before | 1615 // Checks the case where the timed out tab is successfully navigated before |
1613 // logging in. | 1616 // logging in. |
1614 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, NavigateBrokenTab) { | 1617 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, NavigateBrokenTab) { |
1615 // Go to the error page. | 1618 // Go to the error page. |
1616 SlowLoadBehindCaptivePortal(browser(), true); | 1619 SlowLoadBehindCaptivePortal(browser(), true); |
1617 FailLoadsWithoutLogin(browser(), 1); | 1620 FailLoadsWithoutLogin(browser(), 1); |
1618 | 1621 |
1619 // Navigate the error tab to a non-error page. | 1622 // Navigate the error tab to a non-error page. |
1620 browser()->ActivateTabAt(0, true); | 1623 chrome::ActivateTabAt(browser(), 0, true); |
1621 ui_test_utils::NavigateToURL(browser(), | 1624 ui_test_utils::NavigateToURL(browser(), |
1622 URLRequestMockHTTPJob::GetMockUrl( | 1625 URLRequestMockHTTPJob::GetMockUrl( |
1623 FilePath(FILE_PATH_LITERAL("title2.html")))); | 1626 FilePath(FILE_PATH_LITERAL("title2.html")))); |
1624 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1627 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1625 GetStateOfTabReloaderAt(browser(), 0)); | 1628 GetStateOfTabReloaderAt(browser(), 0)); |
1626 | 1629 |
1627 // Simulate logging in. | 1630 // Simulate logging in. |
1628 browser()->ActivateTabAt(1, true); | 1631 chrome::ActivateTabAt(browser(), 1, true); |
1629 Login(browser(), 0, 0); | 1632 Login(browser(), 0, 0); |
1630 } | 1633 } |
1631 | 1634 |
1632 // Navigates a broken, but still loading, tab to another such page before | 1635 // Navigates a broken, but still loading, tab to another such page before |
1633 // logging in. | 1636 // logging in. |
1634 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | 1637 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
1635 NavigateBrokenToTimeoutTabWhileLoading) { | 1638 NavigateBrokenToTimeoutTabWhileLoading) { |
1636 // Go to the error page. | 1639 // Go to the error page. |
1637 SlowLoadBehindCaptivePortal(browser(), true); | 1640 SlowLoadBehindCaptivePortal(browser(), true); |
1638 | 1641 |
1639 // Abandon the request. | 1642 // Abandon the request. |
1640 URLRequestTimeoutOnDemandJob::WaitForJobs(1); | 1643 URLRequestTimeoutOnDemandJob::WaitForJobs(1); |
1641 URLRequestTimeoutOnDemandJob::AbandonJobs(1); | 1644 URLRequestTimeoutOnDemandJob::AbandonJobs(1); |
1642 | 1645 |
1643 CaptivePortalTabReloader* tab_reloader = | 1646 CaptivePortalTabReloader* tab_reloader = |
1644 GetTabReloader(browser()->GetTabContentsAt(0)); | 1647 GetTabReloader(chrome::GetTabContentsAt(browser(), 0)); |
1645 ASSERT_TRUE(tab_reloader); | 1648 ASSERT_TRUE(tab_reloader); |
1646 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); | 1649 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); |
1647 | 1650 |
1648 CaptivePortalObserver portal_observer(browser()->profile()); | 1651 CaptivePortalObserver portal_observer(browser()->profile()); |
1649 MultiNavigationObserver navigation_observer; | 1652 MultiNavigationObserver navigation_observer; |
1650 | 1653 |
1651 // Navigate the error tab to another slow loading page. Can't have | 1654 // Navigate the error tab to another slow loading page. Can't have |
1652 // ui_test_utils do the navigation because it will wait for loading tabs to | 1655 // ui_test_utils do the navigation because it will wait for loading tabs to |
1653 // stop loading before navigating. | 1656 // stop loading before navigating. |
1654 browser()->ActivateTabAt(0, true); | 1657 chrome::ActivateTabAt(browser(), 0, true); |
1655 browser()->OpenURL(content::OpenURLParams(GURL(kMockHttpsUrl), | 1658 browser()->OpenURL(content::OpenURLParams(GURL(kMockHttpsUrl), |
1656 content::Referrer(), | 1659 content::Referrer(), |
1657 CURRENT_TAB, | 1660 CURRENT_TAB, |
1658 content::PAGE_TRANSITION_TYPED, | 1661 content::PAGE_TRANSITION_TYPED, |
1659 false)); | 1662 false)); |
1660 navigation_observer.WaitForNavigations(1); | 1663 navigation_observer.WaitForNavigations(1); |
1661 portal_observer.WaitForResults(1); | 1664 portal_observer.WaitForResults(1); |
1662 EXPECT_FALSE(CheckPending(browser())); | 1665 EXPECT_FALSE(CheckPending(browser())); |
1663 EXPECT_EQ(1, NumLoadingTabs()); | 1666 EXPECT_EQ(1, NumLoadingTabs()); |
1664 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1667 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1665 GetStateOfTabReloaderAt(browser(), 0)); | 1668 GetStateOfTabReloaderAt(browser(), 0)); |
1666 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1669 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1667 GetStateOfTabReloader(browser()->GetTabContentsAt(1))); | 1670 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 1))); |
1668 ASSERT_TRUE(IsLoginTab(browser()->GetTabContentsAt(1))); | 1671 ASSERT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser(), 1))); |
1669 | 1672 |
1670 // Need to make sure the request has been issued before logging in. | 1673 // Need to make sure the request has been issued before logging in. |
1671 URLRequestTimeoutOnDemandJob::WaitForJobs(1); | 1674 URLRequestTimeoutOnDemandJob::WaitForJobs(1); |
1672 | 1675 |
1673 // Simulate logging in. | 1676 // Simulate logging in. |
1674 browser()->ActivateTabAt(1, true); | 1677 chrome::ActivateTabAt(browser(), 1, true); |
1675 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); | 1678 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); |
1676 Login(browser(), 1, 0); | 1679 Login(browser(), 1, 0); |
1677 | 1680 |
1678 // Timeout occurs, and page is automatically reloaded. | 1681 // Timeout occurs, and page is automatically reloaded. |
1679 FailLoadsAfterLogin(browser(), 1); | 1682 FailLoadsAfterLogin(browser(), 1); |
1680 } | 1683 } |
1681 | 1684 |
1682 // Checks that navigating a timed out tab back clears its state. | 1685 // Checks that navigating a timed out tab back clears its state. |
1683 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBack) { | 1686 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBack) { |
1684 // Navigate to a working page. | 1687 // Navigate to a working page. |
1685 ui_test_utils::NavigateToURL( | 1688 ui_test_utils::NavigateToURL( |
1686 browser(), | 1689 browser(), |
1687 URLRequestMockHTTPJob::GetMockUrl( | 1690 URLRequestMockHTTPJob::GetMockUrl( |
1688 FilePath(FILE_PATH_LITERAL("title2.html")))); | 1691 FilePath(FILE_PATH_LITERAL("title2.html")))); |
1689 | 1692 |
1690 // Go to the error page. | 1693 // Go to the error page. |
1691 SlowLoadBehindCaptivePortal(browser(), true); | 1694 SlowLoadBehindCaptivePortal(browser(), true); |
1692 FailLoadsWithoutLogin(browser(), 1); | 1695 FailLoadsWithoutLogin(browser(), 1); |
1693 | 1696 |
1694 CaptivePortalObserver portal_observer(browser()->profile()); | 1697 CaptivePortalObserver portal_observer(browser()->profile()); |
1695 MultiNavigationObserver navigation_observer; | 1698 MultiNavigationObserver navigation_observer; |
1696 | 1699 |
1697 // Activate the error page tab again and go back. | 1700 // Activate the error page tab again and go back. |
1698 browser()->ActivateTabAt(0, true); | 1701 chrome::ActivateTabAt(browser(), 0, true); |
1699 chrome::GoBack(browser(), CURRENT_TAB); | 1702 chrome::GoBack(browser(), CURRENT_TAB); |
1700 navigation_observer.WaitForNavigations(1); | 1703 navigation_observer.WaitForNavigations(1); |
1701 | 1704 |
1702 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1705 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1703 browser()->GetWebContentsAt(0))); | 1706 chrome::GetWebContentsAt(browser(), 0))); |
1704 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1707 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1705 GetStateOfTabReloaderAt(browser(), 0)); | 1708 GetStateOfTabReloaderAt(browser(), 0)); |
1706 EXPECT_EQ(0, portal_observer.num_results_received()); | 1709 EXPECT_EQ(0, portal_observer.num_results_received()); |
1707 } | 1710 } |
1708 | 1711 |
1709 // Checks that navigating back to a timeout triggers captive portal detection. | 1712 // Checks that navigating back to a timeout triggers captive portal detection. |
1710 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBackToTimeout) { | 1713 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, GoBackToTimeout) { |
1711 // Disable captive portal detection so the first navigation doesn't open a | 1714 // Disable captive portal detection so the first navigation doesn't open a |
1712 // login tab. | 1715 // login tab. |
1713 EnableCaptivePortalDetection(browser()->profile(), false); | 1716 EnableCaptivePortalDetection(browser()->profile(), false); |
1714 | 1717 |
1715 SlowLoadNoCaptivePortal(browser(), RESULT_INTERNET_CONNECTED); | 1718 SlowLoadNoCaptivePortal(browser(), RESULT_INTERNET_CONNECTED); |
1716 | 1719 |
1717 // Navigate to a working page. | 1720 // Navigate to a working page. |
1718 ui_test_utils::NavigateToURL(browser(), | 1721 ui_test_utils::NavigateToURL(browser(), |
1719 URLRequestMockHTTPJob::GetMockUrl( | 1722 URLRequestMockHTTPJob::GetMockUrl( |
1720 FilePath(FILE_PATH_LITERAL("title2.html")))); | 1723 FilePath(FILE_PATH_LITERAL("title2.html")))); |
1721 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1724 ASSERT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1722 GetStateOfTabReloaderAt(browser(), 0)); | 1725 GetStateOfTabReloaderAt(browser(), 0)); |
1723 | 1726 |
1724 EnableCaptivePortalDetection(browser()->profile(), true); | 1727 EnableCaptivePortalDetection(browser()->profile(), true); |
1725 | 1728 |
1726 CaptivePortalTabReloader* tab_reloader = | 1729 CaptivePortalTabReloader* tab_reloader = |
1727 GetTabReloader(browser()->GetActiveTabContents()); | 1730 GetTabReloader(chrome::GetActiveTabContents(browser())); |
1728 ASSERT_TRUE(tab_reloader); | 1731 ASSERT_TRUE(tab_reloader); |
1729 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); | 1732 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); |
1730 | 1733 |
1731 // Go to the error page. | 1734 // Go to the error page. |
1732 MultiNavigationObserver navigation_observer; | 1735 MultiNavigationObserver navigation_observer; |
1733 CaptivePortalObserver portal_observer(browser()->profile()); | 1736 CaptivePortalObserver portal_observer(browser()->profile()); |
1734 chrome::GoBack(browser(), CURRENT_TAB); | 1737 chrome::GoBack(browser(), CURRENT_TAB); |
1735 | 1738 |
1736 // Wait for both the check triggered by the broken tab and the first load | 1739 // Wait for both the check triggered by the broken tab and the first load |
1737 // of the login tab, and for the login tab to stop loading. | 1740 // of the login tab, and for the login tab to stop loading. |
1738 portal_observer.WaitForResults(2); | 1741 portal_observer.WaitForResults(2); |
1739 navigation_observer.WaitForNavigations(1); | 1742 navigation_observer.WaitForNavigations(1); |
1740 URLRequestTimeoutOnDemandJob::WaitForJobs(1); | 1743 URLRequestTimeoutOnDemandJob::WaitForJobs(1); |
1741 | 1744 |
1742 EXPECT_EQ(2, portal_observer.num_results_received()); | 1745 EXPECT_EQ(2, portal_observer.num_results_received()); |
1743 ASSERT_FALSE(CheckPending(browser())); | 1746 ASSERT_FALSE(CheckPending(browser())); |
1744 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1747 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1745 portal_observer.captive_portal_result()); | 1748 portal_observer.captive_portal_result()); |
1746 | 1749 |
1747 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1750 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1748 GetStateOfTabReloader(browser()->GetTabContentsAt(0))); | 1751 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 0))); |
1749 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1752 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1750 GetStateOfTabReloader(browser()->GetTabContentsAt(1))); | 1753 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 1))); |
1751 ASSERT_TRUE(IsLoginTab(browser()->GetTabContentsAt(1))); | 1754 ASSERT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser(), 1))); |
1752 | 1755 |
1753 ASSERT_EQ(2, browser()->tab_count()); | 1756 ASSERT_EQ(2, browser()->tab_count()); |
1754 EXPECT_EQ(1, browser()->active_index()); | 1757 EXPECT_EQ(1, browser()->active_index()); |
1755 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1758 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1756 browser()->GetWebContentsAt(1))); | 1759 chrome::GetWebContentsAt(browser(), 1))); |
1757 EXPECT_EQ(1, NumLoadingTabs()); | 1760 EXPECT_EQ(1, NumLoadingTabs()); |
1758 | 1761 |
1759 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); | 1762 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); |
1760 Login(browser(), 1, 0); | 1763 Login(browser(), 1, 0); |
1761 FailLoadsAfterLogin(browser(), 1); | 1764 FailLoadsAfterLogin(browser(), 1); |
1762 } | 1765 } |
1763 | 1766 |
1764 // Checks that reloading a timeout triggers captive portal detection. | 1767 // Checks that reloading a timeout triggers captive portal detection. |
1765 // Much like the last test, though the captive portal is disabled before | 1768 // Much like the last test, though the captive portal is disabled before |
1766 // the inital navigation, rather than captive portal detection. | 1769 // the inital navigation, rather than captive portal detection. |
1767 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, ReloadTimeout) { | 1770 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, ReloadTimeout) { |
1768 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | 1771 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); |
1769 | 1772 |
1770 // Do the first navigation while not behind a captive portal. | 1773 // Do the first navigation while not behind a captive portal. |
1771 CaptivePortalObserver portal_observer(browser()->profile()); | 1774 CaptivePortalObserver portal_observer(browser()->profile()); |
1772 ui_test_utils::NavigateToURL(browser(), GURL(kMockHttpsUrl)); | 1775 ui_test_utils::NavigateToURL(browser(), GURL(kMockHttpsUrl)); |
1773 ASSERT_EQ(0, portal_observer.num_results_received()); | 1776 ASSERT_EQ(0, portal_observer.num_results_received()); |
1774 ASSERT_EQ(1, browser()->tab_count()); | 1777 ASSERT_EQ(1, browser()->tab_count()); |
1775 | 1778 |
1776 // A captive portal spontaneously appears. | 1779 // A captive portal spontaneously appears. |
1777 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(true); | 1780 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(true); |
1778 | 1781 |
1779 CaptivePortalTabReloader* tab_reloader = | 1782 CaptivePortalTabReloader* tab_reloader = |
1780 GetTabReloader(browser()->GetActiveTabContents()); | 1783 GetTabReloader(chrome::GetActiveTabContents(browser())); |
1781 ASSERT_TRUE(tab_reloader); | 1784 ASSERT_TRUE(tab_reloader); |
1782 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); | 1785 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); |
1783 | 1786 |
1784 MultiNavigationObserver navigation_observer; | 1787 MultiNavigationObserver navigation_observer; |
1785 browser()->GetActiveWebContents()->GetController().Reload(true); | 1788 chrome::GetActiveWebContents(browser())->GetController().Reload(true); |
1786 | 1789 |
1787 // Wait for the login tab to open, and the two captive portal results from | 1790 // Wait for the login tab to open, and the two captive portal results from |
1788 // opening an it. | 1791 // opening an it. |
1789 portal_observer.WaitForResults(2); | 1792 portal_observer.WaitForResults(2); |
1790 navigation_observer.WaitForNavigations(1); | 1793 navigation_observer.WaitForNavigations(1); |
1791 // Make sure the request has been issued. | 1794 // Make sure the request has been issued. |
1792 URLRequestTimeoutOnDemandJob::WaitForJobs(1); | 1795 URLRequestTimeoutOnDemandJob::WaitForJobs(1); |
1793 | 1796 |
1794 ASSERT_EQ(2, portal_observer.num_results_received()); | 1797 ASSERT_EQ(2, portal_observer.num_results_received()); |
1795 ASSERT_FALSE(CheckPending(browser())); | 1798 ASSERT_FALSE(CheckPending(browser())); |
1796 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1799 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1797 portal_observer.captive_portal_result()); | 1800 portal_observer.captive_portal_result()); |
1798 | 1801 |
1799 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1802 ASSERT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1800 GetStateOfTabReloader(browser()->GetTabContentsAt(0))); | 1803 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 0))); |
1801 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1804 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1802 GetStateOfTabReloader(browser()->GetTabContentsAt(1))); | 1805 GetStateOfTabReloader(chrome::GetTabContentsAt(browser(), 1))); |
1803 ASSERT_TRUE(IsLoginTab(browser()->GetTabContentsAt(1))); | 1806 ASSERT_TRUE(IsLoginTab(chrome::GetTabContentsAt(browser(), 1))); |
1804 | 1807 |
1805 ASSERT_EQ(2, browser()->tab_count()); | 1808 ASSERT_EQ(2, browser()->tab_count()); |
1806 EXPECT_EQ(1, browser()->active_index()); | 1809 EXPECT_EQ(1, browser()->active_index()); |
1807 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1810 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1808 browser()->GetWebContentsAt(1))); | 1811 chrome::GetWebContentsAt(browser(), 1))); |
1809 EXPECT_EQ(1, NumLoadingTabs()); | 1812 EXPECT_EQ(1, NumLoadingTabs()); |
1810 | 1813 |
1811 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); | 1814 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); |
1812 Login(browser(), 1, 0); | 1815 Login(browser(), 1, 0); |
1813 FailLoadsAfterLogin(browser(), 1); | 1816 FailLoadsAfterLogin(browser(), 1); |
1814 } | 1817 } |
1815 | 1818 |
1816 // Checks the case where there are two windows, and there's an SSL timeout in | 1819 // Checks the case where there are two windows, and there's an SSL timeout in |
1817 // the background one. | 1820 // the background one. |
1818 // Disabled: http://crbug.com/134357 | 1821 // Disabled: http://crbug.com/134357 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 | 1858 |
1856 // Make sure the active window hasn't changed, and its new tab is | 1859 // Make sure the active window hasn't changed, and its new tab is |
1857 // active. | 1860 // active. |
1858 ASSERT_EQ(active_browser, | 1861 ASSERT_EQ(active_browser, |
1859 browser::FindTabbedBrowser(browser()->profile(), true)); | 1862 browser::FindTabbedBrowser(browser()->profile(), true)); |
1860 ASSERT_EQ(1, active_browser->active_index()); | 1863 ASSERT_EQ(1, active_browser->active_index()); |
1861 | 1864 |
1862 // Check that the only two navigated tabs were the new error tab in the | 1865 // Check that the only two navigated tabs were the new error tab in the |
1863 // backround windows, and the login tab in the active window. | 1866 // backround windows, and the login tab in the active window. |
1864 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1867 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1865 inactive_browser->GetWebContentsAt(1))); | 1868 chrome::GetWebContentsAt(inactive_browser, 1))); |
1866 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1869 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1867 active_browser->GetWebContentsAt(1))); | 1870 chrome::GetWebContentsAt(active_browser, 1))); |
1868 EXPECT_EQ(0, NumLoadingTabs()); | 1871 EXPECT_EQ(0, NumLoadingTabs()); |
1869 | 1872 |
1870 // Check captive portal test results. | 1873 // Check captive portal test results. |
1871 portal_observer.WaitForResults(2); | 1874 portal_observer.WaitForResults(2); |
1872 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, | 1875 ASSERT_EQ(RESULT_BEHIND_CAPTIVE_PORTAL, |
1873 portal_observer.captive_portal_result()); | 1876 portal_observer.captive_portal_result()); |
1874 EXPECT_EQ(2, portal_observer.num_results_received()); | 1877 EXPECT_EQ(2, portal_observer.num_results_received()); |
1875 | 1878 |
1876 // Check the inactive browser. | 1879 // Check the inactive browser. |
1877 EXPECT_EQ(2, inactive_browser->tab_count()); | 1880 EXPECT_EQ(2, inactive_browser->tab_count()); |
1878 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1881 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1879 GetStateOfTabReloaderAt(inactive_browser, 0)); | 1882 GetStateOfTabReloaderAt(inactive_browser, 0)); |
1880 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1883 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1881 GetStateOfTabReloaderAt(inactive_browser, 1)); | 1884 GetStateOfTabReloaderAt(inactive_browser, 1)); |
1882 | 1885 |
1883 // Check the active browser. | 1886 // Check the active browser. |
1884 ASSERT_EQ(2, active_browser->tab_count()); | 1887 ASSERT_EQ(2, active_browser->tab_count()); |
1885 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1888 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1886 GetStateOfTabReloaderAt(active_browser, 0)); | 1889 GetStateOfTabReloaderAt(active_browser, 0)); |
1887 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1890 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1888 GetStateOfTabReloaderAt(active_browser, 1)); | 1891 GetStateOfTabReloaderAt(active_browser, 1)); |
1889 EXPECT_TRUE(IsLoginTab(active_browser->GetTabContentsAt(1))); | 1892 EXPECT_TRUE(IsLoginTab(chrome::GetTabContentsAt(active_browser, 1))); |
1890 | 1893 |
1891 // Simulate logging in. | 1894 // Simulate logging in. |
1892 Login(active_browser, 0, 1); | 1895 Login(active_browser, 0, 1); |
1893 } | 1896 } |
1894 | 1897 |
1895 } // namespace captive_portal | 1898 } // namespace captive_portal |
OLD | NEW |