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