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; |
50 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; | 51 m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::DontWaitFo
rDebugger; |
51 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; | 52 m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault; |
52 } | 53 } |
53 | 54 |
54 void TearDown() override | 55 void TearDown() override |
55 { | 56 { |
56 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 57 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
57 } | 58 } |
58 | 59 |
59 WebEmbeddedWorkerStartData m_startData; | 60 WebEmbeddedWorkerStartData m_startData; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
.WillOnce(::testing::Return(nullptr)); | 97 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
.WillOnce(::testing::Return(nullptr)); |
97 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 98 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
98 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 99 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
99 | 100 |
100 // Terminate before loading the script. | 101 // Terminate before loading the script. |
101 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); | 102 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); |
102 m_worker->terminateWorkerContext(); | 103 m_worker->terminateWorkerContext(); |
103 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 104 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
104 } | 105 } |
105 | 106 |
| 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 |
106 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) | 138 TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) |
107 { | 139 { |
108 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); | 140 WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js
"); |
109 WebURLResponse response; | 141 WebURLResponse response; |
110 response.initialize(); | 142 response.initialize(); |
111 response.setMIMEType("text/javascript"); | 143 response.setMIMEType("text/javascript"); |
112 response.setHTTPStatusCode(404); | 144 response.setHTTPStatusCode(404); |
113 WebURLError error; | 145 WebURLError error; |
114 error.reason = 1010; | 146 error.reason = 1010; |
115 error.domain = "WebEmbeddedWorkerImplTest"; | 147 error.domain = "WebEmbeddedWorkerImplTest"; |
(...skipping 15 matching lines...) Expand all Loading... |
131 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | 163 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) |
132 .Times(0); | 164 .Times(0); |
133 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | 165 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) |
134 .Times(0); | 166 .Times(0); |
135 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) | 167 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()) |
136 .Times(1); | 168 .Times(1); |
137 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 169 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
138 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 170 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
139 } | 171 } |
140 | 172 |
| 173 // The running worker is detected as a memory leak. crbug.com/586897 |
141 #if defined(ADDRESS_SANITIZER) | 174 #if defined(ADDRESS_SANITIZER) |
142 #define MAYBE_Success DISABLED_Success | 175 #define MAYBE_DontPauseAfterDownload DISABLED_DontPauseAfterDownload |
143 #else | 176 #else |
144 #define MAYBE_Success Success | 177 #define MAYBE_DontPauseAfterDownload DontPauseAfterDownload |
145 #endif | 178 #endif |
146 | 179 |
147 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_Success) | 180 TEST_F(WebEmbeddedWorkerImplTest, DontPauseAfterDownload) |
148 { | 181 { |
149 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) | 182 EXPECT_CALL(*m_mockClient, workerReadyForInspection()) |
150 .Times(1); | 183 .Times(1); |
151 m_worker->startWorkerContext(m_startData); | 184 m_worker->startWorkerContext(m_startData); |
152 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 185 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
153 | 186 |
154 // Load the shadow page. | 187 // Load the shadow page. |
155 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) | 188 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) |
156 .WillOnce(::testing::Return(nullptr)); | 189 .WillOnce(::testing::Return(nullptr)); |
157 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 190 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
158 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 191 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
159 | 192 |
160 // Load the script. | 193 // Load the script. |
161 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) | 194 EXPECT_CALL(*m_mockClient, workerScriptLoaded()) |
162 .Times(1); | 195 .Times(1); |
163 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) | 196 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) |
164 .WillOnce(::testing::Return(nullptr)); | 197 .WillOnce(::testing::Return(nullptr)); |
165 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 198 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
166 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); | 199 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); |
167 } | 200 } |
168 | 201 |
| 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 |
169 } // namespace blink | 238 } // namespace blink |
OLD | NEW |