| 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/WebURLResponse.h" | 10 #include "public/platform/WebURLResponse.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); | 41 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js
"); |
| 42 WebURLResponse response; | 42 WebURLResponse response; |
| 43 response.initialize(); | 43 response.initialize(); |
| 44 response.setMIMEType("text/javascript"); | 44 response.setMIMEType("text/javascript"); |
| 45 response.setHTTPStatusCode(200); | 45 response.setHTTPStatusCode(200); |
| 46 Platform::current()->unitTestSupport()->registerMockedURL(scriptURL, res
ponse, ""); | 46 Platform::current()->unitTestSupport()->registerMockedURL(scriptURL, res
ponse, ""); |
| 47 | 47 |
| 48 m_startData.scriptURL = scriptURL; | 48 m_startData.scriptURL = scriptURL; |
| 49 m_startData.userAgent = WebString("dummy user agent"); | 49 m_startData.userAgent = WebString("dummy user agent"); |
| 50 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::DontPau
seAfterDownload; | |
| 51 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; | 50 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; |
| 52 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; | 51 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; |
| 53 } | 52 } |
| 54 | 53 |
| 55 void TearDown() override | 54 void TearDown() override |
| 56 { | 55 { |
| 57 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 56 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 WebEmbeddedWorkerStartData m_startData; | 59 WebEmbeddedWorkerStartData m_startData; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
.WillOnce(::testing::Return(nullptr)); | 96 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
.WillOnce(::testing::Return(nullptr)); |
| 98 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 97 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 99 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 98 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 100 | 99 |
| 101 // Terminate before loading the script. | 100 // Terminate before loading the script. |
| 102 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); | 101 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); |
| 103 m_worker->terminateWorkerContext(); | 102 m_worker->terminateWorkerContext(); |
| 104 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 103 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 105 } | 104 } |
| 106 | 105 |
| 107 TEST_F(WebEmbeddedWorkerImplTest, TerminateWhilePausedAfterDownload) | |
| 108 { | |
| 109 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) | |
| 110 .Times(1); | |
| 111 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::PauseAfterD
ownload; | |
| 112 m_worker->startWorkerContext(m_startData); | |
| 113 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 114 | |
| 115 // Load the shadow page. | |
| 116 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) | |
| 117 .WillOnce(::testing::Return(nullptr)); | |
| 118 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 119 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 120 | |
| 121 // Load the script. | |
| 122 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | |
| 123 .Times(1); | |
| 124 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | |
| 125 .Times(0); | |
| 126 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 127 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 128 | |
| 129 // Terminate before resuming after download. | |
| 130 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | |
| 131 .Times(0); | |
| 132 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) | |
| 133 .Times(1); | |
| 134 m_worker->terminateWorkerContext(); | |
| 135 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 136 } | |
| 137 | |
| 138 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) | 106 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) |
| 139 { | 107 { |
| 140 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); | 108 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); |
| 141 WebURLResponse response; | 109 WebURLResponse response; |
| 142 response.initialize(); | 110 response.initialize(); |
| 143 response.setMIMEType("text/javascript"); | 111 response.setMIMEType("text/javascript"); |
| 144 response.setHTTPStatusCode(404); | 112 response.setHTTPStatusCode(404); |
| 145 WebURLError error; | 113 WebURLError error; |
| 146 error.reason = 1010; | 114 error.reason = 1010; |
| 147 error.domain = "WebEmbeddedWorkerImplTest"; | 115 error.domain = "WebEmbeddedWorkerImplTest"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | 131 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) |
| 164 .Times(0); | 132 .Times(0); |
| 165 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | 133 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) |
| 166 .Times(0); | 134 .Times(0); |
| 167 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) | 135 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) |
| 168 .Times(1); | 136 .Times(1); |
| 169 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 137 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 170 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 138 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 171 } | 139 } |
| 172 | 140 |
| 173 // The running worker is detected as a memory leak. crbug.com/586897 | |
| 174 #if defined(ADDRESS_SANITIZER) | 141 #if defined(ADDRESS_SANITIZER) |
| 175 #define MAYBE_DontPauseAfterDownload DISABLED_DontPauseAfterDownload | 142 #define MAYBE_Success DISABLED_Success |
| 176 #else | 143 #else |
| 177 #define MAYBE_DontPauseAfterDownload DontPauseAfterDownload | 144 #define MAYBE_Success Success |
| 178 #endif | 145 #endif |
| 179 | 146 |
| 180 TEST_F(WebEmbeddedWorkerImplTest, DontPauseAfterDownload) | 147 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_Success) |
| 181 { | 148 { |
| 182 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) | 149 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) |
| 183 .Times(1); | 150 .Times(1); |
| 184 m_worker->startWorkerContext(m_startData); | 151 m_worker->startWorkerContext(m_startData); |
| 185 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 152 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 186 | 153 |
| 187 // Load the shadow page. | 154 // Load the shadow page. |
| 188 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) | 155 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) |
| 189 .WillOnce(::testing::Return(nullptr)); | 156 .WillOnce(::testing::Return(nullptr)); |
| 190 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 157 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 191 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 158 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 192 | 159 |
| 193 // Load the script. | 160 // Load the script. |
| 194 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | 161 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) |
| 195 .Times(1); | 162 .Times(1); |
| 196 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | 163 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) |
| 197 .WillOnce(::testing::Return(nullptr)); | 164 .WillOnce(::testing::Return(nullptr)); |
| 198 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 165 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 199 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 166 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
| 200 } | 167 } |
| 201 | 168 |
| 202 // The running worker is detected as a memory leak. crbug.com/586897 | |
| 203 #if defined(ADDRESS_SANITIZER) | |
| 204 #define MAYBE_PauseAfterDownload DISABLED_PauseAfterDownload | |
| 205 #else | |
| 206 #define MAYBE_PauseAfterDownload PauseAfterDownload | |
| 207 #endif | |
| 208 | |
| 209 TEST_F(WebEmbeddedWorkerImplTest, PauseAfterDownload) | |
| 210 { | |
| 211 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) | |
| 212 .Times(1); | |
| 213 m_startData.pauseAfterDownloadMode = WebEmbeddedWorkerStartData::PauseAfterD
ownload; | |
| 214 m_worker->startWorkerContext(m_startData); | |
| 215 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 216 | |
| 217 // Load the shadow page. | |
| 218 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) | |
| 219 .WillOnce(::testing::Return(nullptr)); | |
| 220 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 221 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 222 | |
| 223 // Load the script. | |
| 224 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | |
| 225 .Times(1); | |
| 226 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | |
| 227 .Times(0); | |
| 228 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 229 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 230 | |
| 231 // Resume after download. | |
| 232 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | |
| 233 .WillOnce(::testing::Return(nullptr)); | |
| 234 m_worker->resumeAfterDownload(); | |
| 235 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | |
| 236 } | |
| 237 | |
| 238 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |