OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "public/web/WebEmbeddedWorker.h" | 5 #include "public/web/WebEmbeddedWorker.h" |
6 | 6 |
7 #include "platform/testing/URLTestHelpers.h" | 7 #include "platform/testing/URLTestHelpers.h" |
8 #include "platform/testing/UnitTestHelpers.h" | 8 #include "platform/testing/UnitTestHelpers.h" |
9 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
10 #include "public/platform/WebURLLoaderMockFactory.h" | 10 #include "public/platform/WebURLLoaderMockFactory.h" |
11 #include "public/platform/WebURLResponse.h" | 11 #include "public/platform/WebURLResponse.h" |
12 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 12 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
13 #include "public/web/WebCache.h" | 13 #include "public/web/WebCache.h" |
14 #include "public/web/WebEmbeddedWorkerStartData.h" | 14 #include "public/web/WebEmbeddedWorkerStartData.h" |
15 #include "public/web/WebSettings.h" | 15 #include "public/web/WebSettings.h" |
16 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 16 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "wtf/PtrUtil.h" | |
20 #include <memory> | |
21 | 19 |
22 namespace blink { | 20 namespace blink { |
23 namespace { | 21 namespace { |
24 | 22 |
25 class MockServiceWorkerContextClient | 23 class MockServiceWorkerContextClient |
26 : public WebServiceWorkerContextClient { | 24 : public WebServiceWorkerContextClient { |
27 public: | 25 public: |
28 MockServiceWorkerContextClient() | 26 MockServiceWorkerContextClient() |
29 : m_hasAssociatedRegistration(true) | 27 : m_hasAssociatedRegistration(true) |
30 { | 28 { |
(...skipping 25 matching lines...) Expand all Loading... |
56 | 54 |
57 private: | 55 private: |
58 bool m_hasAssociatedRegistration; | 56 bool m_hasAssociatedRegistration; |
59 }; | 57 }; |
60 | 58 |
61 class WebEmbeddedWorkerImplTest : public ::testing::Test { | 59 class WebEmbeddedWorkerImplTest : public ::testing::Test { |
62 protected: | 60 protected: |
63 void SetUp() override | 61 void SetUp() override |
64 { | 62 { |
65 m_mockClient = new MockServiceWorkerContextClient(); | 63 m_mockClient = new MockServiceWorkerContextClient(); |
66 m_worker = wrapUnique(WebEmbeddedWorker::create(m_mockClient, nullptr)); | 64 m_worker = adoptPtr(WebEmbeddedWorker::create(m_mockClient, nullptr)); |
67 | 65 |
68 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); | 66 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); |
69 WebURLResponse response; | 67 WebURLResponse response; |
70 response.initialize(); | 68 response.initialize(); |
71 response.setMIMEType("text/javascript"); | 69 response.setMIMEType("text/javascript"); |
72 response.setHTTPStatusCode(200); | 70 response.setHTTPStatusCode(200); |
73 Platform::current()->getURLLoaderMockFactory()->registerURL(scriptURL, r
esponse, ""); | 71 Platform::current()->getURLLoaderMockFactory()->registerURL(scriptURL, r
esponse, ""); |
74 | 72 |
75 m_startData.scriptURL = scriptURL; | 73 m_startData.scriptURL = scriptURL; |
76 m_startData.userAgent = WebString("dummy user agent"); | 74 m_startData.userAgent = WebString("dummy user agent"); |
77 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau
seAfterDownload; | 75 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau
seAfterDownload; |
78 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; | 76 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; |
79 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; | 77 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; |
80 } | 78 } |
81 | 79 |
82 void TearDown() override | 80 void TearDown() override |
83 { | 81 { |
84 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 82 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
85 WebCache::clear(); | 83 WebCache::clear(); |
86 } | 84 } |
87 | 85 |
88 WebEmbeddedWorkerStartData m_startData; | 86 WebEmbeddedWorkerStartData m_startData; |
89 MockServiceWorkerContextClient* m_mockClient; | 87 MockServiceWorkerContextClient* m_mockClient; |
90 std::unique_ptr<WebEmbeddedWorker> m_worker; | 88 OwnPtr<WebEmbeddedWorker> m_worker; |
91 }; | 89 }; |
92 | 90 |
93 } // namespace | 91 } // namespace |
94 | 92 |
95 TEST_F(WebEmbeddedWorkerImplTest, TerminateSoonAfterStart) | 93 TEST_F(WebEmbeddedWorkerImplTest, TerminateSoonAfterStart) |
96 { | 94 { |
97 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); | 95 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); |
98 m_worker->startWorkerContext(m_startData); | 96 m_worker->startWorkerContext(m_startData); |
99 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 97 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
100 | 98 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 281 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
284 | 282 |
285 // Resume after download. | 283 // Resume after download. |
286 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | 284 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) |
287 .WillOnce(::testing::Return(nullptr)); | 285 .WillOnce(::testing::Return(nullptr)); |
288 m_worker->resumeAfterDownload(); | 286 m_worker->resumeAfterDownload(); |
289 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 287 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
290 } | 288 } |
291 | 289 |
292 } // namespace blink | 290 } // namespace blink |
OLD | NEW |