Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebEmbeddedWorkerImplTest.cpp
blob2f399291fe56a1d0c05e1d7dfa218d362b0e9630
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "public/web/WebEmbeddedWorker.h"
8 #include "platform/testing/URLTestHelpers.h"
9 #include "platform/testing/UnitTestHelpers.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebURLResponse.h"
12 #include "public/platform/WebUnitTestSupport.h"
13 #include "public/web/WebEmbeddedWorkerStartData.h"
14 #include "public/web/WebServiceWorkerContextClient.h"
15 #include "public/web/WebSettings.h"
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
19 namespace blink {
20 namespace {
22 class MockServiceWorkerContextClient
23 : public WebServiceWorkerContextClient {
24 public:
25 MockServiceWorkerContextClient() { }
26 ~MockServiceWorkerContextClient() override { }
27 MOCK_METHOD0(workerReadyForInspection, void());
28 MOCK_METHOD0(workerContextFailedToStart, void());
29 MOCK_METHOD1(createServiceWorkerNetworkProvider, WebServiceWorkerNetworkProvider*(WebDataSource*));
32 class WebEmbeddedWorkerImplFailureTest : public ::testing::Test {
33 protected:
34 void SetUp() override
36 m_mockClient = new MockServiceWorkerContextClient();
37 m_worker = adoptPtr(WebEmbeddedWorker::create(m_mockClient, nullptr));
39 WebURL invalidScriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js");
40 WebURLResponse errorResponse;
41 errorResponse.initialize();
42 errorResponse.setMIMEType("text/html");
43 errorResponse.setHTTPStatusCode(404);
44 WebURLError error;
45 error.reason = 1010;
46 error.domain = "WebEmbeddedWorkerImplTest";
47 Platform::current()->unitTestSupport()->registerMockedErrorURL(invalidScriptURL, errorResponse, error);
49 m_startData.scriptURL = invalidScriptURL;
50 m_startData.userAgent = WebString("dummy user agent");
51 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitForDebugger;
52 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
55 void TearDown() override
57 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
60 WebEmbeddedWorkerStartData m_startData;
61 MockServiceWorkerContextClient* m_mockClient;
62 OwnPtr<WebEmbeddedWorker> m_worker;
65 } // namespace
67 TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
69 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
70 m_worker->startWorkerContext(m_startData);
71 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
73 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
74 m_worker->terminateWorkerContext();
75 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
78 TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
80 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
81 m_worker->startWorkerContext(m_startData);
82 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
84 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)).WillOnce(::testing::Return(nullptr));
85 testing::runPendingTasks();
86 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
88 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
89 m_worker->terminateWorkerContext();
90 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
93 } // namespace blink