OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | |
11 #include "content/browser/service_worker/service_worker_context_core.h" | |
9 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 12 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
10 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
11 #include "content/browser/service_worker/service_worker_registration_status.h" | 14 #include "content/browser/service_worker/service_worker_registration_status.h" |
12 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "ipc/ipc_test_sink.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
14 | 18 |
15 // Unit tests for testing all job registration tasks. | 19 // Unit tests for testing all job registration tasks. |
16 namespace content { | 20 namespace content { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 void SaveRegistrationCallback( | 24 void SaveRegistrationCallback( |
21 ServiceWorkerStatusCode expected_status, | 25 ServiceWorkerStatusCode expected_status, |
22 bool* called, | 26 bool* called, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 } | 88 } |
85 | 89 |
86 } // namespace | 90 } // namespace |
87 | 91 |
88 class ServiceWorkerJobTest : public testing::Test { | 92 class ServiceWorkerJobTest : public testing::Test { |
89 public: | 93 public: |
90 ServiceWorkerJobTest() | 94 ServiceWorkerJobTest() |
91 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 95 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
92 | 96 |
93 virtual void SetUp() OVERRIDE { | 97 virtual void SetUp() OVERRIDE { |
94 storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL)); | 98 context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL)); |
95 job_coordinator_.reset(new ServiceWorkerJobCoordinator(storage_.get())); | 99 helper_.reset(new EmbeddedWorkerTestHelper(context_.get())); |
100 | |
101 storage_ = context_->storage(); | |
102 job_coordinator_ = context_->job_coordinator(); | |
103 | |
104 scoped_ptr<EmbeddedWorkerInstance> worker = | |
105 context_->embedded_worker_registry()->CreateWorker(); | |
106 | |
107 render_process_id_ = 88; | |
108 int embedded_worker_id = worker->embedded_worker_id(); | |
109 helper_->SimulateAddProcess(embedded_worker_id, render_process_id_); | |
96 } | 110 } |
97 | 111 |
98 virtual void TearDown() OVERRIDE { storage_.reset(); } | 112 virtual void TearDown() OVERRIDE { |
113 helper_.reset(); | |
114 context_.reset(); | |
115 } | |
99 | 116 |
100 protected: | 117 protected: |
101 TestBrowserThreadBundle browser_thread_bundle_; | 118 TestBrowserThreadBundle browser_thread_bundle_; |
102 scoped_ptr<ServiceWorkerStorage> storage_; | 119 scoped_ptr<ServiceWorkerContextCore> context_; |
103 scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_; | 120 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
121 | |
122 // these are just shortcuts into context_ above | |
123 ServiceWorkerStorage* storage_; | |
124 ServiceWorkerJobCoordinator* job_coordinator_; | |
kinuko
2014/02/04 03:37:53
nit: could we instead have accessors like storage(
alecflett
2014/02/04 20:09:04
Done.
| |
125 | |
126 int render_process_id_; | |
kinuko
2014/02/04 03:37:53
Please initialize this in ctor (with -1 etc)
alecflett
2014/02/04 20:09:04
Done.
| |
104 }; | 127 }; |
105 | 128 |
106 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { | 129 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { |
107 scoped_refptr<ServiceWorkerRegistration> original_registration; | 130 scoped_refptr<ServiceWorkerRegistration> original_registration; |
108 bool called; | 131 bool called; |
109 job_coordinator_->Register( | 132 job_coordinator_->Register( |
110 GURL("http://www.example.com/*"), | 133 GURL("http://www.example.com/*"), |
111 GURL("http://www.example.com/service_worker.js"), | 134 GURL("http://www.example.com/service_worker.js"), |
135 render_process_id_, | |
112 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 136 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
113 EXPECT_FALSE(called); | 137 EXPECT_FALSE(called); |
114 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
115 EXPECT_TRUE(called); | 139 EXPECT_TRUE(called); |
116 | 140 |
117 scoped_refptr<ServiceWorkerRegistration> registration1; | 141 scoped_refptr<ServiceWorkerRegistration> registration1; |
118 storage_->FindRegistrationForDocument( | 142 storage_->FindRegistrationForDocument( |
119 GURL("http://www.example.com/"), | 143 GURL("http://www.example.com/"), |
120 SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration1)); | 144 SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration1)); |
121 scoped_refptr<ServiceWorkerRegistration> registration2; | 145 scoped_refptr<ServiceWorkerRegistration> registration2; |
(...skipping 12 matching lines...) Expand all Loading... | |
134 | 158 |
135 ASSERT_EQ(registration1, registration2); | 159 ASSERT_EQ(registration1, registration2); |
136 } | 160 } |
137 | 161 |
138 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { | 162 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
139 bool called; | 163 bool called; |
140 scoped_refptr<ServiceWorkerRegistration> original_registration; | 164 scoped_refptr<ServiceWorkerRegistration> original_registration; |
141 job_coordinator_->Register( | 165 job_coordinator_->Register( |
142 GURL("http://www.example.com/*"), | 166 GURL("http://www.example.com/*"), |
143 GURL("http://www.example.com/service_worker.js"), | 167 GURL("http://www.example.com/service_worker.js"), |
168 render_process_id_, | |
144 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 169 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
145 EXPECT_FALSE(called); | 170 EXPECT_FALSE(called); |
146 base::RunLoop().RunUntilIdle(); | 171 base::RunLoop().RunUntilIdle(); |
147 EXPECT_TRUE(called); | 172 EXPECT_TRUE(called); |
148 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), | 173 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), |
149 original_registration.get()); | 174 original_registration.get()); |
150 | 175 |
151 scoped_refptr<ServiceWorkerRegistration> registration1; | 176 scoped_refptr<ServiceWorkerRegistration> registration1; |
152 storage_->FindRegistrationForDocument( | 177 storage_->FindRegistrationForDocument( |
153 GURL("http://www.example.com/one"), | 178 GURL("http://www.example.com/one"), |
(...skipping 13 matching lines...) Expand all Loading... | |
167 | 192 |
168 ASSERT_EQ(registration1, registration2); | 193 ASSERT_EQ(registration1, registration2); |
169 } | 194 } |
170 | 195 |
171 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { | 196 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
172 bool called1; | 197 bool called1; |
173 scoped_refptr<ServiceWorkerRegistration> original_registration1; | 198 scoped_refptr<ServiceWorkerRegistration> original_registration1; |
174 job_coordinator_->Register( | 199 job_coordinator_->Register( |
175 GURL("http://www.example.com/one/*"), | 200 GURL("http://www.example.com/one/*"), |
176 GURL("http://www.example.com/service_worker.js"), | 201 GURL("http://www.example.com/service_worker.js"), |
202 render_process_id_, | |
177 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); | 203 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); |
178 | 204 |
179 bool called2; | 205 bool called2; |
180 scoped_refptr<ServiceWorkerRegistration> original_registration2; | 206 scoped_refptr<ServiceWorkerRegistration> original_registration2; |
181 job_coordinator_->Register( | 207 job_coordinator_->Register( |
182 GURL("http://www.example.com/two/*"), | 208 GURL("http://www.example.com/two/*"), |
183 GURL("http://www.example.com/service_worker.js"), | 209 GURL("http://www.example.com/service_worker.js"), |
210 render_process_id_, | |
184 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); | 211 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); |
185 | 212 |
186 EXPECT_FALSE(called1); | 213 EXPECT_FALSE(called1); |
187 EXPECT_FALSE(called2); | 214 EXPECT_FALSE(called2); |
188 base::RunLoop().RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
189 EXPECT_TRUE(called2); | 216 EXPECT_TRUE(called2); |
190 EXPECT_TRUE(called1); | 217 EXPECT_TRUE(called1); |
191 | 218 |
192 scoped_refptr<ServiceWorkerRegistration> registration1; | 219 scoped_refptr<ServiceWorkerRegistration> registration1; |
193 storage_->FindRegistrationForDocument( | 220 storage_->FindRegistrationForDocument( |
(...skipping 13 matching lines...) Expand all Loading... | |
207 ASSERT_NE(registration1, registration2); | 234 ASSERT_NE(registration1, registration2); |
208 } | 235 } |
209 | 236 |
210 // Make sure basic registration is working. | 237 // Make sure basic registration is working. |
211 TEST_F(ServiceWorkerJobTest, Register) { | 238 TEST_F(ServiceWorkerJobTest, Register) { |
212 bool called = false; | 239 bool called = false; |
213 scoped_refptr<ServiceWorkerRegistration> registration; | 240 scoped_refptr<ServiceWorkerRegistration> registration; |
214 job_coordinator_->Register( | 241 job_coordinator_->Register( |
215 GURL("http://www.example.com/*"), | 242 GURL("http://www.example.com/*"), |
216 GURL("http://www.example.com/service_worker.js"), | 243 GURL("http://www.example.com/service_worker.js"), |
244 render_process_id_, | |
217 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 245 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
218 | 246 |
219 ASSERT_FALSE(called); | 247 ASSERT_FALSE(called); |
220 base::RunLoop().RunUntilIdle(); | 248 base::RunLoop().RunUntilIdle(); |
221 ASSERT_TRUE(called); | 249 ASSERT_TRUE(called); |
222 | 250 |
223 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 251 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
224 } | 252 } |
225 | 253 |
226 // Make sure registrations are cleaned up when they are unregistered. | 254 // Make sure registrations are cleaned up when they are unregistered. |
227 TEST_F(ServiceWorkerJobTest, Unregister) { | 255 TEST_F(ServiceWorkerJobTest, Unregister) { |
228 GURL pattern("http://www.example.com/*"); | 256 GURL pattern("http://www.example.com/*"); |
229 | 257 |
230 bool called; | 258 bool called; |
231 scoped_refptr<ServiceWorkerRegistration> registration; | 259 scoped_refptr<ServiceWorkerRegistration> registration; |
232 job_coordinator_->Register( | 260 job_coordinator_->Register( |
233 pattern, | 261 pattern, |
234 GURL("http://www.example.com/service_worker.js"), | 262 GURL("http://www.example.com/service_worker.js"), |
263 render_process_id_, | |
235 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 264 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
236 | 265 |
237 ASSERT_FALSE(called); | 266 ASSERT_FALSE(called); |
238 base::RunLoop().RunUntilIdle(); | 267 base::RunLoop().RunUntilIdle(); |
239 ASSERT_TRUE(called); | 268 ASSERT_TRUE(called); |
240 | 269 |
241 job_coordinator_->Unregister(pattern, | 270 job_coordinator_->Unregister(pattern, |
271 render_process_id_, | |
242 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 272 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
243 | 273 |
244 ASSERT_FALSE(called); | 274 ASSERT_FALSE(called); |
245 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
246 ASSERT_TRUE(called); | 276 ASSERT_TRUE(called); |
247 | 277 |
248 ASSERT_TRUE(registration->HasOneRef()); | 278 ASSERT_TRUE(registration->HasOneRef()); |
249 | 279 |
250 storage_->FindRegistrationForPattern( | 280 storage_->FindRegistrationForPattern( |
251 pattern, | 281 pattern, |
252 SaveFoundRegistration(false, SERVICE_WORKER_OK, &called, ®istration)); | 282 SaveFoundRegistration(false, SERVICE_WORKER_OK, &called, ®istration)); |
253 | 283 |
254 ASSERT_FALSE(called); | 284 ASSERT_FALSE(called); |
255 base::RunLoop().RunUntilIdle(); | 285 base::RunLoop().RunUntilIdle(); |
256 ASSERT_TRUE(called); | 286 ASSERT_TRUE(called); |
257 | 287 |
258 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 288 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
259 } | 289 } |
260 | 290 |
261 // Make sure that when a new registration replaces an existing | 291 // Make sure that when a new registration replaces an existing |
262 // registration, that the old one is cleaned up. | 292 // registration, that the old one is cleaned up. |
263 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 293 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
264 GURL pattern("http://www.example.com/*"); | 294 GURL pattern("http://www.example.com/*"); |
265 | 295 |
266 bool called; | 296 bool called; |
267 scoped_refptr<ServiceWorkerRegistration> old_registration; | 297 scoped_refptr<ServiceWorkerRegistration> old_registration; |
268 job_coordinator_->Register( | 298 job_coordinator_->Register( |
269 pattern, | 299 pattern, |
270 GURL("http://www.example.com/service_worker.js"), | 300 GURL("http://www.example.com/service_worker.js"), |
301 render_process_id_, | |
271 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
272 | 303 |
273 ASSERT_FALSE(called); | 304 ASSERT_FALSE(called); |
274 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
275 ASSERT_TRUE(called); | 306 ASSERT_TRUE(called); |
276 | 307 |
277 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | 308 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; |
278 storage_->FindRegistrationForPattern( | 309 storage_->FindRegistrationForPattern( |
279 pattern, | 310 pattern, |
280 SaveFoundRegistration( | 311 SaveFoundRegistration( |
281 true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | 312 true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); |
282 | 313 |
283 ASSERT_FALSE(called); | 314 ASSERT_FALSE(called); |
284 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
285 ASSERT_TRUE(called); | 316 ASSERT_TRUE(called); |
286 | 317 |
287 ASSERT_EQ(old_registration, old_registration_by_pattern); | 318 ASSERT_EQ(old_registration, old_registration_by_pattern); |
288 old_registration_by_pattern = NULL; | 319 old_registration_by_pattern = NULL; |
289 | 320 |
290 scoped_refptr<ServiceWorkerRegistration> new_registration; | 321 scoped_refptr<ServiceWorkerRegistration> new_registration; |
291 job_coordinator_->Register( | 322 job_coordinator_->Register( |
292 pattern, | 323 pattern, |
293 GURL("http://www.example.com/service_worker_new.js"), | 324 GURL("http://www.example.com/service_worker_new.js"), |
325 render_process_id_, | |
294 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | 326 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
295 | 327 |
296 ASSERT_FALSE(called); | 328 ASSERT_FALSE(called); |
297 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
298 ASSERT_TRUE(called); | 330 ASSERT_TRUE(called); |
299 | 331 |
300 ASSERT_TRUE(old_registration->HasOneRef()); | 332 ASSERT_TRUE(old_registration->HasOneRef()); |
301 | 333 |
302 ASSERT_NE(old_registration, new_registration); | 334 ASSERT_NE(old_registration, new_registration); |
303 | 335 |
(...skipping 14 matching lines...) Expand all Loading... | |
318 // combination, that the same registration is used. | 350 // combination, that the same registration is used. |
319 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { | 351 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
320 GURL pattern("http://www.example.com/*"); | 352 GURL pattern("http://www.example.com/*"); |
321 GURL script_url("http://www.example.com/service_worker.js"); | 353 GURL script_url("http://www.example.com/service_worker.js"); |
322 | 354 |
323 bool called; | 355 bool called; |
324 scoped_refptr<ServiceWorkerRegistration> old_registration; | 356 scoped_refptr<ServiceWorkerRegistration> old_registration; |
325 job_coordinator_->Register( | 357 job_coordinator_->Register( |
326 pattern, | 358 pattern, |
327 script_url, | 359 script_url, |
360 render_process_id_, | |
328 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 361 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
329 | 362 |
330 ASSERT_FALSE(called); | 363 ASSERT_FALSE(called); |
331 base::RunLoop().RunUntilIdle(); | 364 base::RunLoop().RunUntilIdle(); |
332 ASSERT_TRUE(called); | 365 ASSERT_TRUE(called); |
333 | 366 |
334 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | 367 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; |
335 storage_->FindRegistrationForPattern( | 368 storage_->FindRegistrationForPattern( |
336 pattern, | 369 pattern, |
337 SaveFoundRegistration( | 370 SaveFoundRegistration( |
338 true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | 371 true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); |
339 ASSERT_FALSE(called); | 372 ASSERT_FALSE(called); |
340 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
341 ASSERT_TRUE(called); | 374 ASSERT_TRUE(called); |
342 | 375 |
343 ASSERT_TRUE(old_registration_by_pattern); | 376 ASSERT_TRUE(old_registration_by_pattern); |
344 | 377 |
345 scoped_refptr<ServiceWorkerRegistration> new_registration; | 378 scoped_refptr<ServiceWorkerRegistration> new_registration; |
346 job_coordinator_->Register( | 379 job_coordinator_->Register( |
347 pattern, | 380 pattern, |
348 script_url, | 381 script_url, |
382 render_process_id_, | |
349 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | 383 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
350 | 384 |
351 ASSERT_FALSE(called); | 385 ASSERT_FALSE(called); |
352 base::RunLoop().RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
353 ASSERT_TRUE(called); | 387 ASSERT_TRUE(called); |
354 | 388 |
355 ASSERT_EQ(old_registration, new_registration); | 389 ASSERT_EQ(old_registration, new_registration); |
356 | 390 |
357 ASSERT_FALSE(old_registration->HasOneRef()); | 391 ASSERT_FALSE(old_registration->HasOneRef()); |
358 | 392 |
(...skipping 14 matching lines...) Expand all Loading... | |
373 // process jobs until the last job. | 407 // process jobs until the last job. |
374 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { | 408 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
375 GURL pattern("http://www.example.com/*"); | 409 GURL pattern("http://www.example.com/*"); |
376 GURL script_url("http://www.example.com/service_worker.js"); | 410 GURL script_url("http://www.example.com/service_worker.js"); |
377 | 411 |
378 bool registration_called = false; | 412 bool registration_called = false; |
379 scoped_refptr<ServiceWorkerRegistration> registration; | 413 scoped_refptr<ServiceWorkerRegistration> registration; |
380 job_coordinator_->Register( | 414 job_coordinator_->Register( |
381 pattern, | 415 pattern, |
382 script_url, | 416 script_url, |
417 render_process_id_, | |
383 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 418 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
384 | 419 |
385 bool unregistration_called = false; | 420 bool unregistration_called = false; |
386 job_coordinator_->Unregister( | 421 job_coordinator_->Unregister( |
387 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 422 pattern, |
423 render_process_id_, | |
424 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | |
388 | 425 |
389 ASSERT_FALSE(registration_called); | 426 ASSERT_FALSE(registration_called); |
390 ASSERT_FALSE(unregistration_called); | 427 ASSERT_FALSE(unregistration_called); |
391 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
392 ASSERT_TRUE(registration_called); | 429 ASSERT_TRUE(registration_called); |
393 ASSERT_TRUE(unregistration_called); | 430 ASSERT_TRUE(unregistration_called); |
394 | 431 |
395 ASSERT_TRUE(registration->is_shutdown()); | 432 ASSERT_TRUE(registration->is_shutdown()); |
396 | 433 |
397 bool find_called = false; | 434 bool find_called = false; |
(...skipping 12 matching lines...) Expand all Loading... | |
410 // shutdown. | 447 // shutdown. |
411 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { | 448 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
412 GURL pattern("http://www.example.com/*"); | 449 GURL pattern("http://www.example.com/*"); |
413 | 450 |
414 GURL script_url1("http://www.example.com/service_worker1.js"); | 451 GURL script_url1("http://www.example.com/service_worker1.js"); |
415 bool registration1_called = false; | 452 bool registration1_called = false; |
416 scoped_refptr<ServiceWorkerRegistration> registration1; | 453 scoped_refptr<ServiceWorkerRegistration> registration1; |
417 job_coordinator_->Register( | 454 job_coordinator_->Register( |
418 pattern, | 455 pattern, |
419 script_url1, | 456 script_url1, |
420 SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, | 457 render_process_id_, |
421 ®istration1)); | 458 SaveRegistration( |
459 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | |
422 | 460 |
423 GURL script_url2("http://www.example.com/service_worker2.js"); | 461 GURL script_url2("http://www.example.com/service_worker2.js"); |
424 bool registration2_called = false; | 462 bool registration2_called = false; |
425 scoped_refptr<ServiceWorkerRegistration> registration2; | 463 scoped_refptr<ServiceWorkerRegistration> registration2; |
426 job_coordinator_->Register( | 464 job_coordinator_->Register( |
427 pattern, | 465 pattern, |
428 script_url2, | 466 script_url2, |
429 SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, | 467 render_process_id_, |
430 ®istration2)); | 468 SaveRegistration( |
469 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | |
431 | 470 |
432 ASSERT_FALSE(registration1_called); | 471 ASSERT_FALSE(registration1_called); |
433 ASSERT_FALSE(registration2_called); | 472 ASSERT_FALSE(registration2_called); |
434 base::RunLoop().RunUntilIdle(); | 473 base::RunLoop().RunUntilIdle(); |
435 ASSERT_TRUE(registration1_called); | 474 ASSERT_TRUE(registration1_called); |
436 ASSERT_TRUE(registration2_called); | 475 ASSERT_TRUE(registration2_called); |
437 | 476 |
438 scoped_refptr<ServiceWorkerRegistration> registration; | 477 scoped_refptr<ServiceWorkerRegistration> registration; |
439 bool find_called = false; | 478 bool find_called = false; |
440 storage_->FindRegistrationForPattern( | 479 storage_->FindRegistrationForPattern( |
(...skipping 13 matching lines...) Expand all Loading... | |
454 // object. | 493 // object. |
455 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 494 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
456 GURL pattern("http://www.example.com/*"); | 495 GURL pattern("http://www.example.com/*"); |
457 | 496 |
458 GURL script_url("http://www.example.com/service_worker1.js"); | 497 GURL script_url("http://www.example.com/service_worker1.js"); |
459 bool registration1_called = false; | 498 bool registration1_called = false; |
460 scoped_refptr<ServiceWorkerRegistration> registration1; | 499 scoped_refptr<ServiceWorkerRegistration> registration1; |
461 job_coordinator_->Register( | 500 job_coordinator_->Register( |
462 pattern, | 501 pattern, |
463 script_url, | 502 script_url, |
464 SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, | 503 render_process_id_, |
465 ®istration1)); | 504 SaveRegistration( |
505 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | |
466 | 506 |
467 bool registration2_called = false; | 507 bool registration2_called = false; |
468 scoped_refptr<ServiceWorkerRegistration> registration2; | 508 scoped_refptr<ServiceWorkerRegistration> registration2; |
469 job_coordinator_->Register( | 509 job_coordinator_->Register( |
470 pattern, | 510 pattern, |
471 script_url, | 511 script_url, |
472 SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, | 512 render_process_id_, |
473 ®istration2)); | 513 SaveRegistration( |
514 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | |
474 | 515 |
475 ASSERT_FALSE(registration1_called); | 516 ASSERT_FALSE(registration1_called); |
476 ASSERT_FALSE(registration2_called); | 517 ASSERT_FALSE(registration2_called); |
477 base::RunLoop().RunUntilIdle(); | 518 base::RunLoop().RunUntilIdle(); |
478 ASSERT_TRUE(registration1_called); | 519 ASSERT_TRUE(registration1_called); |
479 ASSERT_TRUE(registration2_called); | 520 ASSERT_TRUE(registration2_called); |
480 | 521 |
481 ASSERT_EQ(registration1, registration2); | 522 ASSERT_EQ(registration1, registration2); |
482 | 523 |
483 scoped_refptr<ServiceWorkerRegistration> registration; | 524 scoped_refptr<ServiceWorkerRegistration> registration; |
484 bool find_called = false; | 525 bool find_called = false; |
485 storage_->FindRegistrationForPattern( | 526 storage_->FindRegistrationForPattern( |
486 pattern, | 527 pattern, |
487 SaveFoundRegistration( | 528 SaveFoundRegistration( |
488 true, SERVICE_WORKER_OK, &find_called, ®istration)); | 529 true, SERVICE_WORKER_OK, &find_called, ®istration)); |
489 | 530 |
490 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
491 ASSERT_EQ(registration, registration1); | 532 ASSERT_EQ(registration, registration1); |
492 } | 533 } |
493 | 534 |
494 // Call simulataneous unregister calls. | 535 // Call simulataneous unregister calls. |
495 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { | 536 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { |
496 GURL pattern("http://www.example.com/*"); | 537 GURL pattern("http://www.example.com/*"); |
497 | 538 |
498 GURL script_url("http://www.example.com/service_worker.js"); | 539 GURL script_url("http://www.example.com/service_worker.js"); |
499 bool unregistration1_called = false; | 540 bool unregistration1_called = false; |
500 job_coordinator_->Unregister( | 541 job_coordinator_->Unregister( |
501 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); | 542 pattern, |
543 render_process_id_, | |
544 SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); | |
502 | 545 |
503 bool unregistration2_called = false; | 546 bool unregistration2_called = false; |
504 job_coordinator_->Unregister( | 547 job_coordinator_->Unregister( |
505 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); | 548 pattern, |
549 render_process_id_, | |
550 SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); | |
506 | 551 |
507 ASSERT_FALSE(unregistration1_called); | 552 ASSERT_FALSE(unregistration1_called); |
508 ASSERT_FALSE(unregistration2_called); | 553 ASSERT_FALSE(unregistration2_called); |
509 base::RunLoop().RunUntilIdle(); | 554 base::RunLoop().RunUntilIdle(); |
510 ASSERT_TRUE(unregistration1_called); | 555 ASSERT_TRUE(unregistration1_called); |
511 ASSERT_TRUE(unregistration2_called); | 556 ASSERT_TRUE(unregistration2_called); |
512 | 557 |
513 // There isn't really a way to test that they are being coalesced, | 558 // There isn't really a way to test that they are being coalesced, |
514 // but we can make sure they can exist simultaneously without | 559 // but we can make sure they can exist simultaneously without |
515 // crashing. | 560 // crashing. |
516 scoped_refptr<ServiceWorkerRegistration> registration; | 561 scoped_refptr<ServiceWorkerRegistration> registration; |
517 bool find_called = false; | 562 bool find_called = false; |
518 storage_->FindRegistrationForPattern( | 563 storage_->FindRegistrationForPattern( |
519 pattern, | 564 pattern, |
520 SaveFoundRegistration( | 565 SaveFoundRegistration( |
521 false, SERVICE_WORKER_OK, &find_called, ®istration)); | 566 false, SERVICE_WORKER_OK, &find_called, ®istration)); |
522 | 567 |
523 base::RunLoop().RunUntilIdle(); | 568 base::RunLoop().RunUntilIdle(); |
524 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 569 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
525 } | 570 } |
526 | 571 |
527 } // namespace content | 572 } // namespace content |
OLD | NEW |