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

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

Issue 506043002: (Reland) Service Worker: Handle same-scope, new script registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 6 years, 3 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/browser/service_worker_context.h" 5 #include "content/public/browser/service_worker_context.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 registration_id, 293 registration_id,
294 pattern.GetOrigin(), 294 pattern.GetOrigin(),
295 base::Bind(&ExpectRegisteredWorkers, 295 base::Bind(&ExpectRegisteredWorkers,
296 SERVICE_WORKER_ERROR_NOT_FOUND, 296 SERVICE_WORKER_ERROR_NOT_FOUND,
297 kInvalidServiceWorkerVersionId, 297 kInvalidServiceWorkerVersionId,
298 false /* expect_waiting */, 298 false /* expect_waiting */,
299 false /* expect_active */)); 299 false /* expect_active */));
300 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
301 } 301 }
302 302
303 // Make sure that when a new registration replaces an existing 303 // Make sure registering a new script creates a new version and shares an
304 // registration, that the old one is cleaned up. 304 // existing registration.
305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
306 GURL pattern("http://www.example.com/"); 306 GURL pattern("http://www.example.com/");
307 307
308 bool called = false; 308 bool called = false;
309 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 309 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
310 int64 old_version_id = kInvalidServiceWorkerVersionId; 310 int64 old_version_id = kInvalidServiceWorkerVersionId;
311 context()->RegisterServiceWorker( 311 context()->RegisterServiceWorker(
312 pattern, 312 pattern,
313 GURL("http://www.example.com/service_worker.js"), 313 GURL("http://www.example.com/service_worker.js"),
314 render_process_id_, 314 render_process_id_,
(...skipping 13 matching lines...) Expand all
328 pattern, 328 pattern,
329 GURL("http://www.example.com/service_worker_new.js"), 329 GURL("http://www.example.com/service_worker_new.js"),
330 render_process_id_, 330 render_process_id_,
331 NULL, 331 NULL,
332 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); 332 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
333 333
334 ASSERT_FALSE(called); 334 ASSERT_FALSE(called);
335 base::RunLoop().RunUntilIdle(); 335 base::RunLoop().RunUntilIdle();
336 ASSERT_TRUE(called); 336 ASSERT_TRUE(called);
337 337
338 // Returned IDs should be valid, and should differ from the values
339 // returned for the previous registration.
340 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id); 338 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id);
341 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id); 339 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id);
342 EXPECT_NE(old_registration_id, new_registration_id); 340 EXPECT_EQ(old_registration_id, new_registration_id);
343 EXPECT_NE(old_version_id, new_version_id); 341 EXPECT_NE(old_version_id, new_version_id);
344 } 342 }
345 343
346 // Make sure that when registering a duplicate pattern+script_url 344 // Make sure that when registering a duplicate pattern+script_url
347 // combination, that the same registration is used. 345 // combination, that the same registration is used.
348 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { 346 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
349 GURL pattern("http://www.example.com/"); 347 GURL pattern("http://www.example.com/");
350 GURL script_url("http://www.example.com/service_worker.js"); 348 GURL script_url("http://www.example.com/service_worker.js");
351 349
352 bool called = false; 350 bool called = false;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 GURL("http://www.example.com"), 449 GURL("http://www.example.com"),
452 base::Bind(&ExpectRegisteredWorkers, 450 base::Bind(&ExpectRegisteredWorkers,
453 SERVICE_WORKER_OK, 451 SERVICE_WORKER_OK,
454 version_id, 452 version_id,
455 false /* expect_waiting */, 453 false /* expect_waiting */,
456 true /* expect_active */)); 454 true /* expect_active */));
457 base::RunLoop().RunUntilIdle(); 455 base::RunLoop().RunUntilIdle();
458 } 456 }
459 457
460 } // namespace content 458 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698