| 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 class WebEmbeddedWorkerImplTest : public ::testing::Test { | 61 class WebEmbeddedWorkerImplTest : public ::testing::Test { |
| 62 protected: | 62 protected: |
| 63 void SetUp() override | 63 void SetUp() override |
| 64 { | 64 { |
| 65 m_mockClient = new MockServiceWorkerContextClient(); | 65 m_mockClient = new MockServiceWorkerContextClient(); |
| 66 m_worker = wrapUnique(WebEmbeddedWorker::create(m_mockClient, nullptr)); | 66 m_worker = wrapUnique(WebEmbeddedWorker::create(m_mockClient, nullptr)); |
| 67 | 67 |
| 68 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); | 68 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); |
| 69 WebURLResponse response; | 69 WebURLResponse response; |
| 70 response.initialize(); | |
| 71 response.setMIMEType("text/javascript"); | 70 response.setMIMEType("text/javascript"); |
| 72 response.setHTTPStatusCode(200); | 71 response.setHTTPStatusCode(200); |
| 73 Platform::current()->getURLLoaderMockFactory()->registerURL(scriptURL, r
esponse, ""); | 72 Platform::current()->getURLLoaderMockFactory()->registerURL(scriptURL, r
esponse, ""); |
| 74 | 73 |
| 75 m_startData.scriptURL = scriptURL; | 74 m_startData.scriptURL = scriptURL; |
| 76 m_startData.userAgent = WebString("dummy user agent"); | 75 m_startData.userAgent = WebString("dummy user agent"); |
| 77 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau
seAfterDownload; | 76 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau
seAfterDownload; |
| 78 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; | 77 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; |
| 79 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; | 78 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; |
| 80 } | 79 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) | 159 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) |
| 161 .Times(1); | 160 .Times(1); |
| 162 m_worker->terminateWorkerContext(); | 161 m_worker->terminateWorkerContext(); |
| 163 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 162 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 164 } | 163 } |
| 165 | 164 |
| 166 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) | 165 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) |
| 167 { | 166 { |
| 168 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); | 167 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); |
| 169 WebURLResponse response; | 168 WebURLResponse response; |
| 170 response.initialize(); | |
| 171 response.setMIMEType("text/javascript"); | 169 response.setMIMEType("text/javascript"); |
| 172 response.setHTTPStatusCode(404); | 170 response.setHTTPStatusCode(404); |
| 173 WebURLError error; | 171 WebURLError error; |
| 174 error.reason = 1010; | 172 error.reason = 1010; |
| 175 error.domain = "WebEmbeddedWorkerImplTest"; | 173 error.domain = "WebEmbeddedWorkerImplTest"; |
| 176 Platform::current()->getURLLoaderMockFactory()->registerErrorURL(scriptURL,
response, error); | 174 Platform::current()->getURLLoaderMockFactory()->registerErrorURL(scriptURL,
response, error); |
| 177 m_startData.scriptURL = scriptURL; | 175 m_startData.scriptURL = scriptURL; |
| 178 | 176 |
| 179 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) | 177 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) |
| 180 .Times(1); | 178 .Times(1); |
| (...skipping 102 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 |