| 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> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 const std::string& keyword, | 67 const std::string& keyword, |
| 68 const std::string& url, | 68 const std::string& url, |
| 69 const std::string& suggest_url, | 69 const std::string& suggest_url, |
| 70 const std::string& alternate_url, | 70 const std::string& alternate_url, |
| 71 const std::string& favicon_url, | 71 const std::string& favicon_url, |
| 72 bool safe_for_autoreplace, | 72 bool safe_for_autoreplace, |
| 73 int prepopulate_id, | 73 int prepopulate_id, |
| 74 const std::string& encodings, | 74 const std::string& encodings, |
| 75 Time date_created, | 75 Time date_created, |
| 76 Time last_modified, | 76 Time last_modified, |
| 77 Time last_visited, |
| 77 TemplateURL::Type type = TemplateURL::NORMAL) { | 78 TemplateURL::Type type = TemplateURL::NORMAL) { |
| 78 TemplateURLData data; | 79 TemplateURLData data; |
| 79 data.SetShortName(base::UTF8ToUTF16(short_name)); | 80 data.SetShortName(base::UTF8ToUTF16(short_name)); |
| 80 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 81 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
| 81 data.SetURL(url); | 82 data.SetURL(url); |
| 82 data.suggestions_url = suggest_url; | 83 data.suggestions_url = suggest_url; |
| 83 if (!alternate_url.empty()) | 84 if (!alternate_url.empty()) |
| 84 data.alternate_urls.push_back(alternate_url); | 85 data.alternate_urls.push_back(alternate_url); |
| 85 data.favicon_url = GURL(favicon_url); | 86 data.favicon_url = GURL(favicon_url); |
| 86 data.safe_for_autoreplace = safe_for_autoreplace; | 87 data.safe_for_autoreplace = safe_for_autoreplace; |
| 87 data.prepopulate_id = prepopulate_id; | 88 data.prepopulate_id = prepopulate_id; |
| 88 data.input_encodings = base::SplitString( | 89 data.input_encodings = base::SplitString( |
| 89 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 90 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 90 data.date_created = date_created; | 91 data.date_created = date_created; |
| 91 data.last_modified = last_modified; | 92 data.last_modified = last_modified; |
| 93 data.last_visited = last_visited; |
| 92 return base::MakeUnique<TemplateURL>(data, type); | 94 return base::MakeUnique<TemplateURL>(data, type); |
| 93 } | 95 } |
| 94 | 96 |
| 95 TemplateURL* AddKeywordWithDate( | 97 TemplateURL* AddKeywordWithDate(TemplateURLService* model, |
| 96 TemplateURLService* model, | 98 const std::string& short_name, |
| 97 const std::string& short_name, | 99 const std::string& keyword, |
| 98 const std::string& keyword, | 100 const std::string& url, |
| 99 const std::string& url, | 101 const std::string& suggest_url, |
| 100 const std::string& suggest_url, | 102 const std::string& alternate_url, |
| 101 const std::string& alternate_url, | 103 const std::string& favicon_url, |
| 102 const std::string& favicon_url, | 104 bool safe_for_autoreplace, |
| 103 bool safe_for_autoreplace, | 105 const std::string& encodings, |
| 104 const std::string& encodings, | 106 Time date_created, |
| 105 Time date_created, | 107 Time last_modified, |
| 106 Time last_modified) { | 108 Time last_visited) { |
| 107 TemplateURL* t_url = model->Add(CreateKeywordWithDate( | 109 TemplateURL* t_url = model->Add(CreateKeywordWithDate( |
| 108 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url, | 110 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url, |
| 109 safe_for_autoreplace, 0, encodings, date_created, last_modified)); | 111 safe_for_autoreplace, 0, encodings, date_created, last_modified, |
| 112 last_visited)); |
| 110 EXPECT_NE(0, t_url->id()); | 113 EXPECT_NE(0, t_url->id()); |
| 111 return t_url; | 114 return t_url; |
| 112 } | 115 } |
| 113 | 116 |
| 114 // Checks that the two TemplateURLs are similar. It does not check the id, the | 117 // Checks that the two TemplateURLs are similar. It does not check the id or |
| 115 // date_created or the last_modified time. Neither pointer should be NULL. | 118 // any time-related fields. Neither pointer should be NULL. |
| 116 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { | 119 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { |
| 117 ASSERT_TRUE(expected != NULL); | 120 ASSERT_TRUE(expected != NULL); |
| 118 ASSERT_TRUE(actual != NULL); | 121 ASSERT_TRUE(actual != NULL); |
| 119 EXPECT_EQ(expected->short_name(), actual->short_name()); | 122 EXPECT_EQ(expected->short_name(), actual->short_name()); |
| 120 EXPECT_EQ(expected->keyword(), actual->keyword()); | 123 EXPECT_EQ(expected->keyword(), actual->keyword()); |
| 121 EXPECT_EQ(expected->url(), actual->url()); | 124 EXPECT_EQ(expected->url(), actual->url()); |
| 122 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); | 125 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); |
| 123 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); | 126 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); |
| 124 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); | 127 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); |
| 125 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); | 128 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 147 | 150 |
| 148 TemplateURL* AddKeywordWithDate(const std::string& short_name, | 151 TemplateURL* AddKeywordWithDate(const std::string& short_name, |
| 149 const std::string& keyword, | 152 const std::string& keyword, |
| 150 const std::string& url, | 153 const std::string& url, |
| 151 const std::string& suggest_url, | 154 const std::string& suggest_url, |
| 152 const std::string& alternate_url, | 155 const std::string& alternate_url, |
| 153 const std::string& favicon_url, | 156 const std::string& favicon_url, |
| 154 bool safe_for_autoreplace, | 157 bool safe_for_autoreplace, |
| 155 const std::string& encodings, | 158 const std::string& encodings, |
| 156 Time date_created, | 159 Time date_created, |
| 157 Time last_modified); | 160 Time last_modified, |
| 161 Time last_visited); |
| 158 | 162 |
| 159 // Verifies the two TemplateURLs are equal. | 163 // Verifies the two TemplateURLs are equal. |
| 160 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); | 164 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); |
| 161 | 165 |
| 162 // Verifies the two timestamps are equal, within the expected degree of | 166 // Verifies the two timestamps are equal, within the expected degree of |
| 163 // precision. | 167 // precision. |
| 164 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); | 168 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); |
| 165 | 169 |
| 166 // Create an URL that appears to have been prepopulated, but won't be in the | 170 // Create an URL that appears to have been prepopulated, but won't be in the |
| 167 // current data. | 171 // current data. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( | 219 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( |
| 216 const std::string& short_name, | 220 const std::string& short_name, |
| 217 const std::string& keyword, | 221 const std::string& keyword, |
| 218 const std::string& url, | 222 const std::string& url, |
| 219 const std::string& suggest_url, | 223 const std::string& suggest_url, |
| 220 const std::string& alternate_url, | 224 const std::string& alternate_url, |
| 221 const std::string& favicon_url, | 225 const std::string& favicon_url, |
| 222 bool safe_for_autoreplace, | 226 bool safe_for_autoreplace, |
| 223 const std::string& encodings, | 227 const std::string& encodings, |
| 224 Time date_created, | 228 Time date_created, |
| 225 Time last_modified) { | 229 Time last_modified, |
| 230 Time last_visited) { |
| 226 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, | 231 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, |
| 227 alternate_url, favicon_url, safe_for_autoreplace, | 232 alternate_url, favicon_url, safe_for_autoreplace, |
| 228 encodings, date_created, last_modified); | 233 encodings, date_created, last_modified, |
| 234 last_visited); |
| 229 } | 235 } |
| 230 | 236 |
| 231 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, | 237 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, |
| 232 const TemplateURL& actual) { | 238 const TemplateURL& actual) { |
| 233 ASSERT_EQ(expected.short_name(), actual.short_name()); | 239 ASSERT_EQ(expected.short_name(), actual.short_name()); |
| 234 ASSERT_EQ(expected.keyword(), actual.keyword()); | 240 ASSERT_EQ(expected.keyword(), actual.keyword()); |
| 235 ASSERT_EQ(expected.url(), actual.url()); | 241 ASSERT_EQ(expected.url(), actual.url()); |
| 236 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 242 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
| 237 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 243 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
| 238 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); | 244 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); |
| 239 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); | 245 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); |
| 240 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 246 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
| 241 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); | 247 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
| 242 ASSERT_EQ(expected.id(), actual.id()); | 248 ASSERT_EQ(expected.id(), actual.id()); |
| 243 ASSERT_EQ(expected.date_created(), actual.date_created()); | 249 ASSERT_EQ(expected.date_created(), actual.date_created()); |
| 244 AssertTimesEqual(expected.last_modified(), actual.last_modified()); | 250 AssertTimesEqual(expected.last_modified(), actual.last_modified()); |
| 251 ASSERT_EQ(expected.last_visited(), actual.last_visited()); |
| 245 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); | 252 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); |
| 246 ASSERT_EQ(expected.search_terms_replacement_key(), | 253 ASSERT_EQ(expected.search_terms_replacement_key(), |
| 247 actual.search_terms_replacement_key()); | 254 actual.search_terms_replacement_key()); |
| 248 } | 255 } |
| 249 | 256 |
| 250 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, | 257 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, |
| 251 const base::Time& actual) { | 258 const base::Time& actual) { |
| 252 // Because times are stored with a granularity of one second, there is a loss | 259 // Because times are stored with a granularity of one second, there is a loss |
| 253 // of precision when serializing and deserializing the timestamps. Hence, only | 260 // of precision when serializing and deserializing the timestamps. Hence, only |
| 254 // expect timestamps to be equal to within one second of one another. | 261 // expect timestamps to be equal to within one second of one another. |
| 255 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); | 262 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); |
| 256 } | 263 } |
| 257 | 264 |
| 258 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( | 265 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( |
| 259 bool safe_for_autoreplace, | 266 bool safe_for_autoreplace, |
| 260 int prepopulate_id) { | 267 int prepopulate_id) { |
| 261 TemplateURLData data; | 268 TemplateURLData data; |
| 262 data.SetShortName(ASCIIToUTF16("unittest")); | 269 data.SetShortName(ASCIIToUTF16("unittest")); |
| 263 data.SetKeyword(ASCIIToUTF16("unittest")); | 270 data.SetKeyword(ASCIIToUTF16("unittest")); |
| 264 data.SetURL("http://www.unittest.com/{searchTerms}"); | 271 data.SetURL("http://www.unittest.com/{searchTerms}"); |
| 265 data.favicon_url = GURL("http://favicon.url"); | 272 data.favicon_url = GURL("http://favicon.url"); |
| 266 data.safe_for_autoreplace = safe_for_autoreplace; | 273 data.safe_for_autoreplace = safe_for_autoreplace; |
| 267 data.input_encodings.push_back("UTF-8"); | 274 data.input_encodings.push_back("UTF-8"); |
| 268 data.date_created = Time::FromTimeT(100); | 275 data.date_created = Time::FromTimeT(100); |
| 269 data.last_modified = Time::FromTimeT(100); | 276 data.last_modified = Time::FromTimeT(100); |
| 277 data.last_visited = Time::FromTimeT(100); |
| 270 data.prepopulate_id = prepopulate_id; | 278 data.prepopulate_id = prepopulate_id; |
| 271 return base::MakeUnique<TemplateURL>(data); | 279 return base::MakeUnique<TemplateURL>(data); |
| 272 } | 280 } |
| 273 | 281 |
| 274 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 282 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
| 275 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); | 283 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); |
| 276 test_util_->ResetObserverCount(); | 284 test_util_->ResetObserverCount(); |
| 277 } | 285 } |
| 278 | 286 |
| 279 void TemplateURLServiceTest::VerifyObserverFired() { | 287 void TemplateURLServiceTest::VerifyObserverFired() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 294 const size_t initial_count = model()->GetTemplateURLs().size(); | 302 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 295 | 303 |
| 296 TemplateURLData data; | 304 TemplateURLData data; |
| 297 data.SetShortName(ASCIIToUTF16("google")); | 305 data.SetShortName(ASCIIToUTF16("google")); |
| 298 data.SetKeyword(ASCIIToUTF16("keyword")); | 306 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 299 data.SetURL("http://www.google.com/foo/bar"); | 307 data.SetURL("http://www.google.com/foo/bar"); |
| 300 data.favicon_url = GURL("http://favicon.url"); | 308 data.favicon_url = GURL("http://favicon.url"); |
| 301 data.safe_for_autoreplace = true; | 309 data.safe_for_autoreplace = true; |
| 302 data.date_created = Time::FromTimeT(100); | 310 data.date_created = Time::FromTimeT(100); |
| 303 data.last_modified = Time::FromTimeT(100); | 311 data.last_modified = Time::FromTimeT(100); |
| 312 data.last_visited = Time::FromTimeT(100); |
| 304 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 313 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
| 305 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 314 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 306 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 315 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
| 307 GURL(), NULL)); | 316 GURL(), NULL)); |
| 308 VerifyObserverCount(1); | 317 VerifyObserverCount(1); |
| 309 base::RunLoop().RunUntilIdle(); | 318 base::RunLoop().RunUntilIdle(); |
| 310 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 319 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 311 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 320 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); |
| 312 // We need to make a second copy as the model takes ownership of |t_url| and | 321 // We need to make a second copy as the model takes ownership of |t_url| and |
| 313 // will delete it. We have to do this after calling Add() since that gives | 322 // will delete it. We have to do this after calling Add() since that gives |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 model()->Remove(loaded_url); | 367 model()->Remove(loaded_url); |
| 359 VerifyObserverCount(1); | 368 VerifyObserverCount(1); |
| 360 test_util()->ResetModel(true); | 369 test_util()->ResetModel(true); |
| 361 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); | 370 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); |
| 362 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); | 371 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); |
| 363 } | 372 } |
| 364 | 373 |
| 365 TEST_F(TemplateURLServiceTest, AddSameKeyword) { | 374 TEST_F(TemplateURLServiceTest, AddSameKeyword) { |
| 366 test_util()->VerifyLoad(); | 375 test_util()->VerifyLoad(); |
| 367 | 376 |
| 368 AddKeywordWithDate( | 377 AddKeywordWithDate("first", "keyword", "http://test1", std::string(), |
| 369 "first", "keyword", "http://test1", std::string(), std::string(), | 378 std::string(), std::string(), true, "UTF-8", Time(), |
| 370 std::string(), true, "UTF-8", Time(), Time()); | 379 Time(), Time()); |
| 371 VerifyObserverCount(1); | 380 VerifyObserverCount(1); |
| 372 | 381 |
| 373 // Test what happens when we try to add a TemplateURL with the same keyword as | 382 // Test what happens when we try to add a TemplateURL with the same keyword as |
| 374 // one in the model. | 383 // one in the model. |
| 375 TemplateURLData data; | 384 TemplateURLData data; |
| 376 data.SetShortName(ASCIIToUTF16("second")); | 385 data.SetShortName(ASCIIToUTF16("second")); |
| 377 data.SetKeyword(ASCIIToUTF16("keyword")); | 386 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 378 data.SetURL("http://test2"); | 387 data.SetURL("http://test2"); |
| 379 data.safe_for_autoreplace = false; | 388 data.safe_for_autoreplace = false; |
| 380 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 389 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 409 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 418 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 410 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); | 419 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); |
| 411 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); | 420 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); |
| 412 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 421 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
| 413 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 422 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
| 414 } | 423 } |
| 415 | 424 |
| 416 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { | 425 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { |
| 417 test_util()->VerifyLoad(); | 426 test_util()->VerifyLoad(); |
| 418 | 427 |
| 419 AddKeywordWithDate( | 428 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(), |
| 420 "replaceable", "keyword1", "http://test1", std::string(), std::string(), | 429 std::string(), std::string(), true, "UTF-8", Time(), |
| 421 std::string(), true, "UTF-8", Time(), Time()); | 430 Time(), Time()); |
| 422 TemplateURL* original2 = AddKeywordWithDate( | 431 TemplateURL* original2 = AddKeywordWithDate( |
| 423 "nonreplaceable", "keyword2", "http://test2", std::string(), | 432 "nonreplaceable", "keyword2", "http://test2", std::string(), |
| 424 std::string(), std::string(), false, "UTF-8", Time(), Time()); | 433 std::string(), std::string(), false, "UTF-8", Time(), Time(), Time()); |
| 425 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", | 434 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", |
| 426 "http://test3"); | 435 "http://test3"); |
| 427 TemplateURL* original3 = | 436 TemplateURL* original3 = |
| 428 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); | 437 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); |
| 429 ASSERT_TRUE(original3); | 438 ASSERT_TRUE(original3); |
| 430 | 439 |
| 431 // Extension keywords should override replaceable keywords. | 440 // Extension keywords should override replaceable keywords. |
| 432 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); | 441 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); |
| 433 TemplateURL* extension1 = model()->FindTemplateURLForExtension( | 442 TemplateURL* extension1 = model()->FindTemplateURLForExtension( |
| 434 "id1", TemplateURL::OMNIBOX_API_EXTENSION); | 443 "id1", TemplateURL::OMNIBOX_API_EXTENSION); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 458 | 467 |
| 459 // Similar to the AddSameKeyword test, but with an extension keyword masking a | 468 // Similar to the AddSameKeyword test, but with an extension keyword masking a |
| 460 // replaceable TemplateURL. We should still do correct conflict resolution | 469 // replaceable TemplateURL. We should still do correct conflict resolution |
| 461 // between the non-template URLs. | 470 // between the non-template URLs. |
| 462 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", | 471 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", |
| 463 "http://test2"); | 472 "http://test2"); |
| 464 TemplateURL* extension = | 473 TemplateURL* extension = |
| 465 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 474 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 466 ASSERT_TRUE(extension); | 475 ASSERT_TRUE(extension); |
| 467 // Adding a keyword that matches the extension. | 476 // Adding a keyword that matches the extension. |
| 468 AddKeywordWithDate( | 477 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(), |
| 469 "replaceable", "keyword", "http://test1", std::string(), std::string(), | 478 std::string(), std::string(), true, "UTF-8", Time(), |
| 470 std::string(), true, "UTF-8", Time(), Time()); | 479 Time(), Time()); |
| 471 | 480 |
| 472 // Adding another replaceable keyword should remove the existing one, but | 481 // Adding another replaceable keyword should remove the existing one, but |
| 473 // leave the extension as is. | 482 // leave the extension as is. |
| 474 TemplateURLData data; | 483 TemplateURLData data; |
| 475 data.SetShortName(ASCIIToUTF16("name1")); | 484 data.SetShortName(ASCIIToUTF16("name1")); |
| 476 data.SetKeyword(ASCIIToUTF16("keyword")); | 485 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 477 data.SetURL("http://test3"); | 486 data.SetURL("http://test3"); |
| 478 data.safe_for_autoreplace = true; | 487 data.safe_for_autoreplace = true; |
| 479 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 488 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 480 EXPECT_EQ(extension, | 489 EXPECT_EQ(extension, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 511 Time now = Time::Now(); | 520 Time now = Time::Now(); |
| 512 TimeDelta one_day = TimeDelta::FromDays(1); | 521 TimeDelta one_day = TimeDelta::FromDays(1); |
| 513 Time month_ago = now - TimeDelta::FromDays(30); | 522 Time month_ago = now - TimeDelta::FromDays(30); |
| 514 | 523 |
| 515 // Nothing has been added. | 524 // Nothing has been added. |
| 516 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 525 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 517 | 526 |
| 518 // Create one with a 0 time. | 527 // Create one with a 0 time. |
| 519 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 528 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
| 520 std::string(), "http://icon1", true, "UTF-8;UTF-16", | 529 std::string(), "http://icon1", true, "UTF-8;UTF-16", |
| 521 Time(), Time()); | 530 Time(), Time(), Time()); |
| 522 // Create one for now and +/- 1 day. | 531 // Create one for now and +/- 1 day. |
| 523 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", | 532 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", |
| 524 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 533 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
| 525 now - one_day, Time()); | 534 now - one_day, Time(), Time()); |
| 526 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 535 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
| 527 std::string(), std::string(), true, std::string(), now, | 536 std::string(), std::string(), true, std::string(), now, |
| 528 Time()); | 537 Time(), Time()); |
| 529 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), | 538 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), |
| 530 std::string(), std::string(), true, std::string(), | 539 std::string(), std::string(), true, std::string(), |
| 531 now + one_day, Time()); | 540 now + one_day, Time(), Time()); |
| 532 // Try the other three states. | 541 // Try the other three states. |
| 533 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", | 542 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", |
| 534 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, | 543 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, |
| 535 Time()); | 544 Time(), Time()); |
| 536 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", | 545 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", |
| 537 std::string(), "http://icon6", false, "UTF-8;UTF-16", | 546 std::string(), "http://icon6", false, "UTF-8;UTF-16", |
| 538 month_ago, Time()); | 547 month_ago, Time(), Time()); |
| 539 | 548 |
| 540 // We just added a few items, validate them. | 549 // We just added a few items, validate them. |
| 541 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); | 550 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); |
| 542 | 551 |
| 543 // Try removing from current timestamp. This should delete the one in the | 552 // Try removing from current timestamp. This should delete the one in the |
| 544 // future and one very recent one. | 553 // future and one very recent one. |
| 545 model()->RemoveAutoGeneratedSince(now); | 554 model()->RemoveAutoGeneratedSince(now); |
| 546 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); | 555 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); |
| 547 | 556 |
| 548 // Try removing from two months ago. This should only delete items that are | 557 // Try removing from two months ago. This should only delete items that are |
| (...skipping 26 matching lines...) Expand all Loading... |
| 575 Time now = Time::Now(); | 584 Time now = Time::Now(); |
| 576 TimeDelta one_day = TimeDelta::FromDays(1); | 585 TimeDelta one_day = TimeDelta::FromDays(1); |
| 577 Time month_ago = now - TimeDelta::FromDays(30); | 586 Time month_ago = now - TimeDelta::FromDays(30); |
| 578 | 587 |
| 579 // Nothing has been added. | 588 // Nothing has been added. |
| 580 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 589 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 581 | 590 |
| 582 // Create one for now and +/- 1 day. | 591 // Create one for now and +/- 1 day. |
| 583 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 592 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
| 584 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 593 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
| 585 now - one_day, Time()); | 594 now - one_day, Time(), Time()); |
| 586 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), | 595 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), |
| 587 std::string(), std::string(), true, std::string(), now, | 596 std::string(), std::string(), true, std::string(), now, |
| 588 Time()); | 597 Time(), Time()); |
| 589 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 598 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
| 590 std::string(), std::string(), true, std::string(), | 599 std::string(), std::string(), true, std::string(), |
| 591 now + one_day, Time()); | 600 now + one_day, Time(), Time()); |
| 592 | 601 |
| 593 // We just added a few items, validate them. | 602 // We just added a few items, validate them. |
| 594 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | 603 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); |
| 595 | 604 |
| 596 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. | 605 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. |
| 597 GURL url2("http://foo2"); | 606 GURL url2("http://foo2"); |
| 598 model()->RemoveAutoGeneratedForUrlsBetween( | 607 model()->RemoveAutoGeneratedForUrlsBetween( |
| 599 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), | 608 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
| 600 url2), | 609 url2), |
| 601 month_ago, now + one_day); | 610 month_ago, now + one_day); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 // Add a new TemplateURL. | 642 // Add a new TemplateURL. |
| 634 test_util()->VerifyLoad(); | 643 test_util()->VerifyLoad(); |
| 635 const size_t initial_count = model()->GetTemplateURLs().size(); | 644 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 636 TemplateURLData data; | 645 TemplateURLData data; |
| 637 data.SetShortName(ASCIIToUTF16("google")); | 646 data.SetShortName(ASCIIToUTF16("google")); |
| 638 data.SetKeyword(ASCIIToUTF16("keyword")); | 647 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 639 data.SetURL("http://www.google.com/foo/bar"); | 648 data.SetURL("http://www.google.com/foo/bar"); |
| 640 data.favicon_url = GURL("http://favicon.url"); | 649 data.favicon_url = GURL("http://favicon.url"); |
| 641 data.date_created = Time::FromTimeT(100); | 650 data.date_created = Time::FromTimeT(100); |
| 642 data.last_modified = Time::FromTimeT(100); | 651 data.last_modified = Time::FromTimeT(100); |
| 652 data.last_visited = Time::FromTimeT(100); |
| 643 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 653 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 644 | 654 |
| 645 VerifyObserverCount(1); | 655 VerifyObserverCount(1); |
| 646 base::RunLoop().RunUntilIdle(); | 656 base::RunLoop().RunUntilIdle(); |
| 647 | 657 |
| 648 base::Time now = base::Time::Now(); | 658 base::Time now = base::Time::Now(); |
| 649 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 659 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
| 650 clock->SetNow(now); | 660 clock->SetNow(now); |
| 651 model()->set_clock(std::move(clock)); | 661 model()->set_clock(std::move(clock)); |
| 652 | 662 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 673 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); | 683 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); |
| 674 ASSERT_TRUE(read_url); | 684 ASSERT_TRUE(read_url); |
| 675 AssertEquals(*cloned_url, *read_url); | 685 AssertEquals(*cloned_url, *read_url); |
| 676 AssertTimesEqual(now, read_url->last_modified()); | 686 AssertTimesEqual(now, read_url->last_modified()); |
| 677 } | 687 } |
| 678 | 688 |
| 679 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { | 689 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { |
| 680 // Add a new TemplateURL. | 690 // Add a new TemplateURL. |
| 681 test_util()->VerifyLoad(); | 691 test_util()->VerifyLoad(); |
| 682 const size_t initial_count = model()->GetTemplateURLs().size(); | 692 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 683 TemplateURL* t_url = AddKeywordWithDate( | 693 TemplateURL* t_url = |
| 684 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 694 AddKeywordWithDate("name1", "key1", "http://foo1/{searchTerms}", |
| 685 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 695 "http://sugg1", std::string(), "http://icon1", true, |
| 696 "UTF-8;UTF-16", Time(), Time(), Time()); |
| 686 test_util()->ResetObserverCount(); | 697 test_util()->ResetObserverCount(); |
| 687 | 698 |
| 688 model()->SetUserSelectedDefaultSearchProvider(t_url); | 699 model()->SetUserSelectedDefaultSearchProvider(t_url); |
| 689 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 700 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 690 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 701 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
| 691 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); | 702 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); |
| 692 | 703 |
| 693 // Setting the default search provider should have caused notification. | 704 // Setting the default search provider should have caused notification. |
| 694 VerifyObserverCount(1); | 705 VerifyObserverCount(1); |
| 695 base::RunLoop().RunUntilIdle(); | 706 base::RunLoop().RunUntilIdle(); |
| 696 | 707 |
| 697 std::unique_ptr<TemplateURL> cloned_url( | 708 std::unique_ptr<TemplateURL> cloned_url( |
| 698 base::MakeUnique<TemplateURL>(t_url->data())); | 709 base::MakeUnique<TemplateURL>(t_url->data())); |
| 699 | 710 |
| 700 // Make sure when we reload we get a default search provider. | 711 // Make sure when we reload we get a default search provider. |
| 701 test_util()->ResetModel(true); | 712 test_util()->ResetModel(true); |
| 702 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 713 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 703 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 714 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 704 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 715 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
| 705 } | 716 } |
| 706 | 717 |
| 707 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { | 718 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { |
| 708 test_util()->ChangeModelToLoadState(); | 719 test_util()->ChangeModelToLoadState(); |
| 709 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), | 720 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), |
| 710 NULL)); | 721 NULL)); |
| 711 TemplateURL* t_url = AddKeywordWithDate( | 722 TemplateURL* t_url = AddKeywordWithDate( |
| 712 "name1", "foo", "http://foo1", "http://sugg1", std::string(), | 723 "name1", "foo", "http://foo1", "http://sugg1", std::string(), |
| 713 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 724 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
| 714 | 725 |
| 715 // Can still replace, newly added template url is marked safe to replace. | 726 // Can still replace, newly added template url is marked safe to replace. |
| 716 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 727 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
| 717 GURL("http://foo2"), NULL)); | 728 GURL("http://foo2"), NULL)); |
| 718 | 729 |
| 719 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 730 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
| 720 // no longer be replaceable. | 731 // no longer be replaceable. |
| 721 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 732 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
| 722 t_url->url()); | 733 t_url->url()); |
| 723 | 734 |
| 724 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 735 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
| 725 GURL("http://foo2"), NULL)); | 736 GURL("http://foo2"), NULL)); |
| 726 } | 737 } |
| 727 | 738 |
| 728 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { | 739 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { |
| 729 test_util()->ChangeModelToLoadState(); | 740 test_util()->ChangeModelToLoadState(); |
| 730 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 741 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
| 731 GURL("http://foo.com"), NULL)); | 742 GURL("http://foo.com"), NULL)); |
| 732 TemplateURL* t_url = AddKeywordWithDate( | 743 TemplateURL* t_url = AddKeywordWithDate( |
| 733 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), | 744 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), |
| 734 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 745 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
| 735 | 746 |
| 736 // Can still replace, newly added template url is marked safe to replace. | 747 // Can still replace, newly added template url is marked safe to replace. |
| 737 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), | 748 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), |
| 738 GURL("http://foo.com"), NULL)); | 749 GURL("http://foo.com"), NULL)); |
| 739 | 750 |
| 740 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 751 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
| 741 // no longer be replaceable. | 752 // no longer be replaceable. |
| 742 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 753 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
| 743 t_url->url()); | 754 t_url->url()); |
| 744 | 755 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 760 test_util()->VerifyLoad(); | 771 test_util()->VerifyLoad(); |
| 761 | 772 |
| 762 TemplateURLData data; | 773 TemplateURLData data; |
| 763 data.SetShortName(ASCIIToUTF16("a")); | 774 data.SetShortName(ASCIIToUTF16("a")); |
| 764 data.safe_for_autoreplace = true; | 775 data.safe_for_autoreplace = true; |
| 765 data.SetURL("http://url/{searchTerms}"); | 776 data.SetURL("http://url/{searchTerms}"); |
| 766 data.suggestions_url = "http://url2"; | 777 data.suggestions_url = "http://url2"; |
| 767 data.instant_url = "http://instant"; | 778 data.instant_url = "http://instant"; |
| 768 data.date_created = Time::FromTimeT(100); | 779 data.date_created = Time::FromTimeT(100); |
| 769 data.last_modified = Time::FromTimeT(100); | 780 data.last_modified = Time::FromTimeT(100); |
| 781 data.last_visited = Time::FromTimeT(100); |
| 770 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 782 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
| 771 const TemplateURLID id = t_url->id(); | 783 const TemplateURLID id = t_url->id(); |
| 772 | 784 |
| 773 model()->SetUserSelectedDefaultSearchProvider(t_url); | 785 model()->SetUserSelectedDefaultSearchProvider(t_url); |
| 774 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
| 775 std::unique_ptr<TemplateURL> cloned_url( | 787 std::unique_ptr<TemplateURL> cloned_url( |
| 776 base::MakeUnique<TemplateURL>(t_url->data())); | 788 base::MakeUnique<TemplateURL>(t_url->data())); |
| 777 | 789 |
| 778 // Reset the model and don't load it. The template url we set as the default | 790 // Reset the model and don't load it. The template url we set as the default |
| 779 // should be pulled from prefs now. | 791 // should be pulled from prefs now. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 804 ASCIIToUTF16("google.com")); | 816 ASCIIToUTF16("google.com")); |
| 805 ASSERT_TRUE(google); | 817 ASSERT_TRUE(google); |
| 806 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), | 818 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), |
| 807 "http://www.foo.com/s?q={searchTerms}"); | 819 "http://www.foo.com/s?q={searchTerms}"); |
| 808 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 820 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
| 809 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); | 821 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); |
| 810 | 822 |
| 811 // Add third-party default search engine. | 823 // Add third-party default search engine. |
| 812 TemplateURL* user_dse = AddKeywordWithDate( | 824 TemplateURL* user_dse = AddKeywordWithDate( |
| 813 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", | 825 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", |
| 814 std::string(), std::string(), std::string(), | 826 std::string(), std::string(), std::string(), true, "UTF-8", Time(), |
| 815 true, "UTF-8", Time(), Time()); | 827 Time(), Time()); |
| 816 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 828 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 817 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 829 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 818 | 830 |
| 819 // Remove bing. | 831 // Remove bing. |
| 820 TemplateURL* bing = model()->GetTemplateURLForKeyword( | 832 TemplateURL* bing = model()->GetTemplateURLForKeyword( |
| 821 ASCIIToUTF16("bing.com")); | 833 ASCIIToUTF16("bing.com")); |
| 822 ASSERT_TRUE(bing); | 834 ASSERT_TRUE(bing); |
| 823 model()->Remove(bing); | 835 model()->Remove(bing); |
| 824 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 836 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
| 825 | 837 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 { "http://x/foo?q=b&q=xx", base::string16() }, | 913 { "http://x/foo?q=b&q=xx", base::string16() }, |
| 902 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, | 914 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, |
| 903 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, | 915 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, |
| 904 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, | 916 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, |
| 905 { "http://x/foo?query=b#q=xx", base::string16() }, | 917 { "http://x/foo?query=b#q=xx", base::string16() }, |
| 906 }; | 918 }; |
| 907 | 919 |
| 908 test_util()->ChangeModelToLoadState(); | 920 test_util()->ChangeModelToLoadState(); |
| 909 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", | 921 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", |
| 910 "http://sugg1", "http://x/foo#query={searchTerms}", | 922 "http://sugg1", "http://x/foo#query={searchTerms}", |
| 911 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 923 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 924 Time()); |
| 912 | 925 |
| 913 for (size_t i = 0; i < arraysize(data); ++i) { | 926 for (size_t i = 0; i < arraysize(data); ++i) { |
| 914 TemplateURLService::URLVisitedDetails details = { | 927 TemplateURLService::URLVisitedDetails details = { |
| 915 GURL(data[i].url), false | 928 GURL(data[i].url), false |
| 916 }; | 929 }; |
| 917 model()->UpdateKeywordSearchTermsForURL(details); | 930 model()->UpdateKeywordSearchTermsForURL(details); |
| 918 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); | 931 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); |
| 919 } | 932 } |
| 920 } | 933 } |
| 921 | 934 |
| 922 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { | 935 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { |
| 923 struct TestData { | 936 struct TestData { |
| 924 const std::string url; | 937 const std::string url; |
| 925 } data[] = { | 938 } data[] = { |
| 926 { "http://foo/" }, | 939 { "http://foo/" }, |
| 927 { "http://x/bar?q=xx" }, | 940 { "http://x/bar?q=xx" }, |
| 928 { "http://x/foo?y=xx" }, | 941 { "http://x/foo?y=xx" }, |
| 929 }; | 942 }; |
| 930 | 943 |
| 931 test_util()->ChangeModelToLoadState(); | 944 test_util()->ChangeModelToLoadState(); |
| 932 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), | 945 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), |
| 933 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 946 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 947 Time()); |
| 934 | 948 |
| 935 for (size_t i = 0; i < arraysize(data); ++i) { | 949 for (size_t i = 0; i < arraysize(data); ++i) { |
| 936 TemplateURLService::URLVisitedDetails details = { | 950 TemplateURLService::URLVisitedDetails details = { |
| 937 GURL(data[i].url), false | 951 GURL(data[i].url), false |
| 938 }; | 952 }; |
| 939 model()->UpdateKeywordSearchTermsForURL(details); | 953 model()->UpdateKeywordSearchTermsForURL(details); |
| 940 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); | 954 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); |
| 941 } | 955 } |
| 942 } | 956 } |
| 943 | 957 |
| 944 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { | 958 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { |
| 945 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} | 959 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} |
| 946 // keyword in it and would confuse this test. | 960 // keyword in it and would confuse this test. |
| 947 test_util()->ChangeModelToLoadState(); | 961 test_util()->ChangeModelToLoadState(); |
| 948 | 962 |
| 949 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); | 963 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); |
| 950 const TemplateURL* t_url = AddKeywordWithDate( | 964 const TemplateURL* t_url = AddKeywordWithDate( |
| 951 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", | 965 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", |
| 952 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 966 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 967 Time()); |
| 953 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); | 968 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); |
| 954 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); | 969 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); |
| 955 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); | 970 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); |
| 956 | 971 |
| 957 // Change the Google base url. | 972 // Change the Google base url. |
| 958 test_util()->ResetObserverCount(); | 973 test_util()->ResetObserverCount(); |
| 959 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); | 974 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); |
| 960 VerifyObserverCount(1); | 975 VerifyObserverCount(1); |
| 961 | 976 |
| 962 // Make sure the host->TemplateURL map was updated appropriately. | 977 // Make sure the host->TemplateURL map was updated appropriately. |
| 963 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); | 978 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); |
| 964 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); | 979 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); |
| 965 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); | 980 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); |
| 966 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); | 981 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); |
| 967 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( | 982 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( |
| 968 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); | 983 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); |
| 969 | 984 |
| 970 // Now add a manual entry and then change the Google base URL such that the | 985 // Now add a manual entry and then change the Google base URL such that the |
| 971 // autogenerated Google search keyword would conflict. | 986 // autogenerated Google search keyword would conflict. |
| 972 TemplateURL* manual = AddKeywordWithDate( | 987 TemplateURL* manual = AddKeywordWithDate( |
| 973 "manual", "google.de", "http://google.de/search?q={searchTerms}", | 988 "manual", "google.de", "http://google.de/search?q={searchTerms}", |
| 974 std::string(), std::string(), std::string(), false, "UTF-8", Time(), | 989 std::string(), std::string(), std::string(), false, "UTF-8", Time(), |
| 975 Time()); | 990 Time(), Time()); |
| 976 test_util()->SetGoogleBaseURL(GURL("http://google.de")); | 991 test_util()->SetGoogleBaseURL(GURL("http://google.de")); |
| 977 | 992 |
| 978 // Verify that the manual entry is untouched, and the autogenerated keyword | 993 // Verify that the manual entry is untouched, and the autogenerated keyword |
| 979 // has not changed. | 994 // has not changed. |
| 980 ASSERT_EQ(manual, | 995 ASSERT_EQ(manual, |
| 981 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); | 996 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); |
| 982 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); | 997 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); |
| 983 ASSERT_EQ(t_url, | 998 ASSERT_EQ(t_url, |
| 984 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); | 999 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); |
| 985 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); | 1000 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1002 // KEYWORD visits. | 1017 // KEYWORD visits. |
| 1003 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { | 1018 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { |
| 1004 test_util()->profile()->CreateBookmarkModel(false); | 1019 test_util()->profile()->CreateBookmarkModel(false); |
| 1005 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); | 1020 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); |
| 1006 test_util()->ResetModel(true); | 1021 test_util()->ResetModel(true); |
| 1007 | 1022 |
| 1008 // Create a keyword. | 1023 // Create a keyword. |
| 1009 TemplateURL* t_url = AddKeywordWithDate( | 1024 TemplateURL* t_url = AddKeywordWithDate( |
| 1010 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", | 1025 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", |
| 1011 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", | 1026 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", |
| 1012 base::Time::Now(), base::Time::Now()); | 1027 base::Time::Now(), base::Time::Now(), base::Time()); |
| 1013 | 1028 |
| 1014 // Add a visit that matches the url of the keyword. | 1029 // Add a visit that matches the url of the keyword. |
| 1015 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 1030 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 1016 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); | 1031 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); |
| 1017 history->AddPage( | 1032 history->AddPage( |
| 1018 GURL(t_url->url_ref().ReplaceSearchTerms( | 1033 GURL(t_url->url_ref().ReplaceSearchTerms( |
| 1019 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), | 1034 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), |
| 1020 search_terms_data())), | 1035 search_terms_data())), |
| 1021 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), | 1036 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), |
| 1022 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); | 1037 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 | 1226 |
| 1212 // Verifies that if the default search URL preference is managed, we report | 1227 // Verifies that if the default search URL preference is managed, we report |
| 1213 // the default search as managed. Also check that we are getting the right | 1228 // the default search as managed. Also check that we are getting the right |
| 1214 // values. | 1229 // values. |
| 1215 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1230 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
| 1216 test_util()->VerifyLoad(); | 1231 test_util()->VerifyLoad(); |
| 1217 const size_t initial_count = model()->GetTemplateURLs().size(); | 1232 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 1218 test_util()->ResetObserverCount(); | 1233 test_util()->ResetObserverCount(); |
| 1219 | 1234 |
| 1220 // Set a regular default search provider. | 1235 // Set a regular default search provider. |
| 1221 TemplateURL* regular_default = AddKeywordWithDate( | 1236 TemplateURL* regular_default = |
| 1222 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 1237 AddKeywordWithDate("name1", "key1", "http://foo1/{searchTerms}", |
| 1223 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 1238 "http://sugg1", std::string(), "http://icon1", true, |
| 1239 "UTF-8;UTF-16", Time(), Time(), Time()); |
| 1224 VerifyObserverCount(1); | 1240 VerifyObserverCount(1); |
| 1225 model()->SetUserSelectedDefaultSearchProvider(regular_default); | 1241 model()->SetUserSelectedDefaultSearchProvider(regular_default); |
| 1226 // Adding the URL and setting the default search provider should have caused | 1242 // Adding the URL and setting the default search provider should have caused |
| 1227 // notifications. | 1243 // notifications. |
| 1228 VerifyObserverCount(1); | 1244 VerifyObserverCount(1); |
| 1229 EXPECT_FALSE(model()->is_default_search_managed()); | 1245 EXPECT_FALSE(model()->is_default_search_managed()); |
| 1230 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1246 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1231 | 1247 |
| 1232 // Set a managed preference that establishes a default search provider. | 1248 // Set a managed preference that establishes a default search provider. |
| 1233 const char kName[] = "test1"; | 1249 const char kName[] = "test1"; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1423 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1408 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1424 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1409 ASSERT_FALSE(loaded_url == NULL); | 1425 ASSERT_FALSE(loaded_url == NULL); |
| 1410 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1426 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
| 1411 } | 1427 } |
| 1412 | 1428 |
| 1413 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { | 1429 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { |
| 1414 test_util()->VerifyLoad(); | 1430 test_util()->VerifyLoad(); |
| 1415 // Add third-party default search engine. | 1431 // Add third-party default search engine. |
| 1416 TemplateURL* user_dse = AddKeywordWithDate( | 1432 TemplateURL* user_dse = AddKeywordWithDate( |
| 1417 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1433 "user", "user", "http://www.goo.com/s?q={searchTerms}", std::string(), |
| 1418 std::string(), std::string(), std::string(), | 1434 std::string(), std::string(), true, "UTF-8", Time(), Time(), Time()); |
| 1419 true, "UTF-8", Time(), Time()); | |
| 1420 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1435 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1421 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1436 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1422 | 1437 |
| 1423 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1438 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1424 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1439 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
| 1425 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1440 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
| 1426 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1441 "UTF-8", Time(), Time(), Time(), |
| 1442 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1427 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1443 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1428 new TemplateURL::AssociatedExtensionInfo("ext")); | 1444 new TemplateURL::AssociatedExtensionInfo("ext")); |
| 1429 extension_info->wants_to_be_default_engine = true; | 1445 extension_info->wants_to_be_default_engine = true; |
| 1430 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1446 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1431 std::move(ext_dse), std::move(extension_info)); | 1447 std::move(ext_dse), std::move(extension_info)); |
| 1432 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1448 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
| 1433 | 1449 |
| 1434 model()->RemoveExtensionControlledTURL( | 1450 model()->RemoveExtensionControlledTURL( |
| 1435 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1451 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1436 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1452 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1437 } | 1453 } |
| 1438 | 1454 |
| 1439 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1455 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
| 1440 test_util()->VerifyLoad(); | 1456 test_util()->VerifyLoad(); |
| 1441 // Add third-party default search engine. | 1457 // Add third-party default search engine. |
| 1442 TemplateURL* user_dse = AddKeywordWithDate( | 1458 TemplateURL* user_dse = AddKeywordWithDate( |
| 1443 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1459 "user", "user", "http://www.goo.com/s?q={searchTerms}", std::string(), |
| 1444 std::string(), std::string(), std::string(), | 1460 std::string(), std::string(), true, "UTF-8", Time(), Time(), Time()); |
| 1445 true, "UTF-8", Time(), Time()); | |
| 1446 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1461 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1447 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1462 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1448 | 1463 |
| 1449 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1464 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1450 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1465 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1451 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), | 1466 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), |
| 1452 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1467 Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1453 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1468 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1454 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1469 new TemplateURL::AssociatedExtensionInfo("ext1")); |
| 1455 extension_info->wants_to_be_default_engine = false; | 1470 extension_info->wants_to_be_default_engine = false; |
| 1456 model()->AddExtensionControlledTURL(std::move(ext_dse), | 1471 model()->AddExtensionControlledTURL(std::move(ext_dse), |
| 1457 std::move(extension_info)); | 1472 std::move(extension_info)); |
| 1458 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1473 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1459 | 1474 |
| 1460 ext_dse = CreateKeywordWithDate( | 1475 ext_dse = CreateKeywordWithDate( |
| 1461 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", | 1476 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", |
| 1462 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1477 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
| 1463 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1478 "UTF-8", Time(), Time(), Time(), |
| 1479 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1464 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); | 1480 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); |
| 1465 extension_info->wants_to_be_default_engine = true; | 1481 extension_info->wants_to_be_default_engine = true; |
| 1466 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1482 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1467 std::move(ext_dse), std::move(extension_info)); | 1483 std::move(ext_dse), std::move(extension_info)); |
| 1468 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1484 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
| 1469 | 1485 |
| 1470 test_util()->ResetModel(true); | 1486 test_util()->ResetModel(true); |
| 1471 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1487 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
| 1472 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1488 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1473 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1489 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1499 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 1515 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
| 1500 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); | 1516 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); |
| 1501 EXPECT_TRUE(model()->is_default_search_managed()); | 1517 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1502 const TemplateURL* actual_managed_default = | 1518 const TemplateURL* actual_managed_default = |
| 1503 model()->GetDefaultSearchProvider(); | 1519 model()->GetDefaultSearchProvider(); |
| 1504 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1520 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1505 | 1521 |
| 1506 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1522 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1507 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1523 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1508 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1524 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
| 1509 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1525 "UTF-8", Time(), Time(), Time(), |
| 1526 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1510 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1527 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1511 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1528 new TemplateURL::AssociatedExtensionInfo("ext1")); |
| 1512 extension_info->wants_to_be_default_engine = true; | 1529 extension_info->wants_to_be_default_engine = true; |
| 1513 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1530 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1514 std::move(ext_dse), std::move(extension_info)); | 1531 std::move(ext_dse), std::move(extension_info)); |
| 1515 EXPECT_EQ(ext_dse_ptr, | 1532 EXPECT_EQ(ext_dse_ptr, |
| 1516 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1533 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1517 EXPECT_TRUE(model()->is_default_search_managed()); | 1534 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1518 actual_managed_default = model()->GetDefaultSearchProvider(); | 1535 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 1519 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1536 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1520 } | 1537 } |
| 1538 |
| 1539 TEST_F(TemplateURLServiceTest, LastVisitedTimeUpdate) { |
| 1540 test_util()->VerifyLoad(); |
| 1541 TemplateURL* original_url = AddKeywordWithDate( |
| 1542 "name1", "key1", "http://foo1", "http://suggest1", std::string(), |
| 1543 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
| 1544 const base::Time original_last_visited = original_url->last_visited(); |
| 1545 model()->UpdateTemplateURLVisitTime(original_url); |
| 1546 TemplateURL* modified_url = |
| 1547 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 1548 const base::Time modified_last_visited = modified_url->last_visited(); |
| 1549 EXPECT_NE(original_last_visited, modified_last_visited); |
| 1550 test_util()->ResetModel(true); |
| 1551 TemplateURL* reloaded_url = |
| 1552 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 1553 AssertTimesEqual(modified_last_visited, reloaded_url->last_visited()); |
| 1554 } |
| OLD | NEW |