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

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

Issue 1106723002: ServiceWorker: Decompose SWRegistration::SetVersionInternal for readability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make the argument const-ref Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/service_worker/embedded_worker_registry.h" 9 #include "content/browser/service_worker/embedded_worker_registry.h"
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" 10 #include "content/browser/service_worker/embedded_worker_test_helper.h"
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // Manually create the waiting worker since there is no way to become a 641 // Manually create the waiting worker since there is no way to become a
642 // waiting worker until Update is implemented. 642 // waiting worker until Update is implemented.
643 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 643 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
644 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); 644 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr());
645 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 645 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
646 version->StartWorker(CreateReceiverOnCurrentThread(&status)); 646 version->StartWorker(CreateReceiverOnCurrentThread(&status));
647 base::RunLoop().RunUntilIdle(); 647 base::RunLoop().RunUntilIdle();
648 ASSERT_EQ(SERVICE_WORKER_OK, status); 648 ASSERT_EQ(SERVICE_WORKER_OK, status);
649 649
650 version->SetStatus(ServiceWorkerVersion::INSTALLED); 650 version->SetStatus(ServiceWorkerVersion::INSTALLED);
651 registration->SetWaitingVersion(version.get()); 651 registration->SetWaitingVersion(version);
652 EXPECT_EQ(ServiceWorkerVersion::RUNNING, 652 EXPECT_EQ(ServiceWorkerVersion::RUNNING,
653 version->running_status()); 653 version->running_status());
654 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); 654 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
655 655
656 RunUnregisterJob(GURL("http://www.example.com/")); 656 RunUnregisterJob(GURL("http://www.example.com/"));
657 657
658 // The version should be stopped since there is no controllee after 658 // The version should be stopped since there is no controllee after
659 // unregistration. 659 // unregistration.
660 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); 660 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
661 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 661 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 1023
1024 // Queue an Update, it should abort when it starts and sees the new version. 1024 // Queue an Update, it should abort when it starts and sees the new version.
1025 job_coordinator()->Update(registration.get(), false); 1025 job_coordinator()->Update(registration.get(), false);
1026 1026
1027 // Add a waiting version with new script. 1027 // Add a waiting version with new script.
1028 scoped_refptr<ServiceWorkerVersion> version = 1028 scoped_refptr<ServiceWorkerVersion> version =
1029 new ServiceWorkerVersion(registration.get(), 1029 new ServiceWorkerVersion(registration.get(),
1030 GURL("http://www.example.com/new_worker.js"), 1030 GURL("http://www.example.com/new_worker.js"),
1031 2L /* dummy version id */, 1031 2L /* dummy version id */,
1032 helper_->context()->AsWeakPtr()); 1032 helper_->context()->AsWeakPtr());
1033 registration->SetWaitingVersion(version.get()); 1033 registration->SetWaitingVersion(version);
1034 1034
1035 base::RunLoop().RunUntilIdle(); 1035 base::RunLoop().RunUntilIdle();
1036 1036
1037 // Verify the registration was not modified by the Update. 1037 // Verify the registration was not modified by the Update.
1038 EXPECT_EQ(active_version, registration->active_version()); 1038 EXPECT_EQ(active_version, registration->active_version());
1039 EXPECT_EQ(version.get(), registration->waiting_version()); 1039 EXPECT_EQ(version.get(), registration->waiting_version());
1040 EXPECT_EQ(NULL, registration->installing_version()); 1040 EXPECT_EQ(NULL, registration->installing_version());
1041 } 1041 }
1042 1042
1043 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { 1043 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 EXPECT_FALSE(registration->is_uninstalling()); 1394 EXPECT_FALSE(registration->is_uninstalling());
1395 EXPECT_TRUE(registration->is_uninstalled()); 1395 EXPECT_TRUE(registration->is_uninstalled());
1396 1396
1397 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); 1397 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status());
1398 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); 1398 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status());
1399 1399
1400 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); 1400 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
1401 } 1401 }
1402 1402
1403 } // namespace content 1403 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698