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 <deque> | 5 #include <deque> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 base::FilePath app_dir; | 1115 base::FilePath app_dir; |
1116 PathService::Get(chrome::DIR_APP, &app_dir); | 1116 PathService::Get(chrome::DIR_APP, &app_dir); |
1117 command_line->AppendSwitchPath( | 1117 command_line->AppendSwitchPath( |
1118 switches::kExtraPluginDir, | 1118 switches::kExtraPluginDir, |
1119 app_dir.Append(FILE_PATH_LITERAL("plugins"))); | 1119 app_dir.Append(FILE_PATH_LITERAL("plugins"))); |
1120 #endif | 1120 #endif |
1121 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins); | 1121 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins); |
1122 command_line->AppendSwitch(switches::kEnableNpapi); | 1122 command_line->AppendSwitch(switches::kEnableNpapi); |
1123 } | 1123 } |
1124 | 1124 |
1125 void SetPreference(NetworkPredictionOptions value) { | |
1126 browser()->profile()->GetPrefs()->SetInteger( | |
1127 prefs::kNetworkPredictionOptions, value); | |
1128 } | |
1129 | |
1130 // Verifies whether ShouldDisableLocalPredictorDueToPreferencesAndNetwork | |
1131 // produces the desired output. | |
1132 void TestShouldDisableLocalPredictorPreferenceNetworkMatrix( | |
1133 bool preference_wifi_network_wifi, | |
1134 bool preference_wifi_network_4g, | |
1135 bool preference_always_network_wifi, | |
1136 bool preference_always_network_4g, | |
1137 bool preference_never_network_wifi, | |
1138 bool preference_never_network_4g) { | |
1139 Profile* profile = browser()->profile(); | |
1140 | |
1141 // Set real NetworkChangeNotifier singleton aside. | |
1142 scoped_ptr<NetworkChangeNotifier::DisableForTest> disable_for_test( | |
1143 new NetworkChangeNotifier::DisableForTest); | |
1144 | |
1145 // Set preference to WIFI_ONLY: prefetch when not on cellular. | |
1146 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_WIFI_ONLY); | |
1147 { | |
1148 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | |
1149 EXPECT_EQ( | |
1150 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1151 preference_wifi_network_wifi); | |
1152 } | |
1153 { | |
1154 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | |
1155 EXPECT_EQ( | |
1156 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1157 preference_wifi_network_4g); | |
1158 } | |
1159 | |
1160 // Set preference to ALWAYS: always prefetch. | |
1161 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_ALWAYS); | |
1162 { | |
1163 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | |
1164 EXPECT_EQ( | |
1165 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1166 preference_always_network_wifi); | |
1167 } | |
1168 { | |
1169 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | |
1170 EXPECT_EQ( | |
1171 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1172 preference_always_network_4g); | |
1173 } | |
1174 | |
1175 // Set preference to NEVER: never prefetch. | |
1176 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_NEVER); | |
1177 { | |
1178 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | |
1179 EXPECT_EQ( | |
1180 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1181 preference_never_network_wifi); | |
1182 } | |
1183 { | |
1184 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | |
1185 EXPECT_EQ( | |
1186 ShouldDisableLocalPredictorDueToPreferencesAndNetwork(profile), | |
1187 preference_never_network_4g); | |
1188 } | |
1189 } | |
1190 | |
1191 void SetUpOnMainThread() override { | 1125 void SetUpOnMainThread() override { |
1192 current_browser()->profile()->GetPrefs()->SetBoolean( | 1126 current_browser()->profile()->GetPrefs()->SetBoolean( |
1193 prefs::kPromptForDownload, false); | 1127 prefs::kPromptForDownload, false); |
1194 IncreasePrerenderMemory(); | 1128 IncreasePrerenderMemory(); |
1195 if (autostart_test_server_) | 1129 if (autostart_test_server_) |
1196 ASSERT_TRUE(test_server()->Start()); | 1130 ASSERT_TRUE(test_server()->Start()); |
1197 ChromeResourceDispatcherHostDelegate:: | 1131 ChromeResourceDispatcherHostDelegate:: |
1198 SetExternalProtocolHandlerDelegateForTesting( | 1132 SetExternalProtocolHandlerDelegateForTesting( |
1199 &external_protocol_handler_delegate_); | 1133 &external_protocol_handler_delegate_); |
1200 | 1134 |
(...skipping 2936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4137 prerender->contents()->set_skip_final_checks(true); | 4071 prerender->contents()->set_skip_final_checks(true); |
4138 | 4072 |
4139 // Navigate to the URL entered. | 4073 // Navigate to the URL entered. |
4140 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); | 4074 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); |
4141 | 4075 |
4142 // Prerender should be running, but abandoned. | 4076 // Prerender should be running, but abandoned. |
4143 EXPECT_TRUE( | 4077 EXPECT_TRUE( |
4144 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); | 4078 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); |
4145 } | 4079 } |
4146 | 4080 |
4147 // Prefetch should be allowed depending on preference and network type. | |
4148 // This test is for the bsae case: no Finch overrides should never disable. | |
4149 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
4150 LocalPredictorDisableWorksBaseCase) { | |
4151 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( | |
4152 false /*preference_wifi_network_wifi*/, | |
4153 false /*preference_wifi_network_4g*/, | |
4154 false /*preference_always_network_wifi*/, | |
4155 false /*preference_always_network_4g*/, | |
4156 false /*preference_never_network_wifi*/, | |
4157 false /*preference_never_network_4g*/); | |
4158 } | |
4159 | |
4160 } // namespace prerender | 4081 } // namespace prerender |
OLD | NEW |