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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "content/browser/message_port_service.h" | 9 #include "content/browser/message_port_service.h" |
10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 // Verify the receiver received the values. | 557 // Verify the receiver received the values. |
558 ASSERT_EQ(2U, receiver.received_values().size()); | 558 ASSERT_EQ(2U, receiver.received_values().size()); |
559 EXPECT_EQ(555, receiver.received_values()[0]); | 559 EXPECT_EQ(555, receiver.received_values()[0]); |
560 EXPECT_EQ(777, receiver.received_values()[1]); | 560 EXPECT_EQ(777, receiver.received_values()[1]); |
561 } | 561 } |
562 | 562 |
563 TEST_F(ServiceWorkerVersionTest, InstallAndWaitCompletion) { | 563 TEST_F(ServiceWorkerVersionTest, InstallAndWaitCompletion) { |
564 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 564 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
565 | 565 |
566 // Dispatch an install event. | |
567 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::INSTALL); | |
568 | |
569 // Wait for the completion. | 566 // Wait for the completion. |
570 bool status_change_called = false; | 567 bool status_change_called = false; |
571 version_->RegisterStatusChangeCallback( | 568 version_->RegisterStatusChangeCallback( |
572 base::Bind(&VerifyCalled, &status_change_called)); | 569 base::Bind(&VerifyCalled, &status_change_called)); |
573 | 570 |
574 base::RunLoop().RunUntilIdle(); | 571 // Dispatch an install event. |
| 572 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::INSTALL); |
575 | 573 |
576 // Version's status must not have changed during installation. | 574 // Version's status must not have changed during installation. |
577 EXPECT_FALSE(status_change_called); | 575 EXPECT_FALSE(status_change_called); |
578 EXPECT_EQ(ServiceWorkerVersion::INSTALLING, version_->status()); | 576 EXPECT_EQ(ServiceWorkerVersion::INSTALLING, version_->status()); |
579 } | 577 } |
580 | 578 |
581 TEST_F(ServiceWorkerVersionTest, ActivateAndWaitCompletion) { | 579 TEST_F(ServiceWorkerVersionTest, ActivateAndWaitCompletion) { |
| 580 // TODO(mek): This test (and the one above for the install event) made more |
| 581 // sense back when ServiceWorkerVersion was responsible for updating the |
| 582 // status. Now a better version of this test should probably be added to |
| 583 // ServiceWorkerRegistrationTest instead. |
| 584 |
582 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); | 585 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); |
583 | 586 |
584 // Dispatch an activate event. | |
585 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
586 version_->DispatchActivateEvent(CreateReceiverOnCurrentThread(&status)); | |
587 | |
588 // Wait for the completion. | 587 // Wait for the completion. |
589 bool status_change_called = false; | 588 bool status_change_called = false; |
590 version_->RegisterStatusChangeCallback( | 589 version_->RegisterStatusChangeCallback( |
591 base::Bind(&VerifyCalled, &status_change_called)); | 590 base::Bind(&VerifyCalled, &status_change_called)); |
592 | 591 |
593 base::RunLoop().RunUntilIdle(); | 592 // Dispatch an activate event. |
| 593 SimulateDispatchEvent(ServiceWorkerMetrics::EventType::ACTIVATE); |
594 | 594 |
595 // Version's status must not have changed during activation. | 595 // Version's status must not have changed during activation. |
596 EXPECT_EQ(SERVICE_WORKER_OK, status); | |
597 EXPECT_FALSE(status_change_called); | 596 EXPECT_FALSE(status_change_called); |
598 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, version_->status()); | 597 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, version_->status()); |
599 } | 598 } |
600 | 599 |
601 TEST_F(ServiceWorkerVersionTest, RepeatedlyObserveStatusChanges) { | 600 TEST_F(ServiceWorkerVersionTest, RepeatedlyObserveStatusChanges) { |
602 EXPECT_EQ(ServiceWorkerVersion::NEW, version_->status()); | 601 EXPECT_EQ(ServiceWorkerVersion::NEW, version_->status()); |
603 | 602 |
604 // Repeatedly observe status changes (the callback re-registers itself). | 603 // Repeatedly observe status changes (the callback re-registers itself). |
605 std::vector<ServiceWorkerVersion::Status> statuses; | 604 std::vector<ServiceWorkerVersion::Status> statuses; |
606 version_->RegisterStatusChangeCallback( | 605 version_->RegisterStatusChangeCallback( |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 base::RunLoop().RunUntilIdle(); | 1015 base::RunLoop().RunUntilIdle(); |
1017 | 1016 |
1018 // Callback completed. | 1017 // Callback completed. |
1019 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | 1018 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); |
1020 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); | 1019 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); |
1021 } | 1020 } |
1022 | 1021 |
1023 TEST_F(ServiceWorkerFailToStartTest, Timeout) { | 1022 TEST_F(ServiceWorkerFailToStartTest, Timeout) { |
1024 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value | 1023 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value |
1025 | 1024 |
1026 // We could just call StartWorker but make it interesting and test | 1025 // Start starting the worker. |
1027 // starting the worker as part of dispatching an event. | 1026 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
1028 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); | |
1029 version_->DispatchActivateEvent(CreateReceiverOnCurrentThread(&status)); | |
1030 base::RunLoop().RunUntilIdle(); | 1027 base::RunLoop().RunUntilIdle(); |
1031 | 1028 |
1032 // Callback has not completed yet. | 1029 // Callback has not completed yet. |
1033 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); | 1030 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, status); |
1034 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); | 1031 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); |
1035 | 1032 |
1036 // Simulate timeout. | 1033 // Simulate timeout. |
1037 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); | 1034 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); |
1038 version_->start_time_ = | 1035 version_->start_time_ = |
1039 base::TimeTicks::Now() - | 1036 base::TimeTicks::Now() - |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 helper_->SimulateSendSimpleEventResult( | 1496 helper_->SimulateSendSimpleEventResult( |
1500 version_->embedded_worker()->embedded_worker_id(), request_id, | 1497 version_->embedded_worker()->embedded_worker_id(), request_id, |
1501 blink::WebServiceWorkerEventResultRejected); | 1498 blink::WebServiceWorkerEventResultRejected); |
1502 runner->Run(); | 1499 runner->Run(); |
1503 | 1500 |
1504 // Verify callback was called with correct status. | 1501 // Verify callback was called with correct status. |
1505 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status); | 1502 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status); |
1506 } | 1503 } |
1507 | 1504 |
1508 } // namespace content | 1505 } // namespace content |
OLD | NEW |