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