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

Unified Diff: chrome/browser/chrome_content_browser_client_unittest.cc

Issue 2368923003: Support the Clear-Site-Data header on resource requests (Closed)
Patch Set: Addressed comments, formatted. Created 3 years, 6 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
Index: chrome/browser/chrome_content_browser_client_unittest.cc
diff --git a/chrome/browser/chrome_content_browser_client_unittest.cc b/chrome/browser/chrome_content_browser_client_unittest.cc
index 2040adc53097d2bce0bd059650b692b7219256c0..853335e1da52d99d65549f7a735c8e63cfc5100d 100644
--- a/chrome/browser/chrome_content_browser_client_unittest.cc
+++ b/chrome/browser/chrome_content_browser_client_unittest.cc
@@ -20,7 +20,6 @@
#include "build/build_config.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
-#include "chrome/browser/browsing_data/mock_browsing_data_remover_delegate.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
@@ -343,241 +342,3 @@ TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) {
} // namespace content
#endif // !defined(OS_ANDROID)
-
-namespace {
-
-// Tests for ChromeContentBrowserClient::ClearSiteData().
-class ChromeContentBrowserClientClearSiteDataTest : public testing::Test {
- public:
- void SetUp() override {
- content::BrowserContext::GetBrowsingDataRemover(profile())
- ->SetEmbedderDelegate(&mock_delegate_);
- run_loop_.reset(new base::RunLoop());
- }
-
- content::BrowserContext* profile() { return &profile_; }
-
- MockBrowsingDataRemoverDelegate* delegate() { return &mock_delegate_; }
-
- void OnClearingFinished() { run_loop_->Quit(); }
-
- void WaitForClearingFinished() {
- run_loop_->Run();
- run_loop_.reset(new base::RunLoop());
- }
-
- private:
- std::unique_ptr<base::RunLoop> run_loop_;
- MockBrowsingDataRemoverDelegate mock_delegate_;
- content::TestBrowserThreadBundle thread_bundle_;
- TestingProfile profile_;
-};
-
-// Tests that the parameters to ClearBrowsingData() are translated to
-// the correct BrowsingDataRemover::RemoveInternal() operation. The fourth
-// parameter, |filter_builder|, is tested in detail in the RegistrableDomains
-// test below.
-TEST_F(ChromeContentBrowserClientClearSiteDataTest, Parameters) {
- ChromeContentBrowserClient client;
-
- struct TestCase {
- bool cookies;
- bool storage;
- bool cache;
- int mask;
- } test_cases[] = {
- {false, false, false, 0},
- {true, false, false,
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA},
- {false, true, false, content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE},
- {false, false, true, content::BrowsingDataRemover::DATA_TYPE_CACHE},
- {true, true, false,
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
- content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE},
- {true, false, true,
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
- content::BrowsingDataRemover::DATA_TYPE_CACHE},
- {false, true, true,
- content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE |
- content::BrowsingDataRemover::DATA_TYPE_CACHE},
- {true, true, true,
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
- content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE |
- content::BrowsingDataRemover::DATA_TYPE_CACHE},
- };
-
- for (unsigned int i = 0; i < arraysize(test_cases); ++i) {
- SCOPED_TRACE(base::StringPrintf("Test case %d", i));
- const TestCase& test_case = test_cases[i];
-
- // We always delete data for all time and all origin types.
- int all_origin_types = ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES;
-
- // Some data are deleted for the origin and some for the registrable domain.
- // Depending on the chosen datatypes, this might result into one or two
- // calls. In the latter case, the removal mask will be split into two
- // parts - one for the origin deletion and one for the registrable domain.
- const int domain_scoped_types =
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA;
- int registrable_domain_deletion_mask = test_case.mask & domain_scoped_types;
- int origin_deletion_mask = test_case.mask & ~domain_scoped_types;
-
- if (registrable_domain_deletion_mask) {
- delegate()->ExpectCallDontCareAboutFilterBuilder(
- base::Time(), base::Time::Max(), registrable_domain_deletion_mask,
- all_origin_types);
- }
-
- if (origin_deletion_mask) {
- delegate()->ExpectCallDontCareAboutFilterBuilder(
- base::Time(), base::Time::Max(), origin_deletion_mask,
- all_origin_types);
- }
-
- client.ClearSiteData(
- profile(), url::Origin(GURL("https://www.example.com")),
- test_case.cookies, test_case.storage, test_case.cache,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-
- delegate()->VerifyAndClearExpectations();
- }
-}
-
-// Tests that ClearBrowsingData() called for an origin deletes cookies in the
-// scope of the registrable domain corresponding to that origin, while cache
-// is deleted for that exact origin.
-TEST_F(ChromeContentBrowserClientClearSiteDataTest, RegistrableDomains) {
- ChromeContentBrowserClient client;
-
- struct TestCase {
- const char* origin; // origin on which ClearSiteData() is called.
- const char* domain; // domain on which cookies will be deleted.
- } test_cases[] = {
- // TLD has no embedded dot.
- {"https://example.com", "example.com"},
- {"https://www.example.com", "example.com"},
- {"https://www.fourth.third.second.com", "second.com"},
-
- // TLD has one embedded dot.
- {"https://www.example.co.uk", "example.co.uk"},
- {"https://example.co.uk", "example.co.uk"},
-
- // TLD has more embedded dots.
- {"https://www.website.sp.nom.br", "website.sp.nom.br"},
-
- // IP addresses.
- {"http://127.0.0.1", "127.0.0.1"},
- {"http://192.168.0.1", "192.168.0.1"},
- {"http://192.168.0.1", "192.168.0.1"},
-
- // Internal hostnames.
- {"http://localhost", "localhost"},
- {"http://fileserver", "fileserver"},
-
- // These are not subdomains of internal hostnames, but subdomain of
- // unknown TLDs.
- {"http://subdomain.localhost", "subdomain.localhost"},
- {"http://www.subdomain.localhost", "subdomain.localhost"},
- {"http://documents.fileserver", "documents.fileserver"},
-
- // Scheme and port don't matter.
- {"http://example.com", "example.com"},
- {"http://example.com:8080", "example.com"},
- {"https://example.com:4433", "example.com"},
- };
-
- for (const TestCase& test_case : test_cases) {
- SCOPED_TRACE(test_case.origin);
-
- std::unique_ptr<BrowsingDataFilterBuilder>
- registrable_domain_filter_builder(BrowsingDataFilterBuilder::Create(
- BrowsingDataFilterBuilder::WHITELIST));
- registrable_domain_filter_builder->AddRegisterableDomain(test_case.domain);
-
- delegate()->ExpectCall(
- base::Time(), base::Time::Max(),
- content::BrowsingDataRemover::DATA_TYPE_COOKIES |
- content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
- ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA,
- ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
- *registrable_domain_filter_builder);
-
- std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
- BrowsingDataFilterBuilder::Create(
- BrowsingDataFilterBuilder::WHITELIST));
- origin_filter_builder->AddOrigin(url::Origin(GURL(test_case.origin)));
-
- delegate()->ExpectCall(base::Time(), base::Time::Max(),
- content::BrowsingDataRemover::DATA_TYPE_CACHE,
- ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
- *origin_filter_builder);
-
- client.ClearSiteData(
- profile(), url::Origin(GURL(test_case.origin)), true /* cookies */,
- false /* storage */, true /* cache */,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-
- delegate()->VerifyAndClearExpectations();
- }
-}
-
-// Tests that we always wait for all scheduled BrowsingDataRemover tasks and
-// that BrowsingDataRemoverObserver never leaks.
-TEST_F(ChromeContentBrowserClientClearSiteDataTest, Tasks) {
- ChromeContentBrowserClient client;
- url::Origin origin(GURL("https://www.example.com"));
-
- // No removal tasks.
- client.ClearSiteData(
- profile(), origin, false /* cookies */, false /* storage */,
- false /* cache */,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-
- // One removal task: deleting cookies with a domain filter.
- client.ClearSiteData(
- profile(), origin, true /* cookies */, false /* storage */,
- false /* cache */,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-
- // One removal task: deleting cache with a domain filter.
- client.ClearSiteData(
- profile(), origin, false /* cookies */, false /* storage */,
- true /* cache */,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-
- // Two removal tasks, with domain and origin filters respectively.
- client.ClearSiteData(
- profile(), origin, true /* cookies */, false /* storage */,
- true /* cache */,
- base::Bind(
- &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
- base::Unretained(this)));
- WaitForClearingFinished();
-}
-
-} // namespace
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | content/browser/browsing_data/clear_site_data_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698