Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2519)

Unified Diff: Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp

Issue 540823003: ServiceWorker: Implement navigator.serviceWorker.getRegistration [3/3] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp b/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
index 73ef62c4c7fb035684857ff1acfadc06217a62d6..5205b50ec6eee4d8a75ba057ccfccf344165212d 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
@@ -205,6 +205,18 @@ protected:
container->willBeDetachedFromFrame();
}
+ void testGetRegistrationRejected(const String& documentURL, const ScriptValueTest& valueTest)
+ {
+ provide(adoptPtr(new NotReachedWebServiceWorkerProvider()));
+
+ ServiceWorkerContainer* container = ServiceWorkerContainer::create(executionContext());
+ ScriptState::Scope scriptScope(scriptState());
+ ScriptPromise promise = container->getRegistration(scriptState(), documentURL);
+ expectRejected(scriptState(), promise, valueTest);
+
+ container->willBeDetachedFromFrame();
+ }
+
private:
OwnPtr<DummyPageHolder> m_page;
};
@@ -252,11 +264,28 @@ TEST_F(ServiceWorkerContainerTest, Unregister_CrossOriginScopeIsRejected)
ExpectDOMException("SecurityError", "The scope must match the current origin."));
}
+TEST_F(ServiceWorkerContainerTest, GetRegistration_NonSecureOriginIsRejected)
+{
+ setPageURL("http://www.example.com/");
+ testGetRegistrationRejected(
+ "http://www.example.com/",
+ ExpectDOMException("NotSupportedError", "Only secure origins are allowed. http://goo.gl/lq4gCo"));
+}
+
+TEST_F(ServiceWorkerContainerTest, GetRegistration_CrossOriginURLIsRejected)
+{
+ setPageURL("https://www.example.com/");
+ testGetRegistrationRejected(
+ "https://foo.example.com/", // Differs by host
+ ExpectDOMException("SecurityError", "The documentURL must match the current origin."));
+}
+
class StubWebServiceWorkerProvider {
public:
StubWebServiceWorkerProvider()
: m_registerCallCount(0)
, m_unregisterCallCount(0)
+ , m_getRegistrationCallCount(0)
{
}
@@ -274,6 +303,8 @@ public:
const WebURL& registerScriptURL() { return m_registerScriptURL; }
size_t unregisterCallCount() { return m_unregisterCallCount; }
const WebURL& unregisterScope() { return m_unregisterScope; }
+ size_t getRegistrationCallCount() { return m_getRegistrationCallCount; }
+ const WebURL& getRegistrationURL() { return m_getRegistrationURL; }
private:
class WebServiceWorkerProviderImpl : public WebServiceWorkerProvider {
@@ -300,10 +331,18 @@ private:
m_unregistrationCallbacksToDelete.append(adoptPtr(callbacks));
}
+ virtual void getRegistration(const WebURL& documentURL, WebServiceWorkerGetRegistrationCallbacks* callbacks) OVERRIDE
+ {
+ m_owner.m_getRegistrationCallCount++;
+ m_owner.m_getRegistrationURL = documentURL;
+ m_getRegistrationCallbacksToDelete.append(adoptPtr(callbacks));
+ }
+
private:
StubWebServiceWorkerProvider& m_owner;
Vector<OwnPtr<WebServiceWorkerRegistrationCallbacks> > m_registrationCallbacksToDelete;
Vector<OwnPtr<WebServiceWorkerUnregistrationCallbacks> > m_unregistrationCallbacksToDelete;
+ Vector<OwnPtr<WebServiceWorkerGetRegistrationCallbacks> > m_getRegistrationCallbacksToDelete;
};
private:
@@ -312,6 +351,8 @@ private:
WebURL m_registerScriptURL;
size_t m_unregisterCallCount;
WebURL m_unregisterScope;
+ size_t m_getRegistrationCallCount;
+ WebURL m_getRegistrationURL;
};
TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelegatesToProvider)
@@ -347,5 +388,24 @@ TEST_F(ServiceWorkerContainerTest, RegisterUnregister_NonHttpsSecureOriginDelega
container->willBeDetachedFromFrame();
}
+TEST_F(ServiceWorkerContainerTest, GetRegistration_OmittedDocumentURLDefaultsToPageURL)
+{
+ setPageURL("http://localhost/x/index.html");
+
+ StubWebServiceWorkerProvider stubProvider;
+ provide(stubProvider.provider());
+
+ ServiceWorkerContainer* container = ServiceWorkerContainer::create(executionContext());
+
+ {
+ ScriptState::Scope scriptScope(scriptState());
+ container->getRegistration(scriptState(), "");
+ EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount());
+ EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), stubProvider.getRegistrationURL());
+ }
+
+ container->willBeDetachedFromFrame();
+}
+
} // namespace
} // namespace blink
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698