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_has_fetch_handler(true); |
660 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 661 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
661 registration->SetWaitingVersion(version); | 662 registration->SetWaitingVersion(version); |
662 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); | 663 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); |
663 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 664 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
664 | 665 |
665 RunUnregisterJob(GURL("http://www.example.com/")); | 666 RunUnregisterJob(GURL("http://www.example.com/")); |
666 | 667 |
667 // The version should be stopped since there is no controllee after | 668 // The version should be stopped since there is no controllee after |
668 // unregistration. | 669 // unregistration. |
669 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); | 670 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; | 1587 EventCallbackHelper* helper = new EventCallbackHelper; |
1587 helper_.reset(helper); | 1588 helper_.reset(helper); |
1588 | 1589 |
1589 GURL pattern("http://www.example.com/"); | 1590 GURL pattern("http://www.example.com/"); |
1590 GURL script("http://www.example.com/service_worker.js"); | 1591 GURL script("http://www.example.com/service_worker.js"); |
1591 scoped_refptr<ServiceWorkerRegistration> registration; | 1592 scoped_refptr<ServiceWorkerRegistration> registration; |
1592 | 1593 |
1593 helper->set_has_fetch_handler(true); | 1594 helper->set_has_fetch_handler(true); |
1594 RunRegisterJob(pattern, script); | 1595 RunRegisterJob(pattern, script); |
1595 registration = FindRegistrationForPattern(pattern); | 1596 registration = FindRegistrationForPattern(pattern); |
1596 EXPECT_TRUE(registration->active_version()->has_fetch_handler()); | 1597 EXPECT_TRUE(registration->active_version()->has_fetch_handler().value()); |
1597 RunUnregisterJob(pattern); | 1598 RunUnregisterJob(pattern); |
1598 | 1599 |
1599 helper->set_has_fetch_handler(false); | 1600 helper->set_has_fetch_handler(false); |
1600 RunRegisterJob(pattern, script); | 1601 RunRegisterJob(pattern, script); |
1601 registration = FindRegistrationForPattern(pattern); | 1602 registration = FindRegistrationForPattern(pattern); |
1602 EXPECT_FALSE(registration->active_version()->has_fetch_handler()); | 1603 EXPECT_FALSE(registration->active_version()->has_fetch_handler().value()); |
1603 RunUnregisterJob(pattern); | 1604 RunUnregisterJob(pattern); |
1604 } | 1605 } |
1605 | 1606 |
1606 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 1607 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |
1607 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1608 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
1608 helper_.reset(update_helper); | 1609 helper_.reset(update_helper); |
1609 IPC::TestSink* sink = update_helper->ipc_sink(); | 1610 IPC::TestSink* sink = update_helper->ipc_sink(); |
1610 | 1611 |
1611 // The initial version should not pause after download. | 1612 // The initial version should not pause after download. |
1612 scoped_refptr<ServiceWorkerRegistration> registration = | 1613 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 | 1690 // should not be promoted to ACTIVATED because failure occur |
1690 // during shutdown. | 1691 // during shutdown. |
1691 runner->RunUntilIdle(); | 1692 runner->RunUntilIdle(); |
1692 base::RunLoop().RunUntilIdle(); | 1693 base::RunLoop().RunUntilIdle(); |
1693 EXPECT_EQ(new_version.get(), registration->active_version()); | 1694 EXPECT_EQ(new_version.get(), registration->active_version()); |
1694 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1695 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1695 registration->RemoveListener(update_helper); | 1696 registration->RemoveListener(update_helper); |
1696 } | 1697 } |
1697 | 1698 |
1698 } // namespace content | 1699 } // namespace content |
OLD | NEW |