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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/web/WebEmbeddedWorkerImpl.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "config.h"
6 #include "public/web/WebEmbeddedWorker.h"
7
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>
18
19 namespace blink {
20 namespace {
21
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, WebServiceWorkerNetworkProv ider*(WebDataSource*));
30 };
31
32 class WebEmbeddedWorkerImplFailureTest : public ::testing::Test {
33 protected:
34 void SetUp() override
35 {
36 m_mockClient = new MockServiceWorkerContextClient();
37 m_worker = adoptPtr(WebEmbeddedWorker::create(m_mockClient, nullptr));
38
39 WebURL invalidScriptURL = URLTestHelpers::toKURL("https://www.example.co m/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(invalidSc riptURL, errorResponse, error);
48
49 m_startData.scriptURL = invalidScriptURL;
50 m_startData.userAgent = WebString("dummy user agent");
51 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau seAfterDownload;
52 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo rDebugger;
53 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
54 }
55
56 void TearDown() override
57 {
58 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
59 }
60
61 WebEmbeddedWorkerStartData m_startData;
62 MockServiceWorkerContextClient* m_mockClient;
63 OwnPtr<WebEmbeddedWorker> m_worker;
64 };
65
66 } // namespace
67
68 TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateSoonAfterStart)
69 {
70 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
71 m_worker->startWorkerContext(m_startData);
72 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
73
74 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
75 m_worker->terminateWorkerContext();
76 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
77 }
78
79 TEST_F(WebEmbeddedWorkerImplFailureTest, TerminateWhileLoadingScript)
80 {
81 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
82 m_worker->startWorkerContext(m_startData);
83 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
84
85 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) .WillOnce(::testing::Return(nullptr));
86 testing::runPendingTasks();
87 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
88
89 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
90 m_worker->terminateWorkerContext();
91 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
92 }
93
94 } // namespace blink
OLDNEW
« 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