| OLD | NEW |
| 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 #include <tuple> | 6 #include <tuple> |
| 7 | 7 |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/service_worker/embedded_worker_registry.h" | 14 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 15 #include "content/browser/service_worker/embedded_worker_status.h" |
| 15 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 16 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 16 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
| 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 18 #include "content/browser/service_worker/service_worker_disk_cache.h" | 19 #include "content/browser/service_worker/service_worker_disk_cache.h" |
| 19 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 20 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| 20 #include "content/browser/service_worker/service_worker_registration.h" | 21 #include "content/browser/service_worker/service_worker_registration.h" |
| 21 #include "content/browser/service_worker/service_worker_registration_status.h" | 22 #include "content/browser/service_worker/service_worker_registration_status.h" |
| 22 #include "content/browser/service_worker/service_worker_test_utils.h" | 23 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 23 #include "content/common/service_worker/embedded_worker_messages.h" | 24 #include "content/common/service_worker/embedded_worker_messages.h" |
| 24 #include "content/common/service_worker/service_worker_messages.h" | 25 #include "content/common/service_worker/service_worker_messages.h" |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 651 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
| 651 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 652 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); |
| 652 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 653 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 653 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 654 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 654 CreateReceiverOnCurrentThread(&status)); | 655 CreateReceiverOnCurrentThread(&status)); |
| 655 base::RunLoop().RunUntilIdle(); | 656 base::RunLoop().RunUntilIdle(); |
| 656 ASSERT_EQ(SERVICE_WORKER_OK, status); | 657 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 657 | 658 |
| 658 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 659 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 659 registration->SetWaitingVersion(version); | 660 registration->SetWaitingVersion(version); |
| 660 EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 661 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
| 661 version->running_status()); | |
| 662 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 662 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
| 663 | 663 |
| 664 RunUnregisterJob(GURL("http://www.example.com/")); | 664 RunUnregisterJob(GURL("http://www.example.com/")); |
| 665 | 665 |
| 666 // The version should be stopped since there is no controllee after | 666 // The version should be stopped since there is no controllee after |
| 667 // unregistration. | 667 // unregistration. |
| 668 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 668 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); |
| 669 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 669 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
| 670 } | 670 } |
| 671 | 671 |
| 672 // Tests that the active worker enters the 'redundant' state upon | 672 // Tests that the active worker enters the 'redundant' state upon |
| 673 // unregistration. | 673 // unregistration. |
| 674 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { | 674 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { |
| 675 scoped_refptr<ServiceWorkerRegistration> registration = | 675 scoped_refptr<ServiceWorkerRegistration> registration = |
| 676 RunRegisterJob(GURL("http://www.example.com/"), | 676 RunRegisterJob(GURL("http://www.example.com/"), |
| 677 GURL("http://www.example.com/service_worker.js")); | 677 GURL("http://www.example.com/service_worker.js")); |
| 678 ASSERT_TRUE(registration.get()); | 678 ASSERT_TRUE(registration.get()); |
| 679 | 679 |
| 680 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 680 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
| 681 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 681 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
| 682 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 682 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 683 | 683 |
| 684 RunUnregisterJob(GURL("http://www.example.com/")); | 684 RunUnregisterJob(GURL("http://www.example.com/")); |
| 685 | 685 |
| 686 // The version should be stopped since there is no controllee after | 686 // The version should be stopped since there is no controllee after |
| 687 // unregistration. | 687 // unregistration. |
| 688 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 688 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); |
| 689 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 689 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
| 690 } | 690 } |
| 691 | 691 |
| 692 // Tests that the active worker enters the 'redundant' state upon | 692 // Tests that the active worker enters the 'redundant' state upon |
| 693 // unregistration. | 693 // unregistration. |
| 694 TEST_F(ServiceWorkerJobTest, | 694 TEST_F(ServiceWorkerJobTest, |
| 695 UnregisterActiveSetsRedundant_WaitForNoControllee) { | 695 UnregisterActiveSetsRedundant_WaitForNoControllee) { |
| 696 scoped_refptr<ServiceWorkerRegistration> registration = | 696 scoped_refptr<ServiceWorkerRegistration> registration = |
| 697 RunRegisterJob(GURL("http://www.example.com/"), | 697 RunRegisterJob(GURL("http://www.example.com/"), |
| 698 GURL("http://www.example.com/service_worker.js")); | 698 GURL("http://www.example.com/service_worker.js")); |
| 699 ASSERT_TRUE(registration.get()); | 699 ASSERT_TRUE(registration.get()); |
| 700 | 700 |
| 701 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); | 701 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); |
| 702 registration->active_version()->AddControllee(host.get()); | 702 registration->active_version()->AddControllee(host.get()); |
| 703 | 703 |
| 704 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 704 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
| 705 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 705 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
| 706 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 706 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 707 | 707 |
| 708 RunUnregisterJob(GURL("http://www.example.com/")); | 708 RunUnregisterJob(GURL("http://www.example.com/")); |
| 709 | 709 |
| 710 // The version should be running since there is still a controllee. | 710 // The version should be running since there is still a controllee. |
| 711 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 711 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
| 712 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 712 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 713 | 713 |
| 714 registration->active_version()->RemoveControllee(host.get()); | 714 registration->active_version()->RemoveControllee(host.get()); |
| 715 base::RunLoop().RunUntilIdle(); | 715 base::RunLoop().RunUntilIdle(); |
| 716 | 716 |
| 717 // The version should be stopped since there is no controllee. | 717 // The version should be stopped since there is no controllee. |
| 718 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 718 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); |
| 719 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 719 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
| 720 } | 720 } |
| 721 | 721 |
| 722 namespace { // Helpers for the update job tests. | 722 namespace { // Helpers for the update job tests. |
| 723 | 723 |
| 724 const GURL kNoChangeOrigin("http://nochange/"); | 724 const GURL kNoChangeOrigin("http://nochange/"); |
| 725 const GURL kNewVersionOrigin("http://newversion/"); | 725 const GURL kNewVersionOrigin("http://newversion/"); |
| 726 const std::string kScope("scope/"); | 726 const std::string kScope("scope/"); |
| 727 const std::string kScript("script.js"); | 727 const std::string kScript("script.js"); |
| 728 | 728 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1245 |
| 1246 EXPECT_FALSE(registration->is_uninstalling()); | 1246 EXPECT_FALSE(registration->is_uninstalling()); |
| 1247 EXPECT_EQ(old_version, registration->active_version()); | 1247 EXPECT_EQ(old_version, registration->active_version()); |
| 1248 | 1248 |
| 1249 scoped_refptr<ServiceWorkerVersion> new_version = | 1249 scoped_refptr<ServiceWorkerVersion> new_version = |
| 1250 registration->waiting_version(); | 1250 registration->waiting_version(); |
| 1251 | 1251 |
| 1252 // Verify the new version is installed but not activated yet. | 1252 // Verify the new version is installed but not activated yet. |
| 1253 EXPECT_EQ(NULL, registration->installing_version()); | 1253 EXPECT_EQ(NULL, registration->installing_version()); |
| 1254 EXPECT_TRUE(new_version); | 1254 EXPECT_TRUE(new_version); |
| 1255 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); | 1255 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
| 1256 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); | 1256 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); |
| 1257 | 1257 |
| 1258 old_version->RemoveControllee(host.get()); | 1258 old_version->RemoveControllee(host.get()); |
| 1259 base::RunLoop().RunUntilIdle(); | 1259 base::RunLoop().RunUntilIdle(); |
| 1260 | 1260 |
| 1261 EXPECT_FALSE(registration->is_uninstalling()); | 1261 EXPECT_FALSE(registration->is_uninstalling()); |
| 1262 EXPECT_FALSE(registration->is_uninstalled()); | 1262 EXPECT_FALSE(registration->is_uninstalled()); |
| 1263 | 1263 |
| 1264 // Verify the new version is activated. | 1264 // Verify the new version is activated. |
| 1265 EXPECT_EQ(NULL, registration->installing_version()); | 1265 EXPECT_EQ(NULL, registration->installing_version()); |
| 1266 EXPECT_EQ(NULL, registration->waiting_version()); | 1266 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1267 EXPECT_EQ(new_version, registration->active_version()); | 1267 EXPECT_EQ(new_version, registration->active_version()); |
| 1268 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1268 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
| 1269 | 1269 |
| 1270 runner->RunUntilIdle(); | 1270 runner->RunUntilIdle(); |
| 1271 base::RunLoop().RunUntilIdle(); | 1271 base::RunLoop().RunUntilIdle(); |
| 1272 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); | 1272 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
| 1273 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1273 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { | 1276 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { |
| 1277 GURL pattern("http://www.example.com/one/"); | 1277 GURL pattern("http://www.example.com/one/"); |
| 1278 GURL script1("http://www.example.com/service_worker.js"); | 1278 GURL script1("http://www.example.com/service_worker.js"); |
| 1279 GURL script2("http://www.example.com/service_worker.js?new"); | 1279 GURL script2("http://www.example.com/service_worker.js?new"); |
| 1280 | 1280 |
| 1281 scoped_refptr<ServiceWorkerRegistration> registration = | 1281 scoped_refptr<ServiceWorkerRegistration> registration = |
| 1282 RunRegisterJob(pattern, script1); | 1282 RunRegisterJob(pattern, script1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1297 | 1297 |
| 1298 // Unregister the registration (but it's still live). | 1298 // Unregister the registration (but it's still live). |
| 1299 RunUnregisterJob(pattern); | 1299 RunUnregisterJob(pattern); |
| 1300 // Now it's not found in the storage. | 1300 // Now it's not found in the storage. |
| 1301 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); | 1301 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
| 1302 | 1302 |
| 1303 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); | 1303 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
| 1304 EXPECT_TRUE(registration->is_uninstalling()); | 1304 EXPECT_TRUE(registration->is_uninstalling()); |
| 1305 EXPECT_EQ(old_version, registration->active_version()); | 1305 EXPECT_EQ(old_version, registration->active_version()); |
| 1306 | 1306 |
| 1307 EXPECT_EQ(ServiceWorkerVersion::RUNNING, old_version->running_status()); | 1307 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, old_version->running_status()); |
| 1308 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, old_version->status()); | 1308 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, old_version->status()); |
| 1309 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); | 1309 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
| 1310 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); | 1310 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); |
| 1311 | 1311 |
| 1312 old_version->RemoveControllee(host.get()); | 1312 old_version->RemoveControllee(host.get()); |
| 1313 base::RunLoop().RunUntilIdle(); | 1313 base::RunLoop().RunUntilIdle(); |
| 1314 | 1314 |
| 1315 EXPECT_FALSE(registration->is_uninstalling()); | 1315 EXPECT_FALSE(registration->is_uninstalling()); |
| 1316 EXPECT_TRUE(registration->is_uninstalled()); | 1316 EXPECT_TRUE(registration->is_uninstalled()); |
| 1317 | 1317 |
| 1318 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1318 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); |
| 1319 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1319 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
| 1320 EXPECT_EQ(ServiceWorkerVersion::STOPPED, new_version->running_status()); | 1320 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, new_version->running_status()); |
| 1321 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status()); | 1321 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status()); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { | 1324 TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { |
| 1325 GURL pattern("http://www.example.com/one/"); | 1325 GURL pattern("http://www.example.com/one/"); |
| 1326 GURL script1("http://www.example.com/service_worker.js"); | 1326 GURL script1("http://www.example.com/service_worker.js"); |
| 1327 GURL script2("http://www.example.com/service_worker.js?new"); | 1327 GURL script2("http://www.example.com/service_worker.js?new"); |
| 1328 | 1328 |
| 1329 scoped_refptr<ServiceWorkerRegistration> registration = | 1329 scoped_refptr<ServiceWorkerRegistration> registration = |
| 1330 RunRegisterJob(pattern, script1); | 1330 RunRegisterJob(pattern, script1); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1361 EXPECT_FALSE(registration->is_uninstalled()); | 1361 EXPECT_FALSE(registration->is_uninstalled()); |
| 1362 | 1362 |
| 1363 // Verify the new version is activated. | 1363 // Verify the new version is activated. |
| 1364 EXPECT_EQ(NULL, registration->installing_version()); | 1364 EXPECT_EQ(NULL, registration->installing_version()); |
| 1365 EXPECT_EQ(NULL, registration->waiting_version()); | 1365 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1366 EXPECT_EQ(new_version, registration->active_version()); | 1366 EXPECT_EQ(new_version, registration->active_version()); |
| 1367 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1367 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
| 1368 | 1368 |
| 1369 runner->RunUntilIdle(); | 1369 runner->RunUntilIdle(); |
| 1370 base::RunLoop().RunUntilIdle(); | 1370 base::RunLoop().RunUntilIdle(); |
| 1371 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); | 1371 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
| 1372 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1372 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { | 1375 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { |
| 1376 GURL pattern("http://www.example.com/one/"); | 1376 GURL pattern("http://www.example.com/one/"); |
| 1377 GURL script1("http://www.example.com/service_worker.js?first"); | 1377 GURL script1("http://www.example.com/service_worker.js?first"); |
| 1378 GURL script2("http://www.example.com/service_worker.js?second"); | 1378 GURL script2("http://www.example.com/service_worker.js?second"); |
| 1379 GURL script3("http://www.example.com/service_worker.js?third"); | 1379 GURL script3("http://www.example.com/service_worker.js?third"); |
| 1380 | 1380 |
| 1381 scoped_refptr<ServiceWorkerRegistration> registration = | 1381 scoped_refptr<ServiceWorkerRegistration> registration = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 EXPECT_FALSE(registration->is_uninstalled()); | 1417 EXPECT_FALSE(registration->is_uninstalled()); |
| 1418 | 1418 |
| 1419 // Verify the new version is activated. | 1419 // Verify the new version is activated. |
| 1420 EXPECT_EQ(NULL, registration->installing_version()); | 1420 EXPECT_EQ(NULL, registration->installing_version()); |
| 1421 EXPECT_EQ(NULL, registration->waiting_version()); | 1421 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1422 EXPECT_EQ(third_version, registration->active_version()); | 1422 EXPECT_EQ(third_version, registration->active_version()); |
| 1423 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, third_version->status()); | 1423 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, third_version->status()); |
| 1424 | 1424 |
| 1425 runner->RunUntilIdle(); | 1425 runner->RunUntilIdle(); |
| 1426 base::RunLoop().RunUntilIdle(); | 1426 base::RunLoop().RunUntilIdle(); |
| 1427 EXPECT_EQ(ServiceWorkerVersion::RUNNING, third_version->running_status()); | 1427 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, third_version->running_status()); |
| 1428 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); | 1428 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 class EventCallbackHelper : public EmbeddedWorkerTestHelper { | 1431 class EventCallbackHelper : public EmbeddedWorkerTestHelper { |
| 1432 public: | 1432 public: |
| 1433 EventCallbackHelper() | 1433 EventCallbackHelper() |
| 1434 : EmbeddedWorkerTestHelper(base::FilePath()), | 1434 : EmbeddedWorkerTestHelper(base::FilePath()), |
| 1435 install_event_result_(blink::WebServiceWorkerEventResultCompleted), | 1435 install_event_result_(blink::WebServiceWorkerEventResultCompleted), |
| 1436 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} | 1436 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} |
| 1437 | 1437 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 EXPECT_FALSE(registration->is_uninstalling()); | 1496 EXPECT_FALSE(registration->is_uninstalling()); |
| 1497 EXPECT_FALSE(registration->is_uninstalled()); | 1497 EXPECT_FALSE(registration->is_uninstalled()); |
| 1498 | 1498 |
| 1499 // Verify the new version is activated. | 1499 // Verify the new version is activated. |
| 1500 scoped_refptr<ServiceWorkerVersion> new_version = | 1500 scoped_refptr<ServiceWorkerVersion> new_version = |
| 1501 registration->active_version(); | 1501 registration->active_version(); |
| 1502 EXPECT_NE(old_version, new_version); | 1502 EXPECT_NE(old_version, new_version); |
| 1503 EXPECT_EQ(NULL, registration->installing_version()); | 1503 EXPECT_EQ(NULL, registration->installing_version()); |
| 1504 EXPECT_EQ(NULL, registration->waiting_version()); | 1504 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1505 EXPECT_EQ(new_version, registration->active_version()); | 1505 EXPECT_EQ(new_version, registration->active_version()); |
| 1506 EXPECT_EQ(ServiceWorkerVersion::RUNNING, new_version->running_status()); | 1506 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
| 1507 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1507 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
| 1508 | 1508 |
| 1509 EXPECT_EQ(registration, FindRegistrationForPattern(pattern)); | 1509 EXPECT_EQ(registration, FindRegistrationForPattern(pattern)); |
| 1510 } | 1510 } |
| 1511 | 1511 |
| 1512 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) { | 1512 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) { |
| 1513 EventCallbackHelper* helper = new EventCallbackHelper; | 1513 EventCallbackHelper* helper = new EventCallbackHelper; |
| 1514 helper_.reset(helper); | 1514 helper_.reset(helper); |
| 1515 | 1515 |
| 1516 GURL pattern("http://www.example.com/one/"); | 1516 GURL pattern("http://www.example.com/one/"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1532 helper->set_install_callback( | 1532 helper->set_install_callback( |
| 1533 base::Bind(&ServiceWorkerVersion::RemoveControllee, | 1533 base::Bind(&ServiceWorkerVersion::RemoveControllee, |
| 1534 old_version, host.get())); | 1534 old_version, host.get())); |
| 1535 helper->set_install_event_result(blink::WebServiceWorkerEventResultRejected); | 1535 helper->set_install_event_result(blink::WebServiceWorkerEventResultRejected); |
| 1536 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); | 1536 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); |
| 1537 | 1537 |
| 1538 // Verify the registration was uninstalled. | 1538 // Verify the registration was uninstalled. |
| 1539 EXPECT_FALSE(registration->is_uninstalling()); | 1539 EXPECT_FALSE(registration->is_uninstalling()); |
| 1540 EXPECT_TRUE(registration->is_uninstalled()); | 1540 EXPECT_TRUE(registration->is_uninstalled()); |
| 1541 | 1541 |
| 1542 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1542 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); |
| 1543 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1543 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
| 1544 | 1544 |
| 1545 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); | 1545 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
| 1546 } | 1546 } |
| 1547 | 1547 |
| 1548 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall_RejectActivate) { | 1548 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall_RejectActivate) { |
| 1549 EventCallbackHelper* helper = new EventCallbackHelper; | 1549 EventCallbackHelper* helper = new EventCallbackHelper; |
| 1550 helper_.reset(helper); | 1550 helper_.reset(helper); |
| 1551 | 1551 |
| 1552 GURL pattern("http://www.example.com/one/"); | 1552 GURL pattern("http://www.example.com/one/"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1568 helper->set_install_callback( | 1568 helper->set_install_callback( |
| 1569 base::Bind(&ServiceWorkerVersion::RemoveControllee, | 1569 base::Bind(&ServiceWorkerVersion::RemoveControllee, |
| 1570 old_version, host.get())); | 1570 old_version, host.get())); |
| 1571 helper->set_activate_event_result(blink::WebServiceWorkerEventResultRejected); | 1571 helper->set_activate_event_result(blink::WebServiceWorkerEventResultRejected); |
| 1572 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); | 1572 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); |
| 1573 | 1573 |
| 1574 // Verify the registration remains. | 1574 // Verify the registration remains. |
| 1575 EXPECT_FALSE(registration->is_uninstalling()); | 1575 EXPECT_FALSE(registration->is_uninstalling()); |
| 1576 EXPECT_FALSE(registration->is_uninstalled()); | 1576 EXPECT_FALSE(registration->is_uninstalled()); |
| 1577 | 1577 |
| 1578 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1578 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); |
| 1579 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1579 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
| 1580 | 1580 |
| 1581 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); | 1581 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); |
| 1582 } | 1582 } |
| 1583 | 1583 |
| 1584 TEST_F(ServiceWorkerJobTest, HasFetchHandler) { | 1584 TEST_F(ServiceWorkerJobTest, HasFetchHandler) { |
| 1585 EventCallbackHelper* helper = new EventCallbackHelper; | 1585 EventCallbackHelper* helper = new EventCallbackHelper; |
| 1586 helper_.reset(helper); | 1586 helper_.reset(helper); |
| 1587 | 1587 |
| 1588 GURL pattern("http://www.example.com/"); | 1588 GURL pattern("http://www.example.com/"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 // should not be promoted to ACTIVATED because failure occur | 1688 // should not be promoted to ACTIVATED because failure occur |
| 1689 // during shutdown. | 1689 // during shutdown. |
| 1690 runner->RunUntilIdle(); | 1690 runner->RunUntilIdle(); |
| 1691 base::RunLoop().RunUntilIdle(); | 1691 base::RunLoop().RunUntilIdle(); |
| 1692 EXPECT_EQ(new_version.get(), registration->active_version()); | 1692 EXPECT_EQ(new_version.get(), registration->active_version()); |
| 1693 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1693 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
| 1694 registration->RemoveListener(update_helper); | 1694 registration->RemoveListener(update_helper); |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 } // namespace content | 1697 } // namespace content |
| OLD | NEW |