| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 : m_page(DummyPageHolder::create()) | 151 : m_page(DummyPageHolder::create()) |
| 152 { | 152 { |
| 153 } | 153 } |
| 154 | 154 |
| 155 ~ServiceWorkerContainerTest() | 155 ~ServiceWorkerContainerTest() |
| 156 { | 156 { |
| 157 m_page.clear(); | 157 m_page.clear(); |
| 158 V8GCController::collectAllGarbageForTesting(isolate()); | 158 V8GCController::collectAllGarbageForTesting(isolate()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ExecutionContext* executionContext() { return &(m_page->document()); } | 161 ExecutionContext* getExecutionContext() { return &(m_page->document()); } |
| 162 v8::Isolate* isolate() { return v8::Isolate::GetCurrent(); } | 162 v8::Isolate* isolate() { return v8::Isolate::GetCurrent(); } |
| 163 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 163 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
| 164 | 164 |
| 165 void provide(PassOwnPtr<WebServiceWorkerProvider> provider) | 165 void provide(PassOwnPtr<WebServiceWorkerProvider> provider) |
| 166 { | 166 { |
| 167 WillBeHeapSupplement<Document>::provideTo(m_page->document(), ServiceWor
kerContainerClient::supplementName(), ServiceWorkerContainerClient::create(provi
der)); | 167 WillBeHeapSupplement<Document>::provideTo(m_page->document(), ServiceWor
kerContainerClient::supplementName(), ServiceWorkerContainerClient::create(provi
der)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void setPageURL(const String& url) | 170 void setPageURL(const String& url) |
| 171 { | 171 { |
| 172 // For URL completion. | 172 // For URL completion. |
| 173 m_page->document().setURL(KURL(KURL(), url)); | 173 m_page->document().setURL(KURL(KURL(), url)); |
| 174 | 174 |
| 175 // The basis for security checks. | 175 // The basis for security checks. |
| 176 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur
l)); | 176 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur
l)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void testRegisterRejected(const String& scriptURL, const String& scope, cons
t ScriptValueTest& valueTest) | 179 void testRegisterRejected(const String& scriptURL, const String& scope, cons
t ScriptValueTest& valueTest) |
| 180 { | 180 { |
| 181 // When the registration is rejected, a register call must not reach | 181 // When the registration is rejected, a register call must not reach |
| 182 // the provider. | 182 // the provider. |
| 183 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); | 183 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); |
| 184 | 184 |
| 185 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu
tionContext()); | 185 ServiceWorkerContainer* container = ServiceWorkerContainer::create(getEx
ecutionContext()); |
| 186 ScriptState::Scope scriptScope(scriptState()); | 186 ScriptState::Scope scriptScope(getScriptState()); |
| 187 RegistrationOptions options; | 187 RegistrationOptions options; |
| 188 options.setScope(scope); | 188 options.setScope(scope); |
| 189 ScriptPromise promise = container->registerServiceWorker(scriptState(),
scriptURL, options); | 189 ScriptPromise promise = container->registerServiceWorker(getScriptState(
), scriptURL, options); |
| 190 expectRejected(scriptState(), promise, valueTest); | 190 expectRejected(getScriptState(), promise, valueTest); |
| 191 | 191 |
| 192 container->willBeDetachedFromFrame(); | 192 container->willBeDetachedFromFrame(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void testGetRegistrationRejected(const String& documentURL, const ScriptValu
eTest& valueTest) | 195 void testGetRegistrationRejected(const String& documentURL, const ScriptValu
eTest& valueTest) |
| 196 { | 196 { |
| 197 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); | 197 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); |
| 198 | 198 |
| 199 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu
tionContext()); | 199 ServiceWorkerContainer* container = ServiceWorkerContainer::create(getEx
ecutionContext()); |
| 200 ScriptState::Scope scriptScope(scriptState()); | 200 ScriptState::Scope scriptScope(getScriptState()); |
| 201 ScriptPromise promise = container->getRegistration(scriptState(), docume
ntURL); | 201 ScriptPromise promise = container->getRegistration(getScriptState(), doc
umentURL); |
| 202 expectRejected(scriptState(), promise, valueTest); | 202 expectRejected(getScriptState(), promise, valueTest); |
| 203 | 203 |
| 204 container->willBeDetachedFromFrame(); | 204 container->willBeDetachedFromFrame(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 OwnPtr<DummyPageHolder> m_page; | 208 OwnPtr<DummyPageHolder> m_page; |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 TEST_F(ServiceWorkerContainerTest, Register_NonSecureOriginIsRejected) | 211 TEST_F(ServiceWorkerContainerTest, Register_NonSecureOriginIsRejected) |
| 212 { | 212 { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 WebURL m_getRegistrationURL; | 318 WebURL m_getRegistrationURL; |
| 319 }; | 319 }; |
| 320 | 320 |
| 321 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) | 321 TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
tesToProvider) |
| 322 { | 322 { |
| 323 setPageURL("http://localhost/x/index.html"); | 323 setPageURL("http://localhost/x/index.html"); |
| 324 | 324 |
| 325 StubWebServiceWorkerProvider stubProvider; | 325 StubWebServiceWorkerProvider stubProvider; |
| 326 provide(stubProvider.provider()); | 326 provide(stubProvider.provider()); |
| 327 | 327 |
| 328 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execution
Context()); | 328 ServiceWorkerContainer* container = ServiceWorkerContainer::create(getExecut
ionContext()); |
| 329 | 329 |
| 330 // register | 330 // register |
| 331 { | 331 { |
| 332 ScriptState::Scope scriptScope(scriptState()); | 332 ScriptState::Scope scriptScope(getScriptState()); |
| 333 RegistrationOptions options; | 333 RegistrationOptions options; |
| 334 options.setScope("y/"); | 334 options.setScope("y/"); |
| 335 container->registerServiceWorker(scriptState(), "/x/y/worker.js", option
s); | 335 container->registerServiceWorker(getScriptState(), "/x/y/worker.js", opt
ions); |
| 336 | 336 |
| 337 EXPECT_EQ(1ul, stubProvider.registerCallCount()); | 337 EXPECT_EQ(1ul, stubProvider.registerCallCount()); |
| 338 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); | 338 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.re
gisterScope()); |
| 339 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")), stubPr
ovider.registerScriptURL()); | 339 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")), stubPr
ovider.registerScriptURL()); |
| 340 } | 340 } |
| 341 | 341 |
| 342 container->willBeDetachedFromFrame(); | 342 container->willBeDetachedFromFrame(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 TEST_F(ServiceWorkerContainerTest, GetRegistration_OmittedDocumentURLDefaultsToP
ageURL) | 345 TEST_F(ServiceWorkerContainerTest, GetRegistration_OmittedDocumentURLDefaultsToP
ageURL) |
| 346 { | 346 { |
| 347 setPageURL("http://localhost/x/index.html"); | 347 setPageURL("http://localhost/x/index.html"); |
| 348 | 348 |
| 349 StubWebServiceWorkerProvider stubProvider; | 349 StubWebServiceWorkerProvider stubProvider; |
| 350 provide(stubProvider.provider()); | 350 provide(stubProvider.provider()); |
| 351 | 351 |
| 352 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execution
Context()); | 352 ServiceWorkerContainer* container = ServiceWorkerContainer::create(getExecut
ionContext()); |
| 353 | 353 |
| 354 { | 354 { |
| 355 ScriptState::Scope scriptScope(scriptState()); | 355 ScriptState::Scope scriptScope(getScriptState()); |
| 356 container->getRegistration(scriptState(), ""); | 356 container->getRegistration(getScriptState(), ""); |
| 357 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount()); | 357 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount()); |
| 358 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), stubPro
vider.getRegistrationURL()); | 358 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), stubPro
vider.getRegistrationURL()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 container->willBeDetachedFromFrame(); | 361 container->willBeDetachedFromFrame(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 } // namespace | 364 } // namespace |
| 365 } // namespace blink | 365 } // namespace blink |
| OLD | NEW |