OLD | NEW |
1 // Copyright (c) 2010 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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/scoped_vector.h" | 6 #include "base/scoped_vector.h" |
7 #include "base/string_split.h" | 7 #include "base/string_split.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
13 #include "chrome/browser/history/history_notifications.h" | 14 #include "chrome/browser/history/history_notifications.h" |
14 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 15 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
15 #include "chrome/browser/search_engines/search_terms_data.h" | 16 #include "chrome/browser/search_engines/search_terms_data.h" |
16 #include "chrome/browser/search_engines/template_url.h" | 17 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/search_engines/template_url_model.h" | 18 #include "chrome/browser/search_engines/template_url_model.h" |
18 #include "chrome/browser/search_engines/template_url_model_test_util.h" | 19 #include "chrome/browser/search_engines/template_url_model_test_util.h" |
19 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 20 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
20 #include "chrome/browser/webdata/web_database.h" | 21 #include "chrome/browser/webdata/web_database.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 virtual std::string GoogleBaseURLValue() const { | 71 virtual std::string GoogleBaseURLValue() const { |
71 return google_base_url_; | 72 return google_base_url_; |
72 } | 73 } |
73 | 74 |
74 virtual std::string GetApplicationLocale() const { | 75 virtual std::string GetApplicationLocale() const { |
75 return "yy"; | 76 return "yy"; |
76 } | 77 } |
77 | 78 |
78 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 79 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
79 // Returns the value for the Chrome Omnibox rlz. | 80 // Returns the value for the Chrome Omnibox rlz. |
80 virtual std::wstring GetRlzParameterValue() const { | 81 virtual string16 GetRlzParameterValue() const { |
81 return std::wstring(); | 82 return string16(); |
82 } | 83 } |
83 #endif | 84 #endif |
84 | 85 |
85 private: | 86 private: |
86 std::string google_base_url_; | 87 std::string google_base_url_; |
87 | 88 |
88 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData); | 89 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData); |
89 }; | 90 }; |
90 | 91 |
91 // Create an URL that appears to have been prepopulated, but won't be in the | 92 // Create an URL that appears to have been prepopulated, but won't be in the |
92 // current data. The caller owns the returned TemplateURL*. | 93 // current data. The caller owns the returned TemplateURL*. |
93 static TemplateURL* CreatePreloadedTemplateURL() { | 94 static TemplateURL* CreatePreloadedTemplateURL() { |
94 TemplateURL* t_url = new TemplateURL(); | 95 TemplateURL* t_url = new TemplateURL(); |
95 t_url->SetURL("http://www.unittest.com/", 0, 0); | 96 t_url->SetURL("http://www.unittest.com/", 0, 0); |
96 t_url->set_keyword(L"unittest"); | 97 t_url->set_keyword(ASCIIToUTF16("unittest")); |
97 t_url->set_short_name(L"unittest"); | 98 t_url->set_short_name(ASCIIToUTF16("unittest")); |
98 t_url->set_safe_for_autoreplace(true); | 99 t_url->set_safe_for_autoreplace(true); |
99 GURL favicon_url("http://favicon.url"); | 100 GURL favicon_url("http://favicon.url"); |
100 t_url->SetFavIconURL(favicon_url); | 101 t_url->SetFavIconURL(favicon_url); |
101 t_url->set_date_created(Time::FromTimeT(100)); | 102 t_url->set_date_created(Time::FromTimeT(100)); |
102 t_url->set_prepopulate_id(999999); | 103 t_url->set_prepopulate_id(999999); |
103 return t_url; | 104 return t_url; |
104 } | 105 } |
105 | 106 |
106 class TemplateURLModelTest : public testing::Test { | 107 class TemplateURLModelTest : public testing::Test { |
107 public: | 108 public: |
108 TemplateURLModelTest() {} | 109 TemplateURLModelTest() {} |
109 | 110 |
110 virtual void SetUp() { | 111 virtual void SetUp() { |
111 test_util_.SetUp(); | 112 test_util_.SetUp(); |
112 } | 113 } |
113 | 114 |
114 virtual void TearDown() { | 115 virtual void TearDown() { |
115 test_util_.TearDown(); | 116 test_util_.TearDown(); |
116 } | 117 } |
117 | 118 |
118 TemplateURL* AddKeywordWithDate(const std::wstring& keyword, | 119 TemplateURL* AddKeywordWithDate(const std::string& keyword, |
119 bool autogenerate_keyword, | 120 bool autogenerate_keyword, |
120 const std::string& url, | 121 const std::string& url, |
121 const std::string& suggest_url, | 122 const std::string& suggest_url, |
122 const std::string& fav_icon_url, | 123 const std::string& fav_icon_url, |
123 const std::string& encodings, | 124 const std::string& encodings, |
124 const std::wstring& short_name, | 125 const std::string& short_name, |
125 bool safe_for_autoreplace, | 126 bool safe_for_autoreplace, |
126 Time created_date) { | 127 Time created_date) { |
127 TemplateURL* template_url = new TemplateURL(); | 128 TemplateURL* template_url = new TemplateURL(); |
128 template_url->SetURL(url, 0, 0); | 129 template_url->SetURL(url, 0, 0); |
129 template_url->SetSuggestionsURL(suggest_url, 0, 0); | 130 template_url->SetSuggestionsURL(suggest_url, 0, 0); |
130 template_url->SetFavIconURL(GURL(fav_icon_url)); | 131 template_url->SetFavIconURL(GURL(fav_icon_url)); |
131 template_url->set_keyword(keyword); | 132 template_url->set_keyword(UTF8ToUTF16(keyword)); |
132 template_url->set_autogenerate_keyword(autogenerate_keyword); | 133 template_url->set_autogenerate_keyword(autogenerate_keyword); |
133 template_url->set_short_name(short_name); | 134 template_url->set_short_name(UTF8ToUTF16(short_name)); |
134 std::vector<std::string> encodings_vector; | 135 std::vector<std::string> encodings_vector; |
135 base::SplitString(encodings, ';', &encodings_vector); | 136 base::SplitString(encodings, ';', &encodings_vector); |
136 template_url->set_input_encodings(encodings_vector); | 137 template_url->set_input_encodings(encodings_vector); |
137 template_url->set_date_created(created_date); | 138 template_url->set_date_created(created_date); |
138 template_url->set_safe_for_autoreplace(safe_for_autoreplace); | 139 template_url->set_safe_for_autoreplace(safe_for_autoreplace); |
139 model()->Add(template_url); | 140 model()->Add(template_url); |
140 EXPECT_NE(0, template_url->id()); | 141 EXPECT_NE(0, template_url->id()); |
141 return template_url; | 142 return template_url; |
142 } | 143 } |
143 | 144 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 service->RemoveManagedPref( | 234 service->RemoveManagedPref( |
234 prefs::kDefaultSearchProviderEncodings); | 235 prefs::kDefaultSearchProviderEncodings); |
235 service->RemoveManagedPref( | 236 service->RemoveManagedPref( |
236 prefs::kDefaultSearchProviderKeyword); | 237 prefs::kDefaultSearchProviderKeyword); |
237 service->RemoveManagedPref( | 238 service->RemoveManagedPref( |
238 prefs::kDefaultSearchProviderID); | 239 prefs::kDefaultSearchProviderID); |
239 service->RemoveManagedPref( | 240 service->RemoveManagedPref( |
240 prefs::kDefaultSearchProviderPrepopulateID); | 241 prefs::kDefaultSearchProviderPrepopulateID); |
241 } | 242 } |
242 | 243 |
243 // Creates a TemplateURL with the same prepopluated id as a real prepopulated | 244 // Creates a TemplateURL with the same prepopulated id as a real prepopulated |
244 // item. The input number determines which prepopulated item. The caller is | 245 // item. The input number determines which prepopulated item. The caller is |
245 // responsible for owning the returned TemplateURL*. | 246 // responsible for owning the returned TemplateURL*. |
246 TemplateURL* CreateReplaceablePreloadedTemplateURL( | 247 TemplateURL* CreateReplaceablePreloadedTemplateURL( |
247 size_t index_offset_from_default, | 248 size_t index_offset_from_default, |
248 std::wstring* prepopulated_display_url); | 249 string16* prepopulated_display_url); |
249 | 250 |
250 // Verifies the behavior of when a preloaded url later gets changed. | 251 // Verifies the behavior of when a preloaded url later gets changed. |
251 // Since the input is the offset from the default, when one passes in | 252 // Since the input is the offset from the default, when one passes in |
252 // 0, it tests the default. Passing in a number > 0 will verify what | 253 // 0, it tests the default. Passing in a number > 0 will verify what |
253 // happens when a preloaded url that is not the default gets updated. | 254 // happens when a preloaded url that is not the default gets updated. |
254 void TestLoadUpdatingPreloadedURL(size_t index_offset_from_default); | 255 void TestLoadUpdatingPreloadedURL(size_t index_offset_from_default); |
255 | 256 |
256 // Helper methods to make calling TemplateURLModelTestUtil methods less | 257 // Helper methods to make calling TemplateURLModelTestUtil methods less |
257 // visually noisy in the test code. | 258 // visually noisy in the test code. |
258 void VerifyObserverCount(int expected_changed_count) { | 259 void VerifyObserverCount(int expected_changed_count) { |
259 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount()); | 260 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount()); |
260 test_util_.ResetObserverCount(); | 261 test_util_.ResetObserverCount(); |
261 } | 262 } |
262 void VerifyObserverFired() { | 263 void VerifyObserverFired() { |
263 EXPECT_LE(1, test_util_.GetObserverCount()); | 264 EXPECT_LE(1, test_util_.GetObserverCount()); |
264 test_util_.ResetObserverCount(); | 265 test_util_.ResetObserverCount(); |
265 } | 266 } |
266 void BlockTillServiceProcessesRequests() { | 267 void BlockTillServiceProcessesRequests() { |
267 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); | 268 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); |
268 } | 269 } |
269 void VerifyLoad() { test_util_.VerifyLoad(); } | 270 void VerifyLoad() { test_util_.VerifyLoad(); } |
270 void ChangeModelToLoadState() { test_util_.ChangeModelToLoadState(); } | 271 void ChangeModelToLoadState() { test_util_.ChangeModelToLoadState(); } |
271 void ResetModel(bool verify_load) { test_util_.ResetModel(verify_load); } | 272 void ResetModel(bool verify_load) { test_util_.ResetModel(verify_load); } |
272 std::wstring GetAndClearSearchTerm() { | 273 string16 GetAndClearSearchTerm() { |
273 return test_util_.GetAndClearSearchTerm(); | 274 return test_util_.GetAndClearSearchTerm(); |
274 } | 275 } |
275 void SetGoogleBaseURL(const std::string& base_url) const { | 276 void SetGoogleBaseURL(const std::string& base_url) const { |
276 test_util_.SetGoogleBaseURL(base_url); | 277 test_util_.SetGoogleBaseURL(base_url); |
277 } | 278 } |
278 WebDataService* GetWebDataService() { return test_util_.GetWebDataService(); } | 279 WebDataService* GetWebDataService() { return test_util_.GetWebDataService(); } |
279 TemplateURLModel* model() { return test_util_.model(); } | 280 TemplateURLModel* model() { return test_util_.model(); } |
280 TestingProfile* profile() { return test_util_.profile(); } | 281 TestingProfile* profile() { return test_util_.profile(); } |
281 | 282 |
282 protected: | 283 protected: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 generate_url_cases[i].expected << " Actual " << result; | 317 generate_url_cases[i].expected << " Actual " << result; |
317 | 318 |
318 everything_passed = false; | 319 everything_passed = false; |
319 } | 320 } |
320 } | 321 } |
321 passed_ = everything_passed; | 322 passed_ = everything_passed; |
322 } | 323 } |
323 | 324 |
324 TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( | 325 TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( |
325 size_t index_offset_from_default, | 326 size_t index_offset_from_default, |
326 std::wstring* prepopulated_display_url) { | 327 string16* prepopulated_display_url) { |
327 TemplateURL* t_url = CreatePreloadedTemplateURL(); | 328 TemplateURL* t_url = CreatePreloadedTemplateURL(); |
328 ScopedVector<TemplateURL> prepopulated_urls; | 329 ScopedVector<TemplateURL> prepopulated_urls; |
329 size_t default_search_provider_index = 0; | 330 size_t default_search_provider_index = 0; |
330 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 331 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
331 profile()->GetPrefs(), | 332 profile()->GetPrefs(), |
332 &prepopulated_urls.get(), | 333 &prepopulated_urls.get(), |
333 &default_search_provider_index); | 334 &default_search_provider_index); |
334 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); | 335 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); |
335 size_t prepopulated_index = | 336 size_t prepopulated_index = |
336 (default_search_provider_index + index_offset_from_default) % | 337 (default_search_provider_index + index_offset_from_default) % |
337 prepopulated_urls.size(); | 338 prepopulated_urls.size(); |
338 t_url->set_prepopulate_id( | 339 t_url->set_prepopulate_id( |
339 prepopulated_urls[prepopulated_index]->prepopulate_id()); | 340 prepopulated_urls[prepopulated_index]->prepopulate_id()); |
340 *prepopulated_display_url = | 341 *prepopulated_display_url = |
341 prepopulated_urls[prepopulated_index]->url()->DisplayURL(); | 342 prepopulated_urls[prepopulated_index]->url()->DisplayURL(); |
342 return t_url; | 343 return t_url; |
343 } | 344 } |
344 | 345 |
345 void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( | 346 void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( |
346 size_t index_offset_from_default) { | 347 size_t index_offset_from_default) { |
347 std::wstring prepopulated_url; | 348 string16 prepopulated_url; |
348 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( | 349 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( |
349 index_offset_from_default, &prepopulated_url); | 350 index_offset_from_default, &prepopulated_url); |
350 t_url->set_safe_for_autoreplace(false); | 351 t_url->set_safe_for_autoreplace(false); |
351 | 352 |
352 std::wstring original_url = t_url->url()->DisplayURL(); | 353 string16 original_url = t_url->url()->DisplayURL(); |
353 ASSERT_STRNE(prepopulated_url.c_str(), original_url.c_str()); | 354 ASSERT_NE(prepopulated_url, original_url); |
354 | 355 |
355 // Then add it to the model and save it all. | 356 // Then add it to the model and save it all. |
356 ChangeModelToLoadState(); | 357 ChangeModelToLoadState(); |
357 model()->Add(t_url); | 358 model()->Add(t_url); |
358 const TemplateURL* keyword_url = | 359 const TemplateURL* keyword_url = |
359 model()->GetTemplateURLForKeyword(L"unittest"); | 360 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
360 ASSERT_EQ(t_url, keyword_url); | 361 ASSERT_EQ(t_url, keyword_url); |
361 ASSERT_STREQ(original_url.c_str(), keyword_url->url()->DisplayURL().c_str()); | 362 ASSERT_EQ(original_url, keyword_url->url()->DisplayURL()); |
362 BlockTillServiceProcessesRequests(); | 363 BlockTillServiceProcessesRequests(); |
363 | 364 |
364 // Now reload the model and verify that the merge updates the url. | 365 // Now reload the model and verify that the merge updates the url. |
365 ResetModel(true); | 366 ResetModel(true); |
366 keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); | 367 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
367 ASSERT_TRUE(keyword_url != NULL); | 368 ASSERT_TRUE(keyword_url != NULL); |
368 ASSERT_STREQ(prepopulated_url.c_str(), | 369 ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); |
369 keyword_url->url()->DisplayURL().c_str()); | |
370 | 370 |
371 // Wait for any saves to finish. | 371 // Wait for any saves to finish. |
372 BlockTillServiceProcessesRequests(); | 372 BlockTillServiceProcessesRequests(); |
373 | 373 |
374 // Reload the model to verify that change was saved correctly. | 374 // Reload the model to verify that change was saved correctly. |
375 ResetModel(true); | 375 ResetModel(true); |
376 keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); | 376 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
377 ASSERT_TRUE(keyword_url != NULL); | 377 ASSERT_TRUE(keyword_url != NULL); |
378 ASSERT_STREQ(prepopulated_url.c_str(), | 378 ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); |
379 keyword_url->url()->DisplayURL().c_str()); | |
380 } | 379 } |
381 | 380 |
382 TEST_F(TemplateURLModelTest, MAYBE_Load) { | 381 TEST_F(TemplateURLModelTest, MAYBE_Load) { |
383 VerifyLoad(); | 382 VerifyLoad(); |
384 } | 383 } |
385 | 384 |
386 TEST_F(TemplateURLModelTest, AddUpdateRemove) { | 385 TEST_F(TemplateURLModelTest, AddUpdateRemove) { |
387 // Add a new TemplateURL. | 386 // Add a new TemplateURL. |
388 VerifyLoad(); | 387 VerifyLoad(); |
389 const size_t initial_count = model()->GetTemplateURLs().size(); | 388 const size_t initial_count = model()->GetTemplateURLs().size(); |
390 | 389 |
391 TemplateURL* t_url = new TemplateURL(); | 390 TemplateURL* t_url = new TemplateURL(); |
392 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); | 391 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); |
393 t_url->set_keyword(L"keyword"); | 392 t_url->set_keyword(ASCIIToUTF16("keyword")); |
394 t_url->set_short_name(L"google"); | 393 t_url->set_short_name(ASCIIToUTF16("google")); |
395 GURL favicon_url("http://favicon.url"); | 394 GURL favicon_url("http://favicon.url"); |
396 t_url->SetFavIconURL(favicon_url); | 395 t_url->SetFavIconURL(favicon_url); |
397 t_url->set_date_created(Time::FromTimeT(100)); | 396 t_url->set_date_created(Time::FromTimeT(100)); |
398 t_url->set_safe_for_autoreplace(true); | 397 t_url->set_safe_for_autoreplace(true); |
399 model()->Add(t_url); | 398 model()->Add(t_url); |
400 ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); | 399 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), |
| 400 GURL(), NULL)); |
401 VerifyObserverCount(1); | 401 VerifyObserverCount(1); |
402 BlockTillServiceProcessesRequests(); | 402 BlockTillServiceProcessesRequests(); |
403 // We need to clone as model takes ownership of TemplateURL and will | 403 // We need to clone as model takes ownership of TemplateURL and will |
404 // delete it. | 404 // delete it. |
405 TemplateURL cloned_url(*t_url); | 405 TemplateURL cloned_url(*t_url); |
406 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 406 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
407 ASSERT_TRUE(model()->GetTemplateURLForKeyword(t_url->keyword()) == t_url); | 407 ASSERT_TRUE(model()->GetTemplateURLForKeyword(t_url->keyword()) == t_url); |
408 ASSERT_TRUE(t_url->date_created() == cloned_url.date_created()); | 408 ASSERT_TRUE(t_url->date_created() == cloned_url.date_created()); |
409 | 409 |
410 // Reload the model to verify it was actually saved to the database. | 410 // Reload the model to verify it was actually saved to the database. |
411 ResetModel(true); | 411 ResetModel(true); |
412 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 412 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
413 const TemplateURL* loaded_url = model()->GetTemplateURLForKeyword(L"keyword"); | 413 const TemplateURL* loaded_url = |
| 414 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
414 ASSERT_TRUE(loaded_url != NULL); | 415 ASSERT_TRUE(loaded_url != NULL); |
415 AssertEquals(cloned_url, *loaded_url); | 416 AssertEquals(cloned_url, *loaded_url); |
416 ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); | 417 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), |
| 418 GURL(), NULL)); |
417 | 419 |
418 // Mutate an element and verify it succeeded. | 420 // Mutate an element and verify it succeeded. |
419 model()->ResetTemplateURL(loaded_url, L"a", L"b", "c"); | 421 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), |
420 ASSERT_EQ(L"a", loaded_url->short_name()); | 422 ASCIIToUTF16("b"), "c"); |
421 ASSERT_EQ(L"b", loaded_url->keyword()); | 423 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
| 424 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
422 ASSERT_EQ("c", loaded_url->url()->url()); | 425 ASSERT_EQ("c", loaded_url->url()->url()); |
423 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 426 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
424 ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); | 427 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), |
425 ASSERT_FALSE(model()->CanReplaceKeyword(L"b", GURL(), NULL)); | 428 GURL(), NULL)); |
| 429 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); |
426 cloned_url = *loaded_url; | 430 cloned_url = *loaded_url; |
427 BlockTillServiceProcessesRequests(); | 431 BlockTillServiceProcessesRequests(); |
428 ResetModel(true); | 432 ResetModel(true); |
429 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 433 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
430 loaded_url = model()->GetTemplateURLForKeyword(L"b"); | 434 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
431 ASSERT_TRUE(loaded_url != NULL); | 435 ASSERT_TRUE(loaded_url != NULL); |
432 AssertEquals(cloned_url, *loaded_url); | 436 AssertEquals(cloned_url, *loaded_url); |
433 | 437 |
434 // Remove an element and verify it succeeded. | 438 // Remove an element and verify it succeeded. |
435 model()->Remove(loaded_url); | 439 model()->Remove(loaded_url); |
436 VerifyObserverCount(1); | 440 VerifyObserverCount(1); |
437 ResetModel(true); | 441 ResetModel(true); |
438 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); | 442 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); |
439 EXPECT_TRUE(model()->GetTemplateURLForKeyword(L"b") == NULL); | 443 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); |
440 } | 444 } |
441 | 445 |
442 TEST_F(TemplateURLModelTest, GenerateKeyword) { | 446 TEST_F(TemplateURLModelTest, GenerateKeyword) { |
443 ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL(), true)); | 447 ASSERT_EQ(string16(), TemplateURLModel::GenerateKeyword(GURL(), true)); |
444 // Shouldn't generate keywords for https. | 448 // Shouldn't generate keywords for https. |
445 ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); | 449 ASSERT_EQ(string16(), |
446 ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://foo"), | 450 TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); |
447 true)); | 451 ASSERT_EQ(ASCIIToUTF16("foo"), |
| 452 TemplateURLModel::GenerateKeyword(GURL("http://foo"), true)); |
448 // www. should be stripped. | 453 // www. should be stripped. |
449 ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), | 454 ASSERT_EQ(ASCIIToUTF16("foo"), |
450 true)); | 455 TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), true)); |
451 // Shouldn't generate keywords with paths, if autodetected. | 456 // Shouldn't generate keywords with paths, if autodetected. |
452 ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), | 457 ASSERT_EQ(string16(), |
453 true)); | 458 TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), true)); |
454 ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), | 459 ASSERT_EQ(ASCIIToUTF16("blah"), |
455 false)); | 460 TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), false)); |
456 // FTP shouldn't generate a keyword. | 461 // FTP shouldn't generate a keyword. |
457 ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); | 462 ASSERT_EQ(string16(), |
| 463 TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); |
458 // Make sure we don't get a trailing / | 464 // Make sure we don't get a trailing / |
459 ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/"), | 465 ASSERT_EQ(ASCIIToUTF16("blah"), |
460 true)); | 466 TemplateURLModel::GenerateKeyword(GURL("http://blah/"), true)); |
461 } | 467 } |
462 | 468 |
463 TEST_F(TemplateURLModelTest, GenerateSearchURL) { | 469 TEST_F(TemplateURLModelTest, GenerateSearchURL) { |
464 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 470 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( |
465 new TestGenerateSearchURL(NULL)); | 471 new TestGenerateSearchURL(NULL)); |
466 test_generate_search_url->RunTest(); | 472 test_generate_search_url->RunTest(); |
467 EXPECT_TRUE(test_generate_search_url->passed()); | 473 EXPECT_TRUE(test_generate_search_url->passed()); |
468 } | 474 } |
469 | 475 |
470 TEST_F(TemplateURLModelTest, GenerateSearchURLUsingTermsData) { | 476 TEST_F(TemplateURLModelTest, GenerateSearchURLUsingTermsData) { |
(...skipping 14 matching lines...) Expand all Loading... |
485 | 491 |
486 TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { | 492 TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { |
487 Time now = Time::Now(); | 493 Time now = Time::Now(); |
488 TimeDelta one_day = TimeDelta::FromDays(1); | 494 TimeDelta one_day = TimeDelta::FromDays(1); |
489 Time month_ago = now - TimeDelta::FromDays(30); | 495 Time month_ago = now - TimeDelta::FromDays(30); |
490 | 496 |
491 // Nothing has been added. | 497 // Nothing has been added. |
492 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 498 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
493 | 499 |
494 // Create one with a 0 time. | 500 // Create one with a 0 time. |
495 AddKeywordWithDate(L"key1", false, "http://foo1", "http://suggest1", | 501 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", |
496 "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); | 502 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); |
497 // Create one for now and +/- 1 day. | 503 // Create one for now and +/- 1 day. |
498 AddKeywordWithDate(L"key2", false, "http://foo2", "http://suggest2", | 504 AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2", |
499 "http://icon2", "UTF-8;UTF-16", L"name2", true, | 505 "http://icon2", "UTF-8;UTF-16", "name2", true, |
500 now - one_day); | 506 now - one_day); |
501 AddKeywordWithDate(L"key3", false, "http://foo3", "", "", "", L"name3", | 507 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", |
502 true, now); | 508 true, now); |
503 AddKeywordWithDate(L"key4", false, "http://foo4", "", "", "", L"name4", | 509 AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4", |
504 true, now + one_day); | 510 true, now + one_day); |
505 // Try the other three states. | 511 // Try the other three states. |
506 AddKeywordWithDate(L"key5", false, "http://foo5", "http://suggest5", | 512 AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5", |
507 "http://icon5", "UTF-8;UTF-16", L"name5", false, now); | 513 "http://icon5", "UTF-8;UTF-16", "name5", false, now); |
508 AddKeywordWithDate(L"key6", false, "http://foo6", "http://suggest6", | 514 AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6", |
509 "http://icon6", "UTF-8;UTF-16", L"name6", false, | 515 "http://icon6", "UTF-8;UTF-16", "name6", false, |
510 month_ago); | 516 month_ago); |
511 | 517 |
512 // We just added a few items, validate them. | 518 // We just added a few items, validate them. |
513 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); | 519 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); |
514 | 520 |
515 // Try removing from current timestamp. This should delete the one in the | 521 // Try removing from current timestamp. This should delete the one in the |
516 // future and one very recent one. | 522 // future and one very recent one. |
517 model()->RemoveAutoGeneratedSince(now); | 523 model()->RemoveAutoGeneratedSince(now); |
518 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); | 524 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); |
519 | 525 |
520 // Try removing from two months ago. This should only delete items that are | 526 // Try removing from two months ago. This should only delete items that are |
521 // auto-generated. | 527 // auto-generated. |
522 model()->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); | 528 model()->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); |
523 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | 529 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); |
524 | 530 |
525 // Make sure the right values remain. | 531 // Make sure the right values remain. |
526 EXPECT_EQ(L"key1", model()->GetTemplateURLs()[0]->keyword()); | 532 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); |
527 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | 533 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); |
528 EXPECT_EQ(0U, | 534 EXPECT_EQ(0U, |
529 model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); | 535 model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); |
530 | 536 |
531 EXPECT_EQ(L"key5", model()->GetTemplateURLs()[1]->keyword()); | 537 EXPECT_EQ(ASCIIToUTF16("key5"), model()->GetTemplateURLs()[1]->keyword()); |
532 EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); | 538 EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); |
533 EXPECT_EQ(now.ToInternalValue(), | 539 EXPECT_EQ(now.ToInternalValue(), |
534 model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); | 540 model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); |
535 | 541 |
536 EXPECT_EQ(L"key6", model()->GetTemplateURLs()[2]->keyword()); | 542 EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); |
537 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); | 543 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); |
538 EXPECT_EQ(month_ago.ToInternalValue(), | 544 EXPECT_EQ(month_ago.ToInternalValue(), |
539 model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); | 545 model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); |
540 | 546 |
541 // Try removing from Time=0. This should delete one more. | 547 // Try removing from Time=0. This should delete one more. |
542 model()->RemoveAutoGeneratedSince(Time()); | 548 model()->RemoveAutoGeneratedSince(Time()); |
543 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); | 549 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); |
544 } | 550 } |
545 | 551 |
546 TEST_F(TemplateURLModelTest, Reset) { | 552 TEST_F(TemplateURLModelTest, Reset) { |
547 // Add a new TemplateURL. | 553 // Add a new TemplateURL. |
548 VerifyLoad(); | 554 VerifyLoad(); |
549 const size_t initial_count = model()->GetTemplateURLs().size(); | 555 const size_t initial_count = model()->GetTemplateURLs().size(); |
550 TemplateURL* t_url = new TemplateURL(); | 556 TemplateURL* t_url = new TemplateURL(); |
551 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); | 557 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); |
552 t_url->set_keyword(L"keyword"); | 558 t_url->set_keyword(ASCIIToUTF16("keyword")); |
553 t_url->set_short_name(L"google"); | 559 t_url->set_short_name(ASCIIToUTF16("google")); |
554 GURL favicon_url("http://favicon.url"); | 560 GURL favicon_url("http://favicon.url"); |
555 t_url->SetFavIconURL(favicon_url); | 561 t_url->SetFavIconURL(favicon_url); |
556 t_url->set_date_created(Time::FromTimeT(100)); | 562 t_url->set_date_created(Time::FromTimeT(100)); |
557 model()->Add(t_url); | 563 model()->Add(t_url); |
558 | 564 |
559 VerifyObserverCount(1); | 565 VerifyObserverCount(1); |
560 BlockTillServiceProcessesRequests(); | 566 BlockTillServiceProcessesRequests(); |
561 | 567 |
562 // Reset the short name, keyword, url and make sure it takes. | 568 // Reset the short name, keyword, url and make sure it takes. |
563 const std::wstring new_short_name(L"a"); | 569 const string16 new_short_name(ASCIIToUTF16("a")); |
564 const std::wstring new_keyword(L"b"); | 570 const string16 new_keyword(ASCIIToUTF16("b")); |
565 const std::string new_url("c"); | 571 const std::string new_url("c"); |
566 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 572 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
567 ASSERT_EQ(new_short_name, t_url->short_name()); | 573 ASSERT_EQ(new_short_name, t_url->short_name()); |
568 ASSERT_EQ(new_keyword, t_url->keyword()); | 574 ASSERT_EQ(new_keyword, t_url->keyword()); |
569 ASSERT_EQ(new_url, t_url->url()->url()); | 575 ASSERT_EQ(new_url, t_url->url()->url()); |
570 | 576 |
571 // Make sure the mappings in the model were updated. | 577 // Make sure the mappings in the model were updated. |
572 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); | 578 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); |
573 ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"keyword") == NULL); | 579 ASSERT_TRUE( |
| 580 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); |
574 | 581 |
575 TemplateURL last_url = *t_url; | 582 TemplateURL last_url = *t_url; |
576 | 583 |
577 // Reload the model from the database and make sure the change took. | 584 // Reload the model from the database and make sure the change took. |
578 ResetModel(true); | 585 ResetModel(true); |
579 t_url = NULL; | 586 t_url = NULL; |
580 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 587 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
581 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); | 588 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); |
582 ASSERT_TRUE(read_url); | 589 ASSERT_TRUE(read_url); |
583 AssertEquals(last_url, *read_url); | 590 AssertEquals(last_url, *read_url); |
584 } | 591 } |
585 | 592 |
586 TEST_F(TemplateURLModelTest, DefaultSearchProvider) { | 593 TEST_F(TemplateURLModelTest, DefaultSearchProvider) { |
587 // Add a new TemplateURL. | 594 // Add a new TemplateURL. |
588 VerifyLoad(); | 595 VerifyLoad(); |
589 const size_t initial_count = model()->GetTemplateURLs().size(); | 596 const size_t initial_count = model()->GetTemplateURLs().size(); |
590 TemplateURL* t_url = AddKeywordWithDate(L"key1", false, "http://foo1", | 597 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", |
591 "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); | 598 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); |
592 | 599 |
593 test_util_.ResetObserverCount(); | 600 test_util_.ResetObserverCount(); |
594 model()->SetDefaultSearchProvider(t_url); | 601 model()->SetDefaultSearchProvider(t_url); |
595 | 602 |
596 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 603 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
597 | 604 |
598 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 605 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
599 ASSERT_TRUE(t_url->show_in_default_list()); | 606 ASSERT_TRUE(t_url->show_in_default_list()); |
600 | 607 |
601 // Setting the default search provider should have caused notification. | 608 // Setting the default search provider should have caused notification. |
(...skipping 10 matching lines...) Expand all Loading... |
612 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 619 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
613 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 620 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
614 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider()); | 621 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider()); |
615 } | 622 } |
616 | 623 |
617 TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { | 624 TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { |
618 VerifyLoad(); | 625 VerifyLoad(); |
619 | 626 |
620 const size_t initial_count = model()->GetTemplateURLs().size(); | 627 const size_t initial_count = model()->GetTemplateURLs().size(); |
621 | 628 |
622 AddKeywordWithDate(std::wstring(), false, "http://foo1", "http://sugg1", | 629 AddKeywordWithDate("", false, "http://foo1", "http://sugg1", |
623 "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); | 630 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); |
624 | 631 |
625 // We just added a few items, validate them. | 632 // We just added a few items, validate them. |
626 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 633 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
627 | 634 |
628 // Reload the model from the database and make sure we get the url back. | 635 // Reload the model from the database and make sure we get the url back. |
629 ResetModel(true); | 636 ResetModel(true); |
630 | 637 |
631 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 638 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
632 | 639 |
633 bool found_keyword = false; | 640 bool found_keyword = false; |
634 for (size_t i = 0; i < initial_count + 1; ++i) { | 641 for (size_t i = 0; i < initial_count + 1; ++i) { |
635 if (model()->GetTemplateURLs()[i]->keyword().empty()) { | 642 if (model()->GetTemplateURLs()[i]->keyword().empty()) { |
636 found_keyword = true; | 643 found_keyword = true; |
637 break; | 644 break; |
638 } | 645 } |
639 } | 646 } |
640 ASSERT_TRUE(found_keyword); | 647 ASSERT_TRUE(found_keyword); |
641 } | 648 } |
642 | 649 |
643 TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { | 650 TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { |
644 ChangeModelToLoadState(); | 651 ChangeModelToLoadState(); |
645 ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL(), NULL)); | 652 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); |
646 TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo1", | 653 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1", |
647 "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); | 654 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); |
648 | 655 |
649 // Can still replace, newly added template url is marked safe to replace. | 656 // Can still replace, newly added template url is marked safe to replace. |
650 ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); | 657 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
| 658 GURL("http://foo2"), NULL)); |
651 | 659 |
652 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 660 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
653 // no longer be replaceable. | 661 // no longer be replaceable. |
654 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 662 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
655 t_url->url()->url()); | 663 t_url->url()->url()); |
656 | 664 |
657 ASSERT_FALSE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); | 665 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
| 666 GURL("http://foo2"), NULL)); |
658 } | 667 } |
659 | 668 |
660 TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { | 669 TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { |
661 ChangeModelToLoadState(); | 670 ChangeModelToLoadState(); |
662 ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo.com"), NULL)); | 671 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
663 TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo.com", | 672 GURL("http://foo.com"), NULL)); |
664 "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); | 673 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", |
| 674 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); |
665 | 675 |
666 // Can still replace, newly added template url is marked safe to replace. | 676 // Can still replace, newly added template url is marked safe to replace. |
667 ASSERT_TRUE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); | 677 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), |
| 678 GURL("http://foo.com"), NULL)); |
668 | 679 |
669 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 680 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
670 // no longer be replaceable. | 681 // no longer be replaceable. |
671 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 682 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
672 t_url->url()->url()); | 683 t_url->url()->url()); |
673 | 684 |
674 ASSERT_FALSE(model()->CanReplaceKeyword(L"bar", | 685 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), |
675 GURL("http://foo.com"), NULL)); | 686 GURL("http://foo.com"), NULL)); |
676 } | 687 } |
677 | 688 |
678 TEST_F(TemplateURLModelTest, HasDefaultSearchProvider) { | 689 TEST_F(TemplateURLModelTest, HasDefaultSearchProvider) { |
679 // We should have a default search provider even if we haven't loaded. | 690 // We should have a default search provider even if we haven't loaded. |
680 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 691 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
681 | 692 |
682 // Now force the model to load and make sure we still have a default. | 693 // Now force the model to load and make sure we still have a default. |
683 VerifyLoad(); | 694 VerifyLoad(); |
684 | 695 |
685 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 696 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
686 } | 697 } |
687 | 698 |
688 TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { | 699 TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { |
689 VerifyLoad(); | 700 VerifyLoad(); |
690 | 701 |
691 TemplateURL* template_url = new TemplateURL(); | 702 TemplateURL* template_url = new TemplateURL(); |
692 template_url->SetURL("http://url", 0, 0); | 703 template_url->SetURL("http://url", 0, 0); |
693 template_url->SetSuggestionsURL("http://url2", 0, 0); | 704 template_url->SetSuggestionsURL("http://url2", 0, 0); |
694 template_url->SetInstantURL("http://instant", 0, 0); | 705 template_url->SetInstantURL("http://instant", 0, 0); |
695 template_url->set_short_name(L"a"); | 706 template_url->set_short_name(ASCIIToUTF16("a")); |
696 template_url->set_safe_for_autoreplace(true); | 707 template_url->set_safe_for_autoreplace(true); |
697 template_url->set_date_created(Time::FromTimeT(100)); | 708 template_url->set_date_created(Time::FromTimeT(100)); |
698 | 709 |
699 model()->Add(template_url); | 710 model()->Add(template_url); |
700 | 711 |
701 const TemplateURLID id = template_url->id(); | 712 const TemplateURLID id = template_url->id(); |
702 | 713 |
703 model()->SetDefaultSearchProvider(template_url); | 714 model()->SetDefaultSearchProvider(template_url); |
704 | 715 |
705 BlockTillServiceProcessesRequests(); | 716 BlockTillServiceProcessesRequests(); |
706 | 717 |
707 TemplateURL first_default_search_provider = *template_url; | 718 TemplateURL first_default_search_provider = *template_url; |
708 | 719 |
709 template_url = NULL; | 720 template_url = NULL; |
710 | 721 |
711 // Reset the model and don't load it. The template url we set as the default | 722 // Reset the model and don't load it. The template url we set as the default |
712 // should be pulled from prefs now. | 723 // should be pulled from prefs now. |
713 ResetModel(false); | 724 ResetModel(false); |
714 | 725 |
715 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 726 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
716 // value are persisted to prefs. | 727 // value are persisted to prefs. |
717 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 728 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
718 ASSERT_TRUE(default_turl); | 729 ASSERT_TRUE(default_turl); |
719 ASSERT_TRUE(default_turl->url()); | 730 ASSERT_TRUE(default_turl->url()); |
720 ASSERT_EQ("http://url", default_turl->url()->url()); | 731 ASSERT_EQ("http://url", default_turl->url()->url()); |
721 ASSERT_TRUE(default_turl->suggestions_url()); | 732 ASSERT_TRUE(default_turl->suggestions_url()); |
722 ASSERT_EQ("http://url2", default_turl->suggestions_url()->url()); | 733 ASSERT_EQ("http://url2", default_turl->suggestions_url()->url()); |
723 ASSERT_TRUE(default_turl->instant_url()); | 734 ASSERT_TRUE(default_turl->instant_url()); |
724 EXPECT_EQ("http://instant", default_turl->instant_url()->url()); | 735 EXPECT_EQ("http://instant", default_turl->instant_url()->url()); |
725 ASSERT_EQ(L"a", default_turl->short_name()); | 736 ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); |
726 ASSERT_EQ(id, default_turl->id()); | 737 ASSERT_EQ(id, default_turl->id()); |
727 | 738 |
728 // Now do a load and make sure the default search provider really takes. | 739 // Now do a load and make sure the default search provider really takes. |
729 VerifyLoad(); | 740 VerifyLoad(); |
730 | 741 |
731 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 742 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
732 AssertEquals(first_default_search_provider, | 743 AssertEquals(first_default_search_provider, |
733 *model()->GetDefaultSearchProvider()); | 744 *model()->GetDefaultSearchProvider()); |
734 } | 745 } |
735 | 746 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 ASSERT_TRUE(term_iterator != terms.end()); | 786 ASSERT_TRUE(term_iterator != terms.end()); |
776 ASSERT_EQ(values[j], term_iterator->second); | 787 ASSERT_EQ(values[j], term_iterator->second); |
777 } | 788 } |
778 } | 789 } |
779 } | 790 } |
780 } | 791 } |
781 | 792 |
782 TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { | 793 TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { |
783 struct TestData { | 794 struct TestData { |
784 const std::string url; | 795 const std::string url; |
785 const std::wstring term; | 796 const string16 term; |
786 } data[] = { | 797 } data[] = { |
787 { "http://foo/", L"" }, | 798 { "http://foo/", string16() }, |
788 { "http://foo/foo?q=xx", L"" }, | 799 { "http://foo/foo?q=xx", string16() }, |
789 { "http://x/bar?q=xx", L"" }, | 800 { "http://x/bar?q=xx", string16() }, |
790 { "http://x/foo?y=xx", L"" }, | 801 { "http://x/foo?y=xx", string16() }, |
791 { "http://x/foo?q=xx", L"xx" }, | 802 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, |
792 { "http://x/foo?a=b&q=xx", L"xx" }, | 803 { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") }, |
793 { "http://x/foo?q=b&q=xx", L"" }, | 804 { "http://x/foo?q=b&q=xx", string16() }, |
794 }; | 805 }; |
795 | 806 |
796 ChangeModelToLoadState(); | 807 ChangeModelToLoadState(); |
797 AddKeywordWithDate(L"x", false, "http://x/foo?q={searchTerms}", | 808 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", |
798 "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); | 809 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time()); |
799 | 810 |
800 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 811 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
801 history::URLVisitedDetails details; | 812 history::URLVisitedDetails details; |
802 details.row = history::URLRow(GURL(data[i].url)); | 813 details.row = history::URLRow(GURL(data[i].url)); |
803 details.transition = 0; | 814 details.transition = 0; |
804 model()->UpdateKeywordSearchTermsForURL(details); | 815 model()->UpdateKeywordSearchTermsForURL(details); |
805 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); | 816 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); |
806 } | 817 } |
807 } | 818 } |
808 | 819 |
809 TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { | 820 TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { |
810 struct TestData { | 821 struct TestData { |
811 const std::string url; | 822 const std::string url; |
812 } data[] = { | 823 } data[] = { |
813 { "http://foo/" }, | 824 { "http://foo/" }, |
814 { "http://x/bar?q=xx" }, | 825 { "http://x/bar?q=xx" }, |
815 { "http://x/foo?y=xx" }, | 826 { "http://x/foo?y=xx" }, |
816 }; | 827 }; |
817 | 828 |
818 ChangeModelToLoadState(); | 829 ChangeModelToLoadState(); |
819 AddKeywordWithDate(L"x", false, "http://x/foo", "http://sugg1", | 830 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", |
820 "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); | 831 "http://icon1", "UTF-8;UTF-16", "name", false, Time()); |
821 | 832 |
822 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 833 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
823 history::URLVisitedDetails details; | 834 history::URLVisitedDetails details; |
824 details.row = history::URLRow(GURL(data[i].url)); | 835 details.row = history::URLRow(GURL(data[i].url)); |
825 details.transition = 0; | 836 details.transition = 0; |
826 model()->UpdateKeywordSearchTermsForURL(details); | 837 model()->UpdateKeywordSearchTermsForURL(details); |
827 ASSERT_EQ(std::wstring(), GetAndClearSearchTerm()); | 838 ASSERT_EQ(string16(), GetAndClearSearchTerm()); |
828 } | 839 } |
829 } | 840 } |
830 | 841 |
831 TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { | 842 TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { |
832 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, | 843 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, |
833 // which also has a {google:baseURL} keyword in it, which will confuse this | 844 // which also has a {google:baseURL} keyword in it, which will confuse this |
834 // test. | 845 // test. |
835 ChangeModelToLoadState(); | 846 ChangeModelToLoadState(); |
836 SetGoogleBaseURL("http://google.com/"); | 847 SetGoogleBaseURL("http://google.com/"); |
837 const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true, | 848 const TemplateURL* t_url = AddKeywordWithDate("", true, |
838 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", | 849 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", |
839 "UTF-8;UTF-16", L"name", false, Time()); | 850 "UTF-8;UTF-16", "name", false, Time()); |
840 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); | 851 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); |
841 EXPECT_EQ("google.com", t_url->url()->GetHost()); | 852 EXPECT_EQ("google.com", t_url->url()->GetHost()); |
842 EXPECT_EQ(L"google.com", t_url->keyword()); | 853 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); |
843 | 854 |
844 // Change the Google base url. | 855 // Change the Google base url. |
845 test_util_.ResetObserverCount(); | 856 test_util_.ResetObserverCount(); |
846 SetGoogleBaseURL("http://foo.com/"); | 857 SetGoogleBaseURL("http://foo.com/"); |
847 VerifyObserverCount(1); | 858 VerifyObserverCount(1); |
848 | 859 |
849 // Make sure the host->TemplateURL map was updated appropriately. | 860 // Make sure the host->TemplateURL map was updated appropriately. |
850 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("foo.com")); | 861 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("foo.com")); |
851 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); | 862 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); |
852 EXPECT_EQ("foo.com", t_url->url()->GetHost()); | 863 EXPECT_EQ("foo.com", t_url->url()->GetHost()); |
853 EXPECT_EQ(L"foo.com", t_url->keyword()); | 864 EXPECT_EQ(ASCIIToUTF16("foo.com"), t_url->keyword()); |
854 EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, | 865 EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, |
855 L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); | 866 ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
856 } | 867 } |
857 | 868 |
858 struct QueryHistoryCallbackImpl { | 869 struct QueryHistoryCallbackImpl { |
859 QueryHistoryCallbackImpl() : success(false) {} | 870 QueryHistoryCallbackImpl() : success(false) {} |
860 | 871 |
861 void Callback(HistoryService::Handle handle, | 872 void Callback(HistoryService::Handle handle, |
862 bool success, const history::URLRow* row, | 873 bool success, const history::URLRow* row, |
863 history::VisitVector* visits) { | 874 history::VisitVector* visits) { |
864 this->success = success; | 875 this->success = success; |
865 if (row) | 876 if (row) |
866 this->row = *row; | 877 this->row = *row; |
867 if (visits) | 878 if (visits) |
868 this->visits = *visits; | 879 this->visits = *visits; |
869 } | 880 } |
870 | 881 |
871 bool success; | 882 bool success; |
872 history::URLRow row; | 883 history::URLRow row; |
873 history::VisitVector visits; | 884 history::VisitVector visits; |
874 }; | 885 }; |
875 | 886 |
876 // Make sure TemplateURLModel generates a KEYWORD_GENERATED visit for | 887 // Make sure TemplateURLModel generates a KEYWORD_GENERATED visit for |
877 // KEYWORD visits. | 888 // KEYWORD visits. |
878 TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { | 889 TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { |
879 VerifyLoad(); | 890 VerifyLoad(); |
880 profile()->CreateHistoryService(true, false); | 891 profile()->CreateHistoryService(true, false); |
881 | 892 |
882 // Create a keyword. | 893 // Create a keyword. |
883 TemplateURL* t_url = AddKeywordWithDate( | 894 TemplateURL* t_url = AddKeywordWithDate( |
884 L"keyword", false, "http://foo.com/foo?query={searchTerms}", | 895 "keyword", false, "http://foo.com/foo?query={searchTerms}", |
885 "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"keyword", true, | 896 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", |
886 base::Time::Now()); | 897 true, base::Time::Now()); |
887 | 898 |
888 // Add a visit that matches the url of the keyword. | 899 // Add a visit that matches the url of the keyword. |
889 HistoryService* history = | 900 HistoryService* history = |
890 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 901 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
891 history->AddPage( | 902 history->AddPage( |
892 GURL(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, | 903 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, |
893 std::wstring())), | 904 string16())), |
894 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), | 905 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), |
895 history::SOURCE_BROWSED, false); | 906 history::SOURCE_BROWSED, false); |
896 | 907 |
897 // Wait for history to finish processing the request. | 908 // Wait for history to finish processing the request. |
898 profile()->BlockUntilHistoryProcessesPendingRequests(); | 909 profile()->BlockUntilHistoryProcessesPendingRequests(); |
899 | 910 |
900 // Query history for the generated url. | 911 // Query history for the generated url. |
901 CancelableRequestConsumer consumer; | 912 CancelableRequestConsumer consumer; |
902 QueryHistoryCallbackImpl callback; | 913 QueryHistoryCallbackImpl callback; |
903 history->QueryURL(GURL("http://keyword"), true, &consumer, | 914 history->QueryURL(GURL("http://keyword"), true, &consumer, |
(...skipping 11 matching lines...) Expand all Loading... |
915 } | 926 } |
916 | 927 |
917 // Make sure that the load routine deletes prepopulated engines that no longer | 928 // Make sure that the load routine deletes prepopulated engines that no longer |
918 // exist in the prepopulate data. | 929 // exist in the prepopulate data. |
919 TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { | 930 TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { |
920 // Create a preloaded template url. Add it to a loaded model and wait for the | 931 // Create a preloaded template url. Add it to a loaded model and wait for the |
921 // saves to finish. | 932 // saves to finish. |
922 TemplateURL* t_url = CreatePreloadedTemplateURL(); | 933 TemplateURL* t_url = CreatePreloadedTemplateURL(); |
923 ChangeModelToLoadState(); | 934 ChangeModelToLoadState(); |
924 model()->Add(t_url); | 935 model()->Add(t_url); |
925 ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); | 936 ASSERT_TRUE( |
| 937 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
926 BlockTillServiceProcessesRequests(); | 938 BlockTillServiceProcessesRequests(); |
927 | 939 |
928 // Ensure that merging clears this engine. | 940 // Ensure that merging clears this engine. |
929 ResetModel(true); | 941 ResetModel(true); |
930 ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); | 942 ASSERT_TRUE( |
| 943 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
931 | 944 |
932 // Wait for any saves to finish. | 945 // Wait for any saves to finish. |
933 BlockTillServiceProcessesRequests(); | 946 BlockTillServiceProcessesRequests(); |
934 | 947 |
935 // Reload the model to verify that the database was updated as a result of the | 948 // Reload the model to verify that the database was updated as a result of the |
936 // merge. | 949 // merge. |
937 ResetModel(true); | 950 ResetModel(true); |
938 ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); | 951 ASSERT_TRUE( |
| 952 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
939 } | 953 } |
940 | 954 |
941 // Make sure that load routine doesn't delete prepopulated engines that no | 955 // Make sure that load routine doesn't delete prepopulated engines that no |
942 // longer exist in the prepopulate data if it has been modified by the user. | 956 // longer exist in the prepopulate data if it has been modified by the user. |
943 TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { | 957 TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { |
944 // Create a preloaded template url and add it to a loaded model. | 958 // Create a preloaded template url and add it to a loaded model. |
945 TemplateURL* t_url = CreatePreloadedTemplateURL(); | 959 TemplateURL* t_url = CreatePreloadedTemplateURL(); |
946 t_url->set_safe_for_autoreplace(false); | 960 t_url->set_safe_for_autoreplace(false); |
947 ChangeModelToLoadState(); | 961 ChangeModelToLoadState(); |
948 model()->Add(t_url); | 962 model()->Add(t_url); |
949 | 963 |
950 // Do the copy after t_url is added so that the id is set. | 964 // Do the copy after t_url is added so that the id is set. |
951 TemplateURL copy_t_url = *t_url; | 965 TemplateURL copy_t_url = *t_url; |
952 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); | 966 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
953 | 967 |
954 // Wait for any saves to finish. | 968 // Wait for any saves to finish. |
955 BlockTillServiceProcessesRequests(); | 969 BlockTillServiceProcessesRequests(); |
956 | 970 |
957 // Ensure that merging won't clear it if the user has edited it. | 971 // Ensure that merging won't clear it if the user has edited it. |
958 ResetModel(true); | 972 ResetModel(true); |
959 const TemplateURL* url_for_unittest = | 973 const TemplateURL* url_for_unittest = |
960 model()->GetTemplateURLForKeyword(L"unittest"); | 974 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
961 ASSERT_TRUE(url_for_unittest != NULL); | 975 ASSERT_TRUE(url_for_unittest != NULL); |
962 AssertEquals(copy_t_url, *url_for_unittest); | 976 AssertEquals(copy_t_url, *url_for_unittest); |
963 | 977 |
964 // Wait for any saves to finish. | 978 // Wait for any saves to finish. |
965 BlockTillServiceProcessesRequests(); | 979 BlockTillServiceProcessesRequests(); |
966 | 980 |
967 // Reload the model to verify that save/reload retains the item. | 981 // Reload the model to verify that save/reload retains the item. |
968 ResetModel(true); | 982 ResetModel(true); |
969 ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); | 983 ASSERT_TRUE( |
| 984 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
970 } | 985 } |
971 | 986 |
972 // Make sure that load routine doesn't delete | 987 // Make sure that load routine doesn't delete |
973 // prepopulated engines that no longer exist in the prepopulate data if | 988 // prepopulated engines that no longer exist in the prepopulate data if |
974 // it has been modified by the user. | 989 // it has been modified by the user. |
975 TEST_F(TemplateURLModelTest, LoadSavesPrepopulatedDefaultSearchProvider) { | 990 TEST_F(TemplateURLModelTest, LoadSavesPrepopulatedDefaultSearchProvider) { |
976 VerifyLoad(); | 991 VerifyLoad(); |
977 // Verify that the default search provider is set to something. | 992 // Verify that the default search provider is set to something. |
978 ASSERT_TRUE(model()->GetDefaultSearchProvider() != NULL); | 993 ASSERT_TRUE(model()->GetDefaultSearchProvider() != NULL); |
979 TemplateURL default_url = *model()->GetDefaultSearchProvider(); | 994 TemplateURL default_url = *model()->GetDefaultSearchProvider(); |
(...skipping 16 matching lines...) Expand all Loading... |
996 // is not in the current set of preloaded template urls and save | 1011 // is not in the current set of preloaded template urls and save |
997 // the result. | 1012 // the result. |
998 TemplateURL* t_url = CreatePreloadedTemplateURL(); | 1013 TemplateURL* t_url = CreatePreloadedTemplateURL(); |
999 ChangeModelToLoadState(); | 1014 ChangeModelToLoadState(); |
1000 model()->Add(t_url); | 1015 model()->Add(t_url); |
1001 model()->SetDefaultSearchProvider(t_url); | 1016 model()->SetDefaultSearchProvider(t_url); |
1002 // Do the copy after t_url is added and set as default so that its | 1017 // Do the copy after t_url is added and set as default so that its |
1003 // internal state is correct. | 1018 // internal state is correct. |
1004 TemplateURL copy_t_url = *t_url; | 1019 TemplateURL copy_t_url = *t_url; |
1005 | 1020 |
1006 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); | 1021 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
1007 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1022 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
1008 BlockTillServiceProcessesRequests(); | 1023 BlockTillServiceProcessesRequests(); |
1009 | 1024 |
1010 // Ensure that merging won't clear the prepopulated template url | 1025 // Ensure that merging won't clear the prepopulated template url |
1011 // which is no longer present if it's the default engine. | 1026 // which is no longer present if it's the default engine. |
1012 ResetModel(true); | 1027 ResetModel(true); |
1013 { | 1028 { |
1014 const TemplateURL* keyword_url = | 1029 const TemplateURL* keyword_url = |
1015 model()->GetTemplateURLForKeyword(L"unittest"); | 1030 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1016 ASSERT_TRUE(keyword_url != NULL); | 1031 ASSERT_TRUE(keyword_url != NULL); |
1017 AssertEquals(copy_t_url, *keyword_url); | 1032 AssertEquals(copy_t_url, *keyword_url); |
1018 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1033 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1019 } | 1034 } |
1020 | 1035 |
1021 // Wait for any saves to finish. | 1036 // Wait for any saves to finish. |
1022 BlockTillServiceProcessesRequests(); | 1037 BlockTillServiceProcessesRequests(); |
1023 | 1038 |
1024 // Reload the model to verify that the update was saved. | 1039 // Reload the model to verify that the update was saved. |
1025 ResetModel(true); | 1040 ResetModel(true); |
1026 { | 1041 { |
1027 const TemplateURL* keyword_url = | 1042 const TemplateURL* keyword_url = |
1028 model()->GetTemplateURLForKeyword(L"unittest"); | 1043 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1029 ASSERT_TRUE(keyword_url != NULL); | 1044 ASSERT_TRUE(keyword_url != NULL); |
1030 AssertEquals(copy_t_url, *keyword_url); | 1045 AssertEquals(copy_t_url, *keyword_url); |
1031 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1046 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1032 } | 1047 } |
1033 } | 1048 } |
1034 | 1049 |
1035 // Make sure that the load routine updates the url of a preexisting | 1050 // Make sure that the load routine updates the url of a preexisting |
1036 // default search engine provider and that the result is saved correctly. | 1051 // default search engine provider and that the result is saved correctly. |
1037 TEST_F(TemplateURLModelTest, LoadUpdatesDefaultSearchURL) { | 1052 TEST_F(TemplateURLModelTest, LoadUpdatesDefaultSearchURL) { |
1038 TestLoadUpdatingPreloadedURL(0); | 1053 TestLoadUpdatingPreloadedURL(0); |
1039 } | 1054 } |
1040 | 1055 |
1041 // Make sure that the load routine updates the url of a preexisting | 1056 // Make sure that the load routine updates the url of a preexisting |
1042 // non-default search engine provider and that the result is saved correctly. | 1057 // non-default search engine provider and that the result is saved correctly. |
1043 TEST_F(TemplateURLModelTest, LoadUpdatesSearchURL) { | 1058 TEST_F(TemplateURLModelTest, LoadUpdatesSearchURL) { |
1044 TestLoadUpdatingPreloadedURL(1); | 1059 TestLoadUpdatingPreloadedURL(1); |
1045 } | 1060 } |
1046 | 1061 |
1047 // Make sure that the load does update of auto-keywords correctly. | 1062 // Make sure that the load does update of auto-keywords correctly. |
1048 // This test basically verifies that no asserts or crashes occur | 1063 // This test basically verifies that no asserts or crashes occur |
1049 // during this operation. | 1064 // during this operation. |
1050 TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { | 1065 TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { |
1051 std::wstring prepopulated_url; | 1066 string16 prepopulated_url; |
1052 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( | 1067 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( |
1053 0, &prepopulated_url); | 1068 0, &prepopulated_url); |
1054 t_url->set_safe_for_autoreplace(false); | 1069 t_url->set_safe_for_autoreplace(false); |
1055 t_url->SetURL("{google:baseURL}?q={searchTerms}", 0, 0); | 1070 t_url->SetURL("{google:baseURL}?q={searchTerms}", 0, 0); |
1056 t_url->set_autogenerate_keyword(true); | 1071 t_url->set_autogenerate_keyword(true); |
1057 | 1072 |
1058 // Then add it to the model and save it all. | 1073 // Then add it to the model and save it all. |
1059 ChangeModelToLoadState(); | 1074 ChangeModelToLoadState(); |
1060 model()->Add(t_url); | 1075 model()->Add(t_url); |
1061 BlockTillServiceProcessesRequests(); | 1076 BlockTillServiceProcessesRequests(); |
(...skipping 23 matching lines...) Expand all Loading... |
1085 | 1100 |
1086 // Verifies that if the default search URL preference is managed, we report | 1101 // Verifies that if the default search URL preference is managed, we report |
1087 // the default search as managed. Also check that we are getting the right | 1102 // the default search as managed. Also check that we are getting the right |
1088 // values. | 1103 // values. |
1089 TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { | 1104 TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { |
1090 VerifyLoad(); | 1105 VerifyLoad(); |
1091 const size_t initial_count = model()->GetTemplateURLs().size(); | 1106 const size_t initial_count = model()->GetTemplateURLs().size(); |
1092 test_util_.ResetObserverCount(); | 1107 test_util_.ResetObserverCount(); |
1093 | 1108 |
1094 // Set a regular default search provider. | 1109 // Set a regular default search provider. |
1095 TemplateURL* regular_default = AddKeywordWithDate(L"key1", false, | 1110 TemplateURL* regular_default = AddKeywordWithDate("key1", false, |
1096 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", | 1111 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", |
1097 true, Time()); | 1112 true, Time()); |
1098 VerifyObserverCount(1); | 1113 VerifyObserverCount(1); |
1099 model()->SetDefaultSearchProvider(regular_default); | 1114 model()->SetDefaultSearchProvider(regular_default); |
1100 // Adding the URL and setting the default search provider should have caused | 1115 // Adding the URL and setting the default search provider should have caused |
1101 // notifications. | 1116 // notifications. |
1102 VerifyObserverCount(1); | 1117 VerifyObserverCount(1); |
1103 EXPECT_FALSE(model()->is_default_search_managed()); | 1118 EXPECT_FALSE(model()->is_default_search_managed()); |
1104 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 1119 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
1105 | 1120 |
1106 // Set a managed preference that establishes a default search provider. | 1121 // Set a managed preference that establishes a default search provider. |
1107 const char kName[] = "test1"; | 1122 const char kName[] = "test1"; |
1108 const char kSearchURL[] = "http://test.com/search?t={searchTerms}"; | 1123 const char kSearchURL[] = "http://test.com/search?t={searchTerms}"; |
1109 const char kIconURL[] = "http://test.com/icon.jpg"; | 1124 const char kIconURL[] = "http://test.com/icon.jpg"; |
1110 const char kEncodings[] = "UTF-16;UTF-32"; | 1125 const char kEncodings[] = "UTF-16;UTF-32"; |
1111 SetManagedDefaultSearchPreferences(true, kName, kSearchURL, "", kIconURL, | 1126 SetManagedDefaultSearchPreferences(true, kName, kSearchURL, "", kIconURL, |
1112 kEncodings, ""); | 1127 kEncodings, ""); |
1113 VerifyObserverFired(); | 1128 VerifyObserverFired(); |
1114 EXPECT_TRUE(model()->is_default_search_managed()); | 1129 EXPECT_TRUE(model()->is_default_search_managed()); |
1115 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); | 1130 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); |
1116 | 1131 |
1117 // Verify that the default manager we are getting is the managed one. | 1132 // Verify that the default manager we are getting is the managed one. |
1118 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL()); | 1133 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL()); |
1119 expected_managed_default1->SetURL(kSearchURL, 0, 0); | 1134 expected_managed_default1->SetURL(kSearchURL, 0, 0); |
1120 expected_managed_default1->SetFavIconURL(GURL(kIconURL)); | 1135 expected_managed_default1->SetFavIconURL(GURL(kIconURL)); |
1121 expected_managed_default1->set_short_name(L"test1"); | 1136 expected_managed_default1->set_short_name(ASCIIToUTF16("test1")); |
1122 std::vector<std::string> encodings_vector; | 1137 std::vector<std::string> encodings_vector; |
1123 base::SplitString(kEncodings, ';', &encodings_vector); | 1138 base::SplitString(kEncodings, ';', &encodings_vector); |
1124 expected_managed_default1->set_input_encodings(encodings_vector); | 1139 expected_managed_default1->set_input_encodings(encodings_vector); |
1125 expected_managed_default1->set_show_in_default_list(true); | 1140 expected_managed_default1->set_show_in_default_list(true); |
1126 const TemplateURL* actual_managed_default = | 1141 const TemplateURL* actual_managed_default = |
1127 model()->GetDefaultSearchProvider(); | 1142 model()->GetDefaultSearchProvider(); |
1128 ExpectSimilar(actual_managed_default, expected_managed_default1.get()); | 1143 ExpectSimilar(actual_managed_default, expected_managed_default1.get()); |
1129 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); | 1144 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); |
1130 | 1145 |
1131 // Update the managed preference and check that the model has changed. | 1146 // Update the managed preference and check that the model has changed. |
1132 const char kNewName[] = "test2"; | 1147 const char kNewName[] = "test2"; |
1133 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; | 1148 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; |
1134 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; | 1149 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; |
1135 SetManagedDefaultSearchPreferences(true, kNewName, kNewSearchURL, | 1150 SetManagedDefaultSearchPreferences(true, kNewName, kNewSearchURL, |
1136 kNewSuggestURL, "", "", ""); | 1151 kNewSuggestURL, "", "", ""); |
1137 VerifyObserverFired(); | 1152 VerifyObserverFired(); |
1138 EXPECT_TRUE(model()->is_default_search_managed()); | 1153 EXPECT_TRUE(model()->is_default_search_managed()); |
1139 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); | 1154 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); |
1140 | 1155 |
1141 // Verify that the default manager we are now getting is the correct one. | 1156 // Verify that the default manager we are now getting is the correct one. |
1142 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL()); | 1157 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL()); |
1143 expected_managed_default2->SetURL(kNewSearchURL, 0, 0); | 1158 expected_managed_default2->SetURL(kNewSearchURL, 0, 0); |
1144 expected_managed_default2->SetSuggestionsURL(kNewSuggestURL, 0, 0); | 1159 expected_managed_default2->SetSuggestionsURL(kNewSuggestURL, 0, 0); |
1145 expected_managed_default2->set_short_name(L"test2"); | 1160 expected_managed_default2->set_short_name(ASCIIToUTF16("test2")); |
1146 expected_managed_default2->set_show_in_default_list(true); | 1161 expected_managed_default2->set_show_in_default_list(true); |
1147 actual_managed_default = model()->GetDefaultSearchProvider(); | 1162 actual_managed_default = model()->GetDefaultSearchProvider(); |
1148 ExpectSimilar(actual_managed_default, expected_managed_default2.get()); | 1163 ExpectSimilar(actual_managed_default, expected_managed_default2.get()); |
1149 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); | 1164 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); |
1150 | 1165 |
1151 // Remove all the managed prefs and check that we are no longer managed. | 1166 // Remove all the managed prefs and check that we are no longer managed. |
1152 RemoveManagedDefaultSearchPreferences(); | 1167 RemoveManagedDefaultSearchPreferences(); |
1153 VerifyObserverFired(); | 1168 VerifyObserverFired(); |
1154 EXPECT_FALSE(model()->is_default_search_managed()); | 1169 EXPECT_FALSE(model()->is_default_search_managed()); |
1155 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 1170 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
(...skipping 17 matching lines...) Expand all Loading... |
1173 kEncodings, ""); | 1188 kEncodings, ""); |
1174 VerifyObserverFired(); | 1189 VerifyObserverFired(); |
1175 EXPECT_TRUE(model()->is_default_search_managed()); | 1190 EXPECT_TRUE(model()->is_default_search_managed()); |
1176 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); | 1191 EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); |
1177 | 1192 |
1178 // Verify that the default manager we are getting is the managed one. | 1193 // Verify that the default manager we are getting is the managed one. |
1179 actual_managed_default = model()->GetDefaultSearchProvider(); | 1194 actual_managed_default = model()->GetDefaultSearchProvider(); |
1180 ExpectSimilar(actual_managed_default, expected_managed_default1.get()); | 1195 ExpectSimilar(actual_managed_default, expected_managed_default1.get()); |
1181 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); | 1196 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); |
1182 } | 1197 } |
OLD | NEW |