| 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  | 
 |    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  Loading... | 
|   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       new 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  Loading... | 
|   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::ServiceWorkerProviderClientInfoPtr provider_client_info) override { | 
|   444     mojom::EmbeddedWorkerInstanceHostAssociatedPtr instance_host_ptr; |   522     mojom::EmbeddedWorkerInstanceHostAssociatedPtr instance_host_ptr; | 
|   445     instance_host_ptr.Bind(std::move(instance_host)); |   523     instance_host_ptr.Bind(std::move(instance_host)); | 
|   446     instance_host_ptr->OnStopped(); |   524     instance_host_ptr->OnStopped(); | 
|   447     base::RunLoop().RunUntilIdle(); |   525     base::RunLoop().RunUntilIdle(); | 
|   448   } |   526   } | 
|   449 }; |   527 }; | 
|   450  |   528  | 
|   451 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |   529 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 
|   452   helper_.reset(new FailToStartWorkerTestHelper); |   530   helper_.reset(new FailToStartWorkerTestHelper); | 
|   453  |   531  | 
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   890     EXPECT_TRUE(called); |   968     EXPECT_TRUE(called); | 
|   891     EXPECT_TRUE(registration.get()); |   969     EXPECT_TRUE(registration.get()); | 
|   892     EXPECT_TRUE(registration->active_version()); |   970     EXPECT_TRUE(registration->active_version()); | 
|   893     EXPECT_FALSE(registration->installing_version()); |   971     EXPECT_FALSE(registration->installing_version()); | 
|   894     EXPECT_FALSE(registration->waiting_version()); |   972     EXPECT_FALSE(registration->waiting_version()); | 
|   895     registration_ = registration; |   973     registration_ = registration; | 
|   896     return registration; |   974     return registration; | 
|   897   } |   975   } | 
|   898  |   976  | 
|   899   // EmbeddedWorkerTestHelper overrides |   977   // EmbeddedWorkerTestHelper overrides | 
|   900   void OnStartWorker(int embedded_worker_id, |   978   void OnStartWorker( | 
|   901                      int64_t version_id, |   979       int embedded_worker_id, | 
|   902                      const GURL& scope, |   980       int64_t version_id, | 
|   903                      const GURL& script, |   981       const GURL& scope, | 
|   904                      bool pause_after_download, |   982       const GURL& script, | 
|   905                      mojom::ServiceWorkerEventDispatcherRequest request, |   983       bool pause_after_download, | 
|   906                      mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |   984       mojom::ServiceWorkerEventDispatcherRequest request, | 
|   907                          instance_host) override { |   985       mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 
 |   986       mojom::ServiceWorkerProviderClientInfoPtr provider_client_info) override { | 
|   908     const std::string kMockScriptBody = "mock_script"; |   987     const std::string kMockScriptBody = "mock_script"; | 
|   909     const uint64_t kMockScriptSize = 19284; |   988     const uint64_t kMockScriptSize = 19284; | 
|   910     ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |   989     ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 
|   911     ServiceWorkerRegistration* registration = |   990     ServiceWorkerRegistration* registration = | 
|   912         context()->GetLiveRegistration(version->registration_id()); |   991         context()->GetLiveRegistration(version->registration_id()); | 
|   913     bool is_update = registration->active_version() && |   992     bool is_update = registration->active_version() && | 
|   914                      version != registration->active_version(); |   993                      version != registration->active_version(); | 
|   915  |   994  | 
|   916     ASSERT_TRUE(version); |   995     ASSERT_TRUE(version); | 
|   917     version->AddListener(this); |   996     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. |  1032       // Spoof caching the script for the new version. | 
|   954       WriteStringResponse(storage(), resource_id, "mock_different_script"); |  1033       WriteStringResponse(storage(), resource_id, "mock_different_script"); | 
|   955       version->script_cache_map()->NotifyFinishedCaching( |  1034       version->script_cache_map()->NotifyFinishedCaching( | 
|   956           script, kMockScriptSize, net::OK, std::string()); |  1035           script, kMockScriptSize, net::OK, std::string()); | 
|   957       version->SetMainScriptHttpResponseInfo( |  1036       version->SetMainScriptHttpResponseInfo( | 
|   958           EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); |  1037           EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); | 
|   959     } |  1038     } | 
|   960  |  1039  | 
|   961     EmbeddedWorkerTestHelper::OnStartWorker( |  1040     EmbeddedWorkerTestHelper::OnStartWorker( | 
|   962         embedded_worker_id, version_id, scope, script, pause_after_download, |  1041         embedded_worker_id, version_id, scope, script, pause_after_download, | 
|   963         std::move(request), std::move(instance_host)); |  1042         std::move(request), std::move(instance_host), | 
 |  1043         std::move(provider_client_info)); | 
