| 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/public/browser/service_worker_context.h" | 5 #include "content/public/browser/service_worker_context.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 "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| 11 #include "content/browser/service_worker/embedded_worker_registry.h" | 11 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 12 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 12 #include "content/browser/service_worker/embedded_worker_test_helper.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.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 15 #include "content/browser/service_worker/service_worker_storage.h" | 15 #include "content/browser/service_worker/service_worker_storage.h" |
| 16 #include "content/common/service_worker/embedded_worker_messages.h" |
| 16 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 void SaveResponseCallback(bool* called, | 26 void SaveResponseCallback(bool* called, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 GURL("http://www.example.com/*"), | 144 GURL("http://www.example.com/*"), |
| 144 GURL("http://www.example.com/service_worker.js"), | 145 GURL("http://www.example.com/service_worker.js"), |
| 145 render_process_id_, | 146 render_process_id_, |
| 146 NULL, | 147 NULL, |
| 147 MakeRegisteredCallback(&called, ®istration_id, &version_id)); | 148 MakeRegisteredCallback(&called, ®istration_id, &version_id)); |
| 148 | 149 |
| 149 ASSERT_FALSE(called); | 150 ASSERT_FALSE(called); |
| 150 base::RunLoop().RunUntilIdle(); | 151 base::RunLoop().RunUntilIdle(); |
| 151 EXPECT_TRUE(called); | 152 EXPECT_TRUE(called); |
| 152 | 153 |
| 153 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); | 154 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 155 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 156 EmbeddedWorkerMsg_StartWorker::ID)); |
| 154 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 157 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 155 ServiceWorkerMsg_InstallEvent::ID)); | 158 ServiceWorkerMsg_InstallEvent::ID)); |
| 156 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 159 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 157 ServiceWorkerMsg_ActivateEvent::ID)); | 160 ServiceWorkerMsg_ActivateEvent::ID)); |
| 161 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 162 EmbeddedWorkerMsg_StopWorker::ID)); |
| 158 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 163 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 159 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); | 164 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); |
| 160 | 165 |
| 161 context()->storage()->FindRegistrationForId( | 166 context()->storage()->FindRegistrationForId( |
| 162 registration_id, | 167 registration_id, |
| 163 GURL("http://www.example.com"), | 168 GURL("http://www.example.com"), |
| 164 base::Bind(&ExpectRegisteredWorkers, | 169 base::Bind(&ExpectRegisteredWorkers, |
| 165 SERVICE_WORKER_OK, | 170 SERVICE_WORKER_OK, |
| 166 version_id, | 171 version_id, |
| 167 false /* expect_pending */, | 172 false /* expect_pending */, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 182 GURL("http://www.example.com/*"), | 187 GURL("http://www.example.com/*"), |
| 183 GURL("http://www.example.com/service_worker.js"), | 188 GURL("http://www.example.com/service_worker.js"), |
| 184 render_process_id_, | 189 render_process_id_, |
| 185 NULL, | 190 NULL, |
| 186 MakeRegisteredCallback(&called, ®istration_id, &version_id)); | 191 MakeRegisteredCallback(&called, ®istration_id, &version_id)); |
| 187 | 192 |
| 188 ASSERT_FALSE(called); | 193 ASSERT_FALSE(called); |
| 189 base::RunLoop().RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
| 190 EXPECT_TRUE(called); | 195 EXPECT_TRUE(called); |
| 191 | 196 |
| 192 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 197 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); |
| 198 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 199 EmbeddedWorkerMsg_StartWorker::ID)); |
| 193 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 200 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 194 ServiceWorkerMsg_InstallEvent::ID)); | 201 ServiceWorkerMsg_InstallEvent::ID)); |
| 195 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 202 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 196 ServiceWorkerMsg_ActivateEvent::ID)); | 203 ServiceWorkerMsg_ActivateEvent::ID)); |
| 204 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 205 EmbeddedWorkerMsg_StopWorker::ID)); |
| 197 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 206 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 198 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); | 207 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); |
| 199 | 208 |
| 200 context()->storage()->FindRegistrationForId( | 209 context()->storage()->FindRegistrationForId( |
| 201 registration_id, | 210 registration_id, |
| 202 GURL("http://www.example.com"), | 211 GURL("http://www.example.com"), |
| 203 base::Bind(&ExpectRegisteredWorkers, | 212 base::Bind(&ExpectRegisteredWorkers, |
| 204 SERVICE_WORKER_ERROR_NOT_FOUND, | 213 SERVICE_WORKER_ERROR_NOT_FOUND, |
| 205 kInvalidServiceWorkerVersionId, | 214 kInvalidServiceWorkerVersionId, |
| 206 false /* expect_pending */, | 215 false /* expect_pending */, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 221 GURL("http://www.example.com/*"), | 230 GURL("http://www.example.com/*"), |
| 222 GURL("http://www.example.com/service_worker.js"), | 231 GURL("http://www.example.com/service_worker.js"), |
| 223 render_process_id_, | 232 render_process_id_, |
| 224 NULL, | 233 NULL, |
| 225 MakeRegisteredCallback(&called, ®istration_id, &version_id)); | 234 MakeRegisteredCallback(&called, ®istration_id, &version_id)); |
| 226 | 235 |
| 227 ASSERT_FALSE(called); | 236 ASSERT_FALSE(called); |
| 228 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
| 229 EXPECT_TRUE(called); | 238 EXPECT_TRUE(called); |
| 230 | 239 |
| 231 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); | 240 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 241 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 242 EmbeddedWorkerMsg_StartWorker::ID)); |
| 232 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 243 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 233 ServiceWorkerMsg_InstallEvent::ID)); | 244 ServiceWorkerMsg_InstallEvent::ID)); |
| 234 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 245 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 235 ServiceWorkerMsg_ActivateEvent::ID)); | 246 ServiceWorkerMsg_ActivateEvent::ID)); |
| 247 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 248 EmbeddedWorkerMsg_StopWorker::ID)); |
| 236 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 249 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 237 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); | 250 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); |
| 238 | 251 |
| 239 context()->storage()->FindRegistrationForId( | 252 context()->storage()->FindRegistrationForId( |
| 240 registration_id, | 253 registration_id, |
| 241 GURL("http://www.example.com"), | 254 GURL("http://www.example.com"), |
| 242 base::Bind(&ExpectRegisteredWorkers, | 255 base::Bind(&ExpectRegisteredWorkers, |
| 243 SERVICE_WORKER_ERROR_NOT_FOUND, | 256 SERVICE_WORKER_ERROR_NOT_FOUND, |
| 244 kInvalidServiceWorkerVersionId, | 257 kInvalidServiceWorkerVersionId, |
| 245 false /* expect_pending */, | 258 false /* expect_pending */, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); | 375 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); |
| 363 | 376 |
| 364 ASSERT_FALSE(called); | 377 ASSERT_FALSE(called); |
| 365 base::RunLoop().RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
| 366 ASSERT_TRUE(called); | 379 ASSERT_TRUE(called); |
| 367 EXPECT_EQ(old_registration_id, new_registration_id); | 380 EXPECT_EQ(old_registration_id, new_registration_id); |
| 368 EXPECT_EQ(old_version_id, new_version_id); | 381 EXPECT_EQ(old_version_id, new_version_id); |
| 369 } | 382 } |
| 370 | 383 |
| 371 } // namespace content | 384 } // namespace content |
| OLD | NEW |