Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 113133013: Refactor job coordination into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/service_worker/service_worker_storage.h"
6
7 #include "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 6 #include "base/logging.h"
9 #include "base/run_loop.h" 7 #include "base/run_loop.h"
10 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/service_worker/service_worker_job_coordinator.h"
11 #include "content/browser/service_worker/service_worker_registration.h" 10 #include "content/browser/service_worker/service_worker_registration.h"
11 #include "content/browser/service_worker/service_worker_registration_status.h"
12 #include "content/public/test/test_browser_thread_bundle.h" 12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 // Unit tests for testing all job registration tasks.
15 namespace content { 16 namespace content {
16 17
17 namespace { 18 namespace {
18 19
19 void SaveRegistrationCallback( 20 void SaveRegistrationCallback(
20 ServiceWorkerRegistrationStatus expected_status, 21 ServiceWorkerRegistrationStatus expected_status,
21 bool* called, 22 bool* called,
22 scoped_refptr<ServiceWorkerRegistration>* registration, 23 scoped_refptr<ServiceWorkerRegistration>* registration,
23 ServiceWorkerRegistrationStatus status, 24 ServiceWorkerRegistrationStatus status,
24 const scoped_refptr<ServiceWorkerRegistration>& result) { 25 const scoped_refptr<ServiceWorkerRegistration>& result) {
(...skipping 14 matching lines...) Expand all
39 EXPECT_EQ(expected_status, status); 40 EXPECT_EQ(expected_status, status);
40 *called = true; 41 *called = true;
41 *registration = result; 42 *registration = result;
42 } 43 }
43 44
44 // Creates a callback which both keeps track of if it's been called, 45 // Creates a callback which both keeps track of if it's been called,
45 // as well as the resulting registration. Whent the callback is fired, 46 // as well as the resulting registration. Whent the callback is fired,
46 // it ensures that the resulting status matches the expectation. 47 // it ensures that the resulting status matches the expectation.
47 // 'called' is useful for making sure a sychronous callback is or 48 // 'called' is useful for making sure a sychronous callback is or
48 // isn't called. 49 // isn't called.
49 ServiceWorkerStorage::RegistrationCallback SaveRegistration( 50 ServiceWorkerJobCoordinator::RegistrationCallback SaveRegistration(
50 ServiceWorkerRegistrationStatus expected_status, 51 ServiceWorkerRegistrationStatus expected_status,
51 bool* called, 52 bool* called,
52 scoped_refptr<ServiceWorkerRegistration>* registration) { 53 scoped_refptr<ServiceWorkerRegistration>* registration) {
53 *called = false; 54 *called = false;
54 return base::Bind( 55 return base::Bind(
55 &SaveRegistrationCallback, expected_status, called, registration); 56 &SaveRegistrationCallback, expected_status, called, registration);
56 } 57 }
57 58
58 ServiceWorkerStorage::FindRegistrationCallback SaveFoundRegistration( 59 ServiceWorkerStorage::FindRegistrationCallback SaveFoundRegistration(
59 bool expected_found, 60 bool expected_found,
60 ServiceWorkerRegistrationStatus expected_status, 61 ServiceWorkerRegistrationStatus expected_status,
61 bool* called, 62 bool* called,
62 scoped_refptr<ServiceWorkerRegistration>* registration) { 63 scoped_refptr<ServiceWorkerRegistration>* registration) {
63 *called = false; 64 *called = false;
64 return base::Bind(&SaveFoundRegistrationCallback, 65 return base::Bind(&SaveFoundRegistrationCallback,
65 expected_found, 66 expected_found,
66 expected_status, 67 expected_status,
67 called, 68 called,
68 registration); 69 registration);
69 } 70 }
70 71
71 void SaveUnregistrationCallback(ServiceWorkerRegistrationStatus expected_status, 72 void SaveUnregistrationCallback(ServiceWorkerRegistrationStatus expected_status,
72 bool* called, 73 bool* called,
73 ServiceWorkerRegistrationStatus status) { 74 ServiceWorkerRegistrationStatus status) {
74 EXPECT_EQ(expected_status, status); 75 EXPECT_EQ(expected_status, status);
75 *called = true; 76 *called = true;
76 } 77 }
77 78
78 ServiceWorkerStorage::UnregistrationCallback SaveUnregistration( 79 ServiceWorkerJobCoordinator::UnregistrationCallback SaveUnregistration(
79 ServiceWorkerRegistrationStatus expected_status, 80 ServiceWorkerRegistrationStatus expected_status,
80 bool* called) { 81 bool* called) {
81 *called = false; 82 *called = false;
82 return base::Bind(&SaveUnregistrationCallback, expected_status, called); 83 return base::Bind(&SaveUnregistrationCallback, expected_status, called);
83 } 84 }
84 85
85 } // namespace 86 } // namespace
86 87
87 class ServiceWorkerStorageTest : public testing::Test { 88 class ServiceWorkerJobTest : public testing::Test {
88 public: 89 public:
89 ServiceWorkerStorageTest() 90 ServiceWorkerJobTest()
90 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} 91 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
91 92
92 virtual void SetUp() OVERRIDE { 93 virtual void SetUp() OVERRIDE {
93 storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL)); 94 storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL));
95 job_coordinator_.reset(
96 new ServiceWorkerJobCoordinator(storage_->AsWeakPtr()));
94 } 97 }
95 98
96 virtual void TearDown() OVERRIDE { storage_.reset(); } 99 virtual void TearDown() OVERRIDE { storage_.reset(); }
97 100
98 protected: 101 protected:
99 TestBrowserThreadBundle browser_thread_bundle_; 102 TestBrowserThreadBundle browser_thread_bundle_;
100 scoped_ptr<ServiceWorkerStorage> storage_; 103 scoped_ptr<ServiceWorkerStorage> storage_;
104 scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
101 }; 105 };
102 106
103 TEST_F(ServiceWorkerStorageTest, PatternMatches) { 107 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
104 ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
105 GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
106 ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
107 GURL("http://www.example.com/*"),
108 GURL("http://www.example.com/page.html")));
109
110 ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
111 GURL("http://www.example.com/*"), GURL("https://www.example.com/")));
112 ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
113 GURL("http://www.example.com/*"),
114 GURL("https://www.example.com/page.html")));
115
116 ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
117 GURL("http://www.example.com/*"), GURL("http://www.foo.com/")));
118 ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
119 GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html")));
120 }
121
122 TEST_F(ServiceWorkerStorageTest, SameDocumentSameRegistration) {
123 scoped_refptr<ServiceWorkerRegistration> original_registration; 108 scoped_refptr<ServiceWorkerRegistration> original_registration;
124 bool called; 109 bool called;
125 storage_->Register( 110 job_coordinator_->Register(
126 GURL("http://www.example.com/*"), 111 GURL("http://www.example.com/*"),
127 GURL("http://www.example.com/service_worker.js"), 112 GURL("http://www.example.com/service_worker.js"),
128 SaveRegistration(REGISTRATION_OK, &called, &original_registration)); 113 SaveRegistration(REGISTRATION_OK, &called, &original_registration));
129 EXPECT_FALSE(called); 114 EXPECT_FALSE(called);
130 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
131 EXPECT_TRUE(called); 116 EXPECT_TRUE(called);
132 117
133 scoped_refptr<ServiceWorkerRegistration> registration1; 118 scoped_refptr<ServiceWorkerRegistration> registration1;
134 storage_->FindRegistrationForDocument( 119 storage_->FindRegistrationForDocument(
135 GURL("http://www.example.com/"), 120 GURL("http://www.example.com/"),
136 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration1)); 121 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration1));
137 scoped_refptr<ServiceWorkerRegistration> registration2; 122 scoped_refptr<ServiceWorkerRegistration> registration2;
138 storage_->FindRegistrationForDocument( 123 storage_->FindRegistrationForDocument(
139 GURL("http://www.example.com/"), 124 GURL("http://www.example.com/"),
140 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration2)); 125 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration2));
141 126
142 ServiceWorkerRegistration* null_registration(NULL); 127 ServiceWorkerRegistration* null_registration(NULL);
143 ASSERT_EQ(null_registration, registration1); 128 ASSERT_EQ(null_registration, registration1);
144 ASSERT_EQ(null_registration, registration2); 129 ASSERT_EQ(null_registration, registration2);
145 EXPECT_FALSE(called); 130 EXPECT_FALSE(called);
146 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
147 EXPECT_TRUE(called); 132 EXPECT_TRUE(called);
148 ASSERT_NE(null_registration, registration1); 133 ASSERT_NE(null_registration, registration1);
149 ASSERT_NE(null_registration, registration2); 134 ASSERT_NE(null_registration, registration2);
150 135
151 ASSERT_EQ(registration1, registration2); 136 ASSERT_EQ(registration1, registration2);
152 } 137 }
153 138
154 TEST_F(ServiceWorkerStorageTest, SameMatchSameRegistration) { 139 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
155 bool called; 140 bool called;
156 scoped_refptr<ServiceWorkerRegistration> original_registration; 141 scoped_refptr<ServiceWorkerRegistration> original_registration;
157 storage_->Register( 142 job_coordinator_->Register(
158 GURL("http://www.example.com/*"), 143 GURL("http://www.example.com/*"),
159 GURL("http://www.example.com/service_worker.js"), 144 GURL("http://www.example.com/service_worker.js"),
160 SaveRegistration(REGISTRATION_OK, &called, &original_registration)); 145 SaveRegistration(REGISTRATION_OK, &called, &original_registration));
161 EXPECT_FALSE(called); 146 EXPECT_FALSE(called);
162 base::RunLoop().RunUntilIdle(); 147 base::RunLoop().RunUntilIdle();
163 EXPECT_TRUE(called); 148 EXPECT_TRUE(called);
164 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), 149 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL),
165 original_registration.get()); 150 original_registration.get());
166 151
167 scoped_refptr<ServiceWorkerRegistration> registration1; 152 scoped_refptr<ServiceWorkerRegistration> registration1;
168 storage_->FindRegistrationForDocument( 153 storage_->FindRegistrationForDocument(
169 GURL("http://www.example.com/one"), 154 GURL("http://www.example.com/one"),
170 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration1)); 155 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration1));
171 156
172 EXPECT_FALSE(called); 157 EXPECT_FALSE(called);
173 base::RunLoop().RunUntilIdle(); 158 base::RunLoop().RunUntilIdle();
174 EXPECT_TRUE(called); 159 EXPECT_TRUE(called);
175 160
176 scoped_refptr<ServiceWorkerRegistration> registration2; 161 scoped_refptr<ServiceWorkerRegistration> registration2;
177 storage_->FindRegistrationForDocument( 162 storage_->FindRegistrationForDocument(
178 GURL("http://www.example.com/two"), 163 GURL("http://www.example.com/two"),
179 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration2)); 164 SaveFoundRegistration(true, REGISTRATION_OK, &called, &registration2));
180 EXPECT_FALSE(called); 165 EXPECT_FALSE(called);
181 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
182 EXPECT_TRUE(called); 167 EXPECT_TRUE(called);
183 168
184 ASSERT_EQ(registration1, registration2); 169 ASSERT_EQ(registration1, registration2);
185 } 170 }
186 171
187 TEST_F(ServiceWorkerStorageTest, DifferentMatchDifferentRegistration) { 172 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
188 bool called1; 173 bool called1;
189 scoped_refptr<ServiceWorkerRegistration> original_registration1; 174 scoped_refptr<ServiceWorkerRegistration> original_registration1;
190 storage_->Register( 175 job_coordinator_->Register(
191 GURL("http://www.example.com/one/*"), 176 GURL("http://www.example.com/one/*"),
192 GURL("http://www.example.com/service_worker.js"), 177 GURL("http://www.example.com/service_worker.js"),
193 SaveRegistration(REGISTRATION_OK, &called1, &original_registration1)); 178 SaveRegistration(REGISTRATION_OK, &called1, &original_registration1));
194 179
195 bool called2; 180 bool called2;
196 scoped_refptr<ServiceWorkerRegistration> original_registration2; 181 scoped_refptr<ServiceWorkerRegistration> original_registration2;
197 storage_->Register( 182 job_coordinator_->Register(
198 GURL("http://www.example.com/two/*"), 183 GURL("http://www.example.com/two/*"),
199 GURL("http://www.example.com/service_worker.js"), 184 GURL("http://www.example.com/service_worker.js"),
200 SaveRegistration(REGISTRATION_OK, &called2, &original_registration2)); 185 SaveRegistration(REGISTRATION_OK, &called2, &original_registration2));
201 186
202 EXPECT_FALSE(called1); 187 EXPECT_FALSE(called1);
203 EXPECT_FALSE(called2); 188 EXPECT_FALSE(called2);
204 base::RunLoop().RunUntilIdle(); 189 base::RunLoop().RunUntilIdle();
205 EXPECT_TRUE(called2); 190 EXPECT_TRUE(called2);
206 EXPECT_TRUE(called1); 191 EXPECT_TRUE(called1);
207 192
208 scoped_refptr<ServiceWorkerRegistration> registration1; 193 scoped_refptr<ServiceWorkerRegistration> registration1;
209 storage_->FindRegistrationForDocument( 194 storage_->FindRegistrationForDocument(
210 GURL("http://www.example.com/one/"), 195 GURL("http://www.example.com/one/"),
211 SaveFoundRegistration(true, REGISTRATION_OK, &called1, &registration1)); 196 SaveFoundRegistration(true, REGISTRATION_OK, &called1, &registration1));
212 scoped_refptr<ServiceWorkerRegistration> registration2; 197 scoped_refptr<ServiceWorkerRegistration> registration2;
213 storage_->FindRegistrationForDocument( 198 storage_->FindRegistrationForDocument(
214 GURL("http://www.example.com/two/"), 199 GURL("http://www.example.com/two/"),
215 SaveFoundRegistration(true, REGISTRATION_OK, &called2, &registration2)); 200 SaveFoundRegistration(true, REGISTRATION_OK, &called2, &registration2));
216 201
217 EXPECT_FALSE(called1); 202 EXPECT_FALSE(called1);
218 EXPECT_FALSE(called2); 203 EXPECT_FALSE(called2);
219 base::RunLoop().RunUntilIdle(); 204 base::RunLoop().RunUntilIdle();
220 EXPECT_TRUE(called2); 205 EXPECT_TRUE(called2);
221 EXPECT_TRUE(called1); 206 EXPECT_TRUE(called1);
222 207
223 ASSERT_NE(registration1, registration2); 208 ASSERT_NE(registration1, registration2);
224 } 209 }
225 210
226 // Make sure basic registration is working. 211 // Make sure basic registration is working.
227 TEST_F(ServiceWorkerStorageTest, Register) { 212 TEST_F(ServiceWorkerJobTest, Register) {
228 bool called = false; 213 bool called = false;
229 scoped_refptr<ServiceWorkerRegistration> registration; 214 scoped_refptr<ServiceWorkerRegistration> registration;
230 storage_->Register(GURL("http://www.example.com/*"), 215 job_coordinator_->Register(
231 GURL("http://www.example.com/service_worker.js"), 216 GURL("http://www.example.com/*"),
232 SaveRegistration(REGISTRATION_OK, &called, &registration)); 217 GURL("http://www.example.com/service_worker.js"),
218 SaveRegistration(REGISTRATION_OK, &called, &registration));
233 219
234 ASSERT_FALSE(called); 220 ASSERT_FALSE(called);
235 base::RunLoop().RunUntilIdle(); 221 base::RunLoop().RunUntilIdle();
236 ASSERT_TRUE(called); 222 ASSERT_TRUE(called);
237 223
238 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 224 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
239 } 225 }
240 226
241 // Make sure registrations are cleaned up when they are unregistered. 227 // Make sure registrations are cleaned up when they are unregistered.
242 TEST_F(ServiceWorkerStorageTest, Unregister) { 228 TEST_F(ServiceWorkerJobTest, Unregister) {
243 GURL pattern("http://www.example.com/*"); 229 GURL pattern("http://www.example.com/*");
244 230
245 bool called; 231 bool called;
246 scoped_refptr<ServiceWorkerRegistration> registration; 232 scoped_refptr<ServiceWorkerRegistration> registration;
247 storage_->Register(pattern, 233 job_coordinator_->Register(
248 GURL("http://www.example.com/service_worker.js"), 234 pattern,
249 SaveRegistration(REGISTRATION_OK, &called, &registration)); 235 GURL("http://www.example.com/service_worker.js"),
236 SaveRegistration(REGISTRATION_OK, &called, &registration));
250 237
251 ASSERT_FALSE(called); 238 ASSERT_FALSE(called);
252 base::RunLoop().RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
253 ASSERT_TRUE(called); 240 ASSERT_TRUE(called);
254 241
255 storage_->Unregister(pattern, SaveUnregistration(REGISTRATION_OK, &called)); 242 job_coordinator_->Unregister(pattern,
243 SaveUnregistration(REGISTRATION_OK, &called));
256 244
257 ASSERT_FALSE(called); 245 ASSERT_FALSE(called);
258 base::RunLoop().RunUntilIdle(); 246 base::RunLoop().RunUntilIdle();
259 ASSERT_TRUE(called); 247 ASSERT_TRUE(called);
260 248
261 ASSERT_TRUE(registration->HasOneRef()); 249 ASSERT_TRUE(registration->HasOneRef());
262 250
263 storage_->FindRegistrationForPattern( 251 storage_->FindRegistrationForPattern(
264 pattern, 252 pattern,
265 SaveFoundRegistration(false, REGISTRATION_OK, &called, &registration)); 253 SaveFoundRegistration(false, REGISTRATION_OK, &called, &registration));
266 254
267 ASSERT_FALSE(called); 255 ASSERT_FALSE(called);
268 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
269 ASSERT_TRUE(called); 257 ASSERT_TRUE(called);
270 258
271 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 259 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
272 } 260 }
273 261
274 // Make sure that when a new registration replaces an existing 262 // Make sure that when a new registration replaces an existing
275 // registration, that the old one is cleaned up. 263 // registration, that the old one is cleaned up.
276 TEST_F(ServiceWorkerStorageTest, RegisterNewScript) { 264 TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
277 GURL pattern("http://www.example.com/*"); 265 GURL pattern("http://www.example.com/*");
278 266
279 bool called; 267 bool called;
280 scoped_refptr<ServiceWorkerRegistration> old_registration; 268 scoped_refptr<ServiceWorkerRegistration> old_registration;
281 storage_->Register( 269 job_coordinator_->Register(
282 pattern, 270 pattern,
283 GURL("http://www.example.com/service_worker.js"), 271 GURL("http://www.example.com/service_worker.js"),
284 SaveRegistration(REGISTRATION_OK, &called, &old_registration)); 272 SaveRegistration(REGISTRATION_OK, &called, &old_registration));
285 273
286 ASSERT_FALSE(called); 274 ASSERT_FALSE(called);
287 base::RunLoop().RunUntilIdle(); 275 base::RunLoop().RunUntilIdle();
288 ASSERT_TRUE(called); 276 ASSERT_TRUE(called);
289 277
290 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; 278 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern;
291 storage_->FindRegistrationForPattern( 279 storage_->FindRegistrationForPattern(
292 pattern, 280 pattern,
293 SaveFoundRegistration( 281 SaveFoundRegistration(
294 true, REGISTRATION_OK, &called, &old_registration_by_pattern)); 282 true, REGISTRATION_OK, &called, &old_registration_by_pattern));
295 283
296 ASSERT_FALSE(called); 284 ASSERT_FALSE(called);
297 base::RunLoop().RunUntilIdle(); 285 base::RunLoop().RunUntilIdle();
298 ASSERT_TRUE(called); 286 ASSERT_TRUE(called);
299 287
300 ASSERT_EQ(old_registration, old_registration_by_pattern); 288 ASSERT_EQ(old_registration, old_registration_by_pattern);
301 old_registration_by_pattern = NULL; 289 old_registration_by_pattern = NULL;
302 290
303 scoped_refptr<ServiceWorkerRegistration> new_registration; 291 scoped_refptr<ServiceWorkerRegistration> new_registration;
304 storage_->Register( 292 job_coordinator_->Register(
305 pattern, 293 pattern,
306 GURL("http://www.example.com/service_worker_new.js"), 294 GURL("http://www.example.com/service_worker_new.js"),
307 SaveRegistration(REGISTRATION_OK, &called, &new_registration)); 295 SaveRegistration(REGISTRATION_OK, &called, &new_registration));
308 296
309 ASSERT_FALSE(called); 297 ASSERT_FALSE(called);
310 base::RunLoop().RunUntilIdle(); 298 base::RunLoop().RunUntilIdle();
311 ASSERT_TRUE(called); 299 ASSERT_TRUE(called);
312 300
313 ASSERT_TRUE(old_registration->HasOneRef()); 301 ASSERT_TRUE(old_registration->HasOneRef());
314 302
315 ASSERT_NE(old_registration, new_registration); 303 ASSERT_NE(old_registration, new_registration);
316 304
317 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; 305 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
318 storage_->FindRegistrationForPattern( 306 storage_->FindRegistrationForPattern(
319 pattern, 307 pattern,
320 SaveFoundRegistration(true, REGISTRATION_OK, &called, &new_registration)); 308 SaveFoundRegistration(true, REGISTRATION_OK, &called, &new_registration));
321 309
322 ASSERT_FALSE(called); 310 ASSERT_FALSE(called);
323 base::RunLoop().RunUntilIdle(); 311 base::RunLoop().RunUntilIdle();
324 ASSERT_TRUE(called); 312 ASSERT_TRUE(called);
325 313
326 ASSERT_NE(new_registration_by_pattern, old_registration); 314 ASSERT_NE(new_registration_by_pattern, old_registration);
327 } 315 }
328 316
329 // Make sure that when registering a duplicate pattern+script_url 317 // Make sure that when registering a duplicate pattern+script_url
330 // combination, that the same registration is used. 318 // combination, that the same registration is used.
331 TEST_F(ServiceWorkerStorageTest, RegisterDuplicateScript) { 319 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
332 GURL pattern("http://www.example.com/*"); 320 GURL pattern("http://www.example.com/*");
333 GURL script_url("http://www.example.com/service_worker.js"); 321 GURL script_url("http://www.example.com/service_worker.js");
334 322
335 bool called; 323 bool called;
336 scoped_refptr<ServiceWorkerRegistration> old_registration; 324 scoped_refptr<ServiceWorkerRegistration> old_registration;
337 storage_->Register( 325 job_coordinator_->Register(
338 pattern, 326 pattern,
339 script_url, 327 script_url,
340 SaveRegistration(REGISTRATION_OK, &called, &old_registration)); 328 SaveRegistration(REGISTRATION_OK, &called, &old_registration));
341 329
342 ASSERT_FALSE(called); 330 ASSERT_FALSE(called);
343 base::RunLoop().RunUntilIdle(); 331 base::RunLoop().RunUntilIdle();
344 ASSERT_TRUE(called); 332 ASSERT_TRUE(called);
345 333
346 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; 334 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern;
347 storage_->FindRegistrationForPattern( 335 storage_->FindRegistrationForPattern(
348 pattern, 336 pattern,
349 SaveFoundRegistration( 337 SaveFoundRegistration(
350 true, REGISTRATION_OK, &called, &old_registration_by_pattern)); 338 true, REGISTRATION_OK, &called, &old_registration_by_pattern));
351 ASSERT_FALSE(called); 339 ASSERT_FALSE(called);
352 base::RunLoop().RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
353 ASSERT_TRUE(called); 341 ASSERT_TRUE(called);
354 342
355 ASSERT_TRUE(old_registration_by_pattern); 343 ASSERT_TRUE(old_registration_by_pattern);
356 344
357 scoped_refptr<ServiceWorkerRegistration> new_registration; 345 scoped_refptr<ServiceWorkerRegistration> new_registration;
358 storage_->Register( 346 job_coordinator_->Register(
359 pattern, 347 pattern,
360 script_url, 348 script_url,
361 SaveRegistration(REGISTRATION_OK, &called, &new_registration)); 349 SaveRegistration(REGISTRATION_OK, &called, &new_registration));
362 350
363 ASSERT_FALSE(called); 351 ASSERT_FALSE(called);
364 base::RunLoop().RunUntilIdle(); 352 base::RunLoop().RunUntilIdle();
365 ASSERT_TRUE(called); 353 ASSERT_TRUE(called);
366 354
367 ASSERT_EQ(old_registration, new_registration); 355 ASSERT_EQ(old_registration, new_registration);
368 356
369 ASSERT_FALSE(old_registration->HasOneRef()); 357 ASSERT_FALSE(old_registration->HasOneRef());
370 358
371 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; 359 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
372 storage_->FindRegistrationForPattern( 360 storage_->FindRegistrationForPattern(
373 pattern, 361 pattern,
374 SaveFoundRegistration( 362 SaveFoundRegistration(
375 true, REGISTRATION_OK, &called, &new_registration_by_pattern)); 363 true, REGISTRATION_OK, &called, &new_registration_by_pattern));
376 364
377 ASSERT_FALSE(called); 365 ASSERT_FALSE(called);
378 base::RunLoop().RunUntilIdle(); 366 base::RunLoop().RunUntilIdle();
379 ASSERT_TRUE(called); 367 ASSERT_TRUE(called);
380 368
381 ASSERT_EQ(new_registration, old_registration); 369 ASSERT_EQ(new_registration, old_registration);
382 } 370 }
383 371
384 } // namespace content 372 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698