OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/browsing_data/clear_site_data_throttle.h" | 5 #include "content/browser/browsing_data/clear_site_data_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "content/browser/browsing_data/browsing_data_filter_builder_impl.h" | 15 #include "content/browser/browsing_data/browsing_data_filter_builder_impl.h" |
16 #include "content/browser/service_worker/service_worker_context_observer.h" | 16 #include "content/browser/service_worker/service_worker_context_core_observer.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browsing_data_remover.h" | 19 #include "content/public/browser/browsing_data_remover.h" |
20 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/cache_test_util.h" | 25 #include "content/public/test/cache_test_util.h" |
26 #include "content/public/test/content_browser_test.h" | 26 #include "content/public/test/content_browser_test.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 // A shortcut for the above method, but with only cookies deleted. This is | 107 // A shortcut for the above method, but with only cookies deleted. This is |
108 // useful for most tests that use |kClearCookiesHeader|. | 108 // useful for most tests that use |kClearCookiesHeader|. |
109 void ExpectClearSiteDataCookiesCall(const url::Origin& origin) { | 109 void ExpectClearSiteDataCookiesCall(const url::Origin& origin) { |
110 ExpectClearSiteDataCall(origin, true, false, false); | 110 ExpectClearSiteDataCall(origin, true, false, false); |
111 } | 111 } |
112 }; | 112 }; |
113 | 113 |
114 // TODO(msramek): A class like this already exists in ServiceWorkerBrowserTest. | 114 // TODO(msramek): A class like this already exists in ServiceWorkerBrowserTest. |
115 // Consider extracting it to a test utils file. | 115 // Consider extracting it to a test utils file. |
116 class ServiceWorkerActivationObserver : public ServiceWorkerContextObserver { | 116 class ServiceWorkerActivationObserver |
| 117 : public ServiceWorkerContextCoreObserver { |
117 public: | 118 public: |
118 static void SignalActivation(ServiceWorkerContextWrapper* context, | 119 static void SignalActivation(ServiceWorkerContextWrapper* context, |
119 const base::Closure& callback) { | 120 const base::Closure& callback) { |
120 new ServiceWorkerActivationObserver(context, callback); | 121 new ServiceWorkerActivationObserver(context, callback); |
121 } | 122 } |
122 | 123 |
123 private: | 124 private: |
124 ServiceWorkerActivationObserver(ServiceWorkerContextWrapper* context, | 125 ServiceWorkerActivationObserver(ServiceWorkerContextWrapper* context, |
125 const base::Closure& callback) | 126 const base::Closure& callback) |
126 : context_(context), scoped_observer_(this), callback_(callback) { | 127 : context_(context), scoped_observer_(this), callback_(callback) { |
127 scoped_observer_.Add(context); | 128 scoped_observer_.Add(context); |
128 } | 129 } |
129 | 130 |
130 ~ServiceWorkerActivationObserver() override {} | 131 ~ServiceWorkerActivationObserver() override {} |
131 | 132 |
132 // ServiceWorkerContextObserver overrides. | 133 // ServiceWorkerContextCoreObserver overrides. |
133 void OnVersionStateChanged(int64_t version_id, | 134 void OnVersionStateChanged(int64_t version_id, |
134 ServiceWorkerVersion::Status) override { | 135 ServiceWorkerVersion::Status) override { |
135 if (context_->GetLiveVersion(version_id)->status() == | 136 if (context_->GetLiveVersion(version_id)->status() == |
136 ServiceWorkerVersion::ACTIVATED) { | 137 ServiceWorkerVersion::ACTIVATED) { |
137 callback_.Run(); | 138 callback_.Run(); |
138 delete this; | 139 delete this; |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 ServiceWorkerContextWrapper* context_; | 143 ServiceWorkerContextWrapper* context_; |
143 ScopedObserver<ServiceWorkerContextWrapper, ServiceWorkerContextObserver> | 144 ScopedObserver<ServiceWorkerContextWrapper, ServiceWorkerContextCoreObserver> |
144 scoped_observer_; | 145 scoped_observer_; |
145 base::Closure callback_; | 146 base::Closure callback_; |
146 }; | 147 }; |
147 | 148 |
148 } // namespace | 149 } // namespace |
149 | 150 |
150 class ClearSiteDataThrottleBrowserTest : public ContentBrowserTest { | 151 class ClearSiteDataThrottleBrowserTest : public ContentBrowserTest { |
151 public: | 152 public: |
152 void SetUpCommandLine(base::CommandLine* command_line) override { | 153 void SetUpCommandLine(base::CommandLine* command_line) override { |
153 ContentBrowserTest::SetUpCommandLine(command_line); | 154 ContentBrowserTest::SetUpCommandLine(command_line); |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // Tests that closing the tab right after executing Clear-Site-Data does | 860 // Tests that closing the tab right after executing Clear-Site-Data does |
860 // not crash. | 861 // not crash. |
861 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, ClosedTab) { | 862 IN_PROC_BROWSER_TEST_F(ClearSiteDataThrottleBrowserTest, ClosedTab) { |
862 GURL url = https_server()->GetURL("example.com", "/"); | 863 GURL url = https_server()->GetURL("example.com", "/"); |
863 AddQuery(&url, "header", kClearCookiesHeader); | 864 AddQuery(&url, "header", kClearCookiesHeader); |
864 shell()->LoadURL(url); | 865 shell()->LoadURL(url); |
865 shell()->Close(); | 866 shell()->Close(); |
866 } | 867 } |
867 | 868 |
868 } // namespace content | 869 } // namespace content |
OLD | NEW |