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

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

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Add a newline Created 3 years, 11 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 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/service_worker/link_header_support.h" 5 #include "content/browser/service_worker/link_header_support.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/loader/resource_request_info_impl.h" 10 #include "content/browser/loader/resource_request_info_impl.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 resource_context_(&request_context_) { 60 resource_context_(&request_context_) {
61 base::CommandLine::ForCurrentProcess()->AppendSwitch( 61 base::CommandLine::ForCurrentProcess()->AppendSwitch(
62 switches::kEnableExperimentalWebPlatformFeatures); 62 switches::kEnableExperimentalWebPlatformFeatures);
63 } 63 }
64 ~LinkHeaderServiceWorkerTest() override {} 64 ~LinkHeaderServiceWorkerTest() override {}
65 65
66 void SetUp() override { 66 void SetUp() override {
67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); 67 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
68 68
69 // An empty host. 69 // An empty host.
70 std::unique_ptr<ServiceWorkerProviderHost> host( 70 std::unique_ptr<ServiceWorkerProviderHost> host =
71 new ServiceWorkerProviderHost( 71 ServiceWorkerProviderHost::CreateForTesting(
72 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, 72 render_process_id(), kMockProviderId,
73 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 73 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr());
74 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED,
75 context()->AsWeakPtr(), nullptr));
76 provider_host_ = host->AsWeakPtr(); 74 provider_host_ = host->AsWeakPtr();
77 context()->AddProviderHost(std::move(host)); 75 context()->AddProviderHost(std::move(host));
78 } 76 }
79 77
80 void TearDown() override { helper_.reset(); } 78 void TearDown() override { helper_.reset(); }
81 79
82 ServiceWorkerContextCore* context() { return helper_->context(); } 80 ServiceWorkerContextCore* context() { return helper_->context(); }
83 ServiceWorkerContextWrapper* context_wrapper() { 81 ServiceWorkerContextWrapper* context_wrapper() {
84 return helper_->context_wrapper(); 82 return helper_->context_wrapper();
85 } 83 }
86 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); } 84 ServiceWorkerProviderHost* provider_host() { return provider_host_.get(); }
87 int render_process_id() const { return helper_->mock_render_process_id(); } 85 int render_process_id() const { return helper_->mock_render_process_id(); }
88 86
89 void CreateServiceWorkerProviderHost() { 87 void CreateServiceWorkerProviderHost() {
90 std::unique_ptr<ServiceWorkerProviderHost> host( 88 std::unique_ptr<ServiceWorkerProviderHost> host =
91 new ServiceWorkerProviderHost( 89 ServiceWorkerProviderHost::CreateForTesting(
92 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, 90 render_process_id(), kMockProviderId,
93 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, 91 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, context()->AsWeakPtr());
94 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED,
95 context()->AsWeakPtr(), nullptr));
96 provider_host_ = host->AsWeakPtr(); 92 provider_host_ = host->AsWeakPtr();
97 context()->RemoveProviderHost(host->process_id(), host->provider_id()); 93 context()->RemoveProviderHost(host->process_id(), host->provider_id());
98 context()->AddProviderHost(std::move(host)); 94 context()->AddProviderHost(std::move(host));
99 95
100 scoped_refptr<ServiceWorkerRegistration> registration = 96 scoped_refptr<ServiceWorkerRegistration> registration =
101 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, 97 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L,
102 context()->AsWeakPtr()); 98 context()->AsWeakPtr());
103 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 99 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
104 registration.get(), GURL("https://host/script.js"), 1L, 100 registration.get(), GURL("https://host/script.js"), 1L,
105 context()->AsWeakPtr()); 101 context()->AsWeakPtr());
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 base::RunLoop().RunUntilIdle(); 360 base::RunLoop().RunUntilIdle();
365 361
366 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 362 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
367 ASSERT_EQ(0u, registrations.size()); 363 ASSERT_EQ(0u, registrations.size());
368 } 364 }
369 365
370 TEST_F(LinkHeaderServiceWorkerTest, 366 TEST_F(LinkHeaderServiceWorkerTest,
371 InstallServiceWorker_FromWorkerWithControllees) { 367 InstallServiceWorker_FromWorkerWithControllees) {
372 CreateServiceWorkerProviderHost(); 368 CreateServiceWorkerProviderHost();
373 369
374 std::unique_ptr<ServiceWorkerProviderHost> controllee( 370 std::unique_ptr<ServiceWorkerProviderHost> controllee =
375 new ServiceWorkerProviderHost( 371 ServiceWorkerProviderHost::CreateForTesting(
376 render_process_id(), MSG_ROUTING_NONE, kMockProviderId, 372 render_process_id(), kMockProviderId,
377 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 373 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr());
378 ServiceWorkerProviderHost::FrameSecurityLevel::UNINITIALIZED,
379 context()->AsWeakPtr(), nullptr));
380 provider_host()->running_hosted_version()->AddControllee(controllee.get()); 374 provider_host()->running_hosted_version()->AddControllee(controllee.get());
381 375
382 ProcessLinkHeaderForRequest( 376 ProcessLinkHeaderForRequest(
383 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(), 377 CreateSubresourceRequest(GURL("https://example.com/foo/bar/")).get(),
384 "<../foo.js>; rel=serviceworker", context_wrapper()); 378 "<../foo.js>; rel=serviceworker", context_wrapper());
385 base::RunLoop().RunUntilIdle(); 379 base::RunLoop().RunUntilIdle();
386 380
387 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 381 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
388 ASSERT_EQ(1u, registrations.size()); 382 ASSERT_EQ(1u, registrations.size());
389 } 383 }
390 384
391 } // namespace content 385 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698