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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"),
479 false));
479 // FTP shouldn't generate a keyword. 480 // FTP shouldn't generate a keyword.
480 ASSERT_EQ(string16(), 481 ASSERT_EQ(string16(),
481 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true)); 482 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true));
482 // Make sure we don't get a trailing / 483 // Make sure we don't get a trailing /
483 ASSERT_EQ(ASCIIToUTF16("blah"), 484 ASSERT_EQ(ASCIIToUTF16("blah"),
484 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true)); 485 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true));
485 } 486 }
486 487
487 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { 488 TEST_F(TemplateURLServiceTest, GenerateSearchURL) {
488 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( 489 scoped_refptr<TestGenerateSearchURL> test_generate_search_url(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // We just added a few items, validate them. 538 // We just added a few items, validate them.
538 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); 539 EXPECT_EQ(6U, model()->GetTemplateURLs().size());
539 540
540 // Try removing from current timestamp. This should delete the one in the 541 // Try removing from current timestamp. This should delete the one in the
541 // future and one very recent one. 542 // future and one very recent one.
542 model()->RemoveAutoGeneratedSince(now); 543 model()->RemoveAutoGeneratedSince(now);
543 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); 544 EXPECT_EQ(4U, model()->GetTemplateURLs().size());
544 545
545 // Try removing from two months ago. This should only delete items that are 546 // Try removing from two months ago. This should only delete items that are
546 // auto-generated. 547 // auto-generated.
547 model()->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); 548 model()->RemoveAutoGeneratedBetween(now - TimeDelta::FromDays(60), now);
548 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); 549 EXPECT_EQ(3U, model()->GetTemplateURLs().size());
549 550
550 // Make sure the right values remain. 551 // Make sure the right values remain.
551 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); 552 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
552 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); 553 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
553 EXPECT_EQ(0U, 554 EXPECT_EQ(0U,
554 model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); 555 model()->GetTemplateURLs()[0]->date_created().ToInternalValue());
555 556
556 EXPECT_EQ(ASCIIToUTF16("key5"), model()->GetTemplateURLs()[1]->keyword()); 557 EXPECT_EQ(ASCIIToUTF16("key5"), model()->GetTemplateURLs()[1]->keyword());
557 EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); 558 EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace());
558 EXPECT_EQ(now.ToInternalValue(), 559 EXPECT_EQ(now.ToInternalValue(),
559 model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); 560 model()->GetTemplateURLs()[1]->date_created().ToInternalValue());
560 561
561 EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); 562 EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword());
562 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); 563 EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace());
563 EXPECT_EQ(month_ago.ToInternalValue(), 564 EXPECT_EQ(month_ago.ToInternalValue(),
564 model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); 565 model()->GetTemplateURLs()[2]->date_created().ToInternalValue());
565 566
566 // Try removing from Time=0. This should delete one more. 567 // Try removing from Time=0. This should delete one more.
567 model()->RemoveAutoGeneratedSince(Time()); 568 model()->RemoveAutoGeneratedSince(Time());
568 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); 569 EXPECT_EQ(2U, model()->GetTemplateURLs().size());
569 } 570 }
570 571
572 TEST_F(TemplateURLServiceTest, ClearBrowsingData_KeywordsForOrigin) {
573 Time now = Time::Now();
574 TimeDelta one_day = TimeDelta::FromDays(1);
575 Time month_ago = now - TimeDelta::FromDays(30);
576
577 // Nothing has been added.
578 EXPECT_EQ(0U, model()->GetTemplateURLs().size());
579
580 // Create one for now and +/- 1 day.
581 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1",
582 "http://icon2", "UTF-8;UTF-16", "name2", true,
583 now - one_day, Time());
584 AddKeywordWithDate("key2", false, "http://foo2", "", "", "", "name2",
585 true, now, Time());
586 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3",
587 true, now + one_day, Time());
588
589 // We just added a few items, validate them.
590 EXPECT_EQ(3U, model()->GetTemplateURLs().size());
591
592 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched.
593 model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo2"), month_ago,
594 now + one_day);
595 EXPECT_EQ(2U, model()->GetTemplateURLs().size());
596 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
597 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
598 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword());
599 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace());
600
601 // Try removing foo1, but outside the range in which it was modified. It
602 // should remain untouched.
603 model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo1"), now,
604 now + one_day);
605 EXPECT_EQ(2U, model()->GetTemplateURLs().size());
606 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
607 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
608 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword());
609 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace());
610
611
612 // Try removing foo3. This should delete foo3, but leave foo1 untouched.
613 model()->RemoveAutoGeneratedForOriginBetween(GURL("http://foo3"), month_ago,
614 now + one_day + one_day);
615 EXPECT_EQ(1U, model()->GetTemplateURLs().size());
616 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword());
617 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace());
618 }
619
571 TEST_F(TemplateURLServiceTest, Reset) { 620 TEST_F(TemplateURLServiceTest, Reset) {
572 // Add a new TemplateURL. 621 // Add a new TemplateURL.
573 VerifyLoad(); 622 VerifyLoad();
574 const size_t initial_count = model()->GetTemplateURLs().size(); 623 const size_t initial_count = model()->GetTemplateURLs().size();
575 TemplateURL* t_url = new TemplateURL(); 624 TemplateURL* t_url = new TemplateURL();
576 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); 625 t_url->SetURL("http://www.google.com/foo/bar", 0, 0);
577 t_url->set_keyword(ASCIIToUTF16("keyword")); 626 t_url->set_keyword(ASCIIToUTF16("keyword"));
578 t_url->set_short_name(ASCIIToUTF16("google")); 627 t_url->set_short_name(ASCIIToUTF16("google"));
579 GURL favicon_url("http://favicon.url"); 628 GURL favicon_url("http://favicon.url");
580 t_url->SetFaviconURL(favicon_url); 629 t_url->SetFaviconURL(favicon_url);
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 1317
1269 // Reload the model to verify it was actually saved to the database and 1318 // Reload the model to verify it was actually saved to the database and
1270 // assigned a new GUID when brought back. 1319 // assigned a new GUID when brought back.
1271 ResetModel(true); 1320 ResetModel(true);
1272 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 1321 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
1273 const TemplateURL* loaded_url = 1322 const TemplateURL* loaded_url =
1274 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1323 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1275 ASSERT_TRUE(loaded_url != NULL); 1324 ASSERT_TRUE(loaded_url != NULL);
1276 ASSERT_FALSE(loaded_url->sync_guid().empty()); 1325 ASSERT_FALSE(loaded_url->sync_guid().empty());
1277 } 1326 }
OLDNEW
« 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