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