|   964   } |  1044   } | 
|   965  |  1045  | 
|   966   void OnResumeAfterDownload(int embedded_worker_id) override { |  1046   void OnResumeAfterDownload(int embedded_worker_id) override { | 
|   967     if (!force_start_worker_failure_) { |  1047     if (!force_start_worker_failure_) { | 
|   968       EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); |  1048       EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); | 
|   969     } else { |  1049     } else { | 
|   970       SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id, |  1050       SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id); | 
|   971                                   GetNextProviderId()); |  | 
|   972       SimulateWorkerScriptEvaluated(embedded_worker_id, false); |  1051       SimulateWorkerScriptEvaluated(embedded_worker_id, false); | 
|   973     } |  1052     } | 
|   974   } |  1053   } | 
|   975  |  1054  | 
|   976   // ServiceWorkerRegistration::Listener overrides |  1055   // ServiceWorkerRegistration::Listener overrides | 
|   977   void OnVersionAttributesChanged( |  1056   void OnVersionAttributesChanged( | 
|   978       ServiceWorkerRegistration* registration, |  1057       ServiceWorkerRegistration* registration, | 
|   979       ChangedVersionAttributesMask changed_mask, |  1058       ChangedVersionAttributesMask changed_mask, | 
|   980       const ServiceWorkerRegistrationInfo& info) override { |  1059       const ServiceWorkerRegistrationInfo& info) override { | 
|   981     AttributeChangeLogEntry entry; |  1060     AttributeChangeLogEntry entry; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  1009   bool force_start_worker_failure_ = false; |  1088   bool force_start_worker_failure_ = false; | 
|  1010 }; |  1089 }; | 
|  1011  |  1090  | 
|  1012 // Helper class for update tests that evicts the active version when the update |  1091 // Helper class for update tests that evicts the active version when the update | 
|  1013 // worker is about to be started. |  1092 // worker is about to be started. | 
|  1014 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { |  1093 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { | 
|  1015  public: |  1094  public: | 
|  1016   EvictIncumbentVersionHelper() {} |  1095   EvictIncumbentVersionHelper() {} | 
|  1017   ~EvictIncumbentVersionHelper() override {} |  1096   ~EvictIncumbentVersionHelper() override {} | 
|  1018  |  1097  | 
|  1019   void OnStartWorker(int embedded_worker_id, |  1098   void OnStartWorker( | 
|  1020                      int64_t version_id, |  1099       int embedded_worker_id, | 
|  1021                      const GURL& scope, |  1100       int64_t version_id, | 
|  1022                      const GURL& script, |  1101       const GURL& scope, | 
|  1023                      bool pause_after_download, |  1102       const GURL& script, | 
|  1024                      mojom::ServiceWorkerEventDispatcherRequest request, |  1103       bool pause_after_download, | 
|  1025                      mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |  1104       mojom::ServiceWorkerEventDispatcherRequest request, | 
|  1026                          instance_host) override { |  1105       mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 
 |  1106       mojom::ServiceWorkerProviderClientInfoPtr provider_client_info) override { | 
|  1027     ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |  1107     ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 
|  1028     ServiceWorkerRegistration* registration = |  1108     ServiceWorkerRegistration* registration = | 
|  1029         context()->GetLiveRegistration(version->registration_id()); |  1109         context()->GetLiveRegistration(version->registration_id()); | 
|  1030     bool is_update = registration->active_version() && |  1110     bool is_update = registration->active_version() && | 
|  1031                      version != registration->active_version(); |  1111                      version != registration->active_version(); | 
|  1032     if (is_update) { |  1112     if (is_update) { | 
|  1033       // Evict the incumbent worker. |  1113       // Evict the incumbent worker. | 
|  1034       ASSERT_FALSE(registration->waiting_version()); |  1114       ASSERT_FALSE(registration->waiting_version()); | 
|  1035       registration->DeleteVersion( |  1115       registration->DeleteVersion( | 
|  1036           make_scoped_refptr(registration->active_version())); |  1116           make_scoped_refptr(registration->active_version())); | 
|  1037     } |  1117     } | 
|  1038     UpdateJobTestHelper::OnStartWorker( |  1118     UpdateJobTestHelper::OnStartWorker( | 
|  1039         embedded_worker_id, version_id, scope, script, pause_after_download, |  1119         embedded_worker_id, version_id, scope, script, pause_after_download, | 
|  1040         std::move(request), std::move(instance_host)); |  1120         std::move(request), std::move(instance_host), | 
 |  1121         std::move(provider_client_info)); | 
|  1041   } |  1122   } | 
|  1042  |  1123  | 
|  1043   void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { |  1124   void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { | 
|  1044     registration_failed_ = true; |  1125     registration_failed_ = true; | 
|  1045   } |  1126   } | 
|  1046  |  1127  | 
|  1047   bool registration_failed_ = false; |  1128   bool registration_failed_ = false; | 
|  1048 }; |  1129 }; | 
|  1049  |  1130  | 
|  1050 }  // namespace |  1131 }  // namespace | 
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1703  public: |  1784  public: | 
|  1704   explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( |  1785   explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( | 
|  1705       base::WeakPtr<EmbeddedWorkerTestHelper> helper) |  1786       base::WeakPtr<EmbeddedWorkerTestHelper> helper) | 
|  1706       : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |  1787       : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | 
|  1707   int num_of_startworker() const { return num_of_startworker_; } |  1788   int num_of_startworker() const { return num_of_startworker_; } | 
|  1708   void set_next_pause_after_download(bool expectation) { |  1789   void set_next_pause_after_download(bool expectation) { | 
|  1709     next_pause_after_download_ = expectation; |  1790     next_pause_after_download_ = expectation; | 
|  1710   } |  1791   } | 
|  1711  |  1792  | 
|  1712  protected: |  1793  protected: | 
|  1713   void StartWorker(const EmbeddedWorkerStartParams& params, |  1794   void StartWorker( | 
|  1714                    mojom::ServiceWorkerEventDispatcherRequest request, |  1795       const EmbeddedWorkerStartParams& params, | 
|  1715                    mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |  1796       mojom::ServiceWorkerEventDispatcherRequest request, | 
|  1716                        instance_host) override { |  1797       mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 
 |  1798       mojom::ServiceWorkerProviderClientInfoPtr provider_client_info) override { | 
|  1717     ASSERT_TRUE(next_pause_after_download_.has_value()); |  1799     ASSERT_TRUE(next_pause_after_download_.has_value()); | 
|  1718     EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); |  1800     EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); | 
|  1719     num_of_startworker_++; |  1801     num_of_startworker_++; | 
|  1720     EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( |  1802     EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( | 
|  1721         params, std::move(request), std::move(instance_host)); |  1803         params, std::move(request), std::move(instance_host), | 
 |  1804         std::move(provider_client_info)); | 
