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

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

Issue 2027583002: service worker: Avoid starting up for activation during shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: maybe fix win Created 4 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 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"
11 #include "base/test/test_simple_task_runner.h"
11 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/service_worker/embedded_worker_registry.h" 13 #include "content/browser/service_worker/embedded_worker_registry.h"
13 #include "content/browser/service_worker/embedded_worker_test_helper.h" 14 #include "content/browser/service_worker/embedded_worker_test_helper.h"
14 #include "content/browser/service_worker/service_worker_context_core.h" 15 #include "content/browser/service_worker/service_worker_context_core.h"
15 #include "content/browser/service_worker/service_worker_disk_cache.h" 16 #include "content/browser/service_worker/service_worker_disk_cache.h"
16 #include "content/browser/service_worker/service_worker_job_coordinator.h" 17 #include "content/browser/service_worker/service_worker_job_coordinator.h"
17 #include "content/browser/service_worker/service_worker_registration.h" 18 #include "content/browser/service_worker/service_worker_registration.h"
18 #include "content/browser/service_worker/service_worker_registration_status.h" 19 #include "content/browser/service_worker/service_worker_registration_status.h"
19 #include "content/browser/service_worker/service_worker_test_utils.h" 20 #include "content/browser/service_worker/service_worker_test_utils.h"
20 #include "content/common/service_worker/embedded_worker_messages.h" 21 #include "content/common/service_worker/embedded_worker_messages.h"
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 EXPECT_EQ(NULL, registration->installing_version()); 1219 EXPECT_EQ(NULL, registration->installing_version());
1219 } 1220 }
1220 1221
1221 TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { 1222 TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
1222 GURL pattern("http://www.example.com/one/"); 1223 GURL pattern("http://www.example.com/one/");
1223 GURL script1("http://www.example.com/service_worker.js"); 1224 GURL script1("http://www.example.com/service_worker.js");
1224 GURL script2("http://www.example.com/service_worker.js?new"); 1225 GURL script2("http://www.example.com/service_worker.js?new");
1225 1226
1226 scoped_refptr<ServiceWorkerRegistration> registration = 1227 scoped_refptr<ServiceWorkerRegistration> registration =
1227 RunRegisterJob(pattern, script1); 1228 RunRegisterJob(pattern, script1);
1229 scoped_refptr<base::TestSimpleTaskRunner> runner(
1230 new base::TestSimpleTaskRunner());
1231 registration->SetTimerTaskRunnerForTest(runner);
1228 1232
1229 // Add a controllee and queue an unregister to force the uninstalling state. 1233 // Add a controllee and queue an unregister to force the uninstalling state.
1230 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 1234 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
1231 scoped_refptr<ServiceWorkerVersion> old_version = 1235 scoped_refptr<ServiceWorkerVersion> old_version =
1232 registration->active_version(); 1236 registration->active_version();
1233 old_version->AddControllee(host.get()); 1237 old_version->AddControllee(host.get());
1234 RunUnregisterJob(pattern); 1238 RunUnregisterJob(pattern);
1235 1239
1236 // Register another script. 1240 // Register another script.
1237 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); 1241 EXPECT_EQ(registration, RunRegisterJob(pattern, script2));
(...skipping 13 matching lines...) Expand all
1251 old_version->RemoveControllee(host.get()); 1255 old_version->RemoveControllee(host.get());
1252 base::RunLoop().RunUntilIdle(); 1256 base::RunLoop().RunUntilIdle();
1253 1257
1254 EXPECT_FALSE(registration->is_uninstalling()); 1258 EXPECT_FALSE(registration->is_uninstalling());
1255 EXPECT_FALSE(registration->is_uninstalled()); 1259 EXPECT_FALSE(registration->is_uninstalled());
1256 1260
1257 // Verify the new version is activated. 1261 // Verify the new version is activated.
1258 EXPECT_EQ(NULL, registration->installing_version()); 1262 EXPECT_EQ(NULL, registration->installing_version());
1259 EXPECT_EQ(NULL, registration->waiting_version()); 1263 EXPECT_EQ(NULL, registration->waiting_version());
1260 EXPECT_EQ(new_version, registration->active_version()); 1264 EXPECT_EQ(new_version, registration->active_version());
1265 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1266
1267 runner->RunUntilIdle();
1268 base::RunLoop().RunUntilIdle();
1261 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); 1269 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status());
1262 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); 1270 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status());
1263 } 1271 }
1264 1272
1265 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { 1273 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
1266 GURL pattern("http://www.example.com/one/"); 1274 GURL pattern("http://www.example.com/one/");
1267 GURL script1("http://www.example.com/service_worker.js"); 1275 GURL script1("http://www.example.com/service_worker.js");
1268 GURL script2("http://www.example.com/service_worker.js?new"); 1276 GURL script2("http://www.example.com/service_worker.js?new");
1269 1277
1270 scoped_refptr<ServiceWorkerRegistration> registration = 1278 scoped_refptr<ServiceWorkerRegistration> registration =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status()); 1318 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status());
1311 } 1319 }
1312 1320
1313 TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { 1321 TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
1314 GURL pattern("http://www.example.com/one/"); 1322 GURL pattern("http://www.example.com/one/");
1315 GURL script1("http://www.example.com/service_worker.js"); 1323 GURL script1("http://www.example.com/service_worker.js");
1316 GURL script2("http://www.example.com/service_worker.js?new"); 1324 GURL script2("http://www.example.com/service_worker.js?new");
1317 1325
1318 scoped_refptr<ServiceWorkerRegistration> registration = 1326 scoped_refptr<ServiceWorkerRegistration> registration =
1319 RunRegisterJob(pattern, script1); 1327 RunRegisterJob(pattern, script1);
1328 scoped_refptr<base::TestSimpleTaskRunner> runner(
1329 new base::TestSimpleTaskRunner());
1330 registration->SetTimerTaskRunnerForTest(runner);
1320 1331
1321 // Add a controllee and queue an unregister to force the uninstalling state. 1332 // Add a controllee and queue an unregister to force the uninstalling state.
1322 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 1333 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
1323 scoped_refptr<ServiceWorkerVersion> old_version = 1334 scoped_refptr<ServiceWorkerVersion> old_version =
1324 registration->active_version(); 1335 registration->active_version();
1325 old_version->AddControllee(host.get()); 1336 old_version->AddControllee(host.get());
1326 RunUnregisterJob(pattern); 1337 RunUnregisterJob(pattern);
1327 1338
1328 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); 1339 EXPECT_EQ(registration, RunRegisterJob(pattern, script2));
1329 1340
(...skipping 13 matching lines...) Expand all
1343 old_version->RemoveControllee(host.get()); 1354 old_version->RemoveControllee(host.get());
1344 base::RunLoop().RunUntilIdle(); 1355 base::RunLoop().RunUntilIdle();
1345 1356
1346 EXPECT_FALSE(registration->is_uninstalling()); 1357 EXPECT_FALSE(registration->is_uninstalling());
1347 EXPECT_FALSE(registration->is_uninstalled()); 1358 EXPECT_FALSE(registration->is_uninstalled());
1348 1359
1349 // Verify the new version is activated. 1360 // Verify the new version is activated.
1350 EXPECT_EQ(NULL, registration->installing_version()); 1361 EXPECT_EQ(NULL, registration->installing_version());
1351 EXPECT_EQ(NULL, registration->waiting_version()); 1362 EXPECT_EQ(NULL, registration->waiting_version());
1352 EXPECT_EQ(new_version, registration->active_version()); 1363 EXPECT_EQ(new_version, registration->active_version());
1364 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1365
1366 runner->RunPendingTasks();
nhiroki 2016/06/01 05:51:47 Just to confirm: We call Run*Pending*Tasks() here,
falken 2016/06/01 09:20:05 Good catch. Unintentional. RunUntilIdle seems the
1367 base::RunLoop().RunUntilIdle();
1353 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); 1368 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status());
1354 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); 1369 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status());
1355 } 1370 }
1356 1371
1357 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { 1372 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) {
1358 GURL pattern("http://www.example.com/one/"); 1373 GURL pattern("http://www.example.com/one/");
1359 GURL script1("http://www.example.com/service_worker.js?first"); 1374 GURL script1("http://www.example.com/service_worker.js?first");
1360 GURL script2("http://www.example.com/service_worker.js?second"); 1375 GURL script2("http://www.example.com/service_worker.js?second");
1361 GURL script3("http://www.example.com/service_worker.js?third"); 1376 GURL script3("http://www.example.com/service_worker.js?third");
1362 1377
1363 scoped_refptr<ServiceWorkerRegistration> registration = 1378 scoped_refptr<ServiceWorkerRegistration> registration =
1364 RunRegisterJob(pattern, script1); 1379 RunRegisterJob(pattern, script1);
1380 scoped_refptr<base::TestSimpleTaskRunner> runner(
1381 new base::TestSimpleTaskRunner());
1382 registration->SetTimerTaskRunnerForTest(runner);
1365 1383
1366 // Add a controllee and queue an unregister to force the uninstalling state. 1384 // Add a controllee and queue an unregister to force the uninstalling state.
1367 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 1385 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
1368 scoped_refptr<ServiceWorkerVersion> first_version = 1386 scoped_refptr<ServiceWorkerVersion> first_version =
1369 registration->active_version(); 1387 registration->active_version();
1370 first_version->AddControllee(host.get()); 1388 first_version->AddControllee(host.get());
1371 RunUnregisterJob(pattern); 1389 RunUnregisterJob(pattern);
1372 1390
1373 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); 1391 EXPECT_EQ(registration, RunRegisterJob(pattern, script2));
1374 1392
(...skipping 17 matching lines...) Expand all
1392 first_version->RemoveControllee(host.get()); 1410 first_version->RemoveControllee(host.get());
1393 base::RunLoop().RunUntilIdle(); 1411 base::RunLoop().RunUntilIdle();
1394 1412
1395 EXPECT_FALSE(registration->is_uninstalling()); 1413 EXPECT_FALSE(registration->is_uninstalling());
1396 EXPECT_FALSE(registration->is_uninstalled()); 1414 EXPECT_FALSE(registration->is_uninstalled());
1397 1415
1398 // Verify the new version is activated. 1416 // Verify the new version is activated.
1399 EXPECT_EQ(NULL, registration->installing_version()); 1417 EXPECT_EQ(NULL, registration->installing_version());
1400 EXPECT_EQ(NULL, registration->waiting_version()); 1418 EXPECT_EQ(NULL, registration->waiting_version());
1401 EXPECT_EQ(third_version, registration->active_version()); 1419 EXPECT_EQ(third_version, registration->active_version());
1420 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, third_version->status());
1421
1422 runner->RunUntilIdle();
1423 base::RunLoop().RunUntilIdle();
1402 EXPECT_EQ(ServiceWorkerVersion::RUNNING, third_version->running_status()); 1424 EXPECT_EQ(ServiceWorkerVersion::RUNNING, third_version->running_status());
1403 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); 1425 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status());
1404 } 1426 }
1405 1427
1406 class EventCallbackHelper : public EmbeddedWorkerTestHelper { 1428 class EventCallbackHelper : public EmbeddedWorkerTestHelper {
1407 public: 1429 public:
1408 EventCallbackHelper() 1430 EventCallbackHelper()
1409 : EmbeddedWorkerTestHelper(base::FilePath()), 1431 : EmbeddedWorkerTestHelper(base::FilePath()),
1410 install_event_result_(blink::WebServiceWorkerEventResultCompleted), 1432 install_event_result_(blink::WebServiceWorkerEventResultCompleted),
1411 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} 1433 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {}
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 ASSERT_TRUE(start_msg); 1628 ASSERT_TRUE(start_msg);
1607 EmbeddedWorkerMsg_StartWorker::Param param; 1629 EmbeddedWorkerMsg_StartWorker::Param param;
1608 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param); 1630 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param);
1609 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); 1631 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param);
1610 EXPECT_TRUE(start_params.pause_after_download); 1632 EXPECT_TRUE(start_params.pause_after_download);
1611 sink->ClearMessages(); 1633 sink->ClearMessages();
1612 } 1634 }
1613 } 1635 }
1614 1636
1615 } // namespace content 1637 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698