Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 std::unique_ptr<TemplateURL> t_url_ptr = 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 TemplateURL* t_url = t_url_ptr.get(); |
| 110 model->Add(std::move(t_url_ptr)); | |
| 109 EXPECT_NE(0, t_url->id()); | 111 EXPECT_NE(0, t_url->id()); |
| 110 return t_url; | 112 return t_url; |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Checks that the two TemplateURLs are similar. It does not check the id, the | 115 // 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. | 116 // date_created or the last_modified time. Neither pointer should be NULL. |
| 115 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { | 117 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { |
| 116 ASSERT_TRUE(expected != NULL); | 118 ASSERT_TRUE(expected != NULL); |
| 117 ASSERT_TRUE(actual != NULL); | 119 ASSERT_TRUE(actual != NULL); |
| 118 EXPECT_EQ(expected->short_name(), actual->short_name()); | 120 EXPECT_EQ(expected->short_name(), actual->short_name()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 Time last_modified); | 155 Time last_modified); |
| 154 | 156 |
| 155 // Verifies the two TemplateURLs are equal. | 157 // Verifies the two TemplateURLs are equal. |
| 156 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); | 158 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); |
| 157 | 159 |
| 158 // Verifies the two timestamps are equal, within the expected degree of | 160 // Verifies the two timestamps are equal, within the expected degree of |
| 159 // precision. | 161 // precision. |
| 160 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); | 162 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); |
| 161 | 163 |
| 162 // Create an URL that appears to have been prepopulated, but won't be in the | 164 // Create an URL that appears to have been prepopulated, but won't be in the |
| 163 // current data. The caller owns the returned TemplateURL*. | 165 // current data. |
| 164 TemplateURL* CreatePreloadedTemplateURL(bool safe_for_autoreplace, | 166 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL( |
| 165 int prepopulate_id); | 167 bool safe_for_autoreplace, |
| 168 int prepopulate_id); | |
| 166 | 169 |
| 167 // Helper methods to make calling TemplateURLServiceTestUtil methods less | 170 // Helper methods to make calling TemplateURLServiceTestUtil methods less |
| 168 // visually noisy in the test code. | 171 // visually noisy in the test code. |
| 169 void VerifyObserverCount(int expected_changed_count); | 172 void VerifyObserverCount(int expected_changed_count); |
| 170 void VerifyObserverFired(); | 173 void VerifyObserverFired(); |
| 171 TemplateURLServiceTestUtil* test_util() { return test_util_.get(); } | 174 TemplateURLServiceTestUtil* test_util() { return test_util_.get(); } |
| 172 TemplateURLService* model() { return test_util_->model(); } | 175 TemplateURLService* model() { return test_util_->model(); } |
| 173 const SearchTermsData& search_terms_data() { | 176 const SearchTermsData& search_terms_data() { |
| 174 return model()->search_terms_data(); | 177 return model()->search_terms_data(); |
| 175 } | 178 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 246 } |
| 244 | 247 |
| 245 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, | 248 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, |
| 246 const base::Time& actual) { | 249 const base::Time& actual) { |
| 247 // Because times are stored with a granularity of one second, there is a loss | 250 // 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 | 251 // of precision when serializing and deserializing the timestamps. Hence, only |
| 249 // expect timestamps to be equal to within one second of one another. | 252 // expect timestamps to be equal to within one second of one another. |
| 250 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); | 253 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); |
| 251 } | 254 } |
| 252 | 255 |
| 253 TemplateURL* TemplateURLServiceTest::CreatePreloadedTemplateURL( | 256 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( |
| 254 bool safe_for_autoreplace, | 257 bool safe_for_autoreplace, |
| 255 int prepopulate_id) { | 258 int prepopulate_id) { |
| 256 TemplateURLData data; | 259 TemplateURLData data; |
| 257 data.SetShortName(ASCIIToUTF16("unittest")); | 260 data.SetShortName(ASCIIToUTF16("unittest")); |
| 258 data.SetKeyword(ASCIIToUTF16("unittest")); | 261 data.SetKeyword(ASCIIToUTF16("unittest")); |
| 259 data.SetURL("http://www.unittest.com/{searchTerms}"); | 262 data.SetURL("http://www.unittest.com/{searchTerms}"); |
| 260 data.favicon_url = GURL("http://favicon.url"); | 263 data.favicon_url = GURL("http://favicon.url"); |
| 261 data.show_in_default_list = true; | 264 data.show_in_default_list = true; |
| 262 data.safe_for_autoreplace = safe_for_autoreplace; | 265 data.safe_for_autoreplace = safe_for_autoreplace; |
| 263 data.input_encodings.push_back("UTF-8"); | 266 data.input_encodings.push_back("UTF-8"); |
| 264 data.date_created = Time::FromTimeT(100); | 267 data.date_created = Time::FromTimeT(100); |
| 265 data.last_modified = Time::FromTimeT(100); | 268 data.last_modified = Time::FromTimeT(100); |
| 266 data.prepopulate_id = prepopulate_id; | 269 data.prepopulate_id = prepopulate_id; |
| 267 return new TemplateURL(data); | 270 return base::MakeUnique<TemplateURL>(data); |
| 268 } | 271 } |
| 269 | 272 |
| 270 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 273 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
| 271 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); | 274 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); |
| 272 test_util_->ResetObserverCount(); | 275 test_util_->ResetObserverCount(); |
| 273 } | 276 } |
| 274 | 277 |
| 275 void TemplateURLServiceTest::VerifyObserverFired() { | 278 void TemplateURLServiceTest::VerifyObserverFired() { |
| 276 EXPECT_LE(1, test_util_->GetObserverCount()); | 279 EXPECT_LE(1, test_util_->GetObserverCount()); |
| 277 test_util_->ResetObserverCount(); | 280 test_util_->ResetObserverCount(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 291 | 294 |
| 292 TemplateURLData data; | 295 TemplateURLData data; |
| 293 data.SetShortName(ASCIIToUTF16("google")); | 296 data.SetShortName(ASCIIToUTF16("google")); |
| 294 data.SetKeyword(ASCIIToUTF16("keyword")); | 297 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 295 data.SetURL("http://www.google.com/foo/bar"); | 298 data.SetURL("http://www.google.com/foo/bar"); |
| 296 data.favicon_url = GURL("http://favicon.url"); | 299 data.favicon_url = GURL("http://favicon.url"); |
| 297 data.safe_for_autoreplace = true; | 300 data.safe_for_autoreplace = true; |
| 298 data.date_created = Time::FromTimeT(100); | 301 data.date_created = Time::FromTimeT(100); |
| 299 data.last_modified = Time::FromTimeT(100); | 302 data.last_modified = Time::FromTimeT(100); |
| 300 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 303 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
| 301 TemplateURL* t_url = new TemplateURL(data); | 304 std::unique_ptr<TemplateURL> t_url_ptr = base::MakeUnique<TemplateURL>(data); |
| 302 model()->Add(t_url); | 305 TemplateURL* t_url = t_url_ptr.get(); |
| 306 model()->Add(std::move(t_url_ptr)); | |
| 303 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 307 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
| 304 GURL(), NULL)); | 308 GURL(), NULL)); |
| 305 VerifyObserverCount(1); | 309 VerifyObserverCount(1); |
| 306 base::RunLoop().RunUntilIdle(); | 310 base::RunLoop().RunUntilIdle(); |
| 307 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 311 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 308 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 312 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 | 313 // 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 | 314 // will delete it. We have to do this after calling Add() since that gives |
| 311 // |t_url| its ID. | 315 // |t_url| its ID. |
| 312 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 316 std::unique_ptr<TemplateURL> cloned_url = |
| 317 base::MakeUnique<TemplateURL>(t_url->data()); | |
| 313 | 318 |
| 314 // Reload the model to verify it was actually saved to the database. | 319 // Reload the model to verify it was actually saved to the database. |
| 315 test_util()->ResetModel(true); | 320 test_util()->ResetModel(true); |
| 316 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 321 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 317 TemplateURL* loaded_url = | 322 TemplateURL* loaded_url = |
| 318 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 323 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 319 ASSERT_TRUE(loaded_url != NULL); | 324 ASSERT_TRUE(loaded_url != NULL); |
| 320 AssertEquals(*cloned_url, *loaded_url); | 325 AssertEquals(*cloned_url, *loaded_url); |
| 321 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 326 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
| 322 GURL(), NULL)); | 327 GURL(), NULL)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 std::string(), true, "UTF-8", Time(), Time()); | 371 std::string(), true, "UTF-8", Time(), Time()); |
| 367 VerifyObserverCount(1); | 372 VerifyObserverCount(1); |
| 368 | 373 |
| 369 // Test what happens when we try to add a TemplateURL with the same keyword as | 374 // Test what happens when we try to add a TemplateURL with the same keyword as |
| 370 // one in the model. | 375 // one in the model. |
| 371 TemplateURLData data; | 376 TemplateURLData data; |
| 372 data.SetShortName(ASCIIToUTF16("second")); | 377 data.SetShortName(ASCIIToUTF16("second")); |
| 373 data.SetKeyword(ASCIIToUTF16("keyword")); | 378 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 374 data.SetURL("http://test2"); | 379 data.SetURL("http://test2"); |
| 375 data.safe_for_autoreplace = false; | 380 data.safe_for_autoreplace = false; |
| 376 TemplateURL* t_url = new TemplateURL(data); | 381 std::unique_ptr<TemplateURL> t_url_ptr = base::MakeUnique<TemplateURL>(data); |
| 377 model()->Add(t_url); | 382 TemplateURL* t_url = t_url_ptr.get(); |
| 383 model()->Add(std::move(t_url_ptr)); | |
| 378 | 384 |
| 379 // Because the old TemplateURL was replaceable and the new one wasn't, the new | 385 // Because the old TemplateURL was replaceable and the new one wasn't, the new |
| 380 // one should have replaced the old. | 386 // one should have replaced the old. |
| 381 VerifyObserverCount(1); | 387 VerifyObserverCount(1); |
| 382 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 388 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 383 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 389 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
| 384 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); | 390 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); |
| 385 EXPECT_FALSE(t_url->safe_for_autoreplace()); | 391 EXPECT_FALSE(t_url->safe_for_autoreplace()); |
| 386 | 392 |
| 387 // Now try adding a replaceable TemplateURL. This should just delete the | 393 // Now try adding a replaceable TemplateURL. This should just delete the |
| 388 // passed-in URL. | 394 // passed-in URL. |
| 389 data.SetShortName(ASCIIToUTF16("third")); | 395 data.SetShortName(ASCIIToUTF16("third")); |
| 390 data.SetURL("http://test3"); | 396 data.SetURL("http://test3"); |
| 391 data.safe_for_autoreplace = true; | 397 data.safe_for_autoreplace = true; |
| 392 model()->Add(new TemplateURL(data)); | 398 model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 393 VerifyObserverCount(0); | 399 VerifyObserverCount(0); |
| 394 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 400 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 395 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 401 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
| 396 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); | 402 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); |
| 397 EXPECT_FALSE(t_url->safe_for_autoreplace()); | 403 EXPECT_FALSE(t_url->safe_for_autoreplace()); |
| 398 | 404 |
| 399 // Now try adding a non-replaceable TemplateURL again. This should uniquify | 405 // Now try adding a non-replaceable TemplateURL again. This should uniquify |
| 400 // the existing entry's keyword. | 406 // the existing entry's keyword. |
| 401 data.SetShortName(ASCIIToUTF16("fourth")); | 407 data.SetShortName(ASCIIToUTF16("fourth")); |
| 402 data.SetURL("http://test4"); | 408 data.SetURL("http://test4"); |
| 403 data.safe_for_autoreplace = false; | 409 data.safe_for_autoreplace = false; |
| 404 TemplateURL* t_url2 = new TemplateURL(data); | 410 std::unique_ptr<TemplateURL> t_url2_ptr = base::MakeUnique<TemplateURL>(data); |
| 405 model()->Add(t_url2); | 411 TemplateURL* t_url2 = t_url2_ptr.get(); |
| 412 model()->Add(std::move(t_url2_ptr)); | |
| 406 VerifyObserverCount(1); | 413 VerifyObserverCount(1); |
| 407 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 414 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 408 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); | 415 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); |
| 409 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); | 416 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); |
| 410 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 417 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
| 411 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 418 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
| 412 } | 419 } |
| 413 | 420 |
| 414 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { | 421 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { |
| 415 test_util()->VerifyLoad(); | 422 test_util()->VerifyLoad(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 "replaceable", "keyword", "http://test1", std::string(), std::string(), | 474 "replaceable", "keyword", "http://test1", std::string(), std::string(), |
| 468 std::string(), true, "UTF-8", Time(), Time()); | 475 std::string(), true, "UTF-8", Time(), Time()); |
| 469 | 476 |
| 470 // Adding another replaceable keyword should remove the existing one, but | 477 // Adding another replaceable keyword should remove the existing one, but |
| 471 // leave the extension as is. | 478 // leave the extension as is. |
| 472 TemplateURLData data; | 479 TemplateURLData data; |
| 473 data.SetShortName(ASCIIToUTF16("name1")); | 480 data.SetShortName(ASCIIToUTF16("name1")); |
| 474 data.SetKeyword(ASCIIToUTF16("keyword")); | 481 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 475 data.SetURL("http://test3"); | 482 data.SetURL("http://test3"); |
| 476 data.safe_for_autoreplace = true; | 483 data.safe_for_autoreplace = true; |
| 477 TemplateURL* t_url = new TemplateURL(data); | 484 std::unique_ptr<TemplateURL> t_url_ptr = base::MakeUnique<TemplateURL>(data); |
| 478 model()->Add(t_url); | 485 TemplateURL* t_url = t_url_ptr.get(); |
| 486 model()->Add(std::move(t_url_ptr)); | |
| 479 EXPECT_EQ(extension, | 487 EXPECT_EQ(extension, |
| 480 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 488 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 481 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); | 489 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); |
| 482 | 490 |
| 483 // Adding a nonreplaceable keyword should remove the existing replaceable | 491 // Adding a nonreplaceable keyword should remove the existing replaceable |
| 484 // keyword and replace the extension as the associated URL for this keyword, | 492 // keyword and replace the extension as the associated URL for this keyword, |
| 485 // but not evict the extension from the service entirely. | 493 // but not evict the extension from the service entirely. |
| 486 data.SetShortName(ASCIIToUTF16("name2")); | 494 data.SetShortName(ASCIIToUTF16("name2")); |
| 487 data.SetURL("http://test4"); | 495 data.SetURL("http://test4"); |
| 488 data.safe_for_autoreplace = false; | 496 data.safe_for_autoreplace = false; |
| 489 TemplateURL* t_url2 = new TemplateURL(data); | 497 std::unique_ptr<TemplateURL> t_url2_ptr = base::MakeUnique<TemplateURL>(data); |
| 490 model()->Add(t_url2); | 498 TemplateURL* t_url2 = t_url2_ptr.get(); |
| 499 model()->Add(std::move(t_url2_ptr)); | |
| 491 EXPECT_EQ(t_url2, | 500 EXPECT_EQ(t_url2, |
| 492 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 501 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 493 } | 502 } |
| 494 | 503 |
| 495 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { | 504 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { |
| 496 test_util()->VerifyLoad(); | 505 test_util()->VerifyLoad(); |
| 497 | 506 |
| 498 // Register an omnibox keyword. | 507 // Register an omnibox keyword. |
| 499 model()->RegisterOmniboxKeyword("test", "extension", "keyword", | 508 model()->RegisterOmniboxKeyword("test", "extension", "keyword", |
| 500 "chrome-extension://test"); | 509 "chrome-extension://test"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 // Add a new TemplateURL. | 634 // Add a new TemplateURL. |
| 626 test_util()->VerifyLoad(); | 635 test_util()->VerifyLoad(); |
| 627 const size_t initial_count = model()->GetTemplateURLs().size(); | 636 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 628 TemplateURLData data; | 637 TemplateURLData data; |
| 629 data.SetShortName(ASCIIToUTF16("google")); | 638 data.SetShortName(ASCIIToUTF16("google")); |
| 630 data.SetKeyword(ASCIIToUTF16("keyword")); | 639 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 631 data.SetURL("http://www.google.com/foo/bar"); | 640 data.SetURL("http://www.google.com/foo/bar"); |
| 632 data.favicon_url = GURL("http://favicon.url"); | 641 data.favicon_url = GURL("http://favicon.url"); |
| 633 data.date_created = Time::FromTimeT(100); | 642 data.date_created = Time::FromTimeT(100); |
| 634 data.last_modified = Time::FromTimeT(100); | 643 data.last_modified = Time::FromTimeT(100); |
| 635 TemplateURL* t_url = new TemplateURL(data); | 644 std::unique_ptr<TemplateURL> t_url_ptr = base::MakeUnique<TemplateURL>(data); |
| 636 model()->Add(t_url); | 645 TemplateURL* t_url = t_url_ptr.get(); |
| 646 model()->Add(std::move(t_url_ptr)); | |
| 637 | 647 |
| 638 VerifyObserverCount(1); | 648 VerifyObserverCount(1); |
| 639 base::RunLoop().RunUntilIdle(); | 649 base::RunLoop().RunUntilIdle(); |
| 640 | 650 |
| 641 base::Time now = base::Time::Now(); | 651 base::Time now = base::Time::Now(); |
| 642 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 652 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
| 643 clock->SetNow(now); | 653 clock->SetNow(now); |
| 644 model()->set_clock(std::move(clock)); | 654 model()->set_clock(std::move(clock)); |
| 645 | 655 |
| 646 // Reset the short name, keyword, url and make sure it takes. | 656 // Reset the short name, keyword, url and make sure it takes. |
| 647 const base::string16 new_short_name(ASCIIToUTF16("a")); | 657 const base::string16 new_short_name(ASCIIToUTF16("a")); |
| 648 const base::string16 new_keyword(ASCIIToUTF16("b")); | 658 const base::string16 new_keyword(ASCIIToUTF16("b")); |
| 649 const std::string new_url("c"); | 659 const std::string new_url("c"); |
| 650 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 660 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
| 651 ASSERT_EQ(new_short_name, t_url->short_name()); | 661 ASSERT_EQ(new_short_name, t_url->short_name()); |
| 652 ASSERT_EQ(new_keyword, t_url->keyword()); | 662 ASSERT_EQ(new_keyword, t_url->keyword()); |
| 653 ASSERT_EQ(new_url, t_url->url()); | 663 ASSERT_EQ(new_url, t_url->url()); |
| 654 | 664 |
| 655 // Make sure the mappings in the model were updated. | 665 // Make sure the mappings in the model were updated. |
| 656 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); | 666 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); |
| 657 ASSERT_TRUE( | 667 ASSERT_TRUE( |
| 658 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); | 668 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); |
| 659 | 669 |
| 660 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 670 std::unique_ptr<TemplateURL> cloned_url( |
| 671 base::MakeUnique<TemplateURL>(t_url->data())); | |
| 661 | 672 |
| 662 // Reload the model from the database and make sure the change took. | 673 // Reload the model from the database and make sure the change took. |
| 663 test_util()->ResetModel(true); | 674 test_util()->ResetModel(true); |
| 664 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 675 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 665 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); | 676 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); |
| 666 ASSERT_TRUE(read_url); | 677 ASSERT_TRUE(read_url); |
| 667 AssertEquals(*cloned_url, *read_url); | 678 AssertEquals(*cloned_url, *read_url); |
| 668 AssertTimesEqual(now, read_url->last_modified()); | 679 AssertTimesEqual(now, read_url->last_modified()); |
| 669 } | 680 } |
| 670 | 681 |
| 671 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { | 682 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { |
| 672 // Add a new TemplateURL. | 683 // Add a new TemplateURL. |
| 673 test_util()->VerifyLoad(); | 684 test_util()->VerifyLoad(); |
| 674 const size_t initial_count = model()->GetTemplateURLs().size(); | 685 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 675 TemplateURL* t_url = AddKeywordWithDate( | 686 TemplateURL* t_url = AddKeywordWithDate( |
| 676 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 687 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", |
| 677 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 688 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); |
| 678 test_util()->ResetObserverCount(); | 689 test_util()->ResetObserverCount(); |
| 679 | 690 |
| 680 model()->SetUserSelectedDefaultSearchProvider(t_url); | 691 model()->SetUserSelectedDefaultSearchProvider(t_url); |
| 681 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 692 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 682 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 693 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
| 683 ASSERT_TRUE(t_url->show_in_default_list()); | 694 ASSERT_TRUE(t_url->show_in_default_list()); |
| 684 | 695 |
| 685 // Setting the default search provider should have caused notification. | 696 // Setting the default search provider should have caused notification. |
| 686 VerifyObserverCount(1); | 697 VerifyObserverCount(1); |
| 687 base::RunLoop().RunUntilIdle(); | 698 base::RunLoop().RunUntilIdle(); |
| 688 | 699 |
| 689 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 700 std::unique_ptr<TemplateURL> cloned_url( |
| 701 base::MakeUnique<TemplateURL>(t_url->data())); | |
| 690 | 702 |
| 691 // Make sure when we reload we get a default search provider. | 703 // Make sure when we reload we get a default search provider. |
| 692 test_util()->ResetModel(true); | 704 test_util()->ResetModel(true); |
| 693 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 705 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 694 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 706 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 695 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 707 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
| 696 } | 708 } |
| 697 | 709 |
| 698 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { | 710 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { |
| 699 test_util()->ChangeModelToLoadState(); | 711 test_util()->ChangeModelToLoadState(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 test_util()->VerifyLoad(); | 763 test_util()->VerifyLoad(); |
| 752 | 764 |
| 753 TemplateURLData data; | 765 TemplateURLData data; |
| 754 data.SetShortName(ASCIIToUTF16("a")); | 766 data.SetShortName(ASCIIToUTF16("a")); |
| 755 data.safe_for_autoreplace = true; | 767 data.safe_for_autoreplace = true; |
| 756 data.SetURL("http://url/{searchTerms}"); | 768 data.SetURL("http://url/{searchTerms}"); |
| 757 data.suggestions_url = "http://url2"; | 769 data.suggestions_url = "http://url2"; |
| 758 data.instant_url = "http://instant"; | 770 data.instant_url = "http://instant"; |
| 759 data.date_created = Time::FromTimeT(100); | 771 data.date_created = Time::FromTimeT(100); |
| 760 data.last_modified = Time::FromTimeT(100); | 772 data.last_modified = Time::FromTimeT(100); |
| 761 TemplateURL* t_url = new TemplateURL(data); | 773 std::unique_ptr<TemplateURL> t_url_ptr = base::MakeUnique<TemplateURL>(data); |
| 762 model()->Add(t_url); | 774 TemplateURL* t_url = t_url_ptr.get(); |
| 775 model()->Add(std::move(t_url_ptr)); | |
| 763 const TemplateURLID id = t_url->id(); | 776 const TemplateURLID id = t_url->id(); |
| 764 | 777 |
| 765 model()->SetUserSelectedDefaultSearchProvider(t_url); | 778 model()->SetUserSelectedDefaultSearchProvider(t_url); |
| 766 base::RunLoop().RunUntilIdle(); | 779 base::RunLoop().RunUntilIdle(); |
| 767 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 780 std::unique_ptr<TemplateURL> cloned_url( |
| 781 base::MakeUnique<TemplateURL>(t_url->data())); | |
| 768 | 782 |
| 769 // Reset the model and don't load it. The template url we set as the default | 783 // Reset the model and don't load it. The template url we set as the default |
| 770 // should be pulled from prefs now. | 784 // should be pulled from prefs now. |
| 771 test_util()->ResetModel(false); | 785 test_util()->ResetModel(false); |
| 772 | 786 |
| 773 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 787 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
| 774 // value are persisted to prefs. | 788 // value are persisted to prefs. |
| 775 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 789 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
| 776 ASSERT_TRUE(default_turl); | 790 ASSERT_TRUE(default_turl); |
| 777 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); | 791 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 ASSERT_EQ(1U, callback.visits.size()); | 1047 ASSERT_EQ(1U, callback.visits.size()); |
| 1034 EXPECT_TRUE(ui::PageTransitionCoreTypeIs( | 1048 EXPECT_TRUE(ui::PageTransitionCoreTypeIs( |
| 1035 callback.visits[0].transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED)); | 1049 callback.visits[0].transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED)); |
| 1036 } | 1050 } |
| 1037 | 1051 |
| 1038 // Make sure that the load routine deletes prepopulated engines that no longer | 1052 // Make sure that the load routine deletes prepopulated engines that no longer |
| 1039 // exist in the prepopulate data. | 1053 // exist in the prepopulate data. |
| 1040 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { | 1054 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { |
| 1041 // Create a preloaded template url. Add it to a loaded model and wait for the | 1055 // Create a preloaded template url. Add it to a loaded model and wait for the |
| 1042 // saves to finish. | 1056 // saves to finish. |
| 1043 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); | |
| 1044 test_util()->ChangeModelToLoadState(); | 1057 test_util()->ChangeModelToLoadState(); |
| 1045 model()->Add(t_url); | 1058 model()->Add(CreatePreloadedTemplateURL(true, 999999)); |
| 1046 ASSERT_TRUE( | 1059 ASSERT_TRUE( |
| 1047 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1060 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
| 1048 base::RunLoop().RunUntilIdle(); | 1061 base::RunLoop().RunUntilIdle(); |
| 1049 | 1062 |
| 1050 // Ensure that merging clears this engine. | 1063 // Ensure that merging clears this engine. |
| 1051 test_util()->ResetModel(true); | 1064 test_util()->ResetModel(true); |
| 1052 ASSERT_TRUE( | 1065 ASSERT_TRUE( |
| 1053 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1066 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
| 1054 | 1067 |
| 1055 // Wait for any saves to finish. | 1068 // Wait for any saves to finish. |
| 1056 base::RunLoop().RunUntilIdle(); | 1069 base::RunLoop().RunUntilIdle(); |
| 1057 | 1070 |
| 1058 // Reload the model to verify that the database was updated as a result of the | 1071 // Reload the model to verify that the database was updated as a result of the |
| 1059 // merge. | 1072 // merge. |
| 1060 test_util()->ResetModel(true); | 1073 test_util()->ResetModel(true); |
| 1061 ASSERT_TRUE( | 1074 ASSERT_TRUE( |
| 1062 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1075 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
| 1063 } | 1076 } |
| 1064 | 1077 |
| 1065 // Make sure that load routine doesn't delete prepopulated engines that no | 1078 // Make sure that load routine doesn't delete prepopulated engines that no |
| 1066 // longer exist in the prepopulate data if it has been modified by the user. | 1079 // longer exist in the prepopulate data if it has been modified by the user. |
| 1067 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { | 1080 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { |
| 1068 // Create a preloaded template url and add it to a loaded model. | 1081 // Create a preloaded template url and add it to a loaded model. |
| 1069 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); | 1082 std::unique_ptr<TemplateURL> t_url_ptr = |
| 1083 CreatePreloadedTemplateURL(false, 999999); | |
| 1084 TemplateURL* t_url = t_url_ptr.get(); | |
| 1070 test_util()->ChangeModelToLoadState(); | 1085 test_util()->ChangeModelToLoadState(); |
| 1071 model()->Add(t_url); | 1086 model()->Add(std::move(t_url_ptr)); |
| 1072 | 1087 |
| 1073 // Do the copy after t_url is added so that the id is set. | 1088 // Do the copy after t_url is added so that the id is set. |
| 1074 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 1089 std::unique_ptr<TemplateURL> cloned_url( |
|
Peter Kasting
2016/08/31 04:12:55
Nit: () -> =
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
| 1090 base::MakeUnique<TemplateURL>(t_url->data())); | |
| 1075 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1091 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
| 1076 | 1092 |
| 1077 // Wait for any saves to finish. | 1093 // Wait for any saves to finish. |
| 1078 base::RunLoop().RunUntilIdle(); | 1094 base::RunLoop().RunUntilIdle(); |
| 1079 | 1095 |
| 1080 // Ensure that merging won't clear it if the user has edited it. | 1096 // Ensure that merging won't clear it if the user has edited it. |
| 1081 test_util()->ResetModel(true); | 1097 test_util()->ResetModel(true); |
| 1082 const TemplateURL* url_for_unittest = | 1098 const TemplateURL* url_for_unittest = |
| 1083 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1099 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 1084 ASSERT_TRUE(url_for_unittest != NULL); | 1100 ASSERT_TRUE(url_for_unittest != NULL); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1115 AssertEquals(*cloned_url, *default_search); | 1131 AssertEquals(*cloned_url, *default_search); |
| 1116 } | 1132 } |
| 1117 | 1133 |
| 1118 // Make sure that the load routine doesn't delete | 1134 // Make sure that the load routine doesn't delete |
| 1119 // prepopulated engines that no longer exist in the prepopulate data if | 1135 // prepopulated engines that no longer exist in the prepopulate data if |
| 1120 // it is the default search provider. | 1136 // it is the default search provider. |
| 1121 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { | 1137 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { |
| 1122 // Set the default search provider to a preloaded template url which | 1138 // Set the default search provider to a preloaded template url which |
| 1123 // is not in the current set of preloaded template urls and save | 1139 // is not in the current set of preloaded template urls and save |
| 1124 // the result. | 1140 // the result. |
| 1125 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); | 1141 std::unique_ptr<TemplateURL> t_url_ptr = |
| 1142 CreatePreloadedTemplateURL(true, 999999); | |
| 1143 TemplateURL* t_url = t_url_ptr.get(); | |
| 1126 test_util()->ChangeModelToLoadState(); | 1144 test_util()->ChangeModelToLoadState(); |
| 1127 model()->Add(t_url); | 1145 model()->Add(std::move(t_url_ptr)); |
| 1128 model()->SetUserSelectedDefaultSearchProvider(t_url); | 1146 model()->SetUserSelectedDefaultSearchProvider(t_url); |
| 1129 // Do the copy after t_url is added and set as default so that its | 1147 // Do the copy after t_url is added and set as default so that its |
| 1130 // internal state is correct. | 1148 // internal state is correct. |
| 1131 std::unique_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 1149 std::unique_ptr<TemplateURL> cloned_url( |
|
Peter Kasting
2016/08/31 04:12:56
Nit: () -> =
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
| 1150 base::MakeUnique<TemplateURL>(t_url->data())); | |
| 1132 | 1151 |
| 1133 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1152 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
| 1134 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1153 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 1135 base::RunLoop().RunUntilIdle(); | 1154 base::RunLoop().RunUntilIdle(); |
| 1136 | 1155 |
| 1137 // Ensure that merging won't clear the prepopulated template url | 1156 // Ensure that merging won't clear the prepopulated template url |
| 1138 // which is no longer present if it's the default engine. | 1157 // which is no longer present if it's the default engine. |
| 1139 test_util()->ResetModel(true); | 1158 test_util()->ResetModel(true); |
| 1140 { | 1159 { |
| 1141 const TemplateURL* keyword_url = | 1160 const TemplateURL* keyword_url = |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { | 1357 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { |
| 1339 // Add a new TemplateURL. | 1358 // Add a new TemplateURL. |
| 1340 test_util()->VerifyLoad(); | 1359 test_util()->VerifyLoad(); |
| 1341 const size_t initial_count = model()->GetTemplateURLs().size(); | 1360 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 1342 | 1361 |
| 1343 TemplateURLData data; | 1362 TemplateURLData data; |
| 1344 data.SetShortName(ASCIIToUTF16("google")); | 1363 data.SetShortName(ASCIIToUTF16("google")); |
| 1345 data.SetKeyword(ASCIIToUTF16("keyword")); | 1364 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 1346 data.SetURL("http://www.google.com/foo/bar"); | 1365 data.SetURL("http://www.google.com/foo/bar"); |
| 1347 data.sync_guid.clear(); | 1366 data.sync_guid.clear(); |
| 1348 TemplateURL* t_url = new TemplateURL(data); | 1367 model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 1349 model()->Add(t_url); | |
| 1350 | 1368 |
| 1351 VerifyObserverCount(1); | 1369 VerifyObserverCount(1); |
| 1352 base::RunLoop().RunUntilIdle(); | 1370 base::RunLoop().RunUntilIdle(); |
| 1353 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1371 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1354 | 1372 |
| 1355 // Reload the model to verify it was actually saved to the database and | 1373 // Reload the model to verify it was actually saved to the database and |
| 1356 // assigned a new GUID when brought back. | 1374 // assigned a new GUID when brought back. |
| 1357 test_util()->ResetModel(true); | 1375 test_util()->ResetModel(true); |
| 1358 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1376 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1359 const TemplateURL* loaded_url = | 1377 const TemplateURL* loaded_url = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1375 data.SetURL("http://www.google.com/foo/bar"); | 1393 data.SetURL("http://www.google.com/foo/bar"); |
| 1376 std::vector<std::string> encodings; | 1394 std::vector<std::string> encodings; |
| 1377 data.input_encodings.push_back("UTF-8"); | 1395 data.input_encodings.push_back("UTF-8"); |
| 1378 data.input_encodings.push_back("UTF-8"); | 1396 data.input_encodings.push_back("UTF-8"); |
| 1379 data.input_encodings.push_back("UTF-16"); | 1397 data.input_encodings.push_back("UTF-16"); |
| 1380 data.input_encodings.push_back("UTF-8"); | 1398 data.input_encodings.push_back("UTF-8"); |
| 1381 data.input_encodings.push_back("Big5"); | 1399 data.input_encodings.push_back("Big5"); |
| 1382 data.input_encodings.push_back("UTF-16"); | 1400 data.input_encodings.push_back("UTF-16"); |
| 1383 data.input_encodings.push_back("Big5"); | 1401 data.input_encodings.push_back("Big5"); |
| 1384 data.input_encodings.push_back("Windows-1252"); | 1402 data.input_encodings.push_back("Windows-1252"); |
| 1385 TemplateURL* t_url = new TemplateURL(data); | 1403 model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 1386 model()->Add(t_url); | |
| 1387 | 1404 |
| 1388 VerifyObserverCount(1); | 1405 VerifyObserverCount(1); |
| 1389 base::RunLoop().RunUntilIdle(); | 1406 base::RunLoop().RunUntilIdle(); |
| 1390 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1407 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1391 const TemplateURL* loaded_url = | 1408 const TemplateURL* loaded_url = |
| 1392 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1409 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1393 ASSERT_TRUE(loaded_url != NULL); | 1410 ASSERT_TRUE(loaded_url != NULL); |
| 1394 EXPECT_EQ(8U, loaded_url->input_encodings().size()); | 1411 EXPECT_EQ(8U, loaded_url->input_encodings().size()); |
| 1395 | 1412 |
| 1396 // Reload the model to verify it was actually saved to the database and the | 1413 // Reload the model to verify it was actually saved to the database and the |
| 1397 // duplicate encodings were removed. | 1414 // duplicate encodings were removed. |
| 1398 test_util()->ResetModel(true); | 1415 test_util()->ResetModel(true); |
| 1399 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1416 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1400 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1417 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1401 ASSERT_FALSE(loaded_url == NULL); | 1418 ASSERT_FALSE(loaded_url == NULL); |
| 1402 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1419 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
| 1403 } | 1420 } |
| 1404 | 1421 |
| 1405 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { | 1422 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { |
| 1406 test_util()->VerifyLoad(); | 1423 test_util()->VerifyLoad(); |
| 1407 // Add third-party default search engine. | 1424 // Add third-party default search engine. |
| 1408 TemplateURL* user_dse = AddKeywordWithDate( | 1425 TemplateURL* user_dse = AddKeywordWithDate( |
| 1409 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1426 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
| 1410 std::string(), std::string(), std::string(), | 1427 std::string(), std::string(), std::string(), |
| 1411 true, "UTF-8", Time(), Time()); | 1428 true, "UTF-8", Time(), Time()); |
| 1412 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1429 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1413 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1430 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1414 | 1431 |
| 1415 TemplateURL* ext_dse = CreateKeywordWithDate( | 1432 std::unique_ptr<TemplateURL> ext_dse_ptr = CreateKeywordWithDate( |
| 1416 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1433 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
| 1417 std::string(), std::string(), std::string(), | 1434 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), |
| 1418 true, true, "UTF-8", Time(), Time()); | 1435 Time()); |
| 1436 TemplateURL* ext_dse = ext_dse_ptr.get(); | |
| 1419 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1437 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1420 new TemplateURL::AssociatedExtensionInfo( | 1438 new TemplateURL::AssociatedExtensionInfo( |
| 1421 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); | 1439 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); |
| 1422 extension_info->wants_to_be_default_engine = true; | 1440 extension_info->wants_to_be_default_engine = true; |
| 1423 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); | 1441 model()->AddExtensionControlledTURL(std::move(ext_dse_ptr), |
| 1442 std::move(extension_info)); | |
| 1424 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); | 1443 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); |
| 1425 | 1444 |
| 1426 model()->RemoveExtensionControlledTURL( | 1445 model()->RemoveExtensionControlledTURL( |
| 1427 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1446 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1428 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1447 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1429 } | 1448 } |
| 1430 | 1449 |
| 1431 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1450 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
| 1432 test_util()->VerifyLoad(); | 1451 test_util()->VerifyLoad(); |
| 1433 // Add third-party default search engine. | 1452 // Add third-party default search engine. |
| 1434 TemplateURL* user_dse = AddKeywordWithDate( | 1453 TemplateURL* user_dse = AddKeywordWithDate( |
| 1435 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1454 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
| 1436 std::string(), std::string(), std::string(), | 1455 std::string(), std::string(), std::string(), |
| 1437 true, "UTF-8", Time(), Time()); | 1456 true, "UTF-8", Time(), Time()); |
| 1438 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1457 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1439 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1458 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1440 | 1459 |
| 1441 TemplateURL* ext_dse = CreateKeywordWithDate( | 1460 std::unique_ptr<TemplateURL> ext_dse_ptr = CreateKeywordWithDate( |
| 1442 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1461 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1443 std::string(), std::string(), std::string(), | 1462 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(), |
| 1444 true, false, "UTF-8", Time(), Time()); | 1463 Time()); |
| 1464 TemplateURL* ext_dse = ext_dse_ptr.get(); | |
| 1445 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1465 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1446 new TemplateURL::AssociatedExtensionInfo( | 1466 new TemplateURL::AssociatedExtensionInfo( |
| 1447 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1467 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
| 1448 extension_info->wants_to_be_default_engine = false; | 1468 extension_info->wants_to_be_default_engine = false; |
| 1449 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); | 1469 model()->AddExtensionControlledTURL(std::move(ext_dse_ptr), |
| 1470 std::move(extension_info)); | |
| 1450 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1471 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1451 | 1472 |
| 1452 ext_dse = CreateKeywordWithDate( | 1473 ext_dse_ptr = CreateKeywordWithDate( |
| 1453 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", | 1474 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", |
| 1454 std::string(), std::string(), std::string(), | 1475 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), |
| 1455 true, true, "UTF-8", Time(), Time()); | 1476 Time()); |
| 1477 ext_dse = ext_dse_ptr.get(); | |
| 1456 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( | 1478 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( |
| 1457 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); | 1479 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); |
| 1458 extension_info->wants_to_be_default_engine = true; | 1480 extension_info->wants_to_be_default_engine = true; |
| 1459 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); | 1481 model()->AddExtensionControlledTURL(std::move(ext_dse_ptr), |
| 1482 std::move(extension_info)); | |
| 1460 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); | 1483 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); |
| 1461 | 1484 |
| 1462 test_util()->ResetModel(true); | 1485 test_util()->ResetModel(true); |
| 1463 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1486 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
| 1464 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1487 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1465 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1488 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1466 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); | 1489 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); |
| 1467 } | 1490 } |
| 1468 | 1491 |
| 1469 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { | 1492 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1489 data.input_encodings = base::SplitString( | 1512 data.input_encodings = base::SplitString( |
| 1490 kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1513 kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 1491 data.alternate_urls.push_back(kAlternateURL); | 1514 data.alternate_urls.push_back(kAlternateURL); |
| 1492 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 1515 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
| 1493 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); | 1516 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); |
| 1494 EXPECT_TRUE(model()->is_default_search_managed()); | 1517 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1495 const TemplateURL* actual_managed_default = | 1518 const TemplateURL* actual_managed_default = |
| 1496 model()->GetDefaultSearchProvider(); | 1519 model()->GetDefaultSearchProvider(); |
| 1497 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1520 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1498 | 1521 |
| 1499 TemplateURL* ext_dse = CreateKeywordWithDate( | 1522 std::unique_ptr<TemplateURL> ext_dse_ptr = CreateKeywordWithDate( |
| 1500 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1523 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1501 std::string(), std::string(), std::string(), | 1524 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), |
| 1502 true, true, "UTF-8", Time(), Time()); | 1525 Time()); |
| 1526 TemplateURL* ext_dse = ext_dse_ptr.get(); | |
| 1503 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1527 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1504 new TemplateURL::AssociatedExtensionInfo( | 1528 new TemplateURL::AssociatedExtensionInfo( |
| 1505 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1529 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
| 1506 extension_info->wants_to_be_default_engine = true; | 1530 extension_info->wants_to_be_default_engine = true; |
| 1507 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); | 1531 model()->AddExtensionControlledTURL(std::move(ext_dse_ptr), |
| 1532 std::move(extension_info)); | |
| 1508 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1533 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1509 EXPECT_TRUE(model()->is_default_search_managed()); | 1534 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1510 actual_managed_default = model()->GetDefaultSearchProvider(); | 1535 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 1511 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1536 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1512 } | 1537 } |
| OLD | NEW |