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

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

Issue 1687803002: Expand WebEmbeddedWorkerImplTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
« no previous file with comments | « third_party/WebKit/PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..05e937a591970848549759be8bf146b8e54afd97 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,27 +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");
- WebURLResponse errorResponse;
- errorResponse.initialize();
- errorResponse.setMIMEType("text/html");
- errorResponse.setHTTPStatusCode(404);
- WebURLError error;
- error.reason = 1010;
- error.domain = "WebEmbeddedWorkerImplTest";
- Platform::current()->unitTestSupport()->registerMockedErrorURL(invalidScriptURL, errorResponse, error);
-
- m_startData.scriptURL = invalidScriptURL;
+ WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js");
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType("text/javascript");
+ response.setHTTPStatusCode(200);
+ Platform::current()->unitTestSupport()->registerMockedURL(scriptURL, response, "");
+
+ m_startData.scriptURL = scriptURL;
m_startData.userAgent = WebString("dummy user agent");
m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitForDebugger;
m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
@@ -63,7 +63,7 @@ protected:
} // namespace
-TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
+TEST_F(WebEmbeddedWorkerImplTest, TerminateSoonAfterStart)
{
EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
m_worker->startWorkerContext(m_startData);
@@ -74,7 +74,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,19 +86,78 @@ TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileWaitingForDebugger)
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
-TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
+TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileLoadingScript)
{
EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
m_worker->startWorkerContext(m_startData);
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+ // Load the shadow page.
EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)).WillOnce(::testing::Return(nullptr));
- testing::runPendingTasks();
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+ // Terminate before loading the script.
EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
m_worker->terminateWorkerContext();
::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
+TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound)
+{
+ WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js");
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType("text/javascript");
+ response.setHTTPStatusCode(404);
+ WebURLError error;
+ error.reason = 1010;
+ error.domain = "WebEmbeddedWorkerImplTest";
+ Platform::current()->unitTestSupport()->registerMockedErrorURL(scriptURL, response, error);
+ m_startData.scriptURL = scriptURL;
+
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection())
+ .Times(1);
+ m_worker->startWorkerContext(m_startData);
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ // Load the shadow page.
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
+ .WillOnce(::testing::Return(nullptr));
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ // Load the script.
+ EXPECT_CALL(*m_mockClient, workerScriptLoaded())
+ .Times(0);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
+ .Times(0);
+ EXPECT_CALL(*m_mockClient, workerContextFailedToStart())
+ .Times(1);
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
+TEST_F(WebEmbeddedWorkerImplTest, Success)
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection())
+ .Times(1);
+ m_worker->startWorkerContext(m_startData);
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ // Load the shadow page.
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
+ .WillOnce(::testing::Return(nullptr));
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ // Load the script.
+ EXPECT_CALL(*m_mockClient, workerScriptLoaded())
+ .Times(1);
+ EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
+ .WillOnce(::testing::Return(nullptr));
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698