Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: chrome/browser/search_engines/template_url_model_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698