| 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 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 public: | 1407 public: |
| 1408 EventCallbackHelper() | 1408 EventCallbackHelper() |
| 1409 : EmbeddedWorkerTestHelper(base::FilePath()), | 1409 : EmbeddedWorkerTestHelper(base::FilePath()), |
| 1410 install_event_result_(blink::WebServiceWorkerEventResultCompleted), | 1410 install_event_result_(blink::WebServiceWorkerEventResultCompleted), |
| 1411 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} | 1411 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} |
| 1412 | 1412 |
| 1413 void OnInstallEvent(int embedded_worker_id, | 1413 void OnInstallEvent(int embedded_worker_id, |
| 1414 int request_id) override { | 1414 int request_id) override { |
| 1415 if (!install_callback_.is_null()) | 1415 if (!install_callback_.is_null()) |
| 1416 install_callback_.Run(); | 1416 install_callback_.Run(); |
| 1417 SimulateSend( | 1417 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( |
| 1418 new ServiceWorkerHostMsg_InstallEventFinished( | 1418 embedded_worker_id, request_id, install_event_result_, |
| 1419 embedded_worker_id, request_id, install_event_result_)); | 1419 has_fetch_handler_)); |
| 1420 } | 1420 } |
| 1421 void OnActivateEvent(int embedded_worker_id, int request_id) override { | 1421 void OnActivateEvent(int embedded_worker_id, int request_id) override { |
| 1422 SimulateSend( | 1422 SimulateSend( |
| 1423 new ServiceWorkerHostMsg_ActivateEventFinished( | 1423 new ServiceWorkerHostMsg_ActivateEventFinished( |
| 1424 embedded_worker_id, request_id, activate_event_result_)); | 1424 embedded_worker_id, request_id, activate_event_result_)); |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 void set_install_callback(const base::Closure& callback) { | 1427 void set_install_callback(const base::Closure& callback) { |
| 1428 install_callback_ = callback; | 1428 install_callback_ = callback; |
| 1429 } | 1429 } |
| 1430 void set_install_event_result(blink::WebServiceWorkerEventResult result) { | 1430 void set_install_event_result(blink::WebServiceWorkerEventResult result) { |
| 1431 install_event_result_ = result; | 1431 install_event_result_ = result; |
| 1432 } | 1432 } |
| 1433 void set_activate_event_result(blink::WebServiceWorkerEventResult result) { | 1433 void set_activate_event_result(blink::WebServiceWorkerEventResult result) { |
| 1434 activate_event_result_ = result; | 1434 activate_event_result_ = result; |
| 1435 } | 1435 } |
| 1436 void set_has_fetch_handler(bool has_fetch_handler) { |
| 1437 has_fetch_handler_ = has_fetch_handler; |
| 1438 } |
| 1436 | 1439 |
| 1437 private: | 1440 private: |
| 1438 base::Closure install_callback_; | 1441 base::Closure install_callback_; |
| 1439 blink::WebServiceWorkerEventResult install_event_result_; | 1442 blink::WebServiceWorkerEventResult install_event_result_; |
| 1440 blink::WebServiceWorkerEventResult activate_event_result_; | 1443 blink::WebServiceWorkerEventResult activate_event_result_; |
| 1444 bool has_fetch_handler_ = true; |
| 1441 }; | 1445 }; |
| 1442 | 1446 |
| 1443 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall) { | 1447 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall) { |
| 1444 EventCallbackHelper* helper = new EventCallbackHelper; | 1448 EventCallbackHelper* helper = new EventCallbackHelper; |
| 1445 helper_.reset(helper); | 1449 helper_.reset(helper); |
| 1446 | 1450 |
| 1447 GURL pattern("http://www.example.com/one/"); | 1451 GURL pattern("http://www.example.com/one/"); |
| 1448 GURL script1("http://www.example.com/service_worker.js"); | 1452 GURL script1("http://www.example.com/service_worker.js"); |
| 1449 GURL script2("http://www.example.com/service_worker.js?new"); | 1453 GURL script2("http://www.example.com/service_worker.js?new"); |
| 1450 | 1454 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 // Verify the registration remains. | 1549 // Verify the registration remains. |
| 1546 EXPECT_FALSE(registration->is_uninstalling()); | 1550 EXPECT_FALSE(registration->is_uninstalling()); |
| 1547 EXPECT_FALSE(registration->is_uninstalled()); | 1551 EXPECT_FALSE(registration->is_uninstalled()); |
| 1548 | 1552 |
| 1549 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1553 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); |
| 1550 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1554 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
| 1551 | 1555 |
| 1552 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); | 1556 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); |
| 1553 } | 1557 } |
| 1554 | 1558 |
| 1559 TEST_F(ServiceWorkerJobTest, HasFetchHandler) { |
| 1560 EventCallbackHelper* helper = new EventCallbackHelper; |
| 1561 helper_.reset(helper); |
| 1562 |
| 1563 GURL pattern("http://www.example.com/"); |
| 1564 GURL script("http://www.example.com/service_worker.js"); |
| 1565 scoped_refptr<ServiceWorkerRegistration> registration; |
| 1566 |
| 1567 helper->set_has_fetch_handler(true); |
| 1568 RunRegisterJob(pattern, script); |
| 1569 registration = FindRegistrationForPattern(pattern); |
| 1570 EXPECT_TRUE(registration->active_version()->has_fetch_handler()); |
| 1571 RunUnregisterJob(pattern); |
| 1572 |
| 1573 helper->set_has_fetch_handler(false); |
| 1574 RunRegisterJob(pattern, script); |
| 1575 registration = FindRegistrationForPattern(pattern); |
| 1576 EXPECT_FALSE(registration->active_version()->has_fetch_handler()); |
| 1577 RunUnregisterJob(pattern); |
| 1578 } |
| 1579 |
| 1555 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 1580 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |
| 1556 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1581 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
| 1557 helper_.reset(update_helper); | 1582 helper_.reset(update_helper); |
| 1558 IPC::TestSink* sink = update_helper->ipc_sink(); | 1583 IPC::TestSink* sink = update_helper->ipc_sink(); |
| 1559 | 1584 |
| 1560 // The initial version should not pause after download. | 1585 // The initial version should not pause after download. |
| 1561 scoped_refptr<ServiceWorkerRegistration> registration = | 1586 scoped_refptr<ServiceWorkerRegistration> registration = |
| 1562 update_helper->SetupInitialRegistration(kNewVersionOrigin); | 1587 update_helper->SetupInitialRegistration(kNewVersionOrigin); |
| 1563 { | 1588 { |
| 1564 const IPC::Message* start_msg = | 1589 const IPC::Message* start_msg = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1581 ASSERT_TRUE(start_msg); | 1606 ASSERT_TRUE(start_msg); |
| 1582 EmbeddedWorkerMsg_StartWorker::Param param; | 1607 EmbeddedWorkerMsg_StartWorker::Param param; |
| 1583 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); | 1608 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); |
| 1584 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); | 1609 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); |
| 1585 EXPECT_TRUE(start_params.pause_after_download); | 1610 EXPECT_TRUE(start_params.pause_after_download); |
| 1586 sink->ClearMessages(); | 1611 sink->ClearMessages(); |
| 1587 } | 1612 } |
| 1588 } | 1613 } |
| 1589 | 1614 |
| 1590 } // namespace content | 1615 } // namespace content |
| OLD | NEW |