Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: content/browser/service_worker/service_worker_version_unittest.cc

Issue 1877283002: ServiceWorker: Remove unused MessageEvent implementation from ServiceWorkerGlobalScope (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "content/browser/message_port_service.h"
13 #include "content/browser/service_worker/embedded_worker_registry.h" 12 #include "content/browser/service_worker/embedded_worker_registry.h"
14 #include "content/browser/service_worker/embedded_worker_test_helper.h" 13 #include "content/browser/service_worker/embedded_worker_test_helper.h"
15 #include "content/browser/service_worker/service_worker_context_core.h" 14 #include "content/browser/service_worker/service_worker_context_core.h"
16 #include "content/browser/service_worker/service_worker_registration.h" 15 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/browser/service_worker/service_worker_test_utils.h" 16 #include "content/browser/service_worker/service_worker_test_utils.h"
18 #include "content/common/service_worker/service_worker_utils.h" 17 #include "content/common/service_worker/service_worker_utils.h"
19 #include "content/public/test/mock_render_process_host.h" 18 #include "content/public/test/mock_render_process_host.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "content/public/test/test_mojo_service.mojom.h" 20 #include "content/public/test/test_mojo_service.mojom.h"
22 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 142
144 void OnMessageFromWorker(int value) { received_values_.push_back(value); } 143 void OnMessageFromWorker(int value) { received_values_.push_back(value); }
145 const std::vector<int>& received_values() const { return received_values_; } 144 const std::vector<int>& received_values() const { return received_values_; }
146 145
147 private: 146 private:
148 EmbeddedWorkerInstance* instance_; 147 EmbeddedWorkerInstance* instance_;
149 std::vector<int> received_values_; 148 std::vector<int> received_values_;
150 DISALLOW_COPY_AND_ASSIGN(MessageReceiverFromWorker); 149 DISALLOW_COPY_AND_ASSIGN(MessageReceiverFromWorker);
151 }; 150 };
152 151
153 void SetUpDummyMessagePort(std::vector<TransferredMessagePort>* ports) {
154 int port_id = -1;
155 MessagePortService::GetInstance()->Create(MSG_ROUTING_NONE, nullptr,
156 &port_id);
157 TransferredMessagePort dummy_port;
158 dummy_port.id = port_id;
159 ports->push_back(dummy_port);
160 }
161
162 base::Time GetYesterday() { 152 base::Time GetYesterday() {
163 return base::Time::Now() - base::TimeDelta::FromDays(1) - 153 return base::Time::Now() - base::TimeDelta::FromDays(1) -
164 base::TimeDelta::FromSeconds(1); 154 base::TimeDelta::FromSeconds(1);
165 } 155 }
166 156
167 class TestMojoServiceImpl : public mojom::TestMojoService { 157 class TestMojoServiceImpl : public mojom::TestMojoService {
168 public: 158 public:
169 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) { 159 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) {
170 new TestMojoServiceImpl(std::move(request)); 160 new TestMojoServiceImpl(std::move(request));
171 } 161 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 // Starting and finishing a request resets the idle time. 635 // Starting and finishing a request resets the idle time.
646 version_->idle_time_ -= kOneSecond; 636 version_->idle_time_ -= kOneSecond;
647 idle_time = version_->idle_time_; 637 idle_time = version_->idle_time_;
648 int request_id = 638 int request_id =
649 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC, 639 version_->StartRequest(ServiceWorkerMetrics::EventType::SYNC,
650 CreateReceiverOnCurrentThread(&status)); 640 CreateReceiverOnCurrentThread(&status));
651 EXPECT_TRUE(version_->FinishRequest(request_id, true)); 641 EXPECT_TRUE(version_->FinishRequest(request_id, true));
652 642
653 EXPECT_EQ(SERVICE_WORKER_OK, status); 643 EXPECT_EQ(SERVICE_WORKER_OK, status);
654 EXPECT_LT(idle_time, version_->idle_time_); 644 EXPECT_LT(idle_time, version_->idle_time_);
655
656 // Dispatching a message event resets the idle time.
657 std::vector<TransferredMessagePort> ports;
658 SetUpDummyMessagePort(&ports);
659 status = SERVICE_WORKER_ERROR_FAILED;
660 version_->idle_time_ -= kOneSecond;
661 idle_time = version_->idle_time_;
662 version_->DispatchMessageEvent(base::string16(), ports,
663 CreateReceiverOnCurrentThread(&status));
664 base::RunLoop().RunUntilIdle();
665 MessagePortService::GetInstance()->Destroy(ports[0].id);
666
667 EXPECT_EQ(SERVICE_WORKER_OK, status);
668 EXPECT_LT(idle_time, version_->idle_time_);
669 } 645 }
670 646
671 TEST_F(ServiceWorkerVersionTest, SetDevToolsAttached) { 647 TEST_F(ServiceWorkerVersionTest, SetDevToolsAttached) {
672 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 648 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
673 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 649 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
674 CreateReceiverOnCurrentThread(&status)); 650 CreateReceiverOnCurrentThread(&status));
675 651
676 ASSERT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); 652 ASSERT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
677 653
678 ASSERT_TRUE(version_->timeout_timer_.IsRunning()); 654 ASSERT_TRUE(version_->timeout_timer_.IsRunning());
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 helper_->SimulateSendSimpleEventResult( 1461 helper_->SimulateSendSimpleEventResult(
1486 version_->embedded_worker()->embedded_worker_id(), request_id, 1462 version_->embedded_worker()->embedded_worker_id(), request_id,
1487 blink::WebServiceWorkerEventResultRejected); 1463 blink::WebServiceWorkerEventResultRejected);
1488 runner->Run(); 1464 runner->Run();
1489 1465
1490 // Verify callback was called with correct status. 1466 // Verify callback was called with correct status.
1491 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status); 1467 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status);
1492 } 1468 }
1493 1469
1494 } // namespace content 1470 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.cc ('k') | content/child/service_worker/web_service_worker_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698