Chromium Code Reviews| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu tionContext()); | 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 void testGetRegistrationRejected(const String& documentURL, const ScriptValu eTest& valueTest) | |
| 209 { | |
| 210 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); | |
| 211 | |
| 212 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu tionContext()); | |
| 213 ScriptState::Scope scriptScope(scriptState()); | |
| 214 ScriptPromise promise = container->getRegistration(scriptState(), docume ntURL); | |
| 215 expectRejected(scriptState(), promise, valueTest); | |
| 216 | |
| 217 container->willBeDetachedFromFrame(); | |
| 218 } | |
| 219 | |
| 208 private: | 220 private: |
| 209 OwnPtr<DummyPageHolder> m_page; | 221 OwnPtr<DummyPageHolder> m_page; |
| 210 }; | 222 }; |
| 211 | 223 |
| 212 TEST_F(ServiceWorkerContainerTest, Register_NonSecureOriginIsRejected) | 224 TEST_F(ServiceWorkerContainerTest, Register_NonSecureOriginIsRejected) |
| 213 { | 225 { |
| 214 setPageURL("http://www.example.com/"); | 226 setPageURL("http://www.example.com/"); |
| 215 testRegisterRejected( | 227 testRegisterRejected( |
| 216 "http://www.example.com/worker.js", | 228 "http://www.example.com/worker.js", |
| 217 "http://www.example.com/", | 229 "http://www.example.com/", |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 245 } | 257 } |
| 246 | 258 |
| 247 TEST_F(ServiceWorkerContainerTest, Unregister_CrossOriginScopeIsRejected) | 259 TEST_F(ServiceWorkerContainerTest, Unregister_CrossOriginScopeIsRejected) |
| 248 { | 260 { |
| 249 setPageURL("https://www.example.com"); | 261 setPageURL("https://www.example.com"); |
| 250 testUnregisterRejected( | 262 testUnregisterRejected( |
| 251 "https://example.com/", // Differs by host | 263 "https://example.com/", // Differs by host |
| 252 ExpectDOMException("SecurityError", "The scope must match the current or igin.")); | 264 ExpectDOMException("SecurityError", "The scope must match the current or igin.")); |
| 253 } | 265 } |
| 254 | 266 |
| 267 TEST_F(ServiceWorkerContainerTest, GetRegistration_NonSecureOriginIsRejected) | |
| 268 { | |
| 269 setPageURL("http://www.example.com/"); | |
| 270 testGetRegistrationRejected( | |
| 271 "http://www.example.com/", | |
| 272 ExpectDOMException("NotSupportedError", "Only secure origins are allowed . http://goo.gl/lq4gCo")); | |
| 273 } | |
| 274 | |
|
nhiroki
2014/09/10 07:45:04
Can you test the CrossOriginDocument case?
Kunihiko Sakamoto
2014/09/10 09:34:51
Done.
| |
| 255 class StubWebServiceWorkerProvider { | 275 class StubWebServiceWorkerProvider { |
| 256 public: | 276 public: |
| 257 StubWebServiceWorkerProvider() | 277 StubWebServiceWorkerProvider() |
| 258 : m_registerCallCount(0) | 278 : m_registerCallCount(0) |
| 259 , m_unregisterCallCount(0) | 279 , m_unregisterCallCount(0) |
| 260 { | 280 { |
| 261 } | 281 } |
| 262 | 282 |
| 263 // Creates a WebServiceWorkerProvider. This can outlive the | 283 // Creates a WebServiceWorkerProvider. This can outlive the |
| 264 // StubWebServiceWorkerProvider, but |registerServiceWorker| and | 284 // StubWebServiceWorkerProvider, but |registerServiceWorker| and |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 | 362 |
| 343 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); | 363 EXPECT_EQ(1ul, stubProvider.unregisterCallCount()); |
| 344 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un registerScope()); | 364 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), stubProvider.un registerScope()); |
| 345 } | 365 } |
| 346 | 366 |
| 347 container->willBeDetachedFromFrame(); | 367 container->willBeDetachedFromFrame(); |
| 348 } | 368 } |
| 349 | 369 |
| 350 } // namespace | 370 } // namespace |
| 351 } // namespace blink | 371 } // namespace blink |
| OLD | NEW |