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

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

Issue 2290503003: Remove use of stl_util in search_engines. (Closed)
Patch Set: fix broken test Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/search_engines/template_url_service.h" 5 #include "components/search_engines/template_url_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/task/cancelable_task_tracker.h" 22 #include "base/task/cancelable_task_tracker.h"
22 #include "base/test/simple_test_clock.h" 23 #include "base/test/simple_test_clock.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/time/time.h" 25 #include "base/time/time.h"
25 #include "chrome/browser/history/history_service_factory.h" 26 #include "chrome/browser/history/history_service_factory.h"
(...skipping 27 matching lines...) Expand all
53 this->row = row; 54 this->row = row;
54 this->visits = visits; 55 this->visits = visits;
55 } 56 }
56 } 57 }
57 58
58 bool success; 59 bool success;
59 history::URLRow row; 60 history::URLRow row;
60 history::VisitVector visits; 61 history::VisitVector visits;
61 }; 62 };
62 63
63 TemplateURL* CreateKeywordWithDate( 64 std::unique_ptr<TemplateURL> CreateKeywordWithDate(
64 TemplateURLService* model, 65 TemplateURLService* model,
65 const std::string& short_name, 66 const std::string& short_name,
66 const std::string& keyword, 67 const std::string& keyword,
67 const std::string& url, 68 const std::string& url,
68 const std::string& suggest_url, 69 const std::string& suggest_url,
69 const std::string& alternate_url, 70 const std::string& alternate_url,
70 const std::string& favicon_url, 71 const std::string& favicon_url,
71 bool safe_for_autoreplace, 72 bool safe_for_autoreplace,
72 bool show_in_default_list, 73 bool show_in_default_list,
73 const std::string& encodings, 74 const std::string& encodings,
74 Time date_created, 75 Time date_created,
75 Time last_modified) { 76 Time last_modified) {
76 TemplateURLData data; 77 TemplateURLData data;
77 data.SetShortName(base::UTF8ToUTF16(short_name)); 78 data.SetShortName(base::UTF8ToUTF16(short_name));
78 data.SetKeyword(base::UTF8ToUTF16(keyword)); 79 data.SetKeyword(base::UTF8ToUTF16(keyword));
79 data.SetURL(url); 80 data.SetURL(url);
80 data.suggestions_url = suggest_url; 81 data.suggestions_url = suggest_url;
81 if (!alternate_url.empty()) 82 if (!alternate_url.empty())
82 data.alternate_urls.push_back(alternate_url); 83 data.alternate_urls.push_back(alternate_url);
83 data.favicon_url = GURL(favicon_url); 84 data.favicon_url = GURL(favicon_url);
84 data.safe_for_autoreplace = safe_for_autoreplace; 85 data.safe_for_autoreplace = safe_for_autoreplace;
85 data.show_in_default_list = show_in_default_list; 86 data.show_in_default_list = show_in_default_list;
86 data.input_encodings = base::SplitString( 87 data.input_encodings = base::SplitString(
87 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 88 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
88 data.date_created = date_created; 89 data.date_created = date_created;
89 data.last_modified = last_modified; 90 data.last_modified = last_modified;
90 return new TemplateURL(data); 91 return base::MakeUnique<TemplateURL>(data);
91 } 92 }
92 93
93 TemplateURL* AddKeywordWithDate( 94 TemplateURL* AddKeywordWithDate(
94 TemplateURLService* model, 95 TemplateURLService* model,
95 const std::string& short_name, 96 const std::string& short_name,
96 const std::string& keyword, 97 const std::string& keyword,
97 const std::string& url, 98 const std::string& url,
98 const std::string& suggest_url, 99 const std::string& suggest_url,
99 const std::string& alternate_url, 100 const std::string& alternate_url,
100 const std::string& favicon_url, 101 const std::string& favicon_url,
101 bool safe_for_autoreplace, 102 bool safe_for_autoreplace,
102 const std::string& encodings, 103 const std::string& encodings,
103 Time date_created, 104 Time date_created,
104 Time last_modified) { 105 Time last_modified) {
105 TemplateURL* t_url = CreateKeywordWithDate( 106 TemplateURL* t_url = model->Add(CreateKeywordWithDate(
106 model, short_name, keyword, url, suggest_url, alternate_url,favicon_url, 107 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url,
107 safe_for_autoreplace, false, encodings, date_created, last_modified); 108 safe_for_autoreplace, false, encodings, date_created, last_modified));
108 model->Add(t_url);
109 EXPECT_NE(0, t_url->id()); 109 EXPECT_NE(0, t_url->id());
110 return t_url; 110 return t_url;
111 } 111 }
112 112
113 // Checks that the two TemplateURLs are similar. It does not check the id, the 113 // Checks that the two TemplateURLs are similar. It does not check the id, the
114 // date_created or the last_modified time. Neither pointer should be NULL. 114 // date_created or the last_modified time. Neither pointer should be NULL.
115 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { 115 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) {
116 ASSERT_TRUE(expected != NULL); 116 ASSERT_TRUE(expected != NULL);
117 ASSERT_TRUE(actual != NULL); 117 ASSERT_TRUE(actual != NULL);
118 EXPECT_EQ(expected->short_name(), actual->short_name()); 118 EXPECT_EQ(expected->short_name(), actual->short_name());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 Time last_modified); 153 Time last_modified);
154 154
155 // Verifies the two TemplateURLs are equal. 155 // Verifies the two TemplateURLs are equal.
156 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); 156 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual);
157 157
158 // Verifies the two timestamps are equal, within the expected degree of 158 // Verifies the two timestamps are equal, within the expected degree of
159 // precision. 159 // precision.
160 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); 160 void AssertTimesEqual(const base::Time& expected, const base::Time& actual);
161 161
162 // Create an URL that appears to have been prepopulated, but won't be in the 162 // Create an URL that appears to have been prepopulated, but won't be in the
163 // current data. The caller owns the returned TemplateURL*. 163 // current data.
164 TemplateURL* CreatePreloadedTemplateURL(bool safe_for_autoreplace, 164 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL(
165 int prepopulate_id); 165 bool safe_for_autoreplace,
166 int prepopulate_id);
166 167
167 // Helper methods to make calling TemplateURLServiceTestUtil methods less 168 // Helper methods to make calling TemplateURLServiceTestUtil methods less
168 // visually noisy in the test code. 169 // visually noisy in the test code.
169 void VerifyObserverCount(int expected_changed_count); 170 void VerifyObserverCount(int expected_changed_count);
170 void VerifyObserverFired(); 171 void VerifyObserverFired();
171 TemplateURLServiceTestUtil* test_util() { return test_util_.get(); } 172 TemplateURLServiceTestUtil* test_util() { return test_util_.get(); }
172 TemplateURLService* model() { return test_util_->model(); } 173 TemplateURLService* model() { return test_util_->model(); }
173 const SearchTermsData& search_terms_data() { 174 const SearchTermsData& search_terms_data() {
174 return model()->search_terms_data(); 175 return model()->search_terms_data();
175 } 176 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 244 }
244 245
245 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, 246 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected,
246 const base::Time& actual) { 247 const base::Time& actual) {
247 // Because times are stored with a granularity of one second, there is a loss 248 // Because times are stored with a granularity of one second, there is a loss
248 // of precision when serializing and deserializing the timestamps. Hence, only 249 // of precision when serializing and deserializing the timestamps. Hence, only
249 // expect timestamps to be equal to within one second of one another. 250 // expect timestamps to be equal to within one second of one another.
250 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); 251 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1));
251 } 252 }
252 253
253 TemplateURL* TemplateURLServiceTest::CreatePreloadedTemplateURL( 254 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL(
254 bool safe_for_autoreplace, 255 bool safe_for_autoreplace,
255 int prepopulate_id) { 256 int prepopulate_id) {
256 TemplateURLData data; 257 TemplateURLData data;
257 data.SetShortName(ASCIIToUTF16("unittest")); 258 data.SetShortName(ASCIIToUTF16("unittest"));
258 data.SetKeyword(ASCIIToUTF16("unittest")); 259 data.SetKeyword(ASCIIToUTF16("unittest"));
259 data.SetURL("http://www.unittest.com/{searchTerms}"); 260 data.SetURL("http://www.unittest.com/{searchTerms}");
260 data.favicon_url = GURL("http://favicon.url"); 261 data.favicon_url = GURL("http://favicon.url");
261 data.show_in_default_list = true; 262 data.show_in_default_list = true;
262 data.safe_for_autoreplace = safe_for_autoreplace; 263 data.safe_for_autoreplace = safe_for_autoreplace;
263 data.input_encodings.push_back("UTF-8"); 264 data.input_encodings.push_back("UTF-8");
264 data.date_created = Time::FromTimeT(100); 265 data.date_created = Time::FromTimeT(100);
265 data.last_modified = Time::FromTimeT(100); 266 data.last_modified = Time::FromTimeT(100);
266 data.prepopulate_id = prepopulate_id; 267 data.prepopulate_id = prepopulate_id;
267 return new TemplateURL(data); 268 return base::MakeUnique<TemplateURL>(data);
268 } 269 }
269 270
270 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { 271 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) {
271 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); 272 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount());
272 test_util_->ResetObserverCount(); 273 test_util_->ResetObserverCount();
273 } 274 }
274 275
275 void TemplateURLServiceTest::VerifyObserverFired() { 276 void TemplateURLServiceTest::VerifyObserverFired() {
276 EXPECT_LE(1, test_util_->GetObserverCount()); 277 EXPECT_LE(1, test_util_->GetObserverCount());
277 test_util_->ResetObserverCount(); 278 test_util_->ResetObserverCount();
(...skipping 13 matching lines...) Expand all
291 292
292 TemplateURLData data; 293 TemplateURLData data;
293 data.SetShortName(ASCIIToUTF16("google")); 294 data.SetShortName(ASCIIToUTF16("google"));
294 data.SetKeyword(ASCIIToUTF16("keyword")); 295 data.SetKeyword(ASCIIToUTF16("keyword"));
295 data.SetURL("http://www.google.com/foo/bar"); 296 data.SetURL("http://www.google.com/foo/bar");
296 data.favicon_url = GURL("http://favicon.url"); 297 data.favicon_url = GURL("http://favicon.url");
297 data.safe_for_autoreplace = true; 298 data.safe_for_autoreplace = true;
298 data.date_created = Time::FromTimeT(100); 299 data.date_created = Time::FromTimeT(100);
299 data.last_modified = Time::FromTimeT(100); 300 data.last_modified = Time::FromTimeT(100);
300 data.sync_guid = "00000000-0000-0000-0000-000000000001"; 301 data.sync_guid = "00000000-0000-0000-0000-000000000001";
301 TemplateURL* t_url = new TemplateURL(data); 302 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
302 model()->Add(t_url);
303 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), 303 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"),
304 GURL(), NULL)); 304 GURL(), NULL));
305 VerifyObserverCount(1); 305 VerifyObserverCount(1);
306 base::RunLoop().RunUntilIdle(); 306 base::RunLoop().RunUntilIdle();
307 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 307 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
308 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); 308 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword()));
309 // We need to make a second copy as the model takes ownership of |t_url| and 309 // We need to make a second copy as the model takes ownership of |t_url| and
310 // will delete it. We have to do this after calling Add() since that gives 310 // will delete it. We have to do this after calling Add() since that gives
311 // |t_url| its ID. 311 // |t_url| its ID.
312 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 312 std::unique_ptr<TemplateURL> cloned_url =
313 base::MakeUnique<TemplateURL>(t_url->data());
313 314
314 // Reload the model to verify it was actually saved to the database. 315 // Reload the model to verify it was actually saved to the database.
315 test_util()->ResetModel(true); 316 test_util()->ResetModel(true);
316 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 317 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
317 TemplateURL* loaded_url = 318 TemplateURL* loaded_url =
318 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 319 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
319 ASSERT_TRUE(loaded_url != NULL); 320 ASSERT_TRUE(loaded_url != NULL);
320 AssertEquals(*cloned_url, *loaded_url); 321 AssertEquals(*cloned_url, *loaded_url);
321 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), 322 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"),
322 GURL(), NULL)); 323 GURL(), NULL));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 std::string(), true, "UTF-8", Time(), Time()); 367 std::string(), true, "UTF-8", Time(), Time());
367 VerifyObserverCount(1); 368 VerifyObserverCount(1);
368 369
369 // Test what happens when we try to add a TemplateURL with the same keyword as 370 // Test what happens when we try to add a TemplateURL with the same keyword as
370 // one in the model. 371 // one in the model.
371 TemplateURLData data; 372 TemplateURLData data;
372 data.SetShortName(ASCIIToUTF16("second")); 373 data.SetShortName(ASCIIToUTF16("second"));
373 data.SetKeyword(ASCIIToUTF16("keyword")); 374 data.SetKeyword(ASCIIToUTF16("keyword"));
374 data.SetURL("http://test2"); 375 data.SetURL("http://test2");
375 data.safe_for_autoreplace = false; 376 data.safe_for_autoreplace = false;
376 TemplateURL* t_url = new TemplateURL(data); 377 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
377 model()->Add(t_url);
378 378
379 // Because the old TemplateURL was replaceable and the new one wasn't, the new 379 // Because the old TemplateURL was replaceable and the new one wasn't, the new
380 // one should have replaced the old. 380 // one should have replaced the old.
381 VerifyObserverCount(1); 381 VerifyObserverCount(1);
382 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 382 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
383 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 383 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
384 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); 384 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword());
385 EXPECT_FALSE(t_url->safe_for_autoreplace()); 385 EXPECT_FALSE(t_url->safe_for_autoreplace());
386 386
387 // Now try adding a replaceable TemplateURL. This should just delete the 387 // Now try adding a replaceable TemplateURL. This should just delete the
388 // passed-in URL. 388 // passed-in URL.
389 data.SetShortName(ASCIIToUTF16("third")); 389 data.SetShortName(ASCIIToUTF16("third"));
390 data.SetURL("http://test3"); 390 data.SetURL("http://test3");
391 data.safe_for_autoreplace = true; 391 data.safe_for_autoreplace = true;
392 model()->Add(new TemplateURL(data)); 392 model()->Add(base::MakeUnique<TemplateURL>(data));
393 VerifyObserverCount(0); 393 VerifyObserverCount(0);
394 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 394 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
395 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 395 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
396 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); 396 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword());
397 EXPECT_FALSE(t_url->safe_for_autoreplace()); 397 EXPECT_FALSE(t_url->safe_for_autoreplace());
398 398
399 // Now try adding a non-replaceable TemplateURL again. This should uniquify 399 // Now try adding a non-replaceable TemplateURL again. This should uniquify
400 // the existing entry's keyword. 400 // the existing entry's keyword.
401 data.SetShortName(ASCIIToUTF16("fourth")); 401 data.SetShortName(ASCIIToUTF16("fourth"));
402 data.SetURL("http://test4"); 402 data.SetURL("http://test4");
403 data.safe_for_autoreplace = false; 403 data.safe_for_autoreplace = false;
404 TemplateURL* t_url2 = new TemplateURL(data); 404 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data));
405 model()->Add(t_url2);
406 VerifyObserverCount(1); 405 VerifyObserverCount(1);
407 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 406 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
408 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); 407 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name());
409 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); 408 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword());
410 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 409 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
411 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); 410 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword());
412 } 411 }
413 412
414 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { 413 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) {
415 test_util()->VerifyLoad(); 414 test_util()->VerifyLoad();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 "replaceable", "keyword", "http://test1", std::string(), std::string(), 466 "replaceable", "keyword", "http://test1", std::string(), std::string(),
468 std::string(), true, "UTF-8", Time(), Time()); 467 std::string(), true, "UTF-8", Time(), Time());
469 468
470 // Adding another replaceable keyword should remove the existing one, but 469 // Adding another replaceable keyword should remove the existing one, but
471 // leave the extension as is. 470 // leave the extension as is.
472 TemplateURLData data; 471 TemplateURLData data;
473 data.SetShortName(ASCIIToUTF16("name1")); 472 data.SetShortName(ASCIIToUTF16("name1"));
474 data.SetKeyword(ASCIIToUTF16("keyword")); 473 data.SetKeyword(ASCIIToUTF16("keyword"));
475 data.SetURL("http://test3"); 474 data.SetURL("http://test3");
476 data.safe_for_autoreplace = true; 475 data.safe_for_autoreplace = true;
477 TemplateURL* t_url = new TemplateURL(data); 476 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
478 model()->Add(t_url);
479 EXPECT_EQ(extension, 477 EXPECT_EQ(extension,
480 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 478 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
481 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); 479 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3"));
482 480
483 // Adding a nonreplaceable keyword should remove the existing replaceable 481 // Adding a nonreplaceable keyword should remove the existing replaceable
484 // keyword and replace the extension as the associated URL for this keyword, 482 // keyword and replace the extension as the associated URL for this keyword,
485 // but not evict the extension from the service entirely. 483 // but not evict the extension from the service entirely.
486 data.SetShortName(ASCIIToUTF16("name2")); 484 data.SetShortName(ASCIIToUTF16("name2"));
487 data.SetURL("http://test4"); 485 data.SetURL("http://test4");
488 data.safe_for_autoreplace = false; 486 data.safe_for_autoreplace = false;
489 TemplateURL* t_url2 = new TemplateURL(data); 487 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data));
490 model()->Add(t_url2);
491 EXPECT_EQ(t_url2, 488 EXPECT_EQ(t_url2,
492 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 489 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
493 } 490 }
494 491
495 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { 492 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) {
496 test_util()->VerifyLoad(); 493 test_util()->VerifyLoad();
497 494
498 // Register an omnibox keyword. 495 // Register an omnibox keyword.
499 model()->RegisterOmniboxKeyword("test", "extension", "keyword", 496 model()->RegisterOmniboxKeyword("test", "extension", "keyword",
500 "chrome-extension://test"); 497 "chrome-extension://test");
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // Add a new TemplateURL. 627 // Add a new TemplateURL.
631 test_util()->VerifyLoad(); 628 test_util()->VerifyLoad();
632 const size_t initial_count = model()->GetTemplateURLs().size(); 629 const size_t initial_count = model()->GetTemplateURLs().size();
633 TemplateURLData data; 630 TemplateURLData data;
634 data.SetShortName(ASCIIToUTF16("google")); 631 data.SetShortName(ASCIIToUTF16("google"));
635 data.SetKeyword(ASCIIToUTF16("keyword")); 632 data.SetKeyword(ASCIIToUTF16("keyword"));
636 data.SetURL("http://www.google.com/foo/bar"); 633 data.SetURL("http://www.google.com/foo/bar");
637 data.favicon_url = GURL("http://favicon.url"); 634 data.favicon_url = GURL("http://favicon.url");
638 data.date_created = Time::FromTimeT(100); 635 data.date_created = Time::FromTimeT(100);
639 data.last_modified = Time::FromTimeT(100); 636 data.last_modified = Time::FromTimeT(100);
640 TemplateURL* t_url = new TemplateURL(data); 637 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
641 model()->Add(t_url);
642 638
643 VerifyObserverCount(1); 639 VerifyObserverCount(1);
644 base::RunLoop().RunUntilIdle(); 640 base::RunLoop().RunUntilIdle();
645 641
646 base::Time now = base::Time::Now(); 642 base::Time now = base::Time::Now();
647 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); 643 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock);
648 clock->SetNow(now); 644 clock->SetNow(now);
649 model()->set_clock(std::move(clock)); 645 model()->set_clock(std::move(clock));
650 646
651 // Reset the short name, keyword, url and make sure it takes. 647 // Reset the short name, keyword, url and make sure it takes.
652 const base::string16 new_short_name(ASCIIToUTF16("a")); 648 const base::string16 new_short_name(ASCIIToUTF16("a"));
653 const base::string16 new_keyword(ASCIIToUTF16("b")); 649 const base::string16 new_keyword(ASCIIToUTF16("b"));
654 const std::string new_url("c"); 650 const std::string new_url("c");
655 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); 651 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url);
656 ASSERT_EQ(new_short_name, t_url->short_name()); 652 ASSERT_EQ(new_short_name, t_url->short_name());
657 ASSERT_EQ(new_keyword, t_url->keyword()); 653 ASSERT_EQ(new_keyword, t_url->keyword());
658 ASSERT_EQ(new_url, t_url->url()); 654 ASSERT_EQ(new_url, t_url->url());
659 655
660 // Make sure the mappings in the model were updated. 656 // Make sure the mappings in the model were updated.
661 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); 657 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword));
662 ASSERT_TRUE( 658 ASSERT_TRUE(
663 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); 659 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL);
664 660
665 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 661 std::unique_ptr<TemplateURL> cloned_url(
662 base::MakeUnique<TemplateURL>(t_url->data()));
666 663
667 // Reload the model from the database and make sure the change took. 664 // Reload the model from the database and make sure the change took.
668 test_util()->ResetModel(true); 665 test_util()->ResetModel(true);
669 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 666 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
670 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); 667 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword);
671 ASSERT_TRUE(read_url); 668 ASSERT_TRUE(read_url);
672 AssertEquals(*cloned_url, *read_url); 669 AssertEquals(*cloned_url, *read_url);
673 AssertTimesEqual(now, read_url->last_modified()); 670 AssertTimesEqual(now, read_url->last_modified());
674 } 671 }
675 672
676 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { 673 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
677 // Add a new TemplateURL. 674 // Add a new TemplateURL.
678 test_util()->VerifyLoad(); 675 test_util()->VerifyLoad();
679 const size_t initial_count = model()->GetTemplateURLs().size(); 676 const size_t initial_count = model()->GetTemplateURLs().size();
680 TemplateURL* t_url = AddKeywordWithDate( 677 TemplateURL* t_url = AddKeywordWithDate(
681 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", 678 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1",
682 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); 679 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
683 test_util()->ResetObserverCount(); 680 test_util()->ResetObserverCount();
684 681
685 model()->SetUserSelectedDefaultSearchProvider(t_url); 682 model()->SetUserSelectedDefaultSearchProvider(t_url);
686 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 683 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
687 ASSERT_TRUE(t_url->safe_for_autoreplace()); 684 ASSERT_TRUE(t_url->safe_for_autoreplace());
688 ASSERT_TRUE(t_url->show_in_default_list()); 685 ASSERT_TRUE(t_url->show_in_default_list());
689 686
690 // Setting the default search provider should have caused notification. 687 // Setting the default search provider should have caused notification.
691 VerifyObserverCount(1); 688 VerifyObserverCount(1);
692 base::RunLoop().RunUntilIdle(); 689 base::RunLoop().RunUntilIdle();
693 690
694 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 691 std::unique_ptr<TemplateURL> cloned_url(
692 base::MakeUnique<TemplateURL>(t_url->data()));
695 693
696 // Make sure when we reload we get a default search provider. 694 // Make sure when we reload we get a default search provider.
697 test_util()->ResetModel(true); 695 test_util()->ResetModel(true);
698 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 696 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
699 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 697 ASSERT_TRUE(model()->GetDefaultSearchProvider());
700 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); 698 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider());
701 } 699 }
702 700
703 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { 701 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
704 test_util()->ChangeModelToLoadState(); 702 test_util()->ChangeModelToLoadState();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 test_util()->VerifyLoad(); 754 test_util()->VerifyLoad();
757 755
758 TemplateURLData data; 756 TemplateURLData data;
759 data.SetShortName(ASCIIToUTF16("a")); 757 data.SetShortName(ASCIIToUTF16("a"));
760 data.safe_for_autoreplace = true; 758 data.safe_for_autoreplace = true;
761 data.SetURL("http://url/{searchTerms}"); 759 data.SetURL("http://url/{searchTerms}");
762 data.suggestions_url = "http://url2"; 760 data.suggestions_url = "http://url2";
763 data.instant_url = "http://instant"; 761 data.instant_url = "http://instant";
764 data.date_created = Time::FromTimeT(100); 762 data.date_created = Time::FromTimeT(100);
765 data.last_modified = Time::FromTimeT(100); 763 data.last_modified = Time::FromTimeT(100);
766 TemplateURL* t_url = new TemplateURL(data); 764 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
767 model()->Add(t_url);
768 const TemplateURLID id = t_url->id(); 765 const TemplateURLID id = t_url->id();
769 766
770 model()->SetUserSelectedDefaultSearchProvider(t_url); 767 model()->SetUserSelectedDefaultSearchProvider(t_url);
771 base::RunLoop().RunUntilIdle(); 768 base::RunLoop().RunUntilIdle();
772 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 769 std::unique_ptr<TemplateURL> cloned_url(
770 base::MakeUnique<TemplateURL>(t_url->data()));
773 771
774 // Reset the model and don't load it. The template url we set as the default 772 // Reset the model and don't load it. The template url we set as the default
775 // should be pulled from prefs now. 773 // should be pulled from prefs now.
776 test_util()->ResetModel(false); 774 test_util()->ResetModel(false);
777 775
778 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs 776 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs
779 // value are persisted to prefs. 777 // value are persisted to prefs.
780 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); 778 const TemplateURL* default_turl = model()->GetDefaultSearchProvider();
781 ASSERT_TRUE(default_turl); 779 ASSERT_TRUE(default_turl);
782 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); 780 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 ASSERT_EQ(1U, callback.visits.size()); 1036 ASSERT_EQ(1U, callback.visits.size());
1039 EXPECT_TRUE(ui::PageTransitionCoreTypeIs( 1037 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(
1040 callback.visits[0].transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED)); 1038 callback.visits[0].transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED));
1041 } 1039 }
1042 1040
1043 // Make sure that the load routine deletes prepopulated engines that no longer 1041 // Make sure that the load routine deletes prepopulated engines that no longer
1044 // exist in the prepopulate data. 1042 // exist in the prepopulate data.
1045 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { 1043 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
1046 // Create a preloaded template url. Add it to a loaded model and wait for the 1044 // Create a preloaded template url. Add it to a loaded model and wait for the
1047 // saves to finish. 1045 // saves to finish.
1048 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
1049 test_util()->ChangeModelToLoadState(); 1046 test_util()->ChangeModelToLoadState();
1050 model()->Add(t_url); 1047 model()->Add(CreatePreloadedTemplateURL(true, 999999));
1051 ASSERT_TRUE( 1048 ASSERT_TRUE(
1052 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); 1049 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
1053 base::RunLoop().RunUntilIdle(); 1050 base::RunLoop().RunUntilIdle();
1054 1051
1055 // Ensure that merging clears this engine. 1052 // Ensure that merging clears this engine.
1056 test_util()->ResetModel(true); 1053 test_util()->ResetModel(true);
1057 ASSERT_TRUE( 1054 ASSERT_TRUE(
1058 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); 1055 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
1059 1056
1060 // Wait for any saves to finish. 1057 // Wait for any saves to finish.
1061 base::RunLoop().RunUntilIdle(); 1058 base::RunLoop().RunUntilIdle();
1062 1059
1063 // Reload the model to verify that the database was updated as a result of the 1060 // Reload the model to verify that the database was updated as a result of the
1064 // merge. 1061 // merge.
1065 test_util()->ResetModel(true); 1062 test_util()->ResetModel(true);
1066 ASSERT_TRUE( 1063 ASSERT_TRUE(
1067 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); 1064 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
1068 } 1065 }
1069 1066
1070 // Make sure that load routine doesn't delete prepopulated engines that no 1067 // Make sure that load routine doesn't delete prepopulated engines that no
1071 // longer exist in the prepopulate data if it has been modified by the user. 1068 // longer exist in the prepopulate data if it has been modified by the user.
1072 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { 1069 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
1073 // Create a preloaded template url and add it to a loaded model. 1070 // Create a preloaded template url and add it to a loaded model.
1074 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999);
1075 test_util()->ChangeModelToLoadState(); 1071 test_util()->ChangeModelToLoadState();
1076 model()->Add(t_url); 1072 TemplateURL* t_url = model()->Add(CreatePreloadedTemplateURL(false, 999999));
1077 1073
1078 // Do the copy after t_url is added so that the id is set. 1074 // Do the copy after t_url is added so that the id is set.
1079 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 1075 std::unique_ptr<TemplateURL> cloned_url =
1076 base::MakeUnique<TemplateURL>(t_url->data());
1080 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); 1077 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
1081 1078
1082 // Wait for any saves to finish. 1079 // Wait for any saves to finish.
1083 base::RunLoop().RunUntilIdle(); 1080 base::RunLoop().RunUntilIdle();
1084 1081
1085 // Ensure that merging won't clear it if the user has edited it. 1082 // Ensure that merging won't clear it if the user has edited it.
1086 test_util()->ResetModel(true); 1083 test_util()->ResetModel(true);
1087 const TemplateURL* url_for_unittest = 1084 const TemplateURL* url_for_unittest =
1088 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); 1085 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"));
1089 ASSERT_TRUE(url_for_unittest != NULL); 1086 ASSERT_TRUE(url_for_unittest != NULL);
(...skipping 30 matching lines...) Expand all
1120 AssertEquals(*cloned_url, *default_search); 1117 AssertEquals(*cloned_url, *default_search);
1121 } 1118 }
1122 1119
1123 // Make sure that the load routine doesn't delete 1120 // Make sure that the load routine doesn't delete
1124 // prepopulated engines that no longer exist in the prepopulate data if 1121 // prepopulated engines that no longer exist in the prepopulate data if
1125 // it is the default search provider. 1122 // it is the default search provider.
1126 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { 1123 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
1127 // Set the default search provider to a preloaded template url which 1124 // Set the default search provider to a preloaded template url which
1128 // is not in the current set of preloaded template urls and save 1125 // is not in the current set of preloaded template urls and save
1129 // the result. 1126 // the result.
1130 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
1131 test_util()->ChangeModelToLoadState(); 1127 test_util()->ChangeModelToLoadState();
1132 model()->Add(t_url); 1128 TemplateURL* t_url = model()->Add(CreatePreloadedTemplateURL(true, 999999));
1133 model()->SetUserSelectedDefaultSearchProvider(t_url); 1129 model()->SetUserSelectedDefaultSearchProvider(t_url);
1134 // Do the copy after t_url is added and set as default so that its 1130 // Do the copy after t_url is added and set as default so that its
1135 // internal state is correct. 1131 // internal state is correct.
1136 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); 1132 std::unique_ptr<TemplateURL> cloned_url =
1133 base::MakeUnique<TemplateURL>(t_url->data());
1137 1134
1138 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); 1135 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
1139 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 1136 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
1140 base::RunLoop().RunUntilIdle(); 1137 base::RunLoop().RunUntilIdle();
1141 1138
1142 // Ensure that merging won't clear the prepopulated template url 1139 // Ensure that merging won't clear the prepopulated template url
1143 // which is no longer present if it's the default engine. 1140 // which is no longer present if it's the default engine.
1144 test_util()->ResetModel(true); 1141 test_util()->ResetModel(true);
1145 { 1142 {
1146 const TemplateURL* keyword_url = 1143 const TemplateURL* keyword_url =
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { 1340 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
1344 // Add a new TemplateURL. 1341 // Add a new TemplateURL.
1345 test_util()->VerifyLoad(); 1342 test_util()->VerifyLoad();
1346 const size_t initial_count = model()->GetTemplateURLs().size(); 1343 const size_t initial_count = model()->GetTemplateURLs().size();
1347 1344
1348 TemplateURLData data; 1345 TemplateURLData data;
1349 data.SetShortName(ASCIIToUTF16("google")); 1346 data.SetShortName(ASCIIToUTF16("google"));
1350 data.SetKeyword(ASCIIToUTF16("keyword")); 1347 data.SetKeyword(ASCIIToUTF16("keyword"));
1351 data.SetURL("http://www.google.com/foo/bar"); 1348 data.SetURL("http://www.google.com/foo/bar");
1352 data.sync_guid.clear(); 1349 data.sync_guid.clear();
1353 TemplateURL* t_url = new TemplateURL(data); 1350 model()->Add(base::MakeUnique<TemplateURL>(data));
1354 model()->Add(t_url);
1355 1351
1356 VerifyObserverCount(1); 1352 VerifyObserverCount(1);
1357 base::RunLoop().RunUntilIdle(); 1353 base::RunLoop().RunUntilIdle();
1358 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1354 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1359 1355
1360 // Reload the model to verify it was actually saved to the database and 1356 // Reload the model to verify it was actually saved to the database and
1361 // assigned a new GUID when brought back. 1357 // assigned a new GUID when brought back.
1362 test_util()->ResetModel(true); 1358 test_util()->ResetModel(true);
1363 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1359 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1364 const TemplateURL* loaded_url = 1360 const TemplateURL* loaded_url =
(...skipping 15 matching lines...) Expand all
1380 data.SetURL("http://www.google.com/foo/bar"); 1376 data.SetURL("http://www.google.com/foo/bar");
1381 std::vector<std::string> encodings; 1377 std::vector<std::string> encodings;
1382 data.input_encodings.push_back("UTF-8"); 1378 data.input_encodings.push_back("UTF-8");
1383 data.input_encodings.push_back("UTF-8"); 1379 data.input_encodings.push_back("UTF-8");
1384 data.input_encodings.push_back("UTF-16"); 1380 data.input_encodings.push_back("UTF-16");
1385 data.input_encodings.push_back("UTF-8"); 1381 data.input_encodings.push_back("UTF-8");
1386 data.input_encodings.push_back("Big5"); 1382 data.input_encodings.push_back("Big5");
1387 data.input_encodings.push_back("UTF-16"); 1383 data.input_encodings.push_back("UTF-16");
1388 data.input_encodings.push_back("Big5"); 1384 data.input_encodings.push_back("Big5");
1389 data.input_encodings.push_back("Windows-1252"); 1385 data.input_encodings.push_back("Windows-1252");
1390 TemplateURL* t_url = new TemplateURL(data); 1386 model()->Add(base::MakeUnique<TemplateURL>(data));
1391 model()->Add(t_url);
1392 1387
1393 VerifyObserverCount(1); 1388 VerifyObserverCount(1);
1394 base::RunLoop().RunUntilIdle(); 1389 base::RunLoop().RunUntilIdle();
1395 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1390 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1396 const TemplateURL* loaded_url = 1391 const TemplateURL* loaded_url =
1397 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1392 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1398 ASSERT_TRUE(loaded_url != NULL); 1393 ASSERT_TRUE(loaded_url != NULL);
1399 EXPECT_EQ(8U, loaded_url->input_encodings().size()); 1394 EXPECT_EQ(8U, loaded_url->input_encodings().size());
1400 1395
1401 // Reload the model to verify it was actually saved to the database and the 1396 // Reload the model to verify it was actually saved to the database and the
1402 // duplicate encodings were removed. 1397 // duplicate encodings were removed.
1403 test_util()->ResetModel(true); 1398 test_util()->ResetModel(true);
1404 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1399 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1405 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1400 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1406 ASSERT_FALSE(loaded_url == NULL); 1401 ASSERT_FALSE(loaded_url == NULL);
1407 EXPECT_EQ(4U, loaded_url->input_encodings().size()); 1402 EXPECT_EQ(4U, loaded_url->input_encodings().size());
1408 } 1403 }
1409 1404
1410 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { 1405 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) {
1411 test_util()->VerifyLoad(); 1406 test_util()->VerifyLoad();
1412 // Add third-party default search engine. 1407 // Add third-party default search engine.
1413 TemplateURL* user_dse = AddKeywordWithDate( 1408 TemplateURL* user_dse = AddKeywordWithDate(
1414 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1409 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1415 std::string(), std::string(), std::string(), 1410 std::string(), std::string(), std::string(),
1416 true, "UTF-8", Time(), Time()); 1411 true, "UTF-8", Time(), Time());
1417 model()->SetUserSelectedDefaultSearchProvider(user_dse); 1412 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1418 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1413 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1419 1414
1420 TemplateURL* ext_dse = CreateKeywordWithDate( 1415 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1421 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", 1416 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}",
1422 std::string(), std::string(), std::string(), 1417 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(),
1423 true, true, "UTF-8", Time(), Time()); 1418 Time());
1424 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1419 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1425 new TemplateURL::AssociatedExtensionInfo( 1420 new TemplateURL::AssociatedExtensionInfo(
1426 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); 1421 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext"));
1427 extension_info->wants_to_be_default_engine = true; 1422 extension_info->wants_to_be_default_engine = true;
1428 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); 1423 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1429 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); 1424 std::move(ext_dse), std::move(extension_info));
1425 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider());
1430 1426
1431 model()->RemoveExtensionControlledTURL( 1427 model()->RemoveExtensionControlledTURL(
1432 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); 1428 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1433 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1429 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1434 } 1430 }
1435 1431
1436 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { 1432 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) {
1437 test_util()->VerifyLoad(); 1433 test_util()->VerifyLoad();
1438 // Add third-party default search engine. 1434 // Add third-party default search engine.
1439 TemplateURL* user_dse = AddKeywordWithDate( 1435 TemplateURL* user_dse = AddKeywordWithDate(
1440 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1436 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1441 std::string(), std::string(), std::string(), 1437 std::string(), std::string(), std::string(),
1442 true, "UTF-8", Time(), Time()); 1438 true, "UTF-8", Time(), Time());
1443 model()->SetUserSelectedDefaultSearchProvider(user_dse); 1439 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1444 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1440 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1445 1441
1446 TemplateURL* ext_dse = CreateKeywordWithDate( 1442 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1447 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1443 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1448 std::string(), std::string(), std::string(), 1444 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(),
1449 true, false, "UTF-8", Time(), Time()); 1445 Time());
1450 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1446 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1451 new TemplateURL::AssociatedExtensionInfo( 1447 new TemplateURL::AssociatedExtensionInfo(
1452 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); 1448 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1"));
1453 extension_info->wants_to_be_default_engine = false; 1449 extension_info->wants_to_be_default_engine = false;
1454 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); 1450 model()->AddExtensionControlledTURL(std::move(ext_dse),
1451 std::move(extension_info));
1455 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1452 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1456 1453
1457 ext_dse = CreateKeywordWithDate( 1454 ext_dse = CreateKeywordWithDate(model(), "ext2", "ext2",
1458 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", 1455 "http://www.ext2.com/s?q={searchTerms}",
1459 std::string(), std::string(), std::string(), 1456 std::string(), std::string(), std::string(),
1460 true, true, "UTF-8", Time(), Time()); 1457 true, true, "UTF-8", Time(), Time());
1461 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( 1458 extension_info.reset(new TemplateURL::AssociatedExtensionInfo(
1462 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); 1459 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2"));
1463 extension_info->wants_to_be_default_engine = true; 1460 extension_info->wants_to_be_default_engine = true;
1464 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); 1461 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1465 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); 1462 std::move(ext_dse), std::move(extension_info));
1463 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider());
1466 1464
1467 test_util()->ResetModel(true); 1465 test_util()->ResetModel(true);
1468 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); 1466 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user"));
1469 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1467 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1470 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1468 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1471 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); 1469 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2")));
1472 } 1470 }
1473 1471
1474 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { 1472 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) {
1475 // Set a managed preference that establishes a default search provider. 1473 // Set a managed preference that establishes a default search provider.
(...skipping 18 matching lines...) Expand all
1494 data.input_encodings = base::SplitString( 1492 data.input_encodings = base::SplitString(
1495 kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1493 kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1496 data.alternate_urls.push_back(kAlternateURL); 1494 data.alternate_urls.push_back(kAlternateURL);
1497 data.search_terms_replacement_key = kSearchTermsReplacementKey; 1495 data.search_terms_replacement_key = kSearchTermsReplacementKey;
1498 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); 1496 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data));
1499 EXPECT_TRUE(model()->is_default_search_managed()); 1497 EXPECT_TRUE(model()->is_default_search_managed());
1500 const TemplateURL* actual_managed_default = 1498 const TemplateURL* actual_managed_default =
1501 model()->GetDefaultSearchProvider(); 1499 model()->GetDefaultSearchProvider();
1502 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1500 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1503 1501
1504 TemplateURL* ext_dse = CreateKeywordWithDate( 1502 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1505 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1503 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1506 std::string(), std::string(), std::string(), 1504 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(),
1507 true, true, "UTF-8", Time(), Time()); 1505 Time());
1508 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1506 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1509 new TemplateURL::AssociatedExtensionInfo( 1507 new TemplateURL::AssociatedExtensionInfo(
1510 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); 1508 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1"));
1511 extension_info->wants_to_be_default_engine = true; 1509 extension_info->wants_to_be_default_engine = true;
1512 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); 1510 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1513 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1511 std::move(ext_dse), std::move(extension_info));
1512 EXPECT_EQ(ext_dse_ptr,
1513 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1514 EXPECT_TRUE(model()->is_default_search_managed()); 1514 EXPECT_TRUE(model()->is_default_search_managed());
1515 actual_managed_default = model()->GetDefaultSearchProvider(); 1515 actual_managed_default = model()->GetDefaultSearchProvider();
1516 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1516 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1517 } 1517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698