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

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

Issue 2936623002: Implement dumb URLLoader{Factory} for ServiceWorker script loading (for try)
Patch Set: . 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/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
185 // Create another worker whose requests will be intercepted by the foreign 174 // Create another worker whose requests will be intercepted by the foreign
186 // fetch event handler. 175 // fetch event handler.
187 scoped_refptr<ServiceWorkerRegistration> registration = 176 scoped_refptr<ServiceWorkerRegistration> registration =
188 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L, 177 new ServiceWorkerRegistration(GURL("https://host/scope"), 1L,
189 context()->AsWeakPtr()); 178 context()->AsWeakPtr());
190 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 179 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
191 registration.get(), GURL("https://host/script.js"), 1L, 180 registration.get(), GURL("https://host/script.js"), 1L,
192 context()->AsWeakPtr()); 181 context()->AsWeakPtr());
193 182
194 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 183 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
195 records.push_back( 184 records.push_back(
196 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100)); 185 ServiceWorkerDatabase::ResourceRecord(10, version->script_url(), 100));
197 version->script_cache_map()->SetResources(records); 186 version->script_cache_map()->SetResources(records);
198 version->set_fetch_handler_existence( 187 version->set_fetch_handler_existence(
199 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 188 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
200 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 189 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
201 registration->SetActiveVersion(version); 190 registration->SetActiveVersion(version);
202 context()->storage()->StoreRegistration( 191 context()->storage()->StoreRegistration(
203 registration.get(), version.get(), 192 registration.get(), version.get(),
204 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 193 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
205 base::RunLoop().RunUntilIdle(); 194 base::RunLoop().RunUntilIdle();
206 195
207 provider_host_->running_hosted_version_ = version; 196 remote_endpoints_.emplace_back();
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));
208 } 206 }
209 207
210 private: 208 private:
211 class TestContentClient : public ContentClient { 209 class TestContentClient : public ContentClient {
212 public: 210 public:
213 // ContentRendererClient methods 211 // ContentRendererClient methods
214 OriginTrialPolicy* GetOriginTrialPolicy() override { 212 OriginTrialPolicy* GetOriginTrialPolicy() override {
215 return &origin_trial_policy_; 213 return &origin_trial_policy_;
216 } 214 }
217 215
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // Make sure new request only gets remaining timeout. 382 // Make sure new request only gets remaining timeout.
385 ForeignFetchRequestHandler* handler = 383 ForeignFetchRequestHandler* handler =
386 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, 384 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE,
387 nullptr /* initiator */); 385 nullptr /* initiator */);
388 ASSERT_TRUE(handler); 386 ASSERT_TRUE(handler);
389 ASSERT_TRUE(timeout_for_request(handler).has_value()); 387 ASSERT_TRUE(timeout_for_request(handler).has_value());
390 EXPECT_EQ(remaining_time, timeout_for_request(handler).value()); 388 EXPECT_EQ(remaining_time, timeout_for_request(handler).value());
391 } 389 }
392 390
393 } // namespace content 391 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698