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