| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "content/browser/browser_thread_impl.h" | 12 #include "content/browser/browser_thread_impl.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_registration_handle.h" | 14 #include "content/browser/service_worker/service_worker_registration_handle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class ServiceWorkerRegistrationTest : public testing::Test { | 20 class ServiceWorkerRegistrationTest : public testing::Test { |
| 21 public: | 21 public: |
| 22 ServiceWorkerRegistrationTest() | 22 ServiceWorkerRegistrationTest() |
| 23 : io_thread_(BrowserThread::IO, &message_loop_) {} | 23 : io_thread_(BrowserThread::IO, &message_loop_) {} |
| 24 | 24 |
| 25 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() override { |
| 26 context_.reset( | 26 context_.reset( |
| 27 new ServiceWorkerContextCore(base::FilePath(), | 27 new ServiceWorkerContextCore(base::FilePath(), |
| 28 base::ThreadTaskRunnerHandle::Get(), | 28 base::ThreadTaskRunnerHandle::Get(), |
| 29 base::ThreadTaskRunnerHandle::Get(), | 29 base::ThreadTaskRunnerHandle::Get(), |
| 30 base::ThreadTaskRunnerHandle::Get(), | 30 base::ThreadTaskRunnerHandle::Get(), |
| 31 NULL, | 31 NULL, |
| 32 NULL, | 32 NULL, |
| 33 NULL)); | 33 NULL)); |
| 34 context_ptr_ = context_->AsWeakPtr(); | 34 context_ptr_ = context_->AsWeakPtr(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void TearDown() OVERRIDE { | 37 virtual void TearDown() override { |
| 38 context_.reset(); | 38 context_.reset(); |
| 39 base::RunLoop().RunUntilIdle(); | 39 base::RunLoop().RunUntilIdle(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 class RegistrationListener : public ServiceWorkerRegistration::Listener { | 42 class RegistrationListener : public ServiceWorkerRegistration::Listener { |
| 43 public: | 43 public: |
| 44 RegistrationListener() {} | 44 RegistrationListener() {} |
| 45 ~RegistrationListener() { | 45 ~RegistrationListener() { |
| 46 if (observed_registration_.get()) | 46 if (observed_registration_.get()) |
| 47 observed_registration_->RemoveListener(this); | 47 observed_registration_->RemoveListener(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void OnVersionAttributesChanged( | 50 virtual void OnVersionAttributesChanged( |
| 51 ServiceWorkerRegistration* registration, | 51 ServiceWorkerRegistration* registration, |
| 52 ChangedVersionAttributesMask changed_mask, | 52 ChangedVersionAttributesMask changed_mask, |
| 53 const ServiceWorkerRegistrationInfo& info) OVERRIDE { | 53 const ServiceWorkerRegistrationInfo& info) override { |
| 54 observed_registration_ = registration; | 54 observed_registration_ = registration; |
| 55 observed_changed_mask_ = changed_mask; | 55 observed_changed_mask_ = changed_mask; |
| 56 observed_info_ = info; | 56 observed_info_ = info; |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void OnRegistrationFailed( | 59 virtual void OnRegistrationFailed( |
| 60 ServiceWorkerRegistration* registration) OVERRIDE { | 60 ServiceWorkerRegistration* registration) override { |
| 61 NOTREACHED(); | 61 NOTREACHED(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void OnRegistrationFinishedUninstalling( | 64 virtual void OnRegistrationFinishedUninstalling( |
| 65 ServiceWorkerRegistration* registration) OVERRIDE { | 65 ServiceWorkerRegistration* registration) override { |
| 66 NOTREACHED(); | 66 NOTREACHED(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void OnUpdateFound( | 69 virtual void OnUpdateFound( |
| 70 ServiceWorkerRegistration* registration) OVERRIDE { | 70 ServiceWorkerRegistration* registration) override { |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void Reset() { | 74 void Reset() { |
| 75 observed_registration_ = NULL; | 75 observed_registration_ = NULL; |
| 76 observed_changed_mask_ = ChangedVersionAttributesMask(); | 76 observed_changed_mask_ = ChangedVersionAttributesMask(); |
| 77 observed_info_ = ServiceWorkerRegistrationInfo(); | 77 observed_info_ = ServiceWorkerRegistrationInfo(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 scoped_refptr<ServiceWorkerRegistration> observed_registration_; | 80 scoped_refptr<ServiceWorkerRegistration> observed_registration_; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 scoped_ptr<ServiceWorkerRegistrationHandle> handle( | 169 scoped_ptr<ServiceWorkerRegistrationHandle> handle( |
| 170 new ServiceWorkerRegistrationHandle(context_ptr_, | 170 new ServiceWorkerRegistrationHandle(context_ptr_, |
| 171 NULL, | 171 NULL, |
| 172 kProviderId, | 172 kProviderId, |
| 173 registration.get())); | 173 registration.get())); |
| 174 registration->NotifyRegistrationFailed(); | 174 registration->NotifyRegistrationFailed(); |
| 175 // Don't crash when handle gets destructed. | 175 // Don't crash when handle gets destructed. |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace content | 178 } // namespace content |
| OLD | NEW |