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

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

Issue 2097043002: Clear HTTP auth data on clearing browsing data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor unit tests fixes Created 4 years, 4 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "content/public/browser/browser_context.h" 71 #include "content/public/browser/browser_context.h"
72 #include "content/public/browser/cookie_store_factory.h" 72 #include "content/public/browser/cookie_store_factory.h"
73 #include "content/public/browser/dom_storage_context.h" 73 #include "content/public/browser/dom_storage_context.h"
74 #include "content/public/browser/local_storage_usage_info.h" 74 #include "content/public/browser/local_storage_usage_info.h"
75 #include "content/public/browser/storage_partition.h" 75 #include "content/public/browser/storage_partition.h"
76 #include "content/public/test/mock_download_manager.h" 76 #include "content/public/test/mock_download_manager.h"
77 #include "content/public/test/test_browser_thread.h" 77 #include "content/public/test/test_browser_thread.h"
78 #include "content/public/test/test_browser_thread_bundle.h" 78 #include "content/public/test/test_browser_thread_bundle.h"
79 #include "content/public/test/test_utils.h" 79 #include "content/public/test/test_utils.h"
80 #include "net/cookies/cookie_store.h" 80 #include "net/cookies/cookie_store.h"
81 #include "net/http/http_network_session.h"
82 #include "net/http/http_transaction_factory.h"
81 #include "net/ssl/channel_id_service.h" 83 #include "net/ssl/channel_id_service.h"
82 #include "net/ssl/channel_id_store.h" 84 #include "net/ssl/channel_id_store.h"
83 #include "net/ssl/ssl_client_cert_type.h" 85 #include "net/ssl/ssl_client_cert_type.h"
84 #include "net/url_request/url_request_context.h" 86 #include "net/url_request/url_request_context.h"
85 #include "net/url_request/url_request_context_getter.h" 87 #include "net/url_request/url_request_context_getter.h"
86 #include "testing/gmock/include/gmock/gmock.h" 88 #include "testing/gmock/include/gmock/gmock.h"
87 #include "testing/gtest/include/gtest/gtest.h" 89 #include "testing/gtest/include/gtest/gtest.h"
88 #include "third_party/skia/include/core/SkBitmap.h" 90 #include "third_party/skia/include/core/SkBitmap.h"
89 #include "ui/gfx/favicon_size.h" 91 #include "ui/gfx/favicon_size.h"
90 #include "url/origin.h" 92 #include "url/origin.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const char kTestOrigin2[] = "http://host2.com:1/"; 136 const char kTestOrigin2[] = "http://host2.com:1/";
135 const char kTestOrigin3[] = "http://host3.com:1/"; 137 const char kTestOrigin3[] = "http://host3.com:1/";
136 const char kTestRegisterableDomain3[] = "host3.com"; 138 const char kTestRegisterableDomain3[] = "host3.com";
137 const char kTestOrigin4[] = "https://host3.com:1/"; 139 const char kTestOrigin4[] = "https://host3.com:1/";
138 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 140 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
139 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; 141 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
140 142
141 // For Autofill. 143 // For Autofill.
142 const char kWebOrigin[] = "https://www.example.com/"; 144 const char kWebOrigin[] = "https://www.example.com/";
143 145
146 // For HTTP auth.
147 const char kTestRealm[] = "TestRealm";
148
144 const GURL kOrigin1(kTestOrigin1); 149 const GURL kOrigin1(kTestOrigin1);
145 const GURL kOrigin2(kTestOrigin2); 150 const GURL kOrigin2(kTestOrigin2);
146 const GURL kOrigin3(kTestOrigin3); 151 const GURL kOrigin3(kTestOrigin3);
147 const GURL kOrigin4(kTestOrigin4); 152 const GURL kOrigin4(kTestOrigin4);
148 const GURL kOriginExt(kTestOriginExt); 153 const GURL kOriginExt(kTestOriginExt);
149 const GURL kOriginDevTools(kTestOriginDevTools); 154 const GURL kOriginDevTools(kTestOriginDevTools);
150 155
151 const base::FilePath::CharType kDomStorageOrigin1[] = 156 const base::FilePath::CharType kDomStorageOrigin1[] =
152 FILE_PATH_LITERAL("http_host1_1.localstorage"); 157 FILE_PATH_LITERAL("http_host1_1.localstorage");
153 158
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // We don't own these pointers. 842 // We don't own these pointers.
838 TestingProfile* profile_; 843 TestingProfile* profile_;
839 content::DOMStorageContext* dom_storage_context_ = nullptr; 844 content::DOMStorageContext* dom_storage_context_ = nullptr;
840 845
841 std::vector<content::LocalStorageUsageInfo> infos_; 846 std::vector<content::LocalStorageUsageInfo> infos_;
842 base::Closure quit_closure_; 847 base::Closure quit_closure_;
843 848
844 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 849 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
845 }; 850 };
846 851
852 class ClearHttpAuthDataTester {
mmenke 2016/08/09 14:40:20 Think this makes the tests needlessly obscure. Lo
Tomasz Moniuszko 2016/08/25 10:32:59 Done. I inlined the code.
853 public:
854 explicit ClearHttpAuthDataTester(TestingProfile* profile) {
855 net::HttpNetworkSession* http_session = profile->GetRequestContext()
856 ->GetURLRequestContext()
857 ->http_transaction_factory()
858 ->GetSession();
859 DCHECK(http_session);
860 http_auth_cache_ = http_session->http_auth_cache();
861
862 http_auth_cache_->Add(kOrigin1, kTestRealm,
863 net::HttpAuth::AUTH_SCHEME_BASIC, "test challenge",
864 net::AuthCredentials(base::ASCIIToUTF16("foo"),
865 base::ASCIIToUTF16("bar")),
866 "/");
867 CHECK(http_auth_cache_->Lookup(kOrigin1, kTestRealm,
868 net::HttpAuth::AUTH_SCHEME_BASIC));
869 }
870
871 ~ClearHttpAuthDataTester() {
872 EXPECT_EQ(nullptr,
873 http_auth_cache_->Lookup(kOrigin1, kTestRealm,
874 net::HttpAuth::AUTH_SCHEME_BASIC));
875 }
876
877 private:
878 net::HttpAuthCache* http_auth_cache_;
879
880 DISALLOW_COPY_AND_ASSIGN(ClearHttpAuthDataTester);
881 };
882
847 class MockDomainReliabilityService : public DomainReliabilityService { 883 class MockDomainReliabilityService : public DomainReliabilityService {
848 public: 884 public:
849 MockDomainReliabilityService() {} 885 MockDomainReliabilityService() {}
850 886
851 ~MockDomainReliabilityService() override {} 887 ~MockDomainReliabilityService() override {}
852 888
853 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor( 889 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor(
854 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) 890 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
855 override { 891 override {
856 NOTREACHED(); 892 NOTREACHED();
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 2628 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
2593 base::Bind(&MatchPrimaryPattern, http_pattern)); 2629 base::Bind(&MatchPrimaryPattern, http_pattern));
2594 // Verify we only have one, and it's url1. 2630 // Verify we only have one, and it's url1.
2595 host_content_settings_map->GetSettingsForOneType( 2631 host_content_settings_map->GetSettingsForOneType(
2596 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); 2632 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
2597 EXPECT_EQ(1u, host_settings.size()); 2633 EXPECT_EQ(1u, host_settings.size());
2598 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 2634 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
2599 host_settings[0].primary_pattern); 2635 host_settings[0].primary_pattern);
2600 } 2636 }
2601 2637
2638 // Test that removing cookies clears HTTP auth data.
2639 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemoveCookies) {
2640 ClearHttpAuthDataTester tester(GetProfile());
2641
2642 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME,
2643 BrowsingDataRemover::REMOVE_COOKIES, false);
2644 }
2645
2646 // Test that removing passwords clears HTTP auth data.
2647 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemovePasswords) {
2648 ClearHttpAuthDataTester tester(GetProfile());
2649
2650 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME,
2651 BrowsingDataRemover::REMOVE_PASSWORDS, false);
2652 }
2653
2602 class MultipleTasksObserver { 2654 class MultipleTasksObserver {
2603 public: 2655 public:
2604 // A simple implementation of BrowsingDataRemover::Observer. 2656 // A simple implementation of BrowsingDataRemover::Observer.
2605 // MultipleTasksObserver will use several instances of Target to test 2657 // MultipleTasksObserver will use several instances of Target to test
2606 // that completion callbacks are returned to the correct one. 2658 // that completion callbacks are returned to the correct one.
2607 class Target : public BrowsingDataRemover::Observer { 2659 class Target : public BrowsingDataRemover::Observer {
2608 public: 2660 public:
2609 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) 2661 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
2610 : parent_(parent), 2662 : parent_(parent),
2611 observer_(this) { 2663 observer_(this) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 EXPECT_TRUE(remover->is_removing()); 2839 EXPECT_TRUE(remover->is_removing());
2788 2840
2789 // Add one more deletion and wait for it. 2841 // Add one more deletion and wait for it.
2790 BlockUntilBrowsingDataRemoved( 2842 BlockUntilBrowsingDataRemoved(
2791 browsing_data::ALL_TIME, 2843 browsing_data::ALL_TIME,
2792 BrowsingDataRemover::REMOVE_COOKIES, 2844 BrowsingDataRemover::REMOVE_COOKIES,
2793 BrowsingDataHelper::UNPROTECTED_WEB); 2845 BrowsingDataHelper::UNPROTECTED_WEB);
2794 2846
2795 EXPECT_FALSE(remover->is_removing()); 2847 EXPECT_FALSE(remover->is_removing());
2796 } 2848 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698