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" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 // Manually create the waiting worker since there is no way to become a | 650 // Manually create the waiting worker since there is no way to become a |
651 // waiting worker until Update is implemented. | 651 // waiting worker until Update is implemented. |
652 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 652 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
653 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 653 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); |
654 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 654 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
655 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 655 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
656 CreateReceiverOnCurrentThread(&status)); | 656 CreateReceiverOnCurrentThread(&status)); |
657 base::RunLoop().RunUntilIdle(); | 657 base::RunLoop().RunUntilIdle(); |
658 ASSERT_EQ(SERVICE_WORKER_OK, status); | 658 ASSERT_EQ(SERVICE_WORKER_OK, status); |
659 | 659 |
| 660 version->set_fetch_handler_existence( |
| 661 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
660 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 662 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
661 registration->SetWaitingVersion(version); | 663 registration->SetWaitingVersion(version); |
662 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); | 664 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
663 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 665 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
664 | 666 |
665 RunUnregisterJob(GURL("http://www.example.com/")); | 667 RunUnregisterJob(GURL("http://www.example.com/")); |
666 | 668 |
667 // The version should be stopped since there is no controllee after | 669 // The version should be stopped since there is no controllee after |
668 // unregistration. | 670 // unregistration. |
669 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); | 671 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1586 EventCallbackHelper* helper = new EventCallbackHelper; | 1588 EventCallbackHelper* helper = new EventCallbackHelper; |
1587 helper_.reset(helper); | 1589 helper_.reset(helper); |
1588 | 1590 |
1589 GURL pattern("http://www.example.com/"); | 1591 GURL pattern("http://www.example.com/"); |
1590 GURL script("http://www.example.com/service_worker.js"); | 1592 GURL script("http://www.example.com/service_worker.js"); |
1591 scoped_refptr<ServiceWorkerRegistration> registration; | 1593 scoped_refptr<ServiceWorkerRegistration> registration; |
1592 | 1594 |
1593 helper->set_has_fetch_handler(true); | 1595 helper->set_has_fetch_handler(true); |
1594 RunRegisterJob(pattern, script); | 1596 RunRegisterJob(pattern, script); |
1595 registration = FindRegistrationForPattern(pattern); | 1597 registration = FindRegistrationForPattern(pattern); |
1596 EXPECT_TRUE(registration->active_version()->has_fetch_handler()); | 1598 EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::EXISTS, |
| 1599 registration->active_version()->fetch_handler_existence()); |
1597 RunUnregisterJob(pattern); | 1600 RunUnregisterJob(pattern); |
1598 | 1601 |
1599 helper->set_has_fetch_handler(false); | 1602 helper->set_has_fetch_handler(false); |
1600 RunRegisterJob(pattern, script); | 1603 RunRegisterJob(pattern, script); |
1601 registration = FindRegistrationForPattern(pattern); | 1604 registration = FindRegistrationForPattern(pattern); |
1602 EXPECT_FALSE(registration->active_version()->has_fetch_handler()); | 1605 EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST, |
| 1606 registration->active_version()->fetch_handler_existence()); |
1603 RunUnregisterJob(pattern); | 1607 RunUnregisterJob(pattern); |
1604 } | 1608 } |
1605 | 1609 |
1606 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 1610 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |
1607 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1611 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
1608 helper_.reset(update_helper); | 1612 helper_.reset(update_helper); |
1609 IPC::TestSink* sink = update_helper->ipc_sink(); | 1613 IPC::TestSink* sink = update_helper->ipc_sink(); |
1610 | 1614 |
1611 // The initial version should not pause after download. | 1615 // The initial version should not pause after download. |
1612 scoped_refptr<ServiceWorkerRegistration> registration = | 1616 scoped_refptr<ServiceWorkerRegistration> registration = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 // should not be promoted to ACTIVATED because failure occur | 1693 // should not be promoted to ACTIVATED because failure occur |
1690 // during shutdown. | 1694 // during shutdown. |
1691 runner->RunUntilIdle(); | 1695 runner->RunUntilIdle(); |
1692 base::RunLoop().RunUntilIdle(); | 1696 base::RunLoop().RunUntilIdle(); |
1693 EXPECT_EQ(new_version.get(), registration->active_version()); | 1697 EXPECT_EQ(new_version.get(), registration->active_version()); |
1694 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1698 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1695 registration->RemoveListener(update_helper); | 1699 registration->RemoveListener(update_helper); |
1696 } | 1700 } |
1697 | 1701 |
1698 } // namespace content | 1702 } // namespace content |
OLD | NEW |