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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698