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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 *called = true; | 99 *called = true; |
100 } | 100 } |
101 | 101 |
102 ServiceWorkerUnregisterJob::UnregistrationCallback SaveUnregistration( | 102 ServiceWorkerUnregisterJob::UnregistrationCallback SaveUnregistration( |
103 ServiceWorkerStatusCode expected_status, | 103 ServiceWorkerStatusCode expected_status, |
104 bool* called) { | 104 bool* called) { |
105 *called = false; | 105 *called = false; |
106 return base::Bind(&SaveUnregistrationCallback, expected_status, called); | 106 return base::Bind(&SaveUnregistrationCallback, expected_status, called); |
107 } | 107 } |
108 | 108 |
| 109 ServiceWorkerStatusCode EventResultToStatus( |
| 110 blink::WebServiceWorkerEventResult result) { |
| 111 switch (result) { |
| 112 case blink::WebServiceWorkerEventResultCompleted: |
| 113 return SERVICE_WORKER_OK; |
| 114 case blink::WebServiceWorkerEventResultRejected: |
| 115 return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; |
| 116 } |
| 117 NOTREACHED() << "Got invalid result: " << result; |
| 118 return SERVICE_WORKER_ERROR_FAILED; |
| 119 } |
| 120 |
109 } // namespace | 121 } // namespace |
110 | 122 |
111 class ServiceWorkerJobTest : public testing::Test { | 123 class ServiceWorkerJobTest : public testing::Test { |
112 public: | 124 public: |
113 ServiceWorkerJobTest() | 125 ServiceWorkerJobTest() |
114 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 126 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
115 | 127 |
116 void SetUp() override { | 128 void SetUp() override { |
117 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 129 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
118 } | 130 } |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} | 1465 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} |
1454 | 1466 |
1455 void OnInstallEvent(int embedded_worker_id, | 1467 void OnInstallEvent(int embedded_worker_id, |
1456 int request_id) override { | 1468 int request_id) override { |
1457 if (!install_callback_.is_null()) | 1469 if (!install_callback_.is_null()) |
1458 install_callback_.Run(); | 1470 install_callback_.Run(); |
1459 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 1471 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( |
1460 embedded_worker_id, request_id, install_event_result_, | 1472 embedded_worker_id, request_id, install_event_result_, |
1461 has_fetch_handler_, base::Time::Now())); | 1473 has_fetch_handler_, base::Time::Now())); |
1462 } | 1474 } |
1463 void OnActivateEvent(int embedded_worker_id, int request_id) override { | 1475 |
1464 SimulateSend(new ServiceWorkerHostMsg_ActivateEventFinished( | 1476 void OnActivateEvent( |
1465 embedded_worker_id, request_id, activate_event_result_, | 1477 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& |
1466 base::Time::Now())); | 1478 callback) override { |
| 1479 callback.Run(EventResultToStatus(activate_event_result_), |
| 1480 base::Time::Now()); |
1467 } | 1481 } |
1468 | 1482 |
1469 void set_install_callback(const base::Closure& callback) { | 1483 void set_install_callback(const base::Closure& callback) { |
1470 install_callback_ = callback; | 1484 install_callback_ = callback; |
1471 } | 1485 } |
1472 void set_install_event_result(blink::WebServiceWorkerEventResult result) { | 1486 void set_install_event_result(blink::WebServiceWorkerEventResult result) { |
1473 install_event_result_ = result; | 1487 install_event_result_ = result; |
1474 } | 1488 } |
1475 void set_activate_event_result(blink::WebServiceWorkerEventResult result) { | 1489 void set_activate_event_result(blink::WebServiceWorkerEventResult result) { |
1476 activate_event_result_ = result; | 1490 activate_event_result_ = result; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 // should not be promoted to ACTIVATED because failure occur | 1740 // should not be promoted to ACTIVATED because failure occur |
1727 // during shutdown. | 1741 // during shutdown. |
1728 runner->RunUntilIdle(); | 1742 runner->RunUntilIdle(); |
1729 base::RunLoop().RunUntilIdle(); | 1743 base::RunLoop().RunUntilIdle(); |
1730 EXPECT_EQ(new_version.get(), registration->active_version()); | 1744 EXPECT_EQ(new_version.get(), registration->active_version()); |
1731 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1745 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1732 registration->RemoveListener(update_helper); | 1746 registration->RemoveListener(update_helper); |
1733 } | 1747 } |
1734 | 1748 |
1735 } // namespace content | 1749 } // namespace content |
OLD | NEW |