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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer Created 3 years, 6 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 <stdint.h> 5 #include <stdint.h>
6 #include <tuple> 6 #include <tuple>
7 7
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/optional.h" 12 #include "base/optional.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/test/test_simple_task_runner.h" 14 #include "base/test/test_simple_task_runner.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "content/browser/browser_thread_impl.h" 16 #include "content/browser/browser_thread_impl.h"
17 #include "content/browser/service_worker/embedded_worker_registry.h" 17 #include "content/browser/service_worker/embedded_worker_registry.h"
18 #include "content/browser/service_worker/embedded_worker_status.h" 18 #include "content/browser/service_worker/embedded_worker_status.h"
19 #include "content/browser/service_worker/embedded_worker_test_helper.h" 19 #include "content/browser/service_worker/embedded_worker_test_helper.h"
20 #include "content/browser/service_worker/service_worker_context_core.h" 20 #include "content/browser/service_worker/service_worker_context_core.h"
21 #include "content/browser/service_worker/service_worker_context_wrapper.h" 21 #include "content/browser/service_worker/service_worker_context_wrapper.h"
22 #include "content/browser/service_worker/service_worker_disk_cache.h" 22 #include "content/browser/service_worker/service_worker_disk_cache.h"
23 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
24 #include "content/browser/service_worker/service_worker_handle.h"
23 #include "content/browser/service_worker/service_worker_job_coordinator.h" 25 #include "content/browser/service_worker/service_worker_job_coordinator.h"
24 #include "content/browser/service_worker/service_worker_registration.h" 26 #include "content/browser/service_worker/service_worker_registration.h"
27 #include "content/browser/service_worker/service_worker_registration_handle.h"
25 #include "content/browser/service_worker/service_worker_registration_status.h" 28 #include "content/browser/service_worker/service_worker_registration_status.h"
26 #include "content/browser/service_worker/service_worker_test_utils.h" 29 #include "content/browser/service_worker/service_worker_test_utils.h"
27 #include "content/common/service_worker/embedded_worker_messages.h" 30 #include "content/common/service_worker/embedded_worker_messages.h"
28 #include "content/common/service_worker/service_worker_messages.h" 31 #include "content/common/service_worker/service_worker_messages.h"
29 #include "content/common/service_worker/service_worker_utils.h" 32 #include "content/common/service_worker/service_worker_utils.h"
33 #include "content/public/test/test_browser_context.h"
30 #include "content/public/test/test_browser_thread_bundle.h" 34 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "ipc/ipc_test_sink.h" 35 #include "ipc/ipc_test_sink.h"
32 #include "net/base/io_buffer.h" 36 #include "net/base/io_buffer.h"
33 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
34 #include "net/base/test_completion_callback.h" 38 #include "net/base/test_completion_callback.h"
35 #include "net/http/http_response_headers.h" 39 #include "net/http/http_response_headers.h"
36 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
37 41
38 using net::IOBuffer; 42 using net::IOBuffer;
39 using net::TestCompletionCallback; 43 using net::TestCompletionCallback;
40 using net::WrappedIOBuffer; 44 using net::WrappedIOBuffer;
41 45
42 // Unit tests for testing all job registration tasks. 46 // Unit tests for testing all job registration tasks.
43 namespace content { 47 namespace content {
44 48
45 namespace { 49 namespace {
46 50
51 // A dispatcher host that holds on to all registered ServiceWorkerHandles and
52 // ServiceWorkerRegistrationHandles.
53 class KeepHandlesDispatcherHost : public ServiceWorkerDispatcherHost {
54 public:
55 KeepHandlesDispatcherHost(int render_process_id,
56 ResourceContext* resource_context)
57 : ServiceWorkerDispatcherHost(render_process_id, resource_context) {}
58 void RegisterServiceWorkerHandle(
59 std::unique_ptr<ServiceWorkerHandle> handle) override {
60 handles_.push_back(std::move(handle));
61 }
62 void RegisterServiceWorkerRegistrationHandle(
63 std::unique_ptr<ServiceWorkerRegistrationHandle> handle) override {
64 registration_handles_.push_back(std::move(handle));
65 }
66
67 void RemoveHandles() {
68 handles_.clear();
69 registration_handles_.clear();
70 }
71
72 const std::vector<std::unique_ptr<ServiceWorkerHandle>>& handles() {
73 return handles_;
74 }
75
76 const std::vector<std::unique_ptr<ServiceWorkerRegistrationHandle>>&
77 registration_handles() {
78 return registration_handles_;
79 }
80
81 private:
82 ~KeepHandlesDispatcherHost() override {}
83
84 std::vector<std::unique_ptr<ServiceWorkerHandle>> handles_;
85 std::vector<std::unique_ptr<ServiceWorkerRegistrationHandle>>
86 registration_handles_;
87 DISALLOW_COPY_AND_ASSIGN(KeepHandlesDispatcherHost);
88 };
89
47 void SaveRegistrationCallback( 90 void SaveRegistrationCallback(
48 ServiceWorkerStatusCode expected_status, 91 ServiceWorkerStatusCode expected_status,
49 bool* called, 92 bool* called,
50 scoped_refptr<ServiceWorkerRegistration>* registration_out, 93 scoped_refptr<ServiceWorkerRegistration>* registration_out,
51 ServiceWorkerStatusCode status, 94 ServiceWorkerStatusCode status,
52 const std::string& status_message, 95 const std::string& status_message,
53 ServiceWorkerRegistration* registration) { 96 ServiceWorkerRegistration* registration) {
54 EXPECT_EQ(expected_status, status); 97 EXPECT_EQ(expected_status, status);
55 *called = true; 98 *called = true;
56 *registration_out = registration; 99 *registration_out = registration;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_EQ(valid_scope_1, version_->foreign_fetch_scopes_[0]); 393 EXPECT_EQ(valid_scope_1, version_->foreign_fetch_scopes_[0]);
351 EXPECT_EQ(valid_scope_2, version_->foreign_fetch_scopes_[1]); 394 EXPECT_EQ(valid_scope_2, version_->foreign_fetch_scopes_[1]);
352 EXPECT_EQ(1u, version_->foreign_fetch_origins_.size()); 395 EXPECT_EQ(1u, version_->foreign_fetch_origins_.size());
353 EXPECT_EQ(valid_origin, version_->foreign_fetch_origins_[0]); 396 EXPECT_EQ(valid_origin, version_->foreign_fetch_origins_[0]);
354 } 397 }
355 398
356 // Make sure registrations are cleaned up when they are unregistered. 399 // Make sure registrations are cleaned up when they are unregistered.
357 TEST_F(ServiceWorkerJobTest, Unregister) { 400 TEST_F(ServiceWorkerJobTest, Unregister) {
358 GURL pattern("http://www.example.com/"); 401 GURL pattern("http://www.example.com/");
359 402
403 // During registration, handles will be created for hosting the worker's
404 // context. KeepHandlesDispatcherHost will store the handles.
405 scoped_refptr<KeepHandlesDispatcherHost> dispatcher_host =
406 base::MakeRefCounted<KeepHandlesDispatcherHost>(
407 helper_->mock_render_process_id(),
408 helper_->browser_context()->GetResourceContext());
409 helper_->RegisterDispatcherHost(helper_->mock_render_process_id(),
410 dispatcher_host);
411 dispatcher_host->Init(helper_->context_wrapper());
412
360 scoped_refptr<ServiceWorkerRegistration> registration = 413 scoped_refptr<ServiceWorkerRegistration> registration =
361 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); 414 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js"));
362 415
416 EXPECT_EQ(1UL, dispatcher_host->registration_handles().size());
417 EXPECT_EQ(3UL, dispatcher_host->handles().size());
418
363 RunUnregisterJob(pattern); 419 RunUnregisterJob(pattern);
364 420
421 // Remove the handles. The only reference to the registration object should be
422 // |registration|.
423 dispatcher_host->RemoveHandles();
424 EXPECT_EQ(0UL, dispatcher_host->registration_handles().size());
425 EXPECT_EQ(0UL, dispatcher_host->handles().size());
365 ASSERT_TRUE(registration->HasOneRef()); 426 ASSERT_TRUE(registration->HasOneRef());
366 427
367 registration = FindRegistrationForPattern(pattern, 428 registration = FindRegistrationForPattern(pattern,
368 SERVICE_WORKER_ERROR_NOT_FOUND); 429 SERVICE_WORKER_ERROR_NOT_FOUND);
369 430
370 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 431 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration);
371 } 432 }
372 433
373 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { 434 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
374 GURL pattern("http://www.example.com/"); 435 GURL pattern("http://www.example.com/");
375 436
376 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); 437 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
377 } 438 }
378 439
379 // Make sure registering a new script creates a new version and shares an 440 // Make sure registering a new script creates a new version and shares an
380 // existing registration. 441 // existing registration.
(...skipping 17 matching lines...) Expand all
398 459
399 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = 460 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern =
400 FindRegistrationForPattern(pattern); 461 FindRegistrationForPattern(pattern);
401 462
402 ASSERT_EQ(new_registration, new_registration_by_pattern); 463 ASSERT_EQ(new_registration, new_registration_by_pattern);
403 } 464 }
404 465
405 // Make sure that when registering a duplicate pattern+script_url 466 // Make sure that when registering a duplicate pattern+script_url
406 // combination, that the same registration is used. 467 // combination, that the same registration is used.
407 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { 468 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
469 // During registration, handles will be created for hosting the worker's
470 // context. KeepHandlesDispatcherHost will store the handles.
471 scoped_refptr<KeepHandlesDispatcherHost> dispatcher_host =
472 new KeepHandlesDispatcherHost(
473 helper_->mock_render_process_id(),
474 helper_->browser_context()->GetResourceContext());
475 helper_->RegisterDispatcherHost(helper_->mock_render_process_id(),
476 dispatcher_host);
477 dispatcher_host->Init(helper_->context_wrapper());
478
408 GURL pattern("http://www.example.com/"); 479 GURL pattern("http://www.example.com/");
409 GURL script_url("http://www.example.com/service_worker.js"); 480 GURL script_url("http://www.example.com/service_worker.js");
410 481
411 scoped_refptr<ServiceWorkerRegistration> old_registration = 482 scoped_refptr<ServiceWorkerRegistration> old_registration =
412 RunRegisterJob(pattern, script_url); 483 RunRegisterJob(pattern, script_url);
413 484
485 // Ensure that the registration's handle doesn't have the reference.
486 EXPECT_EQ(1UL, dispatcher_host->registration_handles().size());
487 dispatcher_host->RemoveHandles();
488 EXPECT_EQ(0UL, dispatcher_host->registration_handles().size());
489 ASSERT_TRUE(old_registration->HasOneRef());
490
414 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = 491 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern =
415 FindRegistrationForPattern(pattern); 492 FindRegistrationForPattern(pattern);
416 493
417 ASSERT_TRUE(old_registration_by_pattern.get()); 494 ASSERT_TRUE(old_registration_by_pattern.get());
418 495
419 scoped_refptr<ServiceWorkerRegistration> new_registration = 496 scoped_refptr<ServiceWorkerRegistration> new_registration =
420 RunRegisterJob(pattern, script_url); 497 RunRegisterJob(pattern, script_url);
421 498
422 ASSERT_EQ(old_registration, new_registration); 499 ASSERT_EQ(old_registration, new_registration);
423 500
424 ASSERT_FALSE(old_registration->HasOneRef()); 501 ASSERT_FALSE(old_registration->HasOneRef());
425 502
426 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = 503 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern =
427 FindRegistrationForPattern(pattern); 504 FindRegistrationForPattern(pattern);
428 505
429 ASSERT_EQ(new_registration, old_registration); 506 ASSERT_EQ(new_registration, old_registration);
430 } 507 }
431 508
432 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { 509 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper {
433 public: 510 public:
434 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 511 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
435 512
436 void OnStartWorker(int embedded_worker_id, 513 void OnStartWorker(
437 int64_t service_worker_version_id, 514 int embedded_worker_id,
438 const GURL& scope, 515 int64_t service_worker_version_id,
439 const GURL& script_url, 516 const GURL& scope,
440 bool pause_after_download, 517 const GURL& script_url,
441 mojom::ServiceWorkerEventDispatcherRequest request, 518 bool pause_after_download,
442 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo 519 mojom::ServiceWorkerEventDispatcherRequest request,
443 instance_host) override { 520 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
521 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
522 override {
444 mojom::EmbeddedWorkerInstanceHostAssociatedPtr instance_host_ptr; 523 mojom::EmbeddedWorkerInstanceHostAssociatedPtr instance_host_ptr;
445 instance_host_ptr.Bind(std::move(instance_host)); 524 instance_host_ptr.Bind(std::move(instance_host));
446 instance_host_ptr->OnStopped(); 525 instance_host_ptr->OnStopped();
447 base::RunLoop().RunUntilIdle(); 526 base::RunLoop().RunUntilIdle();
448 } 527 }
449 }; 528 };
450 529
451 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { 530 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
452 helper_.reset(new FailToStartWorkerTestHelper); 531 helper_.reset(new FailToStartWorkerTestHelper);
453 532
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 EXPECT_TRUE(called); 969 EXPECT_TRUE(called);
891 EXPECT_TRUE(registration.get()); 970 EXPECT_TRUE(registration.get());
892 EXPECT_TRUE(registration->active_version()); 971 EXPECT_TRUE(registration->active_version());
893 EXPECT_FALSE(registration->installing_version()); 972 EXPECT_FALSE(registration->installing_version());
894 EXPECT_FALSE(registration->waiting_version()); 973 EXPECT_FALSE(registration->waiting_version());
895 registration_ = registration; 974 registration_ = registration;
896 return registration; 975 return registration;
897 } 976 }
898 977
899 // EmbeddedWorkerTestHelper overrides 978 // EmbeddedWorkerTestHelper overrides
900 void OnStartWorker(int embedded_worker_id, 979 void OnStartWorker(
901 int64_t version_id, 980 int embedded_worker_id,
902 const GURL& scope, 981 int64_t version_id,
903 const GURL& script, 982 const GURL& scope,
904 bool pause_after_download, 983 const GURL& script,
905 mojom::ServiceWorkerEventDispatcherRequest request, 984 bool pause_after_download,
906 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo 985 mojom::ServiceWorkerEventDispatcherRequest request,
907 instance_host) override { 986 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
987 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
988 override {
908 const std::string kMockScriptBody = "mock_script"; 989 const std::string kMockScriptBody = "mock_script";
909 const uint64_t kMockScriptSize = 19284; 990 const uint64_t kMockScriptSize = 19284;
910 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); 991 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
911 ServiceWorkerRegistration* registration = 992 ServiceWorkerRegistration* registration =
912 context()->GetLiveRegistration(version->registration_id()); 993 context()->GetLiveRegistration(version->registration_id());
913 bool is_update = registration->active_version() && 994 bool is_update = registration->active_version() &&
914 version != registration->active_version(); 995 version != registration->active_version();
915 996
916 ASSERT_TRUE(version); 997 ASSERT_TRUE(version);
917 version->AddListener(this); 998 version->AddListener(this);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 // Spoof caching the script for the new version. 1034 // Spoof caching the script for the new version.
954 WriteStringResponse(storage(), resource_id, "mock_different_script"); 1035 WriteStringResponse(storage(), resource_id, "mock_different_script");
955 version->script_cache_map()->NotifyFinishedCaching( 1036 version->script_cache_map()->NotifyFinishedCaching(
956 script, kMockScriptSize, net::OK, std::string()); 1037 script, kMockScriptSize, net::OK, std::string());
957 version->SetMainScriptHttpResponseInfo( 1038 version->SetMainScriptHttpResponseInfo(
958 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); 1039 EmbeddedWorkerTestHelper::CreateHttpResponseInfo());
959 } 1040 }
960 1041
961 EmbeddedWorkerTestHelper::OnStartWorker( 1042 EmbeddedWorkerTestHelper::OnStartWorker(
962 embedded_worker_id, version_id, scope, script, pause_after_download, 1043 embedded_worker_id, version_id, scope, script, pause_after_download,
963 std::move(request), std::move(instance_host)); 1044 std::move(request), std::move(instance_host), std::move(provider_info));
964 } 1045 }
965 1046
966 void OnResumeAfterDownload(int embedded_worker_id) override { 1047 void OnResumeAfterDownload(int embedded_worker_id) override {
967 if (!force_start_worker_failure_) { 1048 if (!force_start_worker_failure_) {
968 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); 1049 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id);
969 } else { 1050 } else {
970 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id, 1051 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id);
971 GetNextProviderId());
972 SimulateWorkerScriptEvaluated(embedded_worker_id, false); 1052 SimulateWorkerScriptEvaluated(embedded_worker_id, false);
973 } 1053 }
974 } 1054 }
975 1055
976 // ServiceWorkerRegistration::Listener overrides 1056 // ServiceWorkerRegistration::Listener overrides
977 void OnVersionAttributesChanged( 1057 void OnVersionAttributesChanged(
978 ServiceWorkerRegistration* registration, 1058 ServiceWorkerRegistration* registration,
979 ChangedVersionAttributesMask changed_mask, 1059 ChangedVersionAttributesMask changed_mask,
980 const ServiceWorkerRegistrationInfo& info) override { 1060 const ServiceWorkerRegistrationInfo& info) override {
981 AttributeChangeLogEntry entry; 1061 AttributeChangeLogEntry entry;
(...skipping 27 matching lines...) Expand all
1009 bool force_start_worker_failure_ = false; 1089 bool force_start_worker_failure_ = false;
1010 }; 1090 };
1011 1091
1012 // Helper class for update tests that evicts the active version when the update 1092 // Helper class for update tests that evicts the active version when the update
1013 // worker is about to be started. 1093 // worker is about to be started.
1014 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { 1094 class EvictIncumbentVersionHelper : public UpdateJobTestHelper {
1015 public: 1095 public:
1016 EvictIncumbentVersionHelper() {} 1096 EvictIncumbentVersionHelper() {}
1017 ~EvictIncumbentVersionHelper() override {} 1097 ~EvictIncumbentVersionHelper() override {}
1018 1098
1019 void OnStartWorker(int embedded_worker_id, 1099 void OnStartWorker(
1020 int64_t version_id, 1100 int embedded_worker_id,
1021 const GURL& scope, 1101 int64_t version_id,
1022 const GURL& script, 1102 const GURL& scope,
1023 bool pause_after_download, 1103 const GURL& script,
1024 mojom::ServiceWorkerEventDispatcherRequest request, 1104 bool pause_after_download,
1025 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo 1105 mojom::ServiceWorkerEventDispatcherRequest request,
1026 instance_host) override { 1106 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
1107 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
1108 override {
1027 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); 1109 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
1028 ServiceWorkerRegistration* registration = 1110 ServiceWorkerRegistration* registration =
1029 context()->GetLiveRegistration(version->registration_id()); 1111 context()->GetLiveRegistration(version->registration_id());
1030 bool is_update = registration->active_version() && 1112 bool is_update = registration->active_version() &&
1031 version != registration->active_version(); 1113 version != registration->active_version();
1032 if (is_update) { 1114 if (is_update) {
1033 // Evict the incumbent worker. 1115 // Evict the incumbent worker.
1034 ASSERT_FALSE(registration->waiting_version()); 1116 ASSERT_FALSE(registration->waiting_version());
1035 registration->DeleteVersion( 1117 registration->DeleteVersion(
1036 make_scoped_refptr(registration->active_version())); 1118 make_scoped_refptr(registration->active_version()));
1037 } 1119 }
1038 UpdateJobTestHelper::OnStartWorker( 1120 UpdateJobTestHelper::OnStartWorker(
1039 embedded_worker_id, version_id, scope, script, pause_after_download, 1121 embedded_worker_id, version_id, scope, script, pause_after_download,
1040 std::move(request), std::move(instance_host)); 1122 std::move(request), std::move(instance_host), std::move(provider_info));
1041 } 1123 }
1042 1124
1043 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { 1125 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override {
1044 registration_failed_ = true; 1126 registration_failed_ = true;
1045 } 1127 }
1046 1128
1047 bool registration_failed_ = false; 1129 bool registration_failed_ = false;
1048 }; 1130 };
1049 1131
1050 } // namespace 1132 } // namespace
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 public: 1785 public:
1704 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( 1786 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient(
1705 base::WeakPtr<EmbeddedWorkerTestHelper> helper) 1787 base::WeakPtr<EmbeddedWorkerTestHelper> helper)
1706 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} 1788 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {}
1707 int num_of_startworker() const { return num_of_startworker_; } 1789 int num_of_startworker() const { return num_of_startworker_; }
1708 void set_next_pause_after_download(bool expectation) { 1790 void set_next_pause_after_download(bool expectation) {
1709 next_pause_after_download_ = expectation; 1791 next_pause_after_download_ = expectation;
1710 } 1792 }
1711 1793
1712 protected: 1794 protected:
1713 void StartWorker(const EmbeddedWorkerStartParams& params, 1795 void StartWorker(
1714 mojom::ServiceWorkerEventDispatcherRequest request, 1796 const EmbeddedWorkerStartParams& params,
1715 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo 1797 mojom::ServiceWorkerEventDispatcherRequest request,
1716 instance_host) override { 1798 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
1799 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
1800 override {
1717 ASSERT_TRUE(next_pause_after_download_.has_value()); 1801 ASSERT_TRUE(next_pause_after_download_.has_value());
1718 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); 1802 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download);
1719 num_of_startworker_++; 1803 num_of_startworker_++;
1720 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( 1804 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker(
1721 params, std::move(request), std::move(instance_host)); 1805 params, std::move(request), std::move(instance_host),
1806 std::move(provider_info));
1722 } 1807 }
1723 1808
1724 private: 1809 private:
1725 base::Optional<bool> next_pause_after_download_; 1810 base::Optional<bool> next_pause_after_download_;
1726 int num_of_startworker_ = 0; 1811 int num_of_startworker_ = 0;
1727 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); 1812 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient);
1728 }; 1813 };
1729 1814
1730 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { 1815 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) {
1731 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 1816 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 // should not be promoted to ACTIVATED because failure occur 1889 // should not be promoted to ACTIVATED because failure occur
1805 // during shutdown. 1890 // during shutdown.
1806 runner->RunPendingTasks(); 1891 runner->RunPendingTasks();
1807 base::RunLoop().RunUntilIdle(); 1892 base::RunLoop().RunUntilIdle();
1808 EXPECT_EQ(new_version.get(), registration->active_version()); 1893 EXPECT_EQ(new_version.get(), registration->active_version());
1809 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1894 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1810 registration->RemoveListener(update_helper); 1895 registration->RemoveListener(update_helper);
1811 } 1896 }
1812 1897
1813 } // namespace content 1898 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698