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

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

Issue 2958753003: Revert "Create ServiceWorkerProviderHost before starting worker" (Closed)
Patch Set: Created 3 years, 5 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/foreign_fetch_request_handler.h" 5 #include "content/browser/service_worker/foreign_fetch_request_handler.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/simple_test_tick_clock.h" 9 #include "base/test/simple_test_tick_clock.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), 164 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(),
165 &remote_endpoints_.back()); 165 &remote_endpoints_.back());
166 EXPECT_FALSE( 166 EXPECT_FALSE(
167 context()->GetProviderHost(host->process_id(), host->provider_id())); 167 context()->GetProviderHost(host->process_id(), host->provider_id()));
168 host->SetDocumentUrl(GURL("https://host/scope/")); 168 host->SetDocumentUrl(GURL("https://host/scope/"));
169 provider_host_ = host->AsWeakPtr(); 169 provider_host_ = host->AsWeakPtr();
170 context()->AddProviderHost(std::move(host)); 170 context()->AddProviderHost(std::move(host));
171 } 171 }
172 172
173 void CreateServiceWorkerTypeProviderHost() { 173 void CreateServiceWorkerTypeProviderHost() {
174 remote_endpoints_.emplace_back();
175 std::unique_ptr<ServiceWorkerProviderHost> host =
176 CreateProviderHostForServiceWorkerContext(
177 helper_->mock_render_process_id(), kMockProviderId,
178 true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(),
179 &remote_endpoints_.back());
180 EXPECT_FALSE(
181 context()->GetProviderHost(host->process_id(), host->provider_id()));
182 provider_host_ = host->AsWeakPtr();
183 context()->AddProviderHost(std::move(host));
184
174 // Create another worker whose requests will be intercepted by the foreign 185 // Create another worker whose requests will be intercepted by the foreign
175 // fetch event handler. 186 // fetch event handler.
176 scoped_refptr<ServiceWorkerRegistration> registration = 187 scoped_refptr<ServiceWorkerRegistration> registration =
177 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, 188 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L,
178 context()->AsWeakPtr()); 189 context()->AsWeakPtr());
179 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 190 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
180 registration.get(), GURL("https://host/script.js"), 1L, 191 registration.get(), GURL("https://host/script.js"), 1L,
181 context()->AsWeakPtr()); 192 context()->AsWeakPtr());
182 193
183 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 194 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
184 records.push_back( 195 records.push_back(
185 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); 196 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100));
186 version->script_cache_map()->SetResources(records); 197 version->script_cache_map()->SetResources(records);
187 version->set_fetch_handler_existence( 198 version->set_fetch_handler_existence(
188 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 199 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
189 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 200 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
190 registration->SetActiveVersion(version); 201 registration->SetActiveVersion(version);
191 context()->storage()->StoreRegistration( 202 context()->storage()->StoreRegistration(
192 registration.get(), version.get(), 203 registration.get(), version.get(),
193 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 204 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
194 base::RunLoop().RunUntilIdle(); 205 base::RunLoop().RunUntilIdle();
195 206
196 remote_endpoints_.emplace_back(); 207 provider_host_->running_hosted_version_ = version;
197 std::unique_ptr<ServiceWorkerProviderHost> host =
198 CreateProviderHostForServiceWorkerContext(
199 helper_->mock_render_process_id(),
200 true /* is_parent_frame_secure */, version.get(),
201 helper_->context()->AsWeakPtr(), &remote_endpoints_.back());
202 EXPECT_FALSE(
203 context()->GetProviderHost(host->process_id(), host->provider_id()));
204 provider_host_ = host->AsWeakPtr();
205 context()->AddProviderHost(std::move(host));
206 } 208 }
207 209
208 private: 210 private:
209 class TestContentClient : public ContentClient { 211 class TestContentClient : public ContentClient {
210 public: 212 public:
211 // ContentRendererClient methods 213 // ContentRendererClient methods
212 OriginTrialPolicy* GetOriginTrialPolicy() override { 214 OriginTrialPolicy* GetOriginTrialPolicy() override {
213 return &origin_trial_policy_; 215 return &origin_trial_policy_;
214 } 216 }
215 217
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Make sure new request only gets remaining timeout. 384 // Make sure new request only gets remaining timeout.
383 ForeignFetchRequestHandler* handler = 385 ForeignFetchRequestHandler* handler =
384 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, 386 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE,
385 nullptr /* initiator */); 387 nullptr /* initiator */);
386 ASSERT_TRUE(handler); 388 ASSERT_TRUE(handler);
387 ASSERT_TRUE(timeout_for_request(handler).has_value()); 389 ASSERT_TRUE(timeout_for_request(handler).has_value());
388 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); 390 EXPECT_EQ(remaining_time, timeout_for_request(handler).value());
389 } 391 }
390 392
391 } // namespace content 393 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698