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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host_unittest.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: change useCache to updateViaCache 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_worker/service_worker_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 void SetUp() override { 51 void SetUp() override {
52 old_content_browser_client_ = 52 old_content_browser_client_ =
53 SetBrowserClientForTesting(&test_content_browser_client_); 53 SetBrowserClientForTesting(&test_content_browser_client_);
54 ResetSchemesAndOriginsWhitelist(); 54 ResetSchemesAndOriginsWhitelist();
55 55
56 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); 56 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
57 context_ = helper_->context(); 57 context_ = helper_->context();
58 script_url_ = GURL("https://www.example.com/service_worker.js"); 58 script_url_ = GURL("https://www.example.com/service_worker.js");
59 registration1_ = new ServiceWorkerRegistration( 59 registration1_ = new ServiceWorkerRegistration(
60 GURL("https://www.example.com/"), 1L, context_->AsWeakPtr()); 60 ServiceWorkerRegistrationOptions(GURL("https://www.example.com/")), 1L,
61 context_->AsWeakPtr());
61 registration2_ = new ServiceWorkerRegistration( 62 registration2_ = new ServiceWorkerRegistration(
62 GURL("https://www.example.com/example"), 2L, context_->AsWeakPtr()); 63 ServiceWorkerRegistrationOptions(
64 GURL("https://www.example.com/example")),
65 2L, context_->AsWeakPtr());
63 registration3_ = new ServiceWorkerRegistration( 66 registration3_ = new ServiceWorkerRegistration(
64 GURL("https://other.example.com/"), 3L, context_->AsWeakPtr()); 67 ServiceWorkerRegistrationOptions(GURL("https://other.example.com/")),
68 3L, context_->AsWeakPtr());
65 } 69 }
66 70
67 void TearDown() override { 71 void TearDown() override {
68 registration1_ = 0; 72 registration1_ = 0;
69 registration2_ = 0; 73 registration2_ = 0;
70 helper_.reset(); 74 helper_.reset();
71 SetBrowserClientForTesting(old_content_browser_client_); 75 SetBrowserClientForTesting(old_content_browser_client_);
72 // Reset cached security schemes so we don't affect other tests. 76 // Reset cached security schemes so we don't affect other tests.
73 ResetSchemesAndOriginsWhitelist(); 77 ResetSchemesAndOriginsWhitelist();
74 } 78 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EXPECT_TRUE(provider_host_secure_parent->IsContextSecureForServiceWorker()); 245 EXPECT_TRUE(provider_host_secure_parent->IsContextSecureForServiceWorker());
242 246
243 // Exceptional service worker scheme with insecure parent frame. 247 // Exceptional service worker scheme with insecure parent frame.
244 provider_host_insecure_parent->SetDocumentUrl(url); 248 provider_host_insecure_parent->SetDocumentUrl(url);
245 EXPECT_FALSE( 249 EXPECT_FALSE(
246 provider_host_insecure_parent->IsContextSecureForServiceWorker()); 250 provider_host_insecure_parent->IsContextSecureForServiceWorker());
247 } 251 }
248 252
249 class MockServiceWorkerRegistration : public ServiceWorkerRegistration { 253 class MockServiceWorkerRegistration : public ServiceWorkerRegistration {
250 public: 254 public:
251 MockServiceWorkerRegistration(const GURL& pattern, 255 MockServiceWorkerRegistration(const ServiceWorkerRegistrationOptions& options,
252 int64_t registration_id, 256 int64_t registration_id,
253 base::WeakPtr<ServiceWorkerContextCore> context) 257 base::WeakPtr<ServiceWorkerContextCore> context)
254 : ServiceWorkerRegistration(pattern, registration_id, context) {} 258 : ServiceWorkerRegistration(options, registration_id, context) {}
255 259
256 void AddListener(ServiceWorkerRegistration::Listener* listener) override { 260 void AddListener(ServiceWorkerRegistration::Listener* listener) override {
257 listeners_.insert(listener); 261 listeners_.insert(listener);
258 } 262 }
259 263
260 void RemoveListener(ServiceWorkerRegistration::Listener* listener) override { 264 void RemoveListener(ServiceWorkerRegistration::Listener* listener) override {
261 listeners_.erase(listener); 265 listeners_.erase(listener);
262 } 266 }
263 267
264 const std::set<ServiceWorkerRegistration::Listener*>& listeners() { 268 const std::set<ServiceWorkerRegistration::Listener*>& listeners() {
265 return listeners_; 269 return listeners_;
266 } 270 }
267 271
268 protected: 272 protected:
269 ~MockServiceWorkerRegistration() override{}; 273 ~MockServiceWorkerRegistration() override{};
270 274
271 private: 275 private:
272 std::set<ServiceWorkerRegistration::Listener*> listeners_; 276 std::set<ServiceWorkerRegistration::Listener*> listeners_;
273 }; 277 };
274 278
275 TEST_F(ServiceWorkerProviderHostTest, CrossSiteTransfer) { 279 TEST_F(ServiceWorkerProviderHostTest, CrossSiteTransfer) {
276 if (IsBrowserSideNavigationEnabled()) 280 if (IsBrowserSideNavigationEnabled())
277 return; 281 return;
278 282
279 // Create a mock registration before creating the provider host which is in 283 // Create a mock registration before creating the provider host which is in
280 // the scope. 284 // the scope.
285 ServiceWorkerRegistrationOptions options(GURL("https://cross.example.com/"));
281 scoped_refptr<MockServiceWorkerRegistration> registration = 286 scoped_refptr<MockServiceWorkerRegistration> registration =
282 new MockServiceWorkerRegistration(GURL("https://cross.example.com/"), 4L, 287 new MockServiceWorkerRegistration(options, 4L,
283 helper_->context()->AsWeakPtr()); 288 helper_->context()->AsWeakPtr());
284 289
285 ServiceWorkerProviderHost* provider_host = 290 ServiceWorkerProviderHost* provider_host =
286 CreateProviderHost(GURL("https://cross.example.com/example.html")); 291 CreateProviderHost(GURL("https://cross.example.com/example.html"));
287 const int process_id = provider_host->process_id(); 292 const int process_id = provider_host->process_id();
288 const int provider_id = provider_host->provider_id(); 293 const int provider_id = provider_host->provider_id();
289 const int frame_id = provider_host->frame_id(); 294 const int frame_id = provider_host->frame_id();
290 const ServiceWorkerProviderType type = provider_host->provider_type(); 295 const ServiceWorkerProviderType type = provider_host->provider_type();
291 const bool is_parent_frame_secure = provider_host->is_parent_frame_secure(); 296 const bool is_parent_frame_secure = provider_host->is_parent_frame_secure();
292 const ServiceWorkerDispatcherHost* dispatcher_host = 297 const ServiceWorkerDispatcherHost* dispatcher_host =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 EXPECT_TRUE(context_->GetProviderHost(process_id, provider_id)); 345 EXPECT_TRUE(context_->GetProviderHost(process_id, provider_id));
341 346
342 // Disconnect the mojo pipe from the renderer side. 347 // Disconnect the mojo pipe from the renderer side.
343 ASSERT_TRUE(remote_endpoints_.back().host_ptr()->is_bound()); 348 ASSERT_TRUE(remote_endpoints_.back().host_ptr()->is_bound());
344 remote_endpoints_.back().host_ptr()->reset(); 349 remote_endpoints_.back().host_ptr()->reset();
345 base::RunLoop().RunUntilIdle(); 350 base::RunLoop().RunUntilIdle();
346 EXPECT_FALSE(context_->GetProviderHost(process_id, provider_id)); 351 EXPECT_FALSE(context_->GetProviderHost(process_id, provider_id));
347 } 352 }
348 353
349 } // namespace content 354 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698