OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | |
10 #include "chrome/browser/net/prediction_options.h" | 9 #include "chrome/browser/net/prediction_options.h" |
11 #include "chrome/browser/predictors/resource_prefetch_common.h" | 10 #include "chrome/browser/predictors/resource_prefetch_common.h" |
12 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
17 #include "components/variations/variations_params_manager.h" | 16 #include "components/variations/variations_params_manager.h" |
18 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 using chrome_browser_net::NetworkPredictionOptions; | 21 using chrome_browser_net::NetworkPredictionOptions; |
23 using net::NetworkChangeNotifier; | 22 using net::NetworkChangeNotifier; |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 class MockNetworkChangeNotifierWIFI : public NetworkChangeNotifier { | 26 class MockNetworkChangeNotifierWIFI : public NetworkChangeNotifier { |
28 public: | 27 public: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 EXPECT_FALSE(config.IsHighConfidenceForTest()); | 70 EXPECT_FALSE(config.IsHighConfidenceForTest()); |
72 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); | 71 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); |
73 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); | 72 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); |
74 EXPECT_FALSE(config.is_url_learning_enabled); | 73 EXPECT_FALSE(config.is_url_learning_enabled); |
75 EXPECT_FALSE(config.is_manifests_enabled); | 74 EXPECT_FALSE(config.is_manifests_enabled); |
76 EXPECT_FALSE(config.is_origin_learning_enabled); | 75 EXPECT_FALSE(config.is_origin_learning_enabled); |
77 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); | 76 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); |
78 } | 77 } |
79 | 78 |
80 protected: | 79 protected: |
81 base::MessageLoop loop_; | 80 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
82 content::TestBrowserThread ui_thread_; | |
83 std::unique_ptr<TestingProfile> profile_; | 81 std::unique_ptr<TestingProfile> profile_; |
84 }; | 82 }; |
85 | 83 |
86 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() | 84 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() |
87 : loop_(base::MessageLoop::TYPE_DEFAULT), | 85 : profile_(new TestingProfile()) {} |
88 ui_thread_(content::BrowserThread::UI, &loop_), | |
89 profile_(new TestingProfile()) { } | |
90 | 86 |
91 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) { | 87 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) { |
92 ResourcePrefetchPredictorConfig config; | 88 ResourcePrefetchPredictorConfig config; |
93 EXPECT_FALSE( | 89 EXPECT_FALSE( |
94 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); | 90 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); |
95 | 91 |
96 EXPECT_FALSE(config.IsLearningEnabled()); | 92 EXPECT_FALSE(config.IsLearningEnabled()); |
97 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(), | 93 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(), |
98 PrefetchOrigin::EXTERNAL)); | 94 PrefetchOrigin::EXTERNAL)); |
99 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( | 95 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 TestIsPrefetchLearning(config); | 204 TestIsPrefetchLearning(config); |
209 } | 205 } |
210 { | 206 { |
211 std::unique_ptr<NetworkChangeNotifier> mock( | 207 std::unique_ptr<NetworkChangeNotifier> mock( |
212 new MockNetworkChangeNotifier4G); | 208 new MockNetworkChangeNotifier4G); |
213 TestIsPrefetchLearning(config); | 209 TestIsPrefetchLearning(config); |
214 } | 210 } |
215 } | 211 } |
216 | 212 |
217 } // namespace predictors | 213 } // namespace predictors |
OLD | NEW |