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

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

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: review Created 4 years, 1 month 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 #include <tuple> 8 #include <tuple>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 ServiceWorkerStallInStoppingTest() : ServiceWorkerVersionTestP() {} 391 ServiceWorkerStallInStoppingTest() : ServiceWorkerVersionTestP() {}
392 392
393 std::unique_ptr<MessageReceiver> GetMessageReceiver() override { 393 std::unique_ptr<MessageReceiver> GetMessageReceiver() override {
394 return base::MakeUnique<MessageReceiverDisallowStop>(); 394 return base::MakeUnique<MessageReceiverDisallowStop>();
395 } 395 }
396 396
397 private: 397 private:
398 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStallInStoppingTest); 398 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStallInStoppingTest);
399 }; 399 };
400 400
401 class MessageReceiverMojoTestService : public MessageReceiver {
402 public:
403 MessageReceiverMojoTestService() : MessageReceiver() {}
404 ~MessageReceiverMojoTestService() override {}
405
406 void OnSetupMojo(int thread_id,
407 service_manager::InterfaceRegistry* registry) override {
408 registry->AddInterface(base::Bind(&TestServiceImpl::Create));
409 }
410
411 private:
412 DISALLOW_COPY_AND_ASSIGN(MessageReceiverMojoTestService);
413 };
414
415 class ServiceWorkerVersionWithMojoTest : public ServiceWorkerVersionTestP {
416 protected:
417 ServiceWorkerVersionWithMojoTest() : ServiceWorkerVersionTestP() {}
418
419 std::unique_ptr<MessageReceiver> GetMessageReceiver() override {
420 return base::MakeUnique<MessageReceiverMojoTestService>();
421 }
422
423 private:
424 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionWithMojoTest);
425 };
426
427 TEST_P(ServiceWorkerVersionTestP, ConcurrentStartAndStop) { 401 TEST_P(ServiceWorkerVersionTestP, ConcurrentStartAndStop) {
428 // Call StartWorker() multiple times. 402 // Call StartWorker() multiple times.
429 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED; 403 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED;
430 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED; 404 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED;
431 ServiceWorkerStatusCode status3 = SERVICE_WORKER_ERROR_FAILED; 405 ServiceWorkerStatusCode status3 = SERVICE_WORKER_ERROR_FAILED;
432 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 406 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
433 CreateReceiverOnCurrentThread(&status1)); 407 CreateReceiverOnCurrentThread(&status1));
434 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 408 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
435 CreateReceiverOnCurrentThread(&status2)); 409 CreateReceiverOnCurrentThread(&status2));
436 410
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 1187
1214 // Callback completed. 1188 // Callback completed.
1215 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status); 1189 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status);
1216 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 1190 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
1217 1191
1218 // Request already failed, calling finsh should return false. 1192 // Request already failed, calling finsh should return false.
1219 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */, 1193 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */,
1220 base::Time::Now())); 1194 base::Time::Now()));
1221 } 1195 }
1222 1196
1223 TEST_P(ServiceWorkerVersionWithMojoTest, MojoService) {
1224 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1225
1226 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
1227 version_->StartWorker(ServiceWorkerMetrics::EventType::SYNC,
1228 CreateReceiverOnCurrentThread(&status));
1229 base::RunLoop().RunUntilIdle();
1230 EXPECT_EQ(SERVICE_WORKER_OK, status);
1231 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
1232
1233 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
1234 int request_id = version_->StartRequest(
1235 ServiceWorkerMetrics::EventType::SYNC,
1236 CreateReceiverOnCurrentThread(&status, runner->QuitClosure()));
1237 base::WeakPtr<mojom::TestService> service =
1238 version_->GetMojoServiceForRequest<mojom::TestService>(request_id);
1239 service->DoSomething(runner->QuitClosure());
1240 runner->Run();
1241
1242 // Mojo service does exist in worker, so error callback should not have been
1243 // called and FinishRequest should return true.
1244 EXPECT_EQ(SERVICE_WORKER_OK, status);
1245 EXPECT_TRUE(version_->FinishRequest(request_id, true /* was_handled */,
1246 base::Time::Now()));
1247 }
1248
1249 TEST_P(ServiceWorkerVersionTestP, NonExistentMojoService) {
1250 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1251
1252 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
1253 version_->StartWorker(ServiceWorkerMetrics::EventType::SYNC,
1254 CreateReceiverOnCurrentThread(&status));
1255 base::RunLoop().RunUntilIdle();
1256 EXPECT_EQ(SERVICE_WORKER_OK, status);
1257 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
1258
1259 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
1260 int request_id = version_->StartRequest(
1261 ServiceWorkerMetrics::EventType::SYNC,
1262 CreateReceiverOnCurrentThread(&status, runner->QuitClosure()));
1263 base::WeakPtr<mojom::TestService> service =
1264 version_->GetMojoServiceForRequest<mojom::TestService>(request_id);
1265 service->DoSomething(runner->QuitClosure());
1266 runner->Run();
1267
1268 // Mojo service doesn't exist in worker, so error callback should have been
1269 // called and FinishRequest should return false.
1270 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, status);
1271 EXPECT_FALSE(version_->FinishRequest(request_id, true /* was_handled */,
1272 base::Time::Now()));
1273 }
1274
1275 TEST_P(ServiceWorkerVersionTestP, DispatchEvent) { 1197 TEST_P(ServiceWorkerVersionTestP, DispatchEvent) {
1276 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value 1198 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value
1277 1199
1278 // Activate and start worker. 1200 // Activate and start worker.
1279 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 1201 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
1280 version_->StartWorker(ServiceWorkerMetrics::EventType::SYNC, 1202 version_->StartWorker(ServiceWorkerMetrics::EventType::SYNC,
1281 CreateReceiverOnCurrentThread(&status)); 1203 CreateReceiverOnCurrentThread(&status));
1282 base::RunLoop().RunUntilIdle(); 1204 base::RunLoop().RunUntilIdle();
1283 EXPECT_EQ(SERVICE_WORKER_OK, status); 1205 EXPECT_EQ(SERVICE_WORKER_OK, status);
1284 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); 1206 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status());
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 testing::Bool()); 1702 testing::Bool());
1781 INSTANTIATE_TEST_CASE_P(ServiceWorkerFailToStartTest, 1703 INSTANTIATE_TEST_CASE_P(ServiceWorkerFailToStartTest,
1782 ServiceWorkerFailToStartTest, 1704 ServiceWorkerFailToStartTest,
1783 testing::Bool()); 1705 testing::Bool());
1784 INSTANTIATE_TEST_CASE_P(ServiceWorkerNavigationHintUMATest, 1706 INSTANTIATE_TEST_CASE_P(ServiceWorkerNavigationHintUMATest,
1785 ServiceWorkerNavigationHintUMATest, 1707 ServiceWorkerNavigationHintUMATest,
1786 testing::Bool()); 1708 testing::Bool());
1787 INSTANTIATE_TEST_CASE_P(ServiceWorkerStallInStoppingTest, 1709 INSTANTIATE_TEST_CASE_P(ServiceWorkerStallInStoppingTest,
1788 ServiceWorkerStallInStoppingTest, 1710 ServiceWorkerStallInStoppingTest,
1789 testing::Bool()); 1711 testing::Bool());
1790 INSTANTIATE_TEST_CASE_P(ServiceWorkerVersionWithMojoTest,
1791 ServiceWorkerVersionWithMojoTest,
1792 testing::Bool());
1793
1794 } // namespace content 1712 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698