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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ASSERT_NE(registration1, registration2); | 288 ASSERT_NE(registration1, registration2); |
289 } | 289 } |
290 | 290 |
291 // Make sure basic registration is working. | 291 // Make sure basic registration is working. |
292 TEST_F(ServiceWorkerJobTest, Register) { | 292 TEST_F(ServiceWorkerJobTest, Register) { |
293 scoped_refptr<ServiceWorkerRegistration> registration = | 293 scoped_refptr<ServiceWorkerRegistration> registration = |
294 RunRegisterJob(GURL("http://www.example.com/"), | 294 RunRegisterJob(GURL("http://www.example.com/"), |
295 GURL("http://www.example.com/service_worker.js")); | 295 GURL("http://www.example.com/service_worker.js")); |
296 | 296 |
297 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 297 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
298 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 298 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, |
299 ServiceWorkerMsg_InstallEvent::ID)); | 299 helper_->dispatched_events()->at(0)); |
300 } | 300 } |
301 | 301 |
302 // Make sure registrations are cleaned up when they are unregistered. | 302 // Make sure registrations are cleaned up when they are unregistered. |
303 TEST_F(ServiceWorkerJobTest, Unregister) { | 303 TEST_F(ServiceWorkerJobTest, Unregister) { |
304 GURL pattern("http://www.example.com/"); | 304 GURL pattern("http://www.example.com/"); |
305 | 305 |
306 scoped_refptr<ServiceWorkerRegistration> registration = | 306 scoped_refptr<ServiceWorkerRegistration> registration = |
307 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); | 307 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); |
308 | 308 |
309 RunUnregisterJob(pattern); | 309 RunUnregisterJob(pattern); |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); | 1454 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); |
1455 } | 1455 } |
1456 | 1456 |
1457 class EventCallbackHelper : public EmbeddedWorkerTestHelper { | 1457 class EventCallbackHelper : public EmbeddedWorkerTestHelper { |
1458 public: | 1458 public: |
1459 EventCallbackHelper() | 1459 EventCallbackHelper() |
1460 : EmbeddedWorkerTestHelper(base::FilePath()), | 1460 : EmbeddedWorkerTestHelper(base::FilePath()), |
1461 install_event_result_(blink::WebServiceWorkerEventResultCompleted), | 1461 install_event_result_(blink::WebServiceWorkerEventResultCompleted), |
1462 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} | 1462 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} |
1463 | 1463 |
1464 void OnInstallEvent(int embedded_worker_id, | 1464 void OnInstallEvent( |
1465 int request_id) override { | 1465 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback& |
| 1466 callback) override { |
1466 if (!install_callback_.is_null()) | 1467 if (!install_callback_.is_null()) |
1467 install_callback_.Run(); | 1468 install_callback_.Run(); |
1468 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 1469 dispatched_events()->push_back(Event::Install); |
1469 embedded_worker_id, request_id, install_event_result_, | 1470 callback.Run(EventResultToStatus(install_event_result_), has_fetch_handler_, |
1470 has_fetch_handler_, base::Time::Now())); | 1471 base::Time::Now()); |
1471 } | 1472 } |
1472 | 1473 |
1473 void OnActivateEvent( | 1474 void OnActivateEvent( |
1474 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | 1475 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& |
1475 callback) override { | 1476 callback) override { |
1476 callback.Run(EventResultToStatus(activate_event_result_), | 1477 callback.Run(EventResultToStatus(activate_event_result_), |
1477 base::Time::Now()); | 1478 base::Time::Now()); |
1478 } | 1479 } |
1479 | 1480 |
1480 void set_install_callback(const base::Closure& callback) { | 1481 void set_install_callback(const base::Closure& callback) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 // should not be promoted to ACTIVATED because failure occur | 1738 // should not be promoted to ACTIVATED because failure occur |
1738 // during shutdown. | 1739 // during shutdown. |
1739 runner->RunUntilIdle(); | 1740 runner->RunUntilIdle(); |
1740 base::RunLoop().RunUntilIdle(); | 1741 base::RunLoop().RunUntilIdle(); |
1741 EXPECT_EQ(new_version.get(), registration->active_version()); | 1742 EXPECT_EQ(new_version.get(), registration->active_version()); |
1742 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1743 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1743 registration->RemoveListener(update_helper); | 1744 registration->RemoveListener(update_helper); |
1744 } | 1745 } |
1745 | 1746 |
1746 } // namespace content | 1747 } // namespace content |
OLD | NEW |