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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/metrics/histogram.h" | 6 #include "base/metrics/histogram.h" |
7 #include "base/metrics/histogram_samples.h" | 7 #include "base/metrics/histogram_samples.h" |
8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
12 #include "chrome/browser/ui/search/instant_ntp.h" | 12 #include "chrome/browser/ui/search/instant_ntp.h" |
13 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" | 13 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" |
14 #include "chrome/common/content_settings.h" | 14 #include "chrome/common/content_settings.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using base::HistogramBase; | 20 using base::HistogramBase; |
21 using base::HistogramSamples; | 21 using base::HistogramSamples; |
22 using base::StatisticsRecorder; | 22 using base::StatisticsRecorder; |
23 | 23 |
24 class TestableInstantNTP : public InstantNTP { | 24 class TestableInstantNTP : public InstantNTP { |
25 public: | 25 public: |
26 TestableInstantNTP(InstantNTPPrerenderer* ntp_prerenderer, | 26 TestableInstantNTP(InstantNTPPrerenderer* ntp_prerenderer, |
27 const std::string& instant_url, | 27 const std::string& instant_url, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 bool test_extended_enabled_; | 129 bool test_extended_enabled_; |
130 bool override_javascript_enabled_; | 130 bool override_javascript_enabled_; |
131 bool test_javascript_enabled_; | 131 bool test_javascript_enabled_; |
132 bool test_in_startup_; | 132 bool test_in_startup_; |
133 InstantNTP* test_ntp_; | 133 InstantNTP* test_ntp_; |
134 }; | 134 }; |
135 | 135 |
136 class InstantNTPPrerendererTest : public testing::Test { | 136 class InstantNTPPrerendererTest : public testing::Test { |
137 public: | 137 public: |
138 InstantNTPPrerendererTest() | 138 InstantNTPPrerendererTest() |
139 : ui_thread_(content::BrowserThread::UI), | 139 : instant_ntp_prerenderer_(new TestableInstantNTPPrerenderer(&profile_)) { |
140 instant_ntp_prerenderer_(new TestableInstantNTPPrerenderer(&profile_)) { | |
141 } | |
142 | |
143 virtual void SetUp() OVERRIDE { | |
144 base::StatisticsRecorder::Initialize(); | 140 base::StatisticsRecorder::Initialize(); |
145 } | 141 } |
146 | 142 |
147 TestableInstantNTPPrerenderer* instant_ntp_prerenderer() { | 143 TestableInstantNTPPrerenderer* instant_ntp_prerenderer() { |
148 return instant_ntp_prerenderer_.get(); | 144 return instant_ntp_prerenderer_.get(); |
149 } | 145 } |
150 | 146 |
151 Profile* profile() { | 147 Profile* profile() { |
152 return instant_ntp_prerenderer()->profile(); | 148 return instant_ntp_prerenderer()->profile(); |
153 } | 149 } |
154 | 150 |
155 private: | 151 private: |
156 content::TestBrowserThread ui_thread_; | 152 content::TestBrowserThreadBundle thread_bundle_; |
157 scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_; | 153 scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_; |
158 mutable TestingProfile profile_; | 154 mutable TestingProfile profile_; |
159 }; | 155 }; |
160 | 156 |
161 TEST_F(InstantNTPPrerendererTest, PrefersRemoteNTPOnStartup) { | 157 TEST_F(InstantNTPPrerendererTest, PrefersRemoteNTPOnStartup) { |
162 std::string instant_url("http://instant_url"); | 158 std::string instant_url("http://instant_url"); |
163 scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP( | 159 scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP( |
164 instant_ntp_prerenderer(), instant_url, profile())); | 160 instant_ntp_prerenderer(), instant_url, profile())); |
165 ntp->set_is_local(false); | 161 ntp->set_is_local(false); |
166 instant_ntp_prerenderer()->set_ntp(ntp.get()); | 162 instant_ntp_prerenderer()->set_ntp(ntp.get()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 282 |
287 TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksPrefs) { | 283 TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksPrefs) { |
288 instant_ntp_prerenderer()->set_override_javascript_enabled(false); | 284 instant_ntp_prerenderer()->set_override_javascript_enabled(false); |
289 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( | 285 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( |
290 prefs::kWebKitJavascriptEnabled, true); | 286 prefs::kWebKitJavascriptEnabled, true); |
291 EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled()); | 287 EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled()); |
292 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( | 288 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( |
293 prefs::kWebKitJavascriptEnabled, false); | 289 prefs::kWebKitJavascriptEnabled, false); |
294 EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled()); | 290 EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled()); |
295 } | 291 } |
OLD | NEW |