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