| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 WebURL m_unregisterScope; | 313 WebURL m_unregisterScope; |
| 314 }; | 314 }; |
| 315 | 315 |
| 316 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) | 316 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) |
| 317 { | 317 { |
| 318 setPageURL("http://localhost/x/index.html"); | 318 setPageURL("http://localhost/x/index.html"); |
| 319 | 319 |
| 320 StubWebServiceWorkerProvider stubProvider; | 320 StubWebServiceWorkerProvider stubProvider; |
| 321 provide(stubProvider.provider()); | 321 provide(stubProvider.provider()); |
| 322 | 322 |
| 323 RefPtrWillBeRawPtr<ServiceWorkerContainer> container = ServiceWorkerContaine
r::create(executionContext()); | 323 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execution
Context()); |
| 324 | 324 |
| 325 // register | 325 // register |
| 326 { | 326 { |
| 327 ScriptState::Scope scriptScope(scriptState()); | 327 ScriptState::Scope scriptScope(scriptState()); |
| 328 Dictionary options = Dictionary::createEmpty(isolate()); | 328 Dictionary options = Dictionary::createEmpty(isolate()); |
| 329 EXPECT_TRUE(options.set("scope", "y/")); | 329 EXPECT_TRUE(options.set("scope", "y/")); |
| 330 container->registerServiceWorker(scriptState(), "/z/worker.js", options)
; | 330 container->registerServiceWorker(scriptState(), "/z/worker.js", options)
; |
| 331 | 331 |
| 332 EXPECT_EQ(1ul, stubProvider.registerCallCount()); | 332 EXPECT_EQ(1ul, stubProvider.registerCallCount()); |
| 333 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); | 333 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); |
| 334 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/z/worker.js")), stubProv
ider.registerScriptURL()); | 334 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/z/worker.js")), stubProv
ider.registerScriptURL()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // unregister | 337 // unregister |
| 338 { | 338 { |
| 339 ScriptState::Scope scriptScope(scriptState()); | 339 ScriptState::Scope scriptScope(scriptState()); |
| 340 container->unregisterServiceWorker(scriptState(), "y/"); | 340 container->unregisterServiceWorker(scriptState(), "y/"); |
| 341 | 341 |
| 342 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); | 342 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); |
| 343 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un
registerScope()); | 343 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un
registerScope()); |
| 344 } | 344 } |
| 345 | 345 |
| 346 container->willBeDetachedFromFrame(); | 346 container->willBeDetachedFromFrame(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace | 349 } // namespace |
| 350 } // namespace blink | 350 } // namespace blink |
| OLD | NEW |