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

Unified Diff: Source/web/WebEmbeddedWorkerImplTest.cpp

Issue 1187813010: Check whether the shadow page has been loaded in WebEmbeddedWorkerImpl::terminateWorkerContext(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add tests Created 5 years, 6 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/web/WebEmbeddedWorkerImpl.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebEmbeddedWorkerImplTest.cpp
diff --git a/Source/web/WebEmbeddedWorkerImplTest.cpp b/Source/web/WebEmbeddedWorkerImplTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b4bbc9632dd7b58fd033041950d6066d83663559
--- /dev/null
+++ b/Source/web/WebEmbeddedWorkerImplTest.cpp
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "public/web/WebEmbeddedWorker.h"
+
+#include "platform/testing/URLTestHelpers.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebURLResponse.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "public/web/WebEmbeddedWorkerStartData.h"
+#include "public/web/WebServiceWorkerContextClient.h"
+#include "public/web/WebSettings.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace blink {
+namespace {
+
+class MockServiceWorkerContextClient
+ : public WebServiceWorkerContextClient {
+public:
+ MockServiceWorkerContextClient() { }
+ ~MockServiceWorkerContextClient() override { }
+ MOCK_METHOD0(workerReadyForInspection, void());
+ MOCK_METHOD0(workerContextFailedToStart, void());
+ MOCK_METHOD1(createServiceWorkerNetworkProvider, WebServiceWorkerNetworkProvider*(WebDataSource*));
+};
+
+class WebEmbeddedWorkerImplFailureTest : 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;
+ m_startData.userAgent = WebString("dummy user agent");
+ m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPauseAfterDownload;
+ m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitForDebugger;
+ m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
+ }
+
+ void TearDown() override
+ {
+ Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
+ }
+
+ WebEmbeddedWorkerStartData m_startData;
+ MockServiceWorkerContextClient* m_mockClient;
+ OwnPtr<WebEmbeddedWorker> m_worker;
+};
+
+} // namespace
+
+TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
+ m_worker->startWorkerContext(m_startData);
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
+ m_worker->terminateWorkerContext();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
+TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
+{
+ EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
+ m_worker->startWorkerContext(m_startData);
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)).WillOnce(::testing::Return(nullptr));
+ testing::runPendingTasks();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+
+ EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
+ m_worker->terminateWorkerContext();
+ ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
+}
+
+} // namespace blink
« no previous file with comments | « Source/web/WebEmbeddedWorkerImpl.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698