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