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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover_unittest.cc

Issue 238863005: Domain Reliability: Remove browsing data when requested. (Closed) Base URL: http://git.chromium.org/chromium/src.git@domrel_bakedin
Patch Set: ...and fix BrowsingDataRemoverTet Created 6 years, 7 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
OLDNEW
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 "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 25 matching lines...) Expand all
36 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
37 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
38 #include "chromeos/dbus/fake_dbus_thread_manager.h" 38 #include "chromeos/dbus/fake_dbus_thread_manager.h"
39 #include "chromeos/dbus/mock_cryptohome_client.h" 39 #include "chromeos/dbus/mock_cryptohome_client.h"
40 #endif 40 #endif
41 #include "components/autofill/core/browser/autofill_profile.h" 41 #include "components/autofill/core/browser/autofill_profile.h"
42 #include "components/autofill/core/browser/autofill_test_utils.h" 42 #include "components/autofill/core/browser/autofill_test_utils.h"
43 #include "components/autofill/core/browser/credit_card.h" 43 #include "components/autofill/core/browser/credit_card.h"
44 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager.h"
45 #include "components/autofill/core/browser/personal_data_manager_observer.h" 45 #include "components/autofill/core/browser/personal_data_manager_observer.h"
46 #include "components/domain_reliability/clear_mode.h"
47 #include "components/domain_reliability/monitor.h"
46 #include "content/public/browser/cookie_store_factory.h" 48 #include "content/public/browser/cookie_store_factory.h"
47 #include "content/public/browser/dom_storage_context.h" 49 #include "content/public/browser/dom_storage_context.h"
48 #include "content/public/browser/local_storage_usage_info.h" 50 #include "content/public/browser/local_storage_usage_info.h"
49 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/storage_partition.h" 52 #include "content/public/browser/storage_partition.h"
51 #include "content/public/test/test_browser_thread.h" 53 #include "content/public/test/test_browser_thread.h"
52 #include "content/public/test/test_browser_thread_bundle.h" 54 #include "content/public/test/test_browser_thread_bundle.h"
53 #include "content/public/test/test_utils.h" 55 #include "content/public/test/test_utils.h"
54 #include "net/cookies/cookie_store.h" 56 #include "net/cookies/cookie_store.h"
55 #include "net/ssl/server_bound_cert_service.h" 57 #include "net/ssl/server_bound_cert_service.h"
56 #include "net/ssl/server_bound_cert_store.h" 58 #include "net/ssl/server_bound_cert_store.h"
57 #include "net/ssl/ssl_client_cert_type.h" 59 #include "net/ssl/ssl_client_cert_type.h"
58 #include "net/url_request/url_request_context.h" 60 #include "net/url_request/url_request_context.h"
59 #include "net/url_request/url_request_context_getter.h" 61 #include "net/url_request/url_request_context_getter.h"
60 #include "testing/gmock/include/gmock/gmock.h" 62 #include "testing/gmock/include/gmock/gmock.h"
61 #include "testing/gtest/include/gtest/gtest.h" 63 #include "testing/gtest/include/gtest/gtest.h"
62 64
63 using content::BrowserThread; 65 using content::BrowserThread;
64 using content::StoragePartition; 66 using content::StoragePartition;
67 using domain_reliability::CLEAR_BEACONS;
68 using domain_reliability::CLEAR_CONTEXTS;
69 using domain_reliability::DomainReliabilityClearMode;
70 using domain_reliability::DomainReliabilityMonitor;
65 using testing::_; 71 using testing::_;
66 using testing::Invoke; 72 using testing::Invoke;
67 using testing::WithArgs; 73 using testing::WithArgs;
68 74
69 namespace { 75 namespace {
70 76
71 const char kTestOrigin1[] = "http://host1:1/"; 77 const char kTestOrigin1[] = "http://host1:1/";
72 const char kTestOrigin2[] = "http://host2:1/"; 78 const char kTestOrigin2[] = "http://host2:1/";
73 const char kTestOrigin3[] = "http://host3:1/"; 79 const char kTestOrigin3[] = "http://host3:1/";
74 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 80 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // We don't own these pointers. 573 // We don't own these pointers.
568 TestingProfile* profile_; 574 TestingProfile* profile_;
569 content::DOMStorageContext* dom_storage_context_; 575 content::DOMStorageContext* dom_storage_context_;
570 576
571 std::vector<content::LocalStorageUsageInfo> infos_; 577 std::vector<content::LocalStorageUsageInfo> infos_;
572 base::Closure quit_closure_; 578 base::Closure quit_closure_;
573 579
574 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 580 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
575 }; 581 };
576 582
583 class TestingProfileWithDomainReliabilityMonitor : public TestingProfile {
584 public:
585 TestingProfileWithDomainReliabilityMonitor() :
586 TestingProfile(),
587 upload_reporter_string_("test-reporter"),
588 monitor_(GetRequestContext()->GetURLRequestContext(),
589 upload_reporter_string_) {}
590
591 virtual void ClearDomainReliabilityMonitor(
592 DomainReliabilityClearMode mode,
593 const base::Closure& completion) OVERRIDE {
594 monitor_.ClearBrowsingData(mode);
595 completion.Run();
596 }
597
598 DomainReliabilityMonitor* monitor() { return &monitor_; }
599
600 private:
601 std::string upload_reporter_string_;
602 DomainReliabilityMonitor monitor_;
603 };
604
577 // Test Class ---------------------------------------------------------------- 605 // Test Class ----------------------------------------------------------------
578 606
579 class BrowsingDataRemoverTest : public testing::Test, 607 class BrowsingDataRemoverTest : public testing::Test,
580 public content::NotificationObserver { 608 public content::NotificationObserver {
581 public: 609 public:
582 BrowsingDataRemoverTest() 610 BrowsingDataRemoverTest()
583 : profile_(new TestingProfile()) { 611 : profile_(new TestingProfile()) {
584 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, 612 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
585 content::Source<Profile>(profile_.get())); 613 content::Source<Profile>(profile_.get()));
586 } 614 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 700
673 // We're not taking ownership of the details object, but storing a copy of 701 // We're not taking ownership of the details object, but storing a copy of
674 // it locally. 702 // it locally.
675 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( 703 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
676 *content::Details<BrowsingDataRemover::NotificationDetails>( 704 *content::Details<BrowsingDataRemover::NotificationDetails>(
677 details).ptr())); 705 details).ptr()));
678 706
679 registrar_.RemoveAll(); 707 registrar_.RemoveAll();
680 } 708 }
681 709
710 DomainReliabilityMonitor *UseProfileWithDomainReliabilityMonitor() {
711 TestingProfileWithDomainReliabilityMonitor* new_profile =
712 new TestingProfileWithDomainReliabilityMonitor();
713 DomainReliabilityMonitor* monitor = new_profile->monitor();
714 profile_.reset(new_profile);
715 return monitor;
716 }
717
682 protected: 718 protected:
683 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 719 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
684 720
685 private: 721 private:
686 content::NotificationRegistrar registrar_; 722 content::NotificationRegistrar registrar_;
687 723
688 content::TestBrowserThreadBundle thread_bundle_; 724 content::TestBrowserThreadBundle thread_bundle_;
689 scoped_ptr<TestingProfile> profile_; 725 scoped_ptr<TestingProfile> profile_;
690 726
691 StoragePartitionRemovalData storage_partition_removal_data_; 727 StoragePartitionRemovalData storage_partition_removal_data_;
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _)) 1647 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1612 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall))); 1648 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1613 1649
1614 BlockUntilBrowsingDataRemoved( 1650 BlockUntilBrowsingDataRemoved(
1615 BrowsingDataRemover::EVERYTHING, 1651 BrowsingDataRemover::EVERYTHING,
1616 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false); 1652 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1617 1653
1618 chromeos::DBusThreadManager::Shutdown(); 1654 chromeos::DBusThreadManager::Shutdown();
1619 } 1655 }
1620 #endif 1656 #endif
1657
1658 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
1659 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1660 EXPECT_FALSE(monitor->was_cleared_for_testing());
1661 }
1662
1663 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
1664 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1665 BlockUntilBrowsingDataRemoved(
1666 BrowsingDataRemover::EVERYTHING,
1667 BrowsingDataRemover::REMOVE_HISTORY, false);
1668 EXPECT_TRUE(monitor->was_cleared_for_testing());
1669 EXPECT_EQ(CLEAR_BEACONS, monitor->cleared_mode_for_testing());
1670 }
1671
1672 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_ProtectedOrigins) {
1673 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1674 BlockUntilBrowsingDataRemoved(
1675 BrowsingDataRemover::EVERYTHING,
1676 BrowsingDataRemover::REMOVE_HISTORY, true);
1677 EXPECT_TRUE(monitor->was_cleared_for_testing());
1678 EXPECT_EQ(CLEAR_BEACONS, monitor->cleared_mode_for_testing());
1679 }
1680
1681 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
1682 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1683 BlockUntilBrowsingDataRemoved(
1684 BrowsingDataRemover::EVERYTHING,
1685 BrowsingDataRemover::REMOVE_COOKIES, false);
1686 EXPECT_TRUE(monitor->was_cleared_for_testing());
1687 EXPECT_EQ(CLEAR_CONTEXTS, monitor->cleared_mode_for_testing());
1688 }
1689
1690 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_ProtectedOrigins) {
1691 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1692 BlockUntilBrowsingDataRemoved(
1693 BrowsingDataRemover::EVERYTHING,
1694 BrowsingDataRemover::REMOVE_COOKIES, true);
1695 EXPECT_TRUE(monitor->was_cleared_for_testing());
1696 EXPECT_EQ(CLEAR_CONTEXTS, monitor->cleared_mode_for_testing());
1697 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.cc ('k') | chrome/browser/profiles/off_the_record_profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698