|  1722   } |  1805   } | 
|  1723  |  1806  | 
|  1724  private: |  1807  private: | 
|  1725   base::Optional<bool> next_pause_after_download_; |  1808   base::Optional<bool> next_pause_after_download_; | 
|  1726   int num_of_startworker_ = 0; |  1809   int num_of_startworker_ = 0; | 
|  1727   DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); |  1810   DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); | 
|  1728 }; |  1811 }; | 
|  1729  |  1812  | 
|  1730 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |  1813 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 
|  1731   UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |  1814   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 |  1887   // should not be promoted to ACTIVATED because failure occur | 
|  1805   // during shutdown. |  1888   // during shutdown. | 
|  1806   runner->RunPendingTasks(); |  1889   runner->RunPendingTasks(); | 
|  1807   base::RunLoop().RunUntilIdle(); |  1890   base::RunLoop().RunUntilIdle(); | 
|  1808   EXPECT_EQ(new_version.get(), registration->active_version()); |  1891   EXPECT_EQ(new_version.get(), registration->active_version()); | 
|  1809   EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |  1892   EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 
|  1810   registration->RemoveListener(update_helper); |  1893   registration->RemoveListener(update_helper); | 
|  1811 } |  1894 } | 
|  1812  |  1895  | 
|  1813 }  // namespace content |  1896 }  // namespace content | 
| OLD | NEW |