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

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

Issue 2425943002: Mojofy unittests: ServiceWorkerHandleTest (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <tuple> 5 #include <tuple>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/service_worker/embedded_worker_registry.h" 10 #include "content/browser/service_worker/embedded_worker_registry.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 134 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
135 std::unique_ptr<ServiceWorkerProviderHost> provider_host_; 135 std::unique_ptr<ServiceWorkerProviderHost> provider_host_;
136 scoped_refptr<ServiceWorkerRegistration> registration_; 136 scoped_refptr<ServiceWorkerRegistration> registration_;
137 scoped_refptr<ServiceWorkerVersion> version_; 137 scoped_refptr<ServiceWorkerVersion> version_;
138 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; 138 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
139 139
140 private: 140 private:
141 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); 141 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest);
142 }; 142 };
143 143
144 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { 144 class ServiceWorkerHandleTestP
145 : public MojoServiceWorkerTestP<ServiceWorkerHandleTest> {};
146
147 TEST_P(ServiceWorkerHandleTestP, OnVersionStateChanged) {
145 std::unique_ptr<ServiceWorkerHandle> handle = 148 std::unique_ptr<ServiceWorkerHandle> handle =
146 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), 149 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(),
147 provider_host_->AsWeakPtr(), version_.get()); 150 provider_host_->AsWeakPtr(), version_.get());
148 151
149 // Start the worker, and then... 152 // Start the worker, and then...
150 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 153 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
151 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 154 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
152 CreateReceiverOnCurrentThread(&status)); 155 CreateReceiverOnCurrentThread(&status));
153 base::RunLoop().RunUntilIdle(); 156 base::RunLoop().RunUntilIdle();
154 EXPECT_EQ(SERVICE_WORKER_OK, status); 157 EXPECT_EQ(SERVICE_WORKER_OK, status);
155 158
156 // ...update state to installed. 159 // ...update state to installed.
157 version_->SetStatus(ServiceWorkerVersion::INSTALLED); 160 version_->SetStatus(ServiceWorkerVersion::INSTALLED);
158 161
159 ASSERT_EQ(2UL, ipc_sink()->message_count());
160 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_); 162 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_);
161 163
162 // We should be sending 1. StartWorker, 164 const IPC::Message* message = nullptr;
163 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID, 165 if (is_mojo_enabled()) {
164 ipc_sink()->GetMessageAt(0)->type()); 166 // StartWorker shouldn't be recorded here.
165 // 2. StateChanged (state == Installed). 167 ASSERT_EQ(1UL, ipc_sink()->message_count());
168 message = ipc_sink()->GetMessageAt(0);
169 } else {
170 ASSERT_EQ(2UL, ipc_sink()->message_count());
171 // We should be sending 1. StartWorker,
172 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID,
173 ipc_sink()->GetMessageAt(0)->type());
174 message = ipc_sink()->GetMessageAt(1);
175 }
176 // StateChanged (state == Installed).
166 VerifyStateChangedMessage(handle->handle_id(), 177 VerifyStateChangedMessage(handle->handle_id(),
167 blink::WebServiceWorkerStateInstalled, 178 blink::WebServiceWorkerStateInstalled, message);
168 ipc_sink()->GetMessageAt(1));
169 } 179 }
170 180
181 INSTANTIATE_TEST_CASE_P(ServiceWorkerHandleTest,
182 ServiceWorkerHandleTestP,
183 ::testing::Values(false, true));
184
171 } // namespace content 185 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698