| 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 <string> | 12 #include <string> |
| 13 #include <tuple> | 13 #include <tuple> |
| 14 | 14 |
| 15 #include "base/atomic_sequence_num.h" | 15 #include "base/atomic_sequence_num.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/run_loop.h" | |
| 19 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 22 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 23 #include "content/browser/shared_worker/worker_storage_partition.h" | 23 #include "content/browser/shared_worker/worker_storage_partition.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" | 26 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/test/test_browser_context.h" | 27 #include "content/public/test/test_browser_context.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
| 30 #include "ipc/ipc_sync_message.h" | 30 #include "ipc/ipc_sync_message.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 base::Lock SharedWorkerServiceImplTest::s_lock_; | 105 base::Lock SharedWorkerServiceImplTest::s_lock_; |
| 106 std::set<int> SharedWorkerServiceImplTest::s_running_process_id_set_; | 106 std::set<int> SharedWorkerServiceImplTest::s_running_process_id_set_; |
| 107 | 107 |
| 108 namespace { | 108 namespace { |
| 109 | 109 |
| 110 static const int kProcessIDs[] = {100, 101, 102}; | 110 static const int kProcessIDs[] = {100, 101, 102}; |
| 111 static const unsigned long long kDocumentIDs[] = {200, 201, 202}; | 111 static const unsigned long long kDocumentIDs[] = {200, 201, 202}; |
| 112 static const int kRenderFrameRouteIDs[] = {300, 301, 302}; | 112 static const int kRenderFrameRouteIDs[] = {300, 301, 302}; |
| 113 | 113 |
| 114 void BlockingReadFromMessagePort(MessagePort port, base::string16* message) { | 114 void BlockingReadFromMessagePort(MessagePort port, base::string16* message) { |
| 115 base::RunLoop run_loop; | 115 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 116 port.SetCallback(run_loop.QuitClosure()); | 116 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 117 run_loop.Run(); | 117 port.SetCallback( |
| 118 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 119 event.Wait(); |
| 118 | 120 |
| 119 std::vector<MessagePort> should_be_empty; | 121 std::vector<MessagePort> should_be_empty; |
| 120 EXPECT_TRUE(port.GetMessage(message, &should_be_empty)); | 122 EXPECT_TRUE(port.GetMessage(message, &should_be_empty)); |
| 121 EXPECT_TRUE(should_be_empty.empty()); | 123 EXPECT_TRUE(should_be_empty.empty()); |
| 122 } | 124 } |
| 123 | 125 |
| 124 class MockSharedWorkerMessageFilter : public SharedWorkerMessageFilter { | 126 class MockSharedWorkerMessageFilter : public SharedWorkerMessageFilter { |
| 125 public: | 127 public: |
| 126 MockSharedWorkerMessageFilter( | 128 MockSharedWorkerMessageFilter( |
| 127 int render_process_id, | 129 int render_process_id, |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 kDocumentIDs[2], | 894 kDocumentIDs[2], |
| 893 kRenderFrameRouteIDs[2]); | 895 kRenderFrameRouteIDs[2]); |
| 894 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); | 896 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); |
| 895 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); | 897 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); |
| 896 RunAllPendingInMessageLoop(); | 898 RunAllPendingInMessageLoop(); |
| 897 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); | 899 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); |
| 898 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); | 900 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); |
| 899 } | 901 } |
| 900 | 902 |
| 901 } // namespace content | 903 } // namespace content |
| OLD | NEW |