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 549 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) { |
| 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 |