Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 TemplateURLService::GenerateKeyword(GURL("https://blah"), true)); | 468 TemplateURLService::GenerateKeyword(GURL("https://blah"), true)); |
| 469 ASSERT_EQ(ASCIIToUTF16("foo"), | 469 ASSERT_EQ(ASCIIToUTF16("foo"), |
| 470 TemplateURLService::GenerateKeyword(GURL("http://foo"), true)); | 470 TemplateURLService::GenerateKeyword(GURL("http://foo"), true)); |
| 471 // www. should be stripped. | 471 // www. should be stripped. |
| 472 ASSERT_EQ(ASCIIToUTF16("foo"), | 472 ASSERT_EQ(ASCIIToUTF16("foo"), |
| 473 TemplateURLService::GenerateKeyword(GURL("http://www.foo"), true)); | 473 TemplateURLService::GenerateKeyword(GURL("http://www.foo"), true)); |
| 474 // Shouldn't generate keywords with paths, if autodetected. | 474 // Shouldn't generate keywords with paths, if autodetected. |
| 475 ASSERT_EQ(string16(), | 475 ASSERT_EQ(string16(), |
| 476 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), true)); | 476 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), true)); |
| 477 ASSERT_EQ(ASCIIToUTF16("blah"), | 477 ASSERT_EQ(ASCIIToUTF16("blah"), |
| 478 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), false)) ; | 478 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), false)) ; |
|
Peter Kasting
2012/02/16 18:16:35
Nit: While here, this line is >80 cols
Use mkwst_at_chromium.org plz.
2012/02/17 10:12:36
Done.
| |
| 479 // FTP shouldn't generate a keyword. | 479 // FTP shouldn't generate a keyword. |
| 480 ASSERT_EQ(string16(), | 480 ASSERT_EQ(string16(), |
| 481 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true)); | 481 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true)); |
| 482 // Make sure we don't get a trailing / | 482 // Make sure we don't get a trailing / |
| 483 ASSERT_EQ(ASCIIToUTF16("blah"), | 483 ASSERT_EQ(ASCIIToUTF16("blah"), |
| 484 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true)); | 484 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true)); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | 487 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { |
| 488 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 488 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 499 new TestGenerateSearchURL(&search_terms_data)); | 499 new TestGenerateSearchURL(&search_terms_data)); |
| 500 | 500 |
| 501 test_util_.StartIOThread(); | 501 test_util_.StartIOThread(); |
| 502 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | 502 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( |
| 503 FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest, | 503 FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest, |
| 504 test_generate_search_url.get())); | 504 test_generate_search_url.get())); |
| 505 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 505 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
| 506 EXPECT_TRUE(test_generate_search_url->passed()); | 506 EXPECT_TRUE(test_generate_search_url->passed()); |
| 507 } | 507 } |
| 508 | 508 |
| 509 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 509 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
|
Peter Kasting
2012/02/16 18:16:35
While here, can you also add a test for the 2-arg
Use mkwst_at_chromium.org plz.
2012/02/17 10:12:36
Done.
| |
| 510 Time now = Time::Now(); | 510 Time now = Time::Now(); |
| 511 TimeDelta one_day = TimeDelta::FromDays(1); | 511 TimeDelta one_day = TimeDelta::FromDays(1); |
| 512 Time month_ago = now - TimeDelta::FromDays(30); | 512 Time month_ago = now - TimeDelta::FromDays(30); |
| 513 | 513 |
| 514 // Nothing has been added. | 514 // Nothing has been added. |
| 515 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 515 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 516 | 516 |
| 517 // Create one with a 0 time. | 517 // Create one with a 0 time. |
| 518 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", | 518 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", |
| 519 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), | 519 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); | 561 EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); |
| 562 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); | 562 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); |
| 563 EXPECT_EQ(month_ago.ToInternalValue(), | 563 EXPECT_EQ(month_ago.ToInternalValue(), |
| 564 model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); | 564 model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); |
| 565 | 565 |
| 566 // Try removing from Time=0. This should delete one more. | 566 // Try removing from Time=0. This should delete one more. |
| 567 model()->RemoveAutoGeneratedSince(Time()); | 567 model()->RemoveAutoGeneratedSince(Time()); |
| 568 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); | 568 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); |
| 569 } | 569 } |
| 570 | 570 |
| 571 TEST_F(TemplateURLServiceTest, ClearBrowsingData_KeywordsForOrigin) { | |
|
Peter Kasting
2012/02/16 18:16:35
Nit: It might be nice to expand this test to have
Use mkwst_at_chromium.org plz.
2012/02/17 10:12:36
Done.
| |
| 572 Time now = Time::Now(); | |
| 573 TimeDelta one_day = TimeDelta::FromDays(1); | |
| 574 Time month_ago = now - TimeDelta::FromDays(30); | |
| 575 | |
| 576 // Nothing has been added. | |
| 577 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | |
| 578 | |
| 579 // Create one for now and +/- 1 day. | |
| 580 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", | |
| 581 "http://icon2", "UTF-8;UTF-16", "name2", true, | |
| 582 now - one_day, Time()); | |
| 583 AddKeywordWithDate("key2", false, "http://foo2", "", "", "", "name2", | |
| 584 true, now, Time()); | |
| 585 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", | |
| 586 true, now + one_day, Time()); | |
| 587 | |
| 588 // We just added a few items, validate them. | |
| 589 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | |
| 590 | |
| 591 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. | |
| 592 model()->RemoveAutoGeneratedForOriginBetween(month_ago, now + one_day, | |
| 593 GURL("http://foo2")); | |
| 594 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); | |
| 595 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); | |
| 596 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | |
| 597 | |
| 598 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword()); | |
| 599 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); | |
| 600 | |
| 601 // Try removing foo1. This should delete foo1, but leave foo3 untouched. | |
| 602 model()->RemoveAutoGeneratedForOriginBetween(month_ago, now + one_day, | |
| 603 GURL("http://foo1")); | |
| 604 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | |
| 605 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[0]->keyword()); | |
| 606 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | |
| 607 } | |
| 608 | |
| 571 TEST_F(TemplateURLServiceTest, Reset) { | 609 TEST_F(TemplateURLServiceTest, Reset) { |
| 572 // Add a new TemplateURL. | 610 // Add a new TemplateURL. |
| 573 VerifyLoad(); | 611 VerifyLoad(); |
| 574 const size_t initial_count = model()->GetTemplateURLs().size(); | 612 const size_t initial_count = model()->GetTemplateURLs().size(); |
| 575 TemplateURL* t_url = new TemplateURL(); | 613 TemplateURL* t_url = new TemplateURL(); |
| 576 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); | 614 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); |
| 577 t_url->set_keyword(ASCIIToUTF16("keyword")); | 615 t_url->set_keyword(ASCIIToUTF16("keyword")); |
| 578 t_url->set_short_name(ASCIIToUTF16("google")); | 616 t_url->set_short_name(ASCIIToUTF16("google")); |
| 579 GURL favicon_url("http://favicon.url"); | 617 GURL favicon_url("http://favicon.url"); |
| 580 t_url->SetFaviconURL(favicon_url); | 618 t_url->SetFaviconURL(favicon_url); |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1268 | 1306 |
| 1269 // Reload the model to verify it was actually saved to the database and | 1307 // Reload the model to verify it was actually saved to the database and |
| 1270 // assigned a new GUID when brought back. | 1308 // assigned a new GUID when brought back. |
| 1271 ResetModel(true); | 1309 ResetModel(true); |
| 1272 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); | 1310 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); |
| 1273 const TemplateURL* loaded_url = | 1311 const TemplateURL* loaded_url = |
| 1274 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1312 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1275 ASSERT_TRUE(loaded_url != NULL); | 1313 ASSERT_TRUE(loaded_url != NULL); |
| 1276 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1314 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
| 1277 } | 1315 } |
| OLD | NEW |