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/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
20 #include "content/browser/message_port_message_filter.h" | 20 #include "content/browser/message_port_message_filter.h" |
21 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 21 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
22 #include "content/browser/shared_worker/worker_storage_partition.h" | 22 #include "content/browser/shared_worker/worker_storage_partition.h" |
23 #include "content/common/message_port_messages.h" | 23 #include "content/common/message_port_messages.h" |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/common/worker_messages.h" | 25 #include "content/common/worker_messages.h" |
26 #include "content/public/browser/storage_partition.h" | |
27 #include "content/public/test/test_browser_context.h" | 26 #include "content/public/test/test_browser_context.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
30 #include "ipc/ipc_sync_message.h" | 29 #include "ipc/ipc_sync_message.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
32 | 31 |
33 namespace content { | 32 namespace content { |
34 | 33 |
35 class SharedWorkerServiceImplTest : public testing::Test { | 34 class SharedWorkerServiceImplTest : public testing::Test { |
36 public: | 35 public: |
37 static void RegisterRunningProcessID(int process_id) { | 36 static void RegisterRunningProcessID(int process_id) { |
38 base::AutoLock lock(s_lock_); | 37 base::AutoLock lock(s_lock_); |
39 s_running_process_id_set_.insert(process_id); | 38 s_running_process_id_set_.insert(process_id); |
40 } | 39 } |
41 static void UnregisterRunningProcessID(int process_id) { | 40 static void UnregisterRunningProcessID(int process_id) { |
42 base::AutoLock lock(s_lock_); | 41 base::AutoLock lock(s_lock_); |
43 s_running_process_id_set_.erase(process_id); | 42 s_running_process_id_set_.erase(process_id); |
44 } | 43 } |
45 | 44 |
46 protected: | 45 protected: |
47 SharedWorkerServiceImplTest() | 46 SharedWorkerServiceImplTest() |
48 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 47 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
49 browser_context_(new TestBrowserContext()), | 48 browser_context_(new TestBrowserContext()), |
50 partition_(new WorkerStoragePartition( | 49 partition_( |
51 BrowserContext::GetDefaultStoragePartition(browser_context_.get())-> | 50 new WorkerStoragePartition(browser_context_->GetRequestContext(), |
52 GetURLRequestContext(), | 51 NULL, |
53 NULL, | 52 NULL, |
54 NULL, | 53 NULL, |
55 NULL, | 54 NULL, |
56 NULL, | 55 NULL, |
57 NULL, | 56 NULL, |
58 NULL, | 57 NULL)) { |
59 NULL)) { | |
60 SharedWorkerServiceImpl::GetInstance() | 58 SharedWorkerServiceImpl::GetInstance() |
61 ->ChangeUpdateWorkerDependencyFuncForTesting( | 59 ->ChangeUpdateWorkerDependencyFuncForTesting( |
62 &SharedWorkerServiceImplTest::MockUpdateWorkerDependency); | 60 &SharedWorkerServiceImplTest::MockUpdateWorkerDependency); |
63 SharedWorkerServiceImpl::GetInstance() | 61 SharedWorkerServiceImpl::GetInstance() |
64 ->ChangeTryIncrementWorkerRefCountFuncForTesting( | 62 ->ChangeTryIncrementWorkerRefCountFuncForTesting( |
65 &SharedWorkerServiceImplTest::MockTryIncrementWorkerRefCount); | 63 &SharedWorkerServiceImplTest::MockTryIncrementWorkerRefCount); |
66 } | 64 } |
67 | 65 |
68 void SetUp() override {} | 66 void SetUp() override {} |
69 void TearDown() override { | 67 void TearDown() override { |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 kDocumentIDs[2], | 916 kDocumentIDs[2], |
919 kRenderFrameRouteIDs[2]); | 917 kRenderFrameRouteIDs[2]); |
920 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); | 918 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); |
921 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); | 919 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); |
922 RunAllPendingInMessageLoop(); | 920 RunAllPendingInMessageLoop(); |
923 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); | 921 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); |
924 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); | 922 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); |
925 } | 923 } |
926 | 924 |
927 } // namespace content | 925 } // namespace content |
OLD | NEW |