OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/background_sync/background_sync_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
10 #include "base/power_monitor/power_monitor_source.h" | 11 #include "base/power_monitor/power_monitor_source.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
13 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
14 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 16 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
15 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
17 #include "content/browser/service_worker/service_worker_storage.h" | 19 #include "content/browser/service_worker/service_worker_storage.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 140 |
139 protected: | 141 protected: |
140 void StoreDataInBackend( | 142 void StoreDataInBackend( |
141 int64 sw_registration_id, | 143 int64 sw_registration_id, |
142 const GURL& origin, | 144 const GURL& origin, |
143 const std::string& key, | 145 const std::string& key, |
144 const std::string& data, | 146 const std::string& data, |
145 const ServiceWorkerStorage::StatusCallback& callback) override { | 147 const ServiceWorkerStorage::StatusCallback& callback) override { |
146 EXPECT_TRUE(continuation_.is_null()); | 148 EXPECT_TRUE(continuation_.is_null()); |
147 if (corrupt_backend_) { | 149 if (corrupt_backend_) { |
148 base::MessageLoop::current()->PostTask( | 150 base::ThreadTaskRunnerHandle::Get()->PostTask( |
149 FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 151 FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
150 return; | 152 return; |
151 } | 153 } |
152 continuation_ = | 154 continuation_ = |
153 base::Bind(&TestBackgroundSyncManager::StoreDataInBackendContinue, | 155 base::Bind(&TestBackgroundSyncManager::StoreDataInBackendContinue, |
154 base::Unretained(this), sw_registration_id, origin, key, | 156 base::Unretained(this), sw_registration_id, origin, key, |
155 data, callback); | 157 data, callback); |
156 if (delay_backend_) | 158 if (delay_backend_) |
157 return; | 159 return; |
158 | 160 |
159 Continue(); | 161 Continue(); |
160 } | 162 } |
161 | 163 |
162 void GetDataFromBackend( | 164 void GetDataFromBackend( |
163 const std::string& key, | 165 const std::string& key, |
164 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& | 166 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
165 callback) override { | 167 callback) override { |
166 EXPECT_TRUE(continuation_.is_null()); | 168 EXPECT_TRUE(continuation_.is_null()); |
167 if (corrupt_backend_) { | 169 if (corrupt_backend_) { |
168 base::MessageLoop::current()->PostTask( | 170 base::ThreadTaskRunnerHandle::Get()->PostTask( |
169 FROM_HERE, | 171 FROM_HERE, |
170 base::Bind(callback, std::vector<std::pair<int64, std::string>>(), | 172 base::Bind(callback, std::vector<std::pair<int64, std::string>>(), |
171 SERVICE_WORKER_ERROR_FAILED)); | 173 SERVICE_WORKER_ERROR_FAILED)); |
172 return; | 174 return; |
173 } | 175 } |
174 continuation_ = | 176 continuation_ = |
175 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue, | 177 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue, |
176 base::Unretained(this), key, callback); | 178 base::Unretained(this), key, callback); |
177 if (delay_backend_) | 179 if (delay_backend_) |
178 return; | 180 return; |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1218 |
1217 RegisterAndVerifySyncEventDelayed(sync_reg_1_); | 1219 RegisterAndVerifySyncEventDelayed(sync_reg_1_); |
1218 | 1220 |
1219 // Create a new manager which should fire the sync again on init. | 1221 // Create a new manager which should fire the sync again on init. |
1220 InitSyncEventTest(); | 1222 InitSyncEventTest(); |
1221 EXPECT_FALSE(GetRegistration(sync_reg_1_)); | 1223 EXPECT_FALSE(GetRegistration(sync_reg_1_)); |
1222 EXPECT_EQ(2, sync_events_called_); | 1224 EXPECT_EQ(2, sync_events_called_); |
1223 } | 1225 } |
1224 | 1226 |
1225 } // namespace content | 1227 } // namespace content |
OLD | NEW |