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

Unified Diff: chrome/browser/search_engines/template_url_service_unittest.cc

Issue 9379008: Add origin-based deletion to BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's feedback. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/template_url_service_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index 69ced91afaf2e84640a9ce3c355b33ff505e7036..195ebe5b994a281a6ce1b559c6dc3ab8ce7f143b 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -475,7 +475,8 @@ TEST_F(TemplateURLServiceTest, GenerateKeyword) {
ASSERT_EQ(string16(),
TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), true));
ASSERT_EQ(ASCIIToUTF16("blah"),
- TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), false));
+ TemplateURLService::GenerateKeyword(GURL("http://blah/foo"),
+ false));
// FTP shouldn't generate a keyword.
ASSERT_EQ(string16(),
TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true));
@@ -544,7 +545,7 @@ TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
// Try removing from two months ago. This should only delete items that are
// auto-generated.
- model()->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60));
+ model()->RemoveAutoGeneratedBetween(now - TimeDelta::FromDays(60), now);
EXPECT_EQ(3U, model()->GetTemplateURLs().size());
// Make sure the right values remain.
@@ -568,6 +569,54 @@ TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
EXPECT_EQ(2U, model()->GetTemplateURLs().size());
}
+TEST_F(TemplateURLServiceTest, ClearBrowsingData_KeywordsForOrigin) {
+ Time now = Time::Now();
+ TimeDelta one_day = TimeDelta::FromDays(1);
+ Time month_ago = now - TimeDelta::FromDays(30);
+
+ // Nothing has been added.
+ EXPECT_EQ(0U, model()->GetTemplateURLs().size());
+
+ // Create one for now and +/- 1 day.
+ AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1",
+ "http://icon2", "UTF-8;UTF-16", "name2", true,
+ now - one_day, Time());
+ AddKeywordWithDate("key2", false, "http://foo2", "", "", "", "name2",
+ true, now, Time());
+ AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3",
+ true, now + one_day, Time());
+
+ // We just added a few items, validate them.
+ EXPECT_EQ(3U, model()->GetTemplateURLs().size());
+
+ // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched.
+ model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo2"), month_ago,
+ now + one_day);
+ EXPECT_EQ(2U, model()->GetTemplateURLs().size());
+ EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
+ EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
+ EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword());
+ EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace());
+
+ // Try removing foo1, but outside the range in which it was modified. It
+ // should remain untouched.
+ model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo1"), now,
+ now + one_day);
+ EXPECT_EQ(2U, model()->GetTemplateURLs().size());
+ EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
+ EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
+ EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword());
+ EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace());
+
+
+ // Try removing foo3. This should delete foo3, but leave foo1 untouched.
+ model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo3"), month_ago,
+ now + one_day + one_day);
+ EXPECT_EQ(1U, model()->GetTemplateURLs().size());
+ EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
+ EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
+}
+
TEST_F(TemplateURLServiceTest, Reset) {
// Add a new TemplateURL.
VerifyLoad();
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698