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

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

Issue 2627543002: ServiceWorker: Returns true for IsMojoForServiceWorkerEnabled (Closed)
Patch Set: Created 3 years, 11 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 <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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 136 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
137 std::unique_ptr<ServiceWorkerProviderHost> provider_host_; 137 std::unique_ptr<ServiceWorkerProviderHost> provider_host_;
138 scoped_refptr<ServiceWorkerRegistration> registration_; 138 scoped_refptr<ServiceWorkerRegistration> registration_;
139 scoped_refptr<ServiceWorkerVersion> version_; 139 scoped_refptr<ServiceWorkerVersion> version_;
140 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; 140 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
141 141
142 private: 142 private:
143 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); 143 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest);
144 }; 144 };
145 145
146 class ServiceWorkerHandleTestP 146 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) {
147 : public MojoServiceWorkerTestP<ServiceWorkerHandleTest> {};
148
149 TEST_P(ServiceWorkerHandleTestP, OnVersionStateChanged) {
150 std::unique_ptr<ServiceWorkerHandle> handle = 147 std::unique_ptr<ServiceWorkerHandle> handle =
151 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), 148 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(),
152 provider_host_->AsWeakPtr(), version_.get()); 149 provider_host_->AsWeakPtr(), version_.get());
153 150
154 // Start the worker, and then... 151 // Start the worker, and then...
155 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 152 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
156 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 153 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
157 CreateReceiverOnCurrentThread(&status)); 154 CreateReceiverOnCurrentThread(&status));
158 base::RunLoop().RunUntilIdle(); 155 base::RunLoop().RunUntilIdle();
159 EXPECT_EQ(SERVICE_WORKER_OK, status); 156 EXPECT_EQ(SERVICE_WORKER_OK, status);
160 157
161 // ...update state to installed. 158 // ...update state to installed.
162 version_->SetStatus(ServiceWorkerVersion::INSTALLED); 159 version_->SetStatus(ServiceWorkerVersion::INSTALLED);
163 160
164 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_); 161 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_);
165 162
166 const IPC::Message* message = nullptr; 163 const IPC::Message* message = nullptr;
167 if (is_mojo_enabled()) { 164 // StartWorker shouldn't be recorded here.
168 // StartWorker shouldn't be recorded here. 165 ASSERT_EQ(1UL, ipc_sink()->message_count());
169 ASSERT_EQ(1UL, ipc_sink()->message_count()); 166 message = ipc_sink()->GetMessageAt(0);
170 message = ipc_sink()->GetMessageAt(0); 167
171 } else {
172 ASSERT_EQ(2UL, ipc_sink()->message_count());
173 // We should be sending 1. StartWorker,
174 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID,
175 ipc_sink()->GetMessageAt(0)->type());
176 message = ipc_sink()->GetMessageAt(1);
177 }
178 // StateChanged (state == Installed). 168 // StateChanged (state == Installed).
179 VerifyStateChangedMessage(handle->handle_id(), 169 VerifyStateChangedMessage(handle->handle_id(),
180 blink::WebServiceWorkerStateInstalled, message); 170 blink::WebServiceWorkerStateInstalled, message);
181 } 171 }
182 172
183 INSTANTIATE_TEST_CASE_P(ServiceWorkerHandleTest,
184 ServiceWorkerHandleTestP,
185 ::testing::Values(false, true));
186
187 } // namespace content 173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698