| 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" | |
| 7 #include "base/metrics/histogram_samples.h" | |
| 8 #include "base/metrics/statistics_recorder.h" | |
| 9 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 8 #include "chrome/browser/search/instant_service_factory.h" |
| 11 #include "chrome/browser/search/search.h" | 9 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/browser/ui/search/instant_ntp.h" | 10 #include "chrome/browser/ui/search/instant_ntp.h" |
| 13 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" | 11 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" |
| 14 #include "chrome/common/content_settings.h" | 12 #include "chrome/common/content_settings.h" |
| 15 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 17 |
| 20 using base::HistogramBase; | |
| 21 using base::HistogramSamples; | |
| 22 using base::StatisticsRecorder; | |
| 23 | |
| 24 class TestableInstantNTP : public InstantNTP { | 18 class TestableInstantNTP : public InstantNTP { |
| 25 public: | 19 public: |
| 26 TestableInstantNTP(InstantNTPPrerenderer* ntp_prerenderer, | 20 TestableInstantNTP(InstantNTPPrerenderer* ntp_prerenderer, |
| 27 const std::string& instant_url, | 21 const std::string& instant_url, |
| 28 Profile* profile) | 22 Profile* profile) |
| 29 : InstantNTP(ntp_prerenderer, instant_url, profile) { | 23 : InstantNTP(ntp_prerenderer, instant_url, profile) { |
| 30 } | 24 } |
| 31 | 25 |
| 32 // Overrides from InstantPage | 26 // Overrides from InstantPage |
| 33 virtual bool supports_instant() const OVERRIDE { | 27 virtual bool supports_instant() const OVERRIDE { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 55 } | 49 } |
| 56 | 50 |
| 57 private: | 51 private: |
| 58 std::string test_instant_url_; | 52 std::string test_instant_url_; |
| 59 bool test_supports_instant_; | 53 bool test_supports_instant_; |
| 60 bool test_is_local_; | 54 bool test_is_local_; |
| 61 }; | 55 }; |
| 62 | 56 |
| 63 class TestableInstantNTPPrerenderer : public InstantNTPPrerenderer { | 57 class TestableInstantNTPPrerenderer : public InstantNTPPrerenderer { |
| 64 public: | 58 public: |
| 65 explicit TestableInstantNTPPrerenderer(TestingProfile* profile) | 59 explicit TestableInstantNTPPrerenderer(TestingProfile* profile, |
| 66 : InstantNTPPrerenderer(profile, NULL), | 60 InstantService* instant_service) |
| 61 : InstantNTPPrerenderer(profile, instant_service, NULL), |
| 67 test_instant_url_("http://test_url"), | 62 test_instant_url_("http://test_url"), |
| 68 override_javascript_enabled_(true), | 63 override_javascript_enabled_(true), |
| 69 test_javascript_enabled_(true), | 64 test_javascript_enabled_(true), |
| 70 test_in_startup_(false), | 65 test_in_startup_(false), |
| 71 test_ntp_(NULL) {} | 66 test_ntp_(NULL) { |
| 67 } |
| 72 | 68 |
| 73 // Overrides from InstantNTPPrerenderer | 69 // Overrides from InstantNTPPrerenderer |
| 74 virtual std::string GetInstantURL() const OVERRIDE { | 70 virtual std::string GetInstantURL() const OVERRIDE { |
| 75 return test_instant_url_; | 71 return test_instant_url_; |
| 76 } | 72 } |
| 77 | 73 |
| 78 virtual std::string GetLocalInstantURL() const OVERRIDE { | 74 virtual std::string GetLocalInstantURL() const OVERRIDE { |
| 79 return "http://local_instant_url"; | 75 return "http://local_instant_url"; |
| 80 } | 76 } |
| 81 | 77 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 private: | 114 private: |
| 119 std::string test_instant_url_; | 115 std::string test_instant_url_; |
| 120 bool override_javascript_enabled_; | 116 bool override_javascript_enabled_; |
| 121 bool test_javascript_enabled_; | 117 bool test_javascript_enabled_; |
| 122 bool test_in_startup_; | 118 bool test_in_startup_; |
| 123 InstantNTP* test_ntp_; | 119 InstantNTP* test_ntp_; |
| 124 }; | 120 }; |
| 125 | 121 |
| 126 class InstantNTPPrerendererTest : public testing::Test { | 122 class InstantNTPPrerendererTest : public testing::Test { |
| 127 public: | 123 public: |
| 128 InstantNTPPrerendererTest() | 124 virtual void SetUp() OVERRIDE { |
| 129 : instant_ntp_prerenderer_(new TestableInstantNTPPrerenderer(&profile_)) { | |
| 130 base::StatisticsRecorder::Initialize(); | |
| 131 chrome::EnableInstantExtendedAPIForTesting(); | 125 chrome::EnableInstantExtendedAPIForTesting(); |
| 126 instant_service_ = InstantServiceFactory::GetForProfile(&profile_); |
| 127 instant_ntp_prerenderer_.reset( |
| 128 new TestableInstantNTPPrerenderer(&profile_, instant_service_)); |
| 129 } |
| 130 |
| 131 virtual void TearDown() OVERRIDE { |
| 132 instant_ntp_prerenderer_.reset(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 TestableInstantNTPPrerenderer* instant_ntp_prerenderer() { | 135 TestableInstantNTPPrerenderer* instant_ntp_prerenderer() { |
| 135 return instant_ntp_prerenderer_.get(); | 136 return instant_ntp_prerenderer_.get(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 Profile* profile() { | 139 Profile* profile() { |
| 139 return instant_ntp_prerenderer()->profile(); | 140 return instant_ntp_prerenderer()->profile(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 content::TestBrowserThreadBundle thread_bundle_; | 144 content::TestBrowserThreadBundle thread_bundle_; |
| 144 scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_; | 145 scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_; |
| 146 InstantService* instant_service_; |
| 145 mutable TestingProfile profile_; | 147 mutable TestingProfile profile_; |
| 146 }; | 148 }; |
| 147 | 149 |
| 148 TEST_F(InstantNTPPrerendererTest, PrefersRemoteNTPOnStartup) { | 150 TEST_F(InstantNTPPrerendererTest, PrefersRemoteNTPOnStartup) { |
| 149 std::string instant_url("http://instant_url"); | 151 std::string instant_url("http://instant_url"); |
| 150 scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP( | 152 scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP( |
| 151 instant_ntp_prerenderer(), instant_url, profile())); | 153 instant_ntp_prerenderer(), instant_url, profile())); |
| 152 ntp->set_is_local(false); | 154 ntp->set_is_local(false); |
| 153 instant_ntp_prerenderer()->set_ntp(ntp.get()); | 155 instant_ntp_prerenderer()->set_ntp(ntp.get()); |
| 154 instant_ntp_prerenderer()->set_javascript_enabled(true); | 156 instant_ntp_prerenderer()->set_javascript_enabled(true); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 269 |
| 268 TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksPrefs) { | 270 TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksPrefs) { |
| 269 instant_ntp_prerenderer()->set_override_javascript_enabled(false); | 271 instant_ntp_prerenderer()->set_override_javascript_enabled(false); |
| 270 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( | 272 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( |
| 271 prefs::kWebKitJavascriptEnabled, true); | 273 prefs::kWebKitJavascriptEnabled, true); |
| 272 EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled()); | 274 EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled()); |
| 273 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( | 275 instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean( |
| 274 prefs::kWebKitJavascriptEnabled, false); | 276 prefs::kWebKitJavascriptEnabled, false); |
| 275 EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled()); | 277 EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled()); |
| 276 } | 278 } |
| OLD | NEW |