OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/net/prediction_options.h" | 8 #include "chrome/browser/net/prediction_options.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 class PrefetchBrowserTestPredictionDisabled : public PrefetchBrowserTestBase { | 86 class PrefetchBrowserTestPredictionDisabled : public PrefetchBrowserTestBase { |
87 public: | 87 public: |
88 PrefetchBrowserTestPredictionDisabled() : PrefetchBrowserTestBase(true) {} | 88 PrefetchBrowserTestPredictionDisabled() : PrefetchBrowserTestBase(true) {} |
89 }; | 89 }; |
90 | 90 |
91 // Prefetch is disabled via field experiment. Prefetch should be dropped. | 91 // Prefetch is disabled via field experiment. Prefetch should be dropped. |
92 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionDisabled, | 92 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionDisabled, |
93 ExperimentDisabled) { | 93 ExperimentDisabled) { |
94 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 94 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
95 // Should not prefetch even if preference is ALWAYS. | 95 // Should not prefetch even if preference is WIFI_ONLY. |
96 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_ALWAYS); | 96 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_WIFI_ONLY); |
97 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 97 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
98 } | 98 } |
99 | 99 |
100 // Prefetch should be allowed depending on preference and network type. | 100 // Prefetch should be allowed depending on preference and network type. |
101 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPrediction, PreferenceWorks) { | 101 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPrediction, PreferenceWorks) { |
102 // Set real NetworkChangeNotifier singleton aside. | 102 // Set real NetworkChangeNotifier singleton aside. |
103 scoped_ptr<NetworkChangeNotifier::DisableForTest> disable_for_test( | 103 scoped_ptr<NetworkChangeNotifier::DisableForTest> disable_for_test( |
104 new NetworkChangeNotifier::DisableForTest); | 104 new NetworkChangeNotifier::DisableForTest); |
105 | 105 |
106 // Preference defaults to WIFI_ONLY: prefetch when not on cellular. | 106 // Preference defaults to WIFI_ONLY: prefetch when not on cellular. |
107 { | 107 { |
108 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | 108 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); |
109 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); | 109 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); |
110 } | 110 } |
111 { | 111 { |
112 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | 112 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); |
113 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 113 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
114 } | 114 } |
115 | 115 |
116 // Set preference to ALWAYS: always prefetch. | |
newt (away)
2016/02/22 19:45:38
The "ALWAYS" state is being merged into the WIFI_O
| |
117 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_ALWAYS); | |
118 { | |
119 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | |
120 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); | |
121 } | |
122 { | |
123 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | |
124 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); | |
125 } | |
126 | |
127 // Set preference to NEVER: never prefetch. | 116 // Set preference to NEVER: never prefetch. |
128 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_NEVER); | 117 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_NEVER); |
129 { | 118 { |
130 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); | 119 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifierWIFI); |
131 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 120 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
132 } | 121 } |
133 { | 122 { |
134 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); | 123 scoped_ptr<NetworkChangeNotifier> mock(new MockNetworkChangeNotifier4G); |
135 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 124 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
136 } | 125 } |
137 } | 126 } |
138 | 127 |
139 // Bug 339909: When in incognito mode the browser crashed due to an | 128 // Bug 339909: When in incognito mode the browser crashed due to an |
140 // uninitialized preference member. Verify that it no longer does. | 129 // uninitialized preference member. Verify that it no longer does. |
141 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPrediction, IncognitoTest) { | 130 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPrediction, IncognitoTest) { |
142 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 131 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
143 Browser* incognito_browser = | 132 Browser* incognito_browser = |
144 new Browser(Browser::CreateParams(incognito_profile)); | 133 new Browser(Browser::CreateParams(incognito_profile)); |
145 | 134 |
146 // Navigate just to have a tab in this window, otherwise there is no | 135 // Navigate just to have a tab in this window, otherwise there is no |
147 // WebContents for the incognito browser. | 136 // WebContents for the incognito browser. |
148 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 137 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
149 | 138 |
150 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); | 139 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); |
151 } | 140 } |
152 | 141 |
153 } // namespace | 142 } // namespace |
OLD | NEW |