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

Unified Diff: third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp

Issue 1675613002: service worker: use 200 OK for update requests even in the no update case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
Index: third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp
diff --git a/third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp b/third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp
index a26ac1ea863580af32e36a542e461623974b06f4..2fef5dd27313edf44163c5a838d3d05e2a1e46af 100644
--- a/third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp
+++ b/third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp
@@ -9,6 +9,7 @@
#include "public/platform/Platform.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/WebUnitTestSupport.h"
+#include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
#include "public/web/WebEmbeddedWorkerStartData.h"
#include "public/web/WebSettings.h"
#include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
@@ -25,17 +26,26 @@ public:
~MockServiceWorkerContextClient() override { }
MOCK_METHOD0(workerReadyForInspection, void());
MOCK_METHOD0(workerContextFailedToStart, void());
+ MOCK_METHOD0(workerScriptLoaded, void());
MOCK_METHOD1(createServiceWorkerNetworkProvider, WebServiceWorkerNetworkProvider*(WebDataSource*));
+ MOCK_METHOD0(createServiceWorkerProvider, WebServiceWorkerProvider*());
};
-class WebEmbeddedWorkerImplFailureTest : public ::testing::Test {
+class WebEmbeddedWorkerImplTest : public ::testing::Test {
protected:
void SetUp() override
{
m_mockClient = new MockServiceWorkerContextClient();
m_worker = adoptPtr(WebEmbeddedWorker::create(m_mockClient, nullptr));
- WebURL invalidScriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js");
+ m_validScriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js");
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType("text/html");
+ response.setHTTPStatusCode(200);
+ Platform::current()->unitTestSupport()->registerMockedURL(m_validScriptURL, response, "");
+
+ m_invalidScriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js");
WebURLResponse errorResponse;
errorResponse.initialize();
errorResponse.setMIMEType("text/html");
@@ -43,10 +53,11 @@ protected:
WebURLError error;
error.reason = 1010;
error.domain = "WebEmbeddedWorkerImplTest";
- Platform::current()->unitTestSupport()->registerMockedErrorURL(invalidScriptURL, errorResponse, error);
+ Platform::current()->unitTestSupport()->registerMockedErrorURL(m_invalidScriptURL, errorResponse, error);
- m_startData.scriptURL = invalidScriptURL;
+ m_startData.scriptURL = m_validScriptURL;
m_startData.userAgent = WebString("dummy user agent");
+ m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPauseAfterDownload;
m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitForDebugger;
m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
}
@@ -56,6 +67,8 @@ protected:
Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
}
+ WebURL m_validScriptURL;
+ WebURL m_invalidScriptURL;
WebEmbeddedWorkerStartData m_startData;
MockServiceWorkerContextClient* m_mockClient;
OwnPtr<WebEmbeddedWorker> m_worker;
@@ -63,9 +76,10 @@ protected:
} // namespace
-TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
+TEST_F(WebEmbeddedWorkerImplTest, TerminateSoonAfterStart)
{
EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
+ m_startData.scriptURL = m_invalidScriptURL;
m_worker->startWorkerContext(m_startData);
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
@@ -74,7 +88,7 @@ TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
-TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileWaitingForDebugger)
+TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileWaitingForDebugger)
{
EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::WaitForDebugger;
@@ -86,9 +100,33 @@ TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileWaitingForDebugger)
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
-TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
+TEST_F(WebEmbeddedWorkerImplTest, TerminateWhilePausedAfterDownload)
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection())
+ .Times(1);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
+ .WillOnce(::testing::Return(nullptr));
+ EXPECT_CALL(*m_mockClient, workerScriptLoaded())
+ .Times(1);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
michaeln 2016/02/06 01:13:58 ok, i'm not too familiar with testing::Mock, the .
falken 2016/02/10 05:40:41 Yes, I was surprised too.
+ .Times(0);
+
+ m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::PauseAfterDownload;
+ m_worker->startWorkerContext(m_startData);
+ testing::runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ EXPECT_CALL(*m_mockClient, workerContextFailedToStart())
+ .Times(1);
+ m_worker->terminateWorkerContext();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
+TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileLoadingScript)
{
EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
+ m_startData.scriptURL = m_invalidScriptURL;
m_worker->startWorkerContext(m_startData);
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
@@ -101,4 +139,38 @@ TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
+TEST_F(WebEmbeddedWorkerImplTest, Success)
michaeln 2016/02/06 01:13:58 DoNotPauseAfterDownload()?
falken 2016/02/10 05:40:41 Done.
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection())
+ .Times(1);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
+ .WillOnce(::testing::Return(nullptr));
nhiroki 2016/02/10 04:56:15 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).T
falken 2016/02/10 05:40:41 Redid these tests to be more thorough.
+ EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
+ .WillOnce(::testing::Return(nullptr));
+ m_worker->startWorkerContext(m_startData);
+ testing::runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
+TEST_F(WebEmbeddedWorkerImplTest, PauseAfterDownload)
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection())
+ .Times(1);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
+ .WillOnce(::testing::Return(nullptr));
+ EXPECT_CALL(*m_mockClient, workerScriptLoaded())
+ .Times(1);
+ m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::PauseAfterDownload;
+ m_worker->startWorkerContext(m_startData);
+ testing::runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
+ .WillOnce(::testing::Return(nullptr));
+ m_worker->resumeAfterDownload();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698