Chromium Code Reviews| 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 scoped_refptr<ServiceWorkerVersion> version; | |
| 1567 | |
| 1568 helper->set_has_fetch_handler(true); | |
| 1569 registration = RunRegisterJob(pattern, script); | |
| 1570 version = registration->active_version(); | |
| 1571 EXPECT_TRUE(version->has_fetch_handler()); | |
| 1572 | |
| 1573 registration = FindRegistrationForPattern(pattern); | |
|
falken
2016/05/25 04:30:17
I think FindRegistraitonForPattern will ultimately
shimazu
2016/05/25 07:22:39
Done.
| |
| 1574 version = registration->active_version(); | |
| 1575 EXPECT_TRUE(version->has_fetch_handler()); | |
| 1576 RunUnregisterJob(pattern); | |
| 1577 | |
| 1578 helper->set_has_fetch_handler(false); | |
| 1579 registration = RunRegisterJob(pattern, script); | |
| 1580 version = registration->active_version(); | |
| 1581 EXPECT_FALSE(version->has_fetch_handler()); | |
| 1582 | |
| 1583 registration = FindRegistrationForPattern(pattern); | |
| 1584 version = registration->active_version(); | |
| 1585 EXPECT_FALSE(version->has_fetch_handler()); | |
| 1586 RunUnregisterJob(pattern); | |
| 1587 } | |
| 1588 | |
| 1555 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 1589 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |
| 1556 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1590 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
| 1557 helper_.reset(update_helper); | 1591 helper_.reset(update_helper); |
| 1558 IPC::TestSink* sink = update_helper->ipc_sink(); | 1592 IPC::TestSink* sink = update_helper->ipc_sink(); |
| 1559 | 1593 |
| 1560 // The initial version should not pause after download. | 1594 // The initial version should not pause after download. |
| 1561 scoped_refptr<ServiceWorkerRegistration> registration = | 1595 scoped_refptr<ServiceWorkerRegistration> registration = |
| 1562 update_helper->SetupInitialRegistration(kNewVersionOrigin); | 1596 update_helper->SetupInitialRegistration(kNewVersionOrigin); |
| 1563 { | 1597 { |
| 1564 const IPC::Message* start_msg = | 1598 const IPC::Message* start_msg = |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1581 ASSERT_TRUE(start_msg); | 1615 ASSERT_TRUE(start_msg); |
| 1582 EmbeddedWorkerMsg_StartWorker::Param param; | 1616 EmbeddedWorkerMsg_StartWorker::Param param; |
| 1583 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); | 1617 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); |
| 1584 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); | 1618 EmbeddedWorkerMsg_StartWorker_Params start_params = base::get<0>(param); |
| 1585 EXPECT_TRUE(start_params.pause_after_download); | 1619 EXPECT_TRUE(start_params.pause_after_download); |
| 1586 sink->ClearMessages(); | 1620 sink->ClearMessages(); |
| 1587 } | 1621 } |
| 1588 } | 1622 } |
| 1589 | 1623 |
| 1590 } // namespace content | 1624 } // namespace content |
| OLD | NEW |