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 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
14 #include "content/browser/devtools/devtools_agent_host_impl.h" | 15 #include "content/browser/devtools/devtools_agent_host_impl.h" |
15 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" | 16 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" |
16 #include "content/browser/shared_worker/shared_worker_instance.h" | 17 #include "content/browser/shared_worker/shared_worker_instance.h" |
17 #include "content/browser/shared_worker/worker_storage_partition.h" | 18 #include "content/browser/shared_worker/worker_storage_partition.h" |
18 #include "content/public/browser/browser_context.h" | |
19 #include "content/public/browser/storage_partition.h" | |
20 #include "content/public/test/test_browser_context.h" | 19 #include "content/public/test/test_browser_context.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
23 | 21 |
24 namespace content { | 22 namespace content { |
25 namespace { | 23 namespace { |
26 | 24 |
27 class TestDevToolsClientHost : public DevToolsAgentHostClient { | 25 class TestDevToolsClientHost : public DevToolsAgentHostClient { |
28 public: | 26 public: |
29 TestDevToolsClientHost() {} | 27 TestDevToolsClientHost() {} |
30 ~TestDevToolsClientHost() override {} | 28 ~TestDevToolsClientHost() override {} |
31 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 29 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
(...skipping 11 matching lines...) Expand all Loading... |
43 scoped_refptr<DevToolsAgentHost> agent_host_; | 41 scoped_refptr<DevToolsAgentHost> agent_host_; |
44 DISALLOW_COPY_AND_ASSIGN(TestDevToolsClientHost); | 42 DISALLOW_COPY_AND_ASSIGN(TestDevToolsClientHost); |
45 }; | 43 }; |
46 } // namespace | 44 } // namespace |
47 | 45 |
48 class SharedWorkerDevToolsManagerTest : public testing::Test { | 46 class SharedWorkerDevToolsManagerTest : public testing::Test { |
49 public: | 47 public: |
50 typedef SharedWorkerDevToolsAgentHost::WorkerState WorkerState; | 48 typedef SharedWorkerDevToolsAgentHost::WorkerState WorkerState; |
51 | 49 |
52 SharedWorkerDevToolsManagerTest() | 50 SharedWorkerDevToolsManagerTest() |
53 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 51 : ui_thread_(BrowserThread::UI, &message_loop_), |
54 browser_context_(new TestBrowserContext()), | 52 browser_context_(new TestBrowserContext()), |
55 partition_(new WorkerStoragePartition( | 53 partition_( |
56 BrowserContext::GetDefaultStoragePartition(browser_context_.get())-> | 54 new WorkerStoragePartition(browser_context_->GetRequestContext(), |
57 GetURLRequestContext(), | 55 NULL, |
58 NULL, | 56 NULL, |
59 NULL, | 57 NULL, |
60 NULL, | 58 NULL, |
61 NULL, | 59 NULL, |
62 NULL, | 60 NULL, |
63 NULL, | 61 NULL)), |
64 NULL)), | |
65 partition_id_(*partition_.get()) {} | 62 partition_id_(*partition_.get()) {} |
66 | 63 |
67 protected: | 64 protected: |
68 void SetUp() override { | 65 void SetUp() override { |
69 manager_ = SharedWorkerDevToolsManager::GetInstance(); | 66 manager_ = SharedWorkerDevToolsManager::GetInstance(); |
70 } | 67 } |
71 void TearDown() override { | 68 void TearDown() override { |
72 SharedWorkerDevToolsManager::GetInstance()->ResetForTesting(); | 69 SharedWorkerDevToolsManager::GetInstance()->ResetForTesting(); |
73 } | 70 } |
74 | 71 |
(...skipping 11 matching lines...) Expand all Loading... |
86 void CheckWorkerNotExist(int worker_process_id, int worker_route_id) { | 83 void CheckWorkerNotExist(int worker_process_id, int worker_route_id) { |
87 const SharedWorkerDevToolsManager::WorkerId id(worker_process_id, | 84 const SharedWorkerDevToolsManager::WorkerId id(worker_process_id, |
88 worker_route_id); | 85 worker_route_id); |
89 EXPECT_TRUE(manager_->workers_.end() == manager_->workers_.find(id)); | 86 EXPECT_TRUE(manager_->workers_.end() == manager_->workers_.find(id)); |
90 } | 87 } |
91 | 88 |
92 void CheckWorkerCount(size_t size) { | 89 void CheckWorkerCount(size_t size) { |
93 EXPECT_EQ(size, manager_->workers_.size()); | 90 EXPECT_EQ(size, manager_->workers_.size()); |
94 } | 91 } |
95 | 92 |
96 TestBrowserThreadBundle browser_thread_bundle_; | 93 base::MessageLoopForIO message_loop_; |
| 94 BrowserThreadImpl ui_thread_; |
97 std::unique_ptr<TestBrowserContext> browser_context_; | 95 std::unique_ptr<TestBrowserContext> browser_context_; |
98 std::unique_ptr<WorkerStoragePartition> partition_; | 96 std::unique_ptr<WorkerStoragePartition> partition_; |
99 const WorkerStoragePartitionId partition_id_; | 97 const WorkerStoragePartitionId partition_id_; |
100 SharedWorkerDevToolsManager* manager_; | 98 SharedWorkerDevToolsManager* manager_; |
101 }; | 99 }; |
102 | 100 |
103 TEST_F(SharedWorkerDevToolsManagerTest, BasicTest) { | 101 TEST_F(SharedWorkerDevToolsManagerTest, BasicTest) { |
104 scoped_refptr<DevToolsAgentHostImpl> agent_host; | 102 scoped_refptr<DevToolsAgentHostImpl> agent_host; |
105 | 103 |
106 SharedWorkerInstance instance1( | 104 SharedWorkerInstance instance1( |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 manager_->WorkerCreated(3, 2, instance); | 292 manager_->WorkerCreated(3, 2, instance); |
295 CheckWorkerState(3, 2, WorkerState::WORKER_UNINSPECTED); | 293 CheckWorkerState(3, 2, WorkerState::WORKER_UNINSPECTED); |
296 agent_host = NULL; | 294 agent_host = NULL; |
297 CheckWorkerState(3, 2, WorkerState::WORKER_UNINSPECTED); | 295 CheckWorkerState(3, 2, WorkerState::WORKER_UNINSPECTED); |
298 manager_->WorkerDestroyed(3, 2); | 296 manager_->WorkerDestroyed(3, 2); |
299 CheckWorkerNotExist(3, 2); | 297 CheckWorkerNotExist(3, 2); |
300 CheckWorkerCount(0); | 298 CheckWorkerCount(0); |
301 } | 299 } |
302 | 300 |
303 } // namespace content | 301 } // namespace content |
OLD | NEW |