OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/devtools/shared_worker_devtools_manager.h" | 5 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 SharedWorkerDevToolsManager* manager_; | 101 SharedWorkerDevToolsManager* manager_; |
102 }; | 102 }; |
103 | 103 |
104 TEST_F(SharedWorkerDevToolsManagerTest, BasicTest) { | 104 TEST_F(SharedWorkerDevToolsManagerTest, BasicTest) { |
105 scoped_refptr<DevToolsAgentHostImpl> agent_host; | 105 scoped_refptr<DevToolsAgentHostImpl> agent_host; |
106 | 106 |
107 SharedWorkerInstance instance1( | 107 SharedWorkerInstance instance1( |
108 GURL("http://example.com/w.js"), base::string16(), base::string16(), | 108 GURL("http://example.com/w.js"), base::string16(), base::string16(), |
109 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, | 109 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, |
110 browser_context_->GetResourceContext(), partition_id_, | 110 browser_context_->GetResourceContext(), partition_id_, |
111 blink::kWebSharedWorkerCreationContextTypeNonsecure); | 111 blink::kWebSharedWorkerCreationContextTypeNonsecure, |
| 112 false /* data_saver_enabled */); |
112 | 113 |
113 agent_host = manager_->GetDevToolsAgentHostForWorker(1, 1); | 114 agent_host = manager_->GetDevToolsAgentHostForWorker(1, 1); |
114 EXPECT_FALSE(agent_host.get()); | 115 EXPECT_FALSE(agent_host.get()); |
115 | 116 |
116 // Created -> Started -> Destroyed | 117 // Created -> Started -> Destroyed |
117 CheckWorkerNotExist(1, 1); | 118 CheckWorkerNotExist(1, 1); |
118 manager_->WorkerCreated(1, 1, instance1); | 119 manager_->WorkerCreated(1, 1, instance1); |
119 CheckWorkerState(1, 1, WorkerState::WORKER_UNINSPECTED); | 120 CheckWorkerState(1, 1, WorkerState::WORKER_UNINSPECTED); |
120 manager_->WorkerReadyForInspection(1, 1); | 121 manager_->WorkerReadyForInspection(1, 1); |
121 CheckWorkerState(1, 1, WorkerState::WORKER_UNINSPECTED); | 122 CheckWorkerState(1, 1, WorkerState::WORKER_UNINSPECTED); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 184 } |
184 | 185 |
185 TEST_F(SharedWorkerDevToolsManagerTest, AttachTest) { | 186 TEST_F(SharedWorkerDevToolsManagerTest, AttachTest) { |
186 scoped_refptr<DevToolsAgentHostImpl> agent_host1; | 187 scoped_refptr<DevToolsAgentHostImpl> agent_host1; |
187 scoped_refptr<DevToolsAgentHostImpl> agent_host2; | 188 scoped_refptr<DevToolsAgentHostImpl> agent_host2; |
188 | 189 |
189 SharedWorkerInstance instance1( | 190 SharedWorkerInstance instance1( |
190 GURL("http://example.com/w1.js"), base::string16(), base::string16(), | 191 GURL("http://example.com/w1.js"), base::string16(), base::string16(), |
191 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, | 192 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, |
192 browser_context_->GetResourceContext(), partition_id_, | 193 browser_context_->GetResourceContext(), partition_id_, |
193 blink::kWebSharedWorkerCreationContextTypeNonsecure); | 194 blink::kWebSharedWorkerCreationContextTypeNonsecure, |
| 195 false /* data_saver_enabled */); |
194 SharedWorkerInstance instance2( | 196 SharedWorkerInstance instance2( |
195 GURL("http://example.com/w2.js"), base::string16(), base::string16(), | 197 GURL("http://example.com/w2.js"), base::string16(), base::string16(), |
196 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, | 198 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, |
197 browser_context_->GetResourceContext(), partition_id_, | 199 browser_context_->GetResourceContext(), partition_id_, |
198 blink::kWebSharedWorkerCreationContextTypeNonsecure); | 200 blink::kWebSharedWorkerCreationContextTypeNonsecure, |
| 201 false /* data_saver_enabled */); |
199 | 202 |
200 // Created -> GetDevToolsAgentHost -> Register -> Started -> Destroyed | 203 // Created -> GetDevToolsAgentHost -> Register -> Started -> Destroyed |
201 std::unique_ptr<TestDevToolsClientHost> client_host1( | 204 std::unique_ptr<TestDevToolsClientHost> client_host1( |
202 new TestDevToolsClientHost()); | 205 new TestDevToolsClientHost()); |
203 CheckWorkerNotExist(2, 1); | 206 CheckWorkerNotExist(2, 1); |
204 manager_->WorkerCreated(2, 1, instance1); | 207 manager_->WorkerCreated(2, 1, instance1); |
205 CheckWorkerState(2, 1, WorkerState::WORKER_UNINSPECTED); | 208 CheckWorkerState(2, 1, WorkerState::WORKER_UNINSPECTED); |
206 agent_host1 = manager_->GetDevToolsAgentHostForWorker(2, 1); | 209 agent_host1 = manager_->GetDevToolsAgentHostForWorker(2, 1); |
207 EXPECT_TRUE(agent_host1.get()); | 210 EXPECT_TRUE(agent_host1.get()); |
208 CheckWorkerState(2, 1, WorkerState::WORKER_UNINSPECTED); | 211 CheckWorkerState(2, 1, WorkerState::WORKER_UNINSPECTED); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 CheckWorkerCount(1); | 271 CheckWorkerCount(1); |
269 manager_->WorkerDestroyed(2, 5); | 272 manager_->WorkerDestroyed(2, 5); |
270 CheckWorkerCount(0); | 273 CheckWorkerCount(0); |
271 } | 274 } |
272 | 275 |
273 TEST_F(SharedWorkerDevToolsManagerTest, ReattachTest) { | 276 TEST_F(SharedWorkerDevToolsManagerTest, ReattachTest) { |
274 SharedWorkerInstance instance( | 277 SharedWorkerInstance instance( |
275 GURL("http://example.com/w3.js"), base::string16(), base::string16(), | 278 GURL("http://example.com/w3.js"), base::string16(), base::string16(), |
276 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, | 279 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, |
277 browser_context_->GetResourceContext(), partition_id_, | 280 browser_context_->GetResourceContext(), partition_id_, |
278 blink::kWebSharedWorkerCreationContextTypeNonsecure); | 281 blink::kWebSharedWorkerCreationContextTypeNonsecure, |
| 282 false /* data_saver_enabled */); |
279 std::unique_ptr<TestDevToolsClientHost> client_host( | 283 std::unique_ptr<TestDevToolsClientHost> client_host( |
280 new TestDevToolsClientHost()); | 284 new TestDevToolsClientHost()); |
281 // Created -> GetDevToolsAgentHost -> Register -> Destroyed | 285 // Created -> GetDevToolsAgentHost -> Register -> Destroyed |
282 manager_->WorkerCreated(3, 1, instance); | 286 manager_->WorkerCreated(3, 1, instance); |
283 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); | 287 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); |
284 scoped_refptr<DevToolsAgentHost> agent_host( | 288 scoped_refptr<DevToolsAgentHost> agent_host( |
285 manager_->GetDevToolsAgentHostForWorker(3, 1)); | 289 manager_->GetDevToolsAgentHostForWorker(3, 1)); |
286 EXPECT_TRUE(agent_host.get()); | 290 EXPECT_TRUE(agent_host.get()); |
287 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); | 291 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); |
288 client_host->InspectAgentHost(agent_host.get()); | 292 client_host->InspectAgentHost(agent_host.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
299 manager_->WorkerDestroyed(3, 2); | 303 manager_->WorkerDestroyed(3, 2); |
300 CheckWorkerNotExist(3, 2); | 304 CheckWorkerNotExist(3, 2); |
301 CheckWorkerCount(0); | 305 CheckWorkerCount(0); |
302 } | 306 } |
303 | 307 |
304 TEST_F(SharedWorkerDevToolsManagerTest, PauseOnStartTest) { | 308 TEST_F(SharedWorkerDevToolsManagerTest, PauseOnStartTest) { |
305 SharedWorkerInstance instance( | 309 SharedWorkerInstance instance( |
306 GURL("http://example.com/w3.js"), base::string16(), base::string16(), | 310 GURL("http://example.com/w3.js"), base::string16(), base::string16(), |
307 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, | 311 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, |
308 browser_context_->GetResourceContext(), partition_id_, | 312 browser_context_->GetResourceContext(), partition_id_, |
309 blink::kWebSharedWorkerCreationContextTypeNonsecure); | 313 blink::kWebSharedWorkerCreationContextTypeNonsecure, |
| 314 false /* data_saver_enabled */); |
310 std::unique_ptr<TestDevToolsClientHost> client_host( | 315 std::unique_ptr<TestDevToolsClientHost> client_host( |
311 new TestDevToolsClientHost()); | 316 new TestDevToolsClientHost()); |
312 manager_->WorkerCreated(3, 1, instance); | 317 manager_->WorkerCreated(3, 1, instance); |
313 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); | 318 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); |
314 scoped_refptr<WorkerDevToolsAgentHost> agent_host( | 319 scoped_refptr<WorkerDevToolsAgentHost> agent_host( |
315 static_cast<WorkerDevToolsAgentHost*>( | 320 static_cast<WorkerDevToolsAgentHost*>( |
316 manager_->GetDevToolsAgentHostForWorker(3, 1))); | 321 manager_->GetDevToolsAgentHostForWorker(3, 1))); |
317 EXPECT_TRUE(agent_host.get()); | 322 EXPECT_TRUE(agent_host.get()); |
318 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); | 323 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); |
319 agent_host->PauseForDebugOnStart(); | 324 agent_host->PauseForDebugOnStart(); |
320 CheckWorkerState(3, 1, WorkerState::WORKER_PAUSED_FOR_DEBUG_ON_START); | 325 CheckWorkerState(3, 1, WorkerState::WORKER_PAUSED_FOR_DEBUG_ON_START); |
321 EXPECT_FALSE(agent_host->IsReadyForInspection()); | 326 EXPECT_FALSE(agent_host->IsReadyForInspection()); |
322 manager_->WorkerReadyForInspection(3, 1); | 327 manager_->WorkerReadyForInspection(3, 1); |
323 CheckWorkerState(3, 1, WorkerState::WORKER_READY_FOR_DEBUG_ON_START); | 328 CheckWorkerState(3, 1, WorkerState::WORKER_READY_FOR_DEBUG_ON_START); |
324 client_host->InspectAgentHost(agent_host.get()); | 329 client_host->InspectAgentHost(agent_host.get()); |
325 CheckWorkerState(3, 1, WorkerState::WORKER_INSPECTED); | 330 CheckWorkerState(3, 1, WorkerState::WORKER_INSPECTED); |
326 client_host->InspectAgentHost(nullptr); | 331 client_host->InspectAgentHost(nullptr); |
327 agent_host = nullptr; | 332 agent_host = nullptr; |
328 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); | 333 CheckWorkerState(3, 1, WorkerState::WORKER_UNINSPECTED); |
329 manager_->WorkerDestroyed(3, 1); | 334 manager_->WorkerDestroyed(3, 1); |
330 CheckWorkerNotExist(3, 1); | 335 CheckWorkerNotExist(3, 1); |
331 CheckWorkerCount(0); | 336 CheckWorkerCount(0); |
332 } | 337 } |
333 | 338 |
334 } // namespace content | 339 } // namespace content |
OLD | NEW |