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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer 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 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 false /* is_parent_frame_secure */, 99 false /* is_parent_frame_secure */,
100 context()->AsWeakPtr(), 100 context()->AsWeakPtr(),
101 &remote_endpoints_.back()); 101 &remote_endpoints_.back());
102 provider_host_ = host->AsWeakPtr(); 102 provider_host_ = host->AsWeakPtr();
103 EXPECT_FALSE( 103 EXPECT_FALSE(
104 context()->GetProviderHost(host->process_id(), host->provider_id())); 104 context()->GetProviderHost(host->process_id(), host->provider_id()));
105 context()->AddProviderHost(std::move(host)); 105 context()->AddProviderHost(std::move(host));
106 } 106 }
107 107
108 void CreateServiceWorkerProviderHost() { 108 void CreateServiceWorkerProviderHost() {
109 remote_endpoints_.emplace_back();
110 std::unique_ptr<ServiceWorkerProviderHost> host =
111 CreateProviderHostForServiceWorkerContext(
112 render_process_id(), kMockProviderId,
113 true /* is_parent_frame_secure */, context()->AsWeakPtr(),
114 &remote_endpoints_.back());
115 provider_host_ = host->AsWeakPtr();
116 EXPECT_FALSE(
117 context()->GetProviderHost(host->process_id(), host->provider_id()));
118 context()->AddProviderHost(std::move(host));
119
120 scoped_refptr<ServiceWorkerRegistration> registration = 109 scoped_refptr<ServiceWorkerRegistration> registration =
121 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, 110 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L,
122 context()->AsWeakPtr()); 111 context()->AsWeakPtr());
123 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 112 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
124 registration.get(), GURL("https://host/script.js"), 1L, 113 registration.get(), GURL("https://host/script.js"), 1L,
125 context()->AsWeakPtr()); 114 context()->AsWeakPtr());
126 115
127 provider_host_->running_hosted_version_ = version; 116 remote_endpoints_.emplace_back();
117 std::unique_ptr<ServiceWorkerProviderHost> host =
118 CreateProviderHostForServiceWorkerContext(
119 render_process_id(), true /* is_parent_frame_secure */,
120 version.get(), context()->AsWeakPtr(), &remote_endpoints_.back());
121 provider_host_ = host->AsWeakPtr();
122 EXPECT_FALSE(
123 context()->GetProviderHost(host->process_id(), host->provider_id()));
124 context()->AddProviderHost(std::move(host));
128 } 125 }
129 126
130 std::unique_ptr<net::URLRequest> CreateRequest(const GURL& request_url, 127 std::unique_ptr<net::URLRequest> CreateRequest(const GURL& request_url,
131 ResourceType resource_type, 128 ResourceType resource_type,
132 int provider_id) { 129 int provider_id) {
133 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest( 130 std::unique_ptr<net::URLRequest> request = request_context_.CreateRequest(
134 request_url, net::DEFAULT_PRIORITY, &request_delegate_, 131 request_url, net::DEFAULT_PRIORITY, &request_delegate_,
135 TRAFFIC_ANNOTATION_FOR_TESTS); 132 TRAFFIC_ANNOTATION_FOR_TESTS);
136 ResourceRequestInfo::AllocateForTesting( 133 ResourceRequestInfo::AllocateForTesting(
137 request.get(), resource_type, &resource_context_, 134 request.get(), resource_type, &resource_context_,
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 provider_host()->provider_id()) 439 provider_host()->provider_id())
443 .get(), 440 .get(),
444 "<../foo.js>; rel=serviceworker", context_wrapper()); 441 "<../foo.js>; rel=serviceworker", context_wrapper());
445 base::RunLoop().RunUntilIdle(); 442 base::RunLoop().RunUntilIdle();
446 443
447 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 444 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
448 ASSERT_EQ(1u, registrations.size()); 445 ASSERT_EQ(1u, registrations.size());
449 } 446 }
450 447
451 } // namespace content 448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698