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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 6 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // The basis for security checks. | 174 // The basis for security checks. |
175 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur
l)); | 175 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur
l)); |
176 } | 176 } |
177 | 177 |
178 void testRegisterRejected(const String& scriptURL, const String& scope, cons
t ScriptValueTest& valueTest) | 178 void testRegisterRejected(const String& scriptURL, const String& scope, cons
t ScriptValueTest& valueTest) |
179 { | 179 { |
180 // When the registration is rejected, a register call must not reach | 180 // When the registration is rejected, a register call must not reach |
181 // the provider. | 181 // the provider. |
182 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); | 182 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); |
183 | 183 |
184 RefPtrWillBeRawPtr<ServiceWorkerContainer> container = ServiceWorkerCont
ainer::create(executionContext()); | 184 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu
tionContext()); |
185 ScriptState::Scope scriptScope(scriptState()); | 185 ScriptState::Scope scriptScope(scriptState()); |
186 Dictionary options = Dictionary::createEmpty(isolate()); | 186 Dictionary options = Dictionary::createEmpty(isolate()); |
187 EXPECT_TRUE(options.set("scope", scope)); | 187 EXPECT_TRUE(options.set("scope", scope)); |
188 ScriptPromise promise = container->registerServiceWorker(scriptState(),
scriptURL, options); | 188 ScriptPromise promise = container->registerServiceWorker(scriptState(),
scriptURL, options); |
189 expectRejected(scriptState(), promise, valueTest); | 189 expectRejected(scriptState(), promise, valueTest); |
190 | 190 |
191 container->willBeDetachedFromFrame(); | 191 container->willBeDetachedFromFrame(); |
192 } | 192 } |
193 | 193 |
194 void testUnregisterRejected(const String& scope, const ScriptValueTest& valu
eTest) | 194 void testUnregisterRejected(const String& scope, const ScriptValueTest& valu
eTest) |
195 { | 195 { |
196 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); | 196 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); |
197 | 197 |
198 RefPtrWillBeRawPtr<ServiceWorkerContainer> container = ServiceWorkerCont
ainer::create(executionContext()); | 198 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu
tionContext()); |
199 ScriptState::Scope scriptScope(scriptState()); | 199 ScriptState::Scope scriptScope(scriptState()); |
200 Dictionary options = Dictionary::createEmpty(isolate()); | 200 Dictionary options = Dictionary::createEmpty(isolate()); |
201 EXPECT_TRUE(options.set("scope", scope)); | 201 EXPECT_TRUE(options.set("scope", scope)); |
202 ScriptPromise promise = container->unregisterServiceWorker(scriptState()
, scope); | 202 ScriptPromise promise = container->unregisterServiceWorker(scriptState()
, scope); |
203 expectRejected(scriptState(), promise, valueTest); | 203 expectRejected(scriptState(), promise, valueTest); |
204 | 204 |
205 container->willBeDetachedFromFrame(); | 205 container->willBeDetachedFromFrame(); |
206 } | 206 } |
207 | 207 |
208 private: | 208 private: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 WebURL m_unregisterScope; | 314 WebURL m_unregisterScope; |
315 }; | 315 }; |
316 | 316 |
317 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) | 317 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) |
318 { | 318 { |
319 setPageURL("http://localhost/x/index.html"); | 319 setPageURL("http://localhost/x/index.html"); |
320 | 320 |
321 StubWebServiceWorkerProvider stubProvider; | 321 StubWebServiceWorkerProvider stubProvider; |
322 provide(stubProvider.provider()); | 322 provide(stubProvider.provider()); |
323 | 323 |
324 RefPtrWillBeRawPtr<ServiceWorkerContainer> container = ServiceWorkerContaine
r::create(executionContext()); | 324 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execution
Context()); |
325 | 325 |
326 // register | 326 // register |
327 { | 327 { |
328 ScriptState::Scope scriptScope(scriptState()); | 328 ScriptState::Scope scriptScope(scriptState()); |
329 Dictionary options = Dictionary::createEmpty(isolate()); | 329 Dictionary options = Dictionary::createEmpty(isolate()); |
330 EXPECT_TRUE(options.set("scope", "y/")); | 330 EXPECT_TRUE(options.set("scope", "y/")); |
331 container->registerServiceWorker(scriptState(), "/z/worker.js", options)
; | 331 container->registerServiceWorker(scriptState(), "/z/worker.js", options)
; |
332 | 332 |
333 EXPECT_EQ(1ul, stubProvider.registerCallCount()); | 333 EXPECT_EQ(1ul, stubProvider.registerCallCount()); |
334 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); | 334 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); |
335 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/z/worker.js")), stubProv
ider.registerScriptURL()); | 335 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/z/worker.js")), stubProv
ider.registerScriptURL()); |
336 } | 336 } |
337 | 337 |
338 // unregister | 338 // unregister |
339 { | 339 { |
340 ScriptState::Scope scriptScope(scriptState()); | 340 ScriptState::Scope scriptScope(scriptState()); |
341 container->unregisterServiceWorker(scriptState(), "y/"); | 341 container->unregisterServiceWorker(scriptState(), "y/"); |
342 | 342 |
343 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); | 343 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); |
344 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un
registerScope()); | 344 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un
registerScope()); |
345 } | 345 } |
346 | 346 |
347 container->willBeDetachedFromFrame(); | 347 container->willBeDetachedFromFrame(); |
348 } | 348 } |
349 | 349 |
350 } // namespace | 350 } // namespace |
351 } // namespace blink | 351 } // namespace blink |
OLD | NEW |