| 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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 class ServiceWorkerJobTest : public testing::Test { | 99 class ServiceWorkerJobTest : public testing::Test { |
| 100 public: | 100 public: |
| 101 ServiceWorkerJobTest() | 101 ServiceWorkerJobTest() |
| 102 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 102 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 103 render_process_id_(kMockRenderProcessId) {} | 103 render_process_id_(kMockRenderProcessId) {} |
| 104 | 104 |
| 105 virtual void SetUp() OVERRIDE { | 105 virtual void SetUp() override { |
| 106 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); | 106 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 virtual void TearDown() OVERRIDE { | 109 virtual void TearDown() override { |
| 110 helper_.reset(); | 110 helper_.reset(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 ServiceWorkerContextCore* context() const { return helper_->context(); } | 113 ServiceWorkerContextCore* context() const { return helper_->context(); } |
| 114 | 114 |
| 115 ServiceWorkerJobCoordinator* job_coordinator() const { | 115 ServiceWorkerJobCoordinator* job_coordinator() const { |
| 116 return context()->job_coordinator(); | 116 return context()->job_coordinator(); |
| 117 } | 117 } |
| 118 ServiceWorkerStorage* storage() const { return context()->storage(); } | 118 ServiceWorkerStorage* storage() const { return context()->storage(); } |
| 119 | 119 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 401 |
| 402 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 402 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
| 403 public: | 403 public: |
| 404 explicit FailToStartWorkerTestHelper(int mock_render_process_id) | 404 explicit FailToStartWorkerTestHelper(int mock_render_process_id) |
| 405 : EmbeddedWorkerTestHelper(mock_render_process_id) {} | 405 : EmbeddedWorkerTestHelper(mock_render_process_id) {} |
| 406 | 406 |
| 407 virtual void OnStartWorker(int embedded_worker_id, | 407 virtual void OnStartWorker(int embedded_worker_id, |
| 408 int64 service_worker_version_id, | 408 int64 service_worker_version_id, |
| 409 const GURL& scope, | 409 const GURL& scope, |
| 410 const GURL& script_url, | 410 const GURL& script_url, |
| 411 bool pause_after_download) OVERRIDE { | 411 bool pause_after_download) override { |
| 412 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 412 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
| 413 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 413 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
| 414 } | 414 } |
| 415 }; | 415 }; |
| 416 | 416 |
| 417 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 417 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
| 418 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); | 418 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); |
| 419 | 419 |
| 420 bool called = false; | 420 bool called = false; |
| 421 scoped_refptr<ServiceWorkerRegistration> registration; | 421 scoped_refptr<ServiceWorkerRegistration> registration; |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 EXPECT_FALSE(registration->waiting_version()); | 924 EXPECT_FALSE(registration->waiting_version()); |
| 925 registration_ = registration; | 925 registration_ = registration; |
| 926 return registration; | 926 return registration; |
| 927 } | 927 } |
| 928 | 928 |
| 929 // EmbeddedWorkerTestHelper overrides | 929 // EmbeddedWorkerTestHelper overrides |
| 930 virtual void OnStartWorker(int embedded_worker_id, | 930 virtual void OnStartWorker(int embedded_worker_id, |
| 931 int64 version_id, | 931 int64 version_id, |
| 932 const GURL& scope, | 932 const GURL& scope, |
| 933 const GURL& script, | 933 const GURL& script, |
| 934 bool pause_after_download) OVERRIDE { | 934 bool pause_after_download) override { |
| 935 const std::string kMockScriptBody = "mock_script"; | 935 const std::string kMockScriptBody = "mock_script"; |
| 936 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 936 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |
| 937 ASSERT_TRUE(version); | 937 ASSERT_TRUE(version); |
| 938 version->AddListener(this); | 938 version->AddListener(this); |
| 939 | 939 |
| 940 if (!pause_after_download) { | 940 if (!pause_after_download) { |
| 941 // Spoof caching the script for the initial version. | 941 // Spoof caching the script for the initial version. |
| 942 int64 resource_id = storage()->NewResourceId(); | 942 int64 resource_id = storage()->NewResourceId(); |
| 943 version->script_cache_map()->NotifyStartedCaching(script, resource_id); | 943 version->script_cache_map()->NotifyStartedCaching(script, resource_id); |
| 944 WriteStringResponse(storage(), resource_id, kMockScriptBody); | 944 WriteStringResponse(storage(), resource_id, kMockScriptBody); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 956 script, net::URLRequestStatus()); | 956 script, net::URLRequestStatus()); |
| 957 } | 957 } |
| 958 EmbeddedWorkerTestHelper::OnStartWorker( | 958 EmbeddedWorkerTestHelper::OnStartWorker( |
| 959 embedded_worker_id, version_id, scope, script, pause_after_download); | 959 embedded_worker_id, version_id, scope, script, pause_after_download); |
| 960 } | 960 } |
| 961 | 961 |
| 962 // ServiceWorkerRegistration::Listener overrides | 962 // ServiceWorkerRegistration::Listener overrides |
| 963 virtual void OnVersionAttributesChanged( | 963 virtual void OnVersionAttributesChanged( |
| 964 ServiceWorkerRegistration* registration, | 964 ServiceWorkerRegistration* registration, |
| 965 ChangedVersionAttributesMask changed_mask, | 965 ChangedVersionAttributesMask changed_mask, |
| 966 const ServiceWorkerRegistrationInfo& info) OVERRIDE { | 966 const ServiceWorkerRegistrationInfo& info) override { |
| 967 AttributeChangeLogEntry entry; | 967 AttributeChangeLogEntry entry; |
| 968 entry.registration_id = registration->id(); | 968 entry.registration_id = registration->id(); |
| 969 entry.mask = changed_mask; | 969 entry.mask = changed_mask; |
| 970 entry.info = info; | 970 entry.info = info; |
| 971 attribute_change_log_.push_back(entry); | 971 attribute_change_log_.push_back(entry); |
| 972 } | 972 } |
| 973 | 973 |
| 974 virtual void OnRegistrationFailed( | 974 virtual void OnRegistrationFailed( |
| 975 ServiceWorkerRegistration* registration) OVERRIDE { | 975 ServiceWorkerRegistration* registration) override { |
| 976 NOTREACHED(); | 976 NOTREACHED(); |
| 977 } | 977 } |
| 978 | 978 |
| 979 virtual void OnRegistrationFinishedUninstalling( | 979 virtual void OnRegistrationFinishedUninstalling( |
| 980 ServiceWorkerRegistration* registration) OVERRIDE { | 980 ServiceWorkerRegistration* registration) override { |
| 981 NOTREACHED(); | 981 NOTREACHED(); |
| 982 } | 982 } |
| 983 | 983 |
| 984 virtual void OnUpdateFound( | 984 virtual void OnUpdateFound( |
| 985 ServiceWorkerRegistration* registration) OVERRIDE { | 985 ServiceWorkerRegistration* registration) override { |
| 986 ASSERT_FALSE(update_found_); | 986 ASSERT_FALSE(update_found_); |
| 987 update_found_ = true; | 987 update_found_ = true; |
| 988 } | 988 } |
| 989 | 989 |
| 990 // ServiceWorkerVersion::Listener overrides | 990 // ServiceWorkerVersion::Listener overrides |
| 991 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE { | 991 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) override { |
| 992 StateChangeLogEntry entry; | 992 StateChangeLogEntry entry; |
| 993 entry.version_id = version->version_id(); | 993 entry.version_id = version->version_id(); |
| 994 entry.status = version->status(); | 994 entry.status = version->status(); |
| 995 state_change_log_.push_back(entry); | 995 state_change_log_.push_back(entry); |
| 996 } | 996 } |
| 997 | 997 |
| 998 scoped_refptr<ServiceWorkerRegistration> registration_; | 998 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 999 | 999 |
| 1000 std::vector<AttributeChangeLogEntry> attribute_change_log_; | 1000 std::vector<AttributeChangeLogEntry> attribute_change_log_; |
| 1001 std::vector<StateChangeLogEntry> state_change_log_; | 1001 std::vector<StateChangeLogEntry> state_change_log_; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 EXPECT_TRUE(called); | 1190 EXPECT_TRUE(called); |
| 1191 | 1191 |
| 1192 // Verify the registration was not modified by the Update. | 1192 // Verify the registration was not modified by the Update. |
| 1193 EXPECT_TRUE(registration->is_uninstalling()); | 1193 EXPECT_TRUE(registration->is_uninstalling()); |
| 1194 EXPECT_EQ(active_version, registration->active_version()); | 1194 EXPECT_EQ(active_version, registration->active_version()); |
| 1195 EXPECT_EQ(NULL, registration->waiting_version()); | 1195 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1196 EXPECT_EQ(NULL, registration->installing_version()); | 1196 EXPECT_EQ(NULL, registration->installing_version()); |
| 1197 } | 1197 } |
| 1198 | 1198 |
| 1199 } // namespace content | 1199 } // namespace content |
| OLD | NEW |