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

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

Issue 1928443003: service worker: Update job gets the script url when the job starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 7 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 <stdint.h> 5 #include <stdint.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/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 update_helper->state_change_log_[3].status); 1125 update_helper->state_change_log_[3].status);
1126 1126
1127 EXPECT_EQ(registration->active_version()->version_id(), 1127 EXPECT_EQ(registration->active_version()->version_id(),
1128 update_helper->state_change_log_[4].version_id); 1128 update_helper->state_change_log_[4].version_id);
1129 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, 1129 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED,
1130 update_helper->state_change_log_[4].status); 1130 update_helper->state_change_log_[4].status);
1131 1131
1132 EXPECT_TRUE(update_helper->update_found_); 1132 EXPECT_TRUE(update_helper->update_found_);
1133 } 1133 }
1134 1134
1135 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { 1135 // Test that the update job uses the script URL of the newest worker when the
1136 // job starts, rather than when it is scheduled.
1137 TEST_F(ServiceWorkerJobTest, Update_ScriptUrlChanged) {
1138 // Create a registration with an active version.
1136 scoped_refptr<ServiceWorkerRegistration> registration = 1139 scoped_refptr<ServiceWorkerRegistration> registration =
1137 RunRegisterJob(GURL("http://www.example.com/one/"), 1140 RunRegisterJob(GURL("http://www.example.com/one/"),
1138 GURL("http://www.example.com/service_worker.js")); 1141 GURL("http://www.example.com/service_worker.js"));
1139 1142
1140 ServiceWorkerVersion* active_version = registration->active_version(); 1143 // Queue an Update. When this runs, it will use the waiting version's script.
1141
1142 // Queue an Update, it should abort when it starts and sees the new version.
1143 job_coordinator()->Update(registration.get(), false); 1144 job_coordinator()->Update(registration.get(), false);
1144 1145
1145 // Add a waiting version with new script. 1146 // Add a waiting version with a new script.
1146 scoped_refptr<ServiceWorkerVersion> version = 1147 GURL new_script("http://www.example.com/new_worker.js");
1147 new ServiceWorkerVersion(registration.get(), 1148 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1148 GURL("http://www.example.com/new_worker.js"), 1149 registration.get(), new_script, 2L /* dummy version id */,
1149 2L /* dummy version id */, 1150 helper_->context()->AsWeakPtr());
1150 helper_->context()->AsWeakPtr());
1151 registration->SetWaitingVersion(version); 1151 registration->SetWaitingVersion(version);
1152 1152
1153 // Run the update job.
1153 base::RunLoop().RunUntilIdle(); 1154 base::RunLoop().RunUntilIdle();
1154 1155
1155 // Verify the registration was not modified by the Update. 1156 // The update job should have created a new version with the new script,
1156 EXPECT_EQ(active_version, registration->active_version()); 1157 // and promoted it to the active version.
1157 EXPECT_EQ(version.get(), registration->waiting_version()); 1158 EXPECT_EQ(new_script, registration->active_version()->script_url());
1158 EXPECT_EQ(NULL, registration->installing_version()); 1159 EXPECT_EQ(nullptr, registration->waiting_version());
1160 EXPECT_EQ(nullptr, registration->installing_version());
1159 } 1161 }
1160 1162
1161 // Test that update succeeds if the incumbent worker was evicted 1163 // Test that update succeeds if the incumbent worker was evicted
1162 // during the update job (this can happen on disk cache failure). 1164 // during the update job (this can happen on disk cache failure).
1163 TEST_F(ServiceWorkerJobTest, Update_EvictedIncumbent) { 1165 TEST_F(ServiceWorkerJobTest, Update_EvictedIncumbent) {
1164 EvictIncumbentVersionHelper* update_helper = new EvictIncumbentVersionHelper; 1166 EvictIncumbentVersionHelper* update_helper = new EvictIncumbentVersionHelper;
1165 helper_.reset(update_helper); 1167 helper_.reset(update_helper);
1166 scoped_refptr<ServiceWorkerRegistration> registration = 1168 scoped_refptr<ServiceWorkerRegistration> registration =
1167 update_helper->SetupInitialRegistration(kNewVersionOrigin); 1169 update_helper->SetupInitialRegistration(kNewVersionOrigin);
1168 ASSERT_TRUE(registration.get()); 1170 ASSERT_TRUE(registration.get());
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 ASSERT_TRUE(start_msg); 1581 ASSERT_TRUE(start_msg);
1580 EmbeddedWorkerMsg_StartWorker::Param param; 1582 EmbeddedWorkerMsg_StartWorker::Param param;
1581 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param); 1583 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param);
1582 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); 1584 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param);
1583 EXPECT_TRUE(start_params.pause_after_download); 1585 EXPECT_TRUE(start_params.pause_after_download);
1584 sink->ClearMessages(); 1586 sink->ClearMessages();
1585 } 1587 }
1586 } 1588 }
1587 1589
1588 } // namespace content 1590 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698