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" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
12 #include "content/browser/browser_thread_impl.h" | |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_registration_handle.h" | 12 #include "content/browser/service_worker/service_worker_registration_handle.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "url/gurl.h" | 15 #include "url/gurl.h" |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 class ServiceWorkerRegistrationTest : public testing::Test { | 19 class ServiceWorkerRegistrationTest : public testing::Test { |
21 public: | 20 public: |
22 ServiceWorkerRegistrationTest() | 21 ServiceWorkerRegistrationTest() |
23 : io_thread_(BrowserThread::IO, &message_loop_) {} | 22 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
24 | 23 |
25 void SetUp() override { | 24 void SetUp() override { |
26 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( | 25 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( |
27 new MockServiceWorkerDatabaseTaskManager( | 26 new MockServiceWorkerDatabaseTaskManager( |
28 base::ThreadTaskRunnerHandle::Get())); | 27 base::ThreadTaskRunnerHandle::Get())); |
29 context_.reset( | 28 context_.reset( |
30 new ServiceWorkerContextCore(base::FilePath(), | 29 new ServiceWorkerContextCore(base::FilePath(), |
31 database_task_manager.Pass(), | 30 database_task_manager.Pass(), |
32 base::ThreadTaskRunnerHandle::Get(), | 31 base::ThreadTaskRunnerHandle::Get(), |
33 NULL, | 32 NULL, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 74 } |
76 | 75 |
77 scoped_refptr<ServiceWorkerRegistration> observed_registration_; | 76 scoped_refptr<ServiceWorkerRegistration> observed_registration_; |
78 ChangedVersionAttributesMask observed_changed_mask_; | 77 ChangedVersionAttributesMask observed_changed_mask_; |
79 ServiceWorkerRegistrationInfo observed_info_; | 78 ServiceWorkerRegistrationInfo observed_info_; |
80 }; | 79 }; |
81 | 80 |
82 protected: | 81 protected: |
83 scoped_ptr<ServiceWorkerContextCore> context_; | 82 scoped_ptr<ServiceWorkerContextCore> context_; |
84 base::WeakPtr<ServiceWorkerContextCore> context_ptr_; | 83 base::WeakPtr<ServiceWorkerContextCore> context_ptr_; |
85 base::MessageLoopForIO message_loop_; | 84 TestBrowserThreadBundle thread_bundle_; |
86 BrowserThreadImpl io_thread_; | |
87 }; | 85 }; |
88 | 86 |
89 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { | 87 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { |
90 const GURL kScope("http://www.example.not/"); | 88 const GURL kScope("http://www.example.not/"); |
91 const GURL kScript("http://www.example.not/service_worker.js"); | 89 const GURL kScript("http://www.example.not/service_worker.js"); |
92 int64 kRegistrationId = 1L; | 90 int64 kRegistrationId = 1L; |
93 scoped_refptr<ServiceWorkerRegistration> registration = | 91 scoped_refptr<ServiceWorkerRegistration> registration = |
94 new ServiceWorkerRegistration( | 92 new ServiceWorkerRegistration( |
95 kScope, | 93 kScope, |
96 kRegistrationId, | 94 kRegistrationId, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 scoped_ptr<ServiceWorkerRegistrationHandle> handle( | 165 scoped_ptr<ServiceWorkerRegistrationHandle> handle( |
168 new ServiceWorkerRegistrationHandle( | 166 new ServiceWorkerRegistrationHandle( |
169 context_ptr_, | 167 context_ptr_, |
170 base::WeakPtr<ServiceWorkerProviderHost>(), | 168 base::WeakPtr<ServiceWorkerProviderHost>(), |
171 registration.get())); | 169 registration.get())); |
172 registration->NotifyRegistrationFailed(); | 170 registration->NotifyRegistrationFailed(); |
173 // Don't crash when handle gets destructed. | 171 // Don't crash when handle gets destructed. |
174 } | 172 } |
175 | 173 |
176 } // namespace content | 174 } // namespace content |
OLD | NEW |