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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
23 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
24 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
25 #include "ipc/ipc_test_sink.h" | 25 #include "ipc/ipc_test_sink.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 | 28 |
29 class MockInstantServiceObserver : public InstantServiceObserver { | 29 class MockInstantServiceObserver : public InstantServiceObserver { |
30 public: | 30 public: |
31 MOCK_METHOD0(DefaultSearchProviderChanged, void()); | 31 MOCK_METHOD1(DefaultSearchProviderChanged, void(bool)); |
32 MOCK_METHOD1(OmniboxStartMarginChanged, void(int)); | 32 MOCK_METHOD1(OmniboxStartMarginChanged, void(int)); |
33 }; | 33 }; |
34 | 34 |
35 class InstantServiceTest : public InstantUnitTestBase { | 35 class InstantServiceTest : public InstantUnitTestBase { |
36 protected: | 36 protected: |
37 void SetUp() override { | 37 void SetUp() override { |
38 InstantUnitTestBase::SetUp(); | 38 InstantUnitTestBase::SetUp(); |
39 | 39 |
40 instant_service_observer_.reset(new MockInstantServiceObserver()); | 40 instant_service_observer_.reset(new MockInstantServiceObserver()); |
41 instant_service_->AddObserver(instant_service_observer_.get()); | 41 instant_service_->AddObserver(instant_service_observer_.get()); |
(...skipping 18 matching lines...) Expand all Loading... |
60 class InstantServiceEnabledTest : public InstantServiceTest { | 60 class InstantServiceEnabledTest : public InstantServiceTest { |
61 protected: | 61 protected: |
62 void SetUp() override { | 62 void SetUp() override { |
63 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 63 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
64 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); | 64 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); |
65 InstantServiceTest::SetUp(); | 65 InstantServiceTest::SetUp(); |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 TEST_F(InstantServiceEnabledTest, DispatchDefaultSearchProviderChanged) { | 69 TEST_F(InstantServiceEnabledTest, DispatchDefaultSearchProviderChanged) { |
70 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 70 EXPECT_CALL(*instant_service_observer_.get(), |
71 .Times(1); | 71 DefaultSearchProviderChanged(false)).Times(1); |
72 | 72 |
73 const std::string new_base_url = "https://bar.com/"; | 73 const std::string new_base_url = "https://bar.com/"; |
74 SetUserSelectedDefaultSearchProvider(new_base_url); | 74 SetUserSelectedDefaultSearchProvider(new_base_url); |
75 } | 75 } |
76 | 76 |
77 TEST_F(InstantServiceTest, DontDispatchGoogleURLUpdatedForNonGoogleURLs) { | 77 TEST_F(InstantServiceTest, DontDispatchGoogleURLUpdatedForNonGoogleURLs) { |
78 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 78 EXPECT_CALL(*instant_service_observer_.get(), |
79 .Times(1); | 79 DefaultSearchProviderChanged(false)).Times(1); |
80 const std::string new_dsp_url = "https://bar.com/"; | 80 const std::string new_dsp_url = "https://bar.com/"; |
81 SetUserSelectedDefaultSearchProvider(new_dsp_url); | 81 SetUserSelectedDefaultSearchProvider(new_dsp_url); |
82 testing::Mock::VerifyAndClearExpectations(instant_service_observer_.get()); | 82 testing::Mock::VerifyAndClearExpectations(instant_service_observer_.get()); |
83 | 83 |
84 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 84 EXPECT_CALL(*instant_service_observer_.get(), |
85 .Times(0); | 85 DefaultSearchProviderChanged(false)).Times(0); |
86 const std::string new_base_url = "https://www.google.es/"; | 86 const std::string new_base_url = "https://www.google.es/"; |
87 NotifyGoogleBaseURLUpdate(new_base_url); | 87 NotifyGoogleBaseURLUpdate(new_base_url); |
88 } | 88 } |
89 | 89 |
90 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) { | 90 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) { |
91 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 91 EXPECT_CALL(*instant_service_observer_.get(), |
92 .Times(1); | 92 DefaultSearchProviderChanged(true)).Times(1); |
93 | 93 |
94 const std::string new_base_url = "https://www.google.es/"; | 94 const std::string new_base_url = "https://www.google.es/"; |
95 NotifyGoogleBaseURLUpdate(new_base_url); | 95 NotifyGoogleBaseURLUpdate(new_base_url); |
96 } | 96 } |
97 | 97 |
98 TEST_F(InstantServiceEnabledTest, SendsSearchURLsToRenderer) { | 98 TEST_F(InstantServiceEnabledTest, SendsSearchURLsToRenderer) { |
99 scoped_ptr<content::MockRenderProcessHost> rph( | 99 scoped_ptr<content::MockRenderProcessHost> rph( |
100 new content::MockRenderProcessHost(profile())); | 100 new content::MockRenderProcessHost(profile())); |
101 rph->sink().ClearMessages(); | 101 rph->sink().ClearMessages(); |
102 instant_service_->Observe( | 102 instant_service_->Observe( |
(...skipping 13 matching lines...) Expand all Loading... |
116 EXPECT_EQ("https://www.google.com/newtab", new_tab_page_url.spec()); | 116 EXPECT_EQ("https://www.google.com/newtab", new_tab_page_url.spec()); |
117 } | 117 } |
118 | 118 |
119 TEST_F(InstantServiceTest, InstantSearchEnabled) { | 119 TEST_F(InstantServiceTest, InstantSearchEnabled) { |
120 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), | 120 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), |
121 GetInstantSearchPrerenderer()); | 121 GetInstantSearchPrerenderer()); |
122 } | 122 } |
123 | 123 |
124 TEST_F(InstantServiceEnabledTest, | 124 TEST_F(InstantServiceEnabledTest, |
125 ResetInstantSearchPrerenderer_DefaultProviderChanged) { | 125 ResetInstantSearchPrerenderer_DefaultProviderChanged) { |
126 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 126 EXPECT_CALL(*instant_service_observer_.get(), |
127 .Times(2); | 127 DefaultSearchProviderChanged(false)).Times(2); |
128 | 128 |
129 // Set a default search provider that doesn't support Instant. | 129 // Set a default search provider that doesn't support Instant. |
130 TemplateURLData data; | 130 TemplateURLData data; |
131 data.SetURL("https://foobar.com/url?bar={searchTerms}"); | 131 data.SetURL("https://foobar.com/url?bar={searchTerms}"); |
132 TemplateURL* template_url = new TemplateURL(data); | 132 TemplateURL* template_url = new TemplateURL(data); |
133 // Takes ownership of |template_url|. | 133 // Takes ownership of |template_url|. |
134 template_url_service_->Add(template_url); | 134 template_url_service_->Add(template_url); |
135 template_url_service_->SetUserSelectedDefaultSearchProvider(template_url); | 135 template_url_service_->SetUserSelectedDefaultSearchProvider(template_url); |
136 | 136 |
137 EXPECT_EQ(static_cast<InstantSearchPrerenderer*>(NULL), | 137 EXPECT_EQ(static_cast<InstantSearchPrerenderer*>(NULL), |
138 GetInstantSearchPrerenderer()); | 138 GetInstantSearchPrerenderer()); |
139 | 139 |
140 // Set a default search provider that supports Instant and make sure | 140 // Set a default search provider that supports Instant and make sure |
141 // InstantSearchPrerenderer is valid. | 141 // InstantSearchPrerenderer is valid. |
142 SetUserSelectedDefaultSearchProvider("https://google.com/"); | 142 SetUserSelectedDefaultSearchProvider("https://google.com/"); |
143 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), | 143 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), |
144 GetInstantSearchPrerenderer()); | 144 GetInstantSearchPrerenderer()); |
145 } | 145 } |
146 | 146 |
147 TEST_F(InstantServiceEnabledTest, | 147 TEST_F(InstantServiceEnabledTest, |
148 ResetInstantSearchPrerenderer_GoogleBaseURLUpdated) { | 148 ResetInstantSearchPrerenderer_GoogleBaseURLUpdated) { |
149 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 149 EXPECT_CALL(*instant_service_observer_.get(), |
150 .Times(1); | 150 DefaultSearchProviderChanged(true)).Times(1); |
151 | 151 |
152 InstantSearchPrerenderer* old_prerenderer = GetInstantSearchPrerenderer(); | 152 InstantSearchPrerenderer* old_prerenderer = GetInstantSearchPrerenderer(); |
153 EXPECT_TRUE(old_prerenderer != NULL); | 153 EXPECT_TRUE(old_prerenderer != NULL); |
154 | 154 |
155 const std::string new_base_url = "https://www.google.es/"; | 155 const std::string new_base_url = "https://www.google.es/"; |
156 NotifyGoogleBaseURLUpdate(new_base_url); | 156 NotifyGoogleBaseURLUpdate(new_base_url); |
157 EXPECT_NE(old_prerenderer, GetInstantSearchPrerenderer()); | 157 EXPECT_NE(old_prerenderer, GetInstantSearchPrerenderer()); |
158 } | 158 } |
159 | 159 |
160 TEST_F(InstantServiceTest, OmniboxStartMarginChanged) { | 160 TEST_F(InstantServiceTest, OmniboxStartMarginChanged) { |
161 int new_start_margin = 92; | 161 int new_start_margin = 92; |
162 EXPECT_CALL(*instant_service_observer_.get(), | 162 EXPECT_CALL(*instant_service_observer_.get(), |
163 OmniboxStartMarginChanged(new_start_margin)).Times(1); | 163 OmniboxStartMarginChanged(new_start_margin)).Times(1); |
164 UpdateOmniboxStartMargin(new_start_margin); | 164 UpdateOmniboxStartMargin(new_start_margin); |
165 } | 165 } |
OLD | NEW |