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

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

Issue 2251633002: Use tri-state enum for the existence of Fetch Handler in ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/status/existence/ Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_registration.h" 5 #include "content/browser/service_worker/service_worker_registration.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 const GURL kScope("https://www.example.not/"); 192 const GURL kScope("https://www.example.not/");
193 const GURL kScript("https://www.example.not/service_worker.js"); 193 const GURL kScript("https://www.example.not/service_worker.js");
194 194
195 registration_ = new ServiceWorkerRegistration( 195 registration_ = new ServiceWorkerRegistration(
196 kScope, storage()->NewRegistrationId(), context()->AsWeakPtr()); 196 kScope, storage()->NewRegistrationId(), context()->AsWeakPtr());
197 197
198 // Create an active version. 198 // Create an active version.
199 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( 199 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion(
200 registration_.get(), kScript, storage()->NewVersionId(), 200 registration_.get(), kScript, storage()->NewVersionId(),
201 context()->AsWeakPtr()); 201 context()->AsWeakPtr());
202 version_1->set_fetch_handler_existence(
203 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
202 registration_->SetActiveVersion(version_1); 204 registration_->SetActiveVersion(version_1);
203 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); 205 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED);
204 206
205 // Store the registration. 207 // Store the registration.
206 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 208 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
207 records.push_back(ServiceWorkerDatabase::ResourceRecord( 209 records.push_back(ServiceWorkerDatabase::ResourceRecord(
208 10, version_1->script_url(), 100)); 210 10, version_1->script_url(), 100));
209 version_1->script_cache_map()->SetResources(records); 211 version_1->script_cache_map()->SetResources(records);
210 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 212 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
211 context()->storage()->StoreRegistration( 213 context()->storage()->StoreRegistration(
(...skipping 11 matching lines...) Expand all
223 context()->AsWeakPtr(), nullptr)); 225 context()->AsWeakPtr(), nullptr));
224 version_1->AddControllee(host_.get()); 226 version_1->AddControllee(host_.get());
225 227
226 // Give the active version an in-flight request. 228 // Give the active version an in-flight request.
227 inflight_request_id_ = CreateInflightRequest(version_1.get()); 229 inflight_request_id_ = CreateInflightRequest(version_1.get());
228 230
229 // Create a waiting version. 231 // Create a waiting version.
230 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( 232 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion(
231 registration_.get(), kScript, storage()->NewVersionId(), 233 registration_.get(), kScript, storage()->NewVersionId(),
232 context()->AsWeakPtr()); 234 context()->AsWeakPtr());
235 version_2->set_fetch_handler_existence(
236 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
233 registration_->SetWaitingVersion(version_2); 237 registration_->SetWaitingVersion(version_2);
234 version_2->SetStatus(ServiceWorkerVersion::INSTALLED); 238 version_2->SetStatus(ServiceWorkerVersion::INSTALLED);
235 239
236 // Set it to activate when ready. The original version should still be 240 // Set it to activate when ready. The original version should still be
237 // active. 241 // active.
238 registration_->ActivateWaitingVersionWhenReady(); 242 registration_->ActivateWaitingVersionWhenReady();
239 base::RunLoop().RunUntilIdle(); 243 base::RunLoop().RunUntilIdle();
240 EXPECT_EQ(version_1.get(), registration_->active_version()); 244 EXPECT_EQ(version_1.get(), registration_->active_version());
241 } 245 }
242 246
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 base::RunLoop().RunUntilIdle(); 325 base::RunLoop().RunUntilIdle();
322 EXPECT_EQ(version_1.get(), reg->active_version()); 326 EXPECT_EQ(version_1.get(), reg->active_version());
323 327
324 // Finish the request. Activation should happen. 328 // Finish the request. Activation should happen.
325 version_1->FinishRequest(inflight_request_id(), true /* was_handled */); 329 version_1->FinishRequest(inflight_request_id(), true /* was_handled */);
326 base::RunLoop().RunUntilIdle(); 330 base::RunLoop().RunUntilIdle();
327 EXPECT_EQ(version_2.get(), reg->active_version()); 331 EXPECT_EQ(version_2.get(), reg->active_version());
328 } 332 }
329 333
330 } // namespace content 334 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698