OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Verify the TableModel has the new data. | 135 // Verify the TableModel has the new data. |
136 ASSERT_EQ(1, table_model()->RowCount()); | 136 ASSERT_EQ(1, table_model()->RowCount()); |
137 | 137 |
138 // Verify the TemplateURLService has the new entry. | 138 // Verify the TemplateURLService has the new entry. |
139 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); | 139 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); |
140 | 140 |
141 // Verify the entry is what we added. | 141 // Verify the entry is what we added. |
142 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 142 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
143 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); | 143 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); |
144 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); | 144 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); |
145 EXPECT_EQ("http://c", turl->url()); | 145 ASSERT_TRUE(turl->url() != NULL); |
| 146 EXPECT_EQ("http://c", turl->url()->url()); |
146 } | 147 } |
147 | 148 |
148 // Tests modifying a TemplateURL. | 149 // Tests modifying a TemplateURL. |
149 TEST_F(KeywordEditorControllerTest, Modify) { | 150 TEST_F(KeywordEditorControllerTest, Modify) { |
150 controller_->AddTemplateURL(kA, kB, "http://c"); | 151 controller_->AddTemplateURL(kA, kB, "http://c"); |
151 ClearChangeCount(); | 152 ClearChangeCount(); |
152 | 153 |
153 // Modify the entry. | 154 // Modify the entry. |
154 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 155 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
155 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); | 156 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); |
156 | 157 |
157 // Make sure it was updated appropriately. | 158 // Make sure it was updated appropriately. |
158 VerifyChangeCount(0, 1, 0, 0); | 159 VerifyChangeCount(0, 1, 0, 0); |
159 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); | 160 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); |
160 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); | 161 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); |
161 EXPECT_EQ("http://c1", turl->url()); | 162 ASSERT_TRUE(turl->url() != NULL); |
| 163 EXPECT_EQ("http://c1", turl->url()->url()); |
162 } | 164 } |
163 | 165 |
164 // Tests making a TemplateURL the default search provider. | 166 // Tests making a TemplateURL the default search provider. |
165 TEST_F(KeywordEditorControllerTest, MakeDefault) { | 167 TEST_F(KeywordEditorControllerTest, MakeDefault) { |
166 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 168 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
167 ClearChangeCount(); | 169 ClearChangeCount(); |
168 | 170 |
169 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 171 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
170 int new_default = controller_->MakeDefaultTemplateURL(0); | 172 int new_default = controller_->MakeDefaultTemplateURL(0); |
171 EXPECT_EQ(0, new_default); | 173 EXPECT_EQ(0, new_default); |
(...skipping 18 matching lines...) Expand all Loading... |
190 const TemplateURL* turl1 = | 192 const TemplateURL* turl1 = |
191 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 193 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
192 ASSERT_TRUE(turl1 != NULL); | 194 ASSERT_TRUE(turl1 != NULL); |
193 const TemplateURL* turl2 = | 195 const TemplateURL* turl2 = |
194 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); | 196 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); |
195 ASSERT_TRUE(turl2 != NULL); | 197 ASSERT_TRUE(turl2 != NULL); |
196 | 198 |
197 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); | 199 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); |
198 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); | 200 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); |
199 | 201 |
200 SimulateDefaultSearchIsManaged(turl2->url()); | 202 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
201 EXPECT_TRUE(model_->is_default_search_managed()); | 203 EXPECT_TRUE(model_->is_default_search_managed()); |
202 | 204 |
203 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); | 205 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); |
204 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); | 206 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); |
205 } | 207 } |
206 | 208 |
207 // Tests that a TemplateURL can't be edited if it is the managed default search | 209 // Tests that a TemplateURL can't be edited if it is the managed default search |
208 // provider. | 210 // provider. |
209 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { | 211 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { |
210 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 212 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
211 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); | 213 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); |
212 ClearChangeCount(); | 214 ClearChangeCount(); |
213 | 215 |
214 const TemplateURL* turl1 = | 216 const TemplateURL* turl1 = |
215 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 217 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
216 ASSERT_TRUE(turl1 != NULL); | 218 ASSERT_TRUE(turl1 != NULL); |
217 const TemplateURL* turl2 = | 219 const TemplateURL* turl2 = |
218 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); | 220 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); |
219 ASSERT_TRUE(turl2 != NULL); | 221 ASSERT_TRUE(turl2 != NULL); |
220 | 222 |
221 EXPECT_TRUE(controller_->CanEdit(turl1)); | 223 EXPECT_TRUE(controller_->CanEdit(turl1)); |
222 EXPECT_TRUE(controller_->CanEdit(turl2)); | 224 EXPECT_TRUE(controller_->CanEdit(turl2)); |
223 | 225 |
224 // Simulate setting a managed default. This will add another template URL to | 226 // Simulate setting a managed default. This will add another template URL to |
225 // the model. | 227 // the model. |
226 SimulateDefaultSearchIsManaged(turl2->url()); | 228 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
227 EXPECT_TRUE(model_->is_default_search_managed()); | 229 EXPECT_TRUE(model_->is_default_search_managed()); |
228 EXPECT_TRUE(controller_->CanEdit(turl1)); | 230 EXPECT_TRUE(controller_->CanEdit(turl1)); |
229 EXPECT_TRUE(controller_->CanEdit(turl2)); | 231 EXPECT_TRUE(controller_->CanEdit(turl2)); |
230 EXPECT_FALSE(controller_->CanEdit(model_->GetDefaultSearchProvider())); | 232 EXPECT_FALSE(controller_->CanEdit(model_->GetDefaultSearchProvider())); |
231 } | 233 } |
232 | 234 |
233 TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) { | 235 TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) { |
234 // Simulate a failure to load Web Data. | 236 // Simulate a failure to load Web Data. |
235 Init(true); | 237 Init(true); |
236 | 238 |
(...skipping 13 matching lines...) Expand all Loading... |
250 turl->set_short_name(ASCIIToUTF16("b")); | 252 turl->set_short_name(ASCIIToUTF16("b")); |
251 model_->Add(turl); | 253 model_->Add(turl); |
252 | 254 |
253 // Table model should have updated. | 255 // Table model should have updated. |
254 VerifyChangeCount(1, 0, 0, 0); | 256 VerifyChangeCount(1, 0, 0, 0); |
255 | 257 |
256 // And should contain the newly added TemplateURL. | 258 // And should contain the newly added TemplateURL. |
257 ASSERT_EQ(1, table_model()->RowCount()); | 259 ASSERT_EQ(1, table_model()->RowCount()); |
258 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); | 260 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); |
259 } | 261 } |
OLD | NEW |