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 "mojo/edk/system/wait_set_dispatcher.h" | 5 #include "mojo/edk/system/wait_set_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "mojo/edk/embedder/embedder_internal.h" | 14 #include "mojo/edk/embedder/embedder_internal.h" |
15 #include "mojo/edk/system/core.h" | 15 #include "mojo/edk/system/core.h" |
16 #include "mojo/edk/system/message_pipe_dispatcher.h" | 16 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 17 #include "mojo/edk/system/request_context.h" |
17 #include "mojo/edk/system/test_utils.h" | 18 #include "mojo/edk/system/test_utils.h" |
18 #include "mojo/edk/system/waiter.h" | 19 #include "mojo/edk/system/waiter.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 namespace edk { | 23 namespace edk { |
23 namespace { | 24 namespace { |
24 | 25 |
25 class WaitSetDispatcherTest : public ::testing::Test { | 26 class WaitSetDispatcherTest : public ::testing::Test { |
26 public: | 27 public: |
27 WaitSetDispatcherTest() {} | 28 WaitSetDispatcherTest() |
| 29 : request_context_(RequestContext::Source::LOCAL_API_CALL) {} |
28 ~WaitSetDispatcherTest() override {} | 30 ~WaitSetDispatcherTest() override {} |
29 | 31 |
30 void SetUp() override { | 32 void SetUp() override { |
31 CreateMessagePipe(&dispatcher0_, &dispatcher1_); | 33 CreateMessagePipe(&dispatcher0_, &dispatcher1_); |
32 } | 34 } |
33 | 35 |
34 void TearDown() override { | 36 void TearDown() override { |
35 for (auto& d : dispatchers_to_close_) | 37 for (auto& d : dispatchers_to_close_) |
36 d->Close(); | 38 d->Close(); |
37 } | 39 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 73 |
72 void CloseOnShutdown(const scoped_refptr<Dispatcher>& dispatcher) { | 74 void CloseOnShutdown(const scoped_refptr<Dispatcher>& dispatcher) { |
73 dispatchers_to_close_.push_back(dispatcher); | 75 dispatchers_to_close_.push_back(dispatcher); |
74 } | 76 } |
75 | 77 |
76 protected: | 78 protected: |
77 scoped_refptr<MessagePipeDispatcher> dispatcher0_; | 79 scoped_refptr<MessagePipeDispatcher> dispatcher0_; |
78 scoped_refptr<MessagePipeDispatcher> dispatcher1_; | 80 scoped_refptr<MessagePipeDispatcher> dispatcher1_; |
79 | 81 |
80 private: | 82 private: |
| 83 // We keep an active RequestContext for the duration of each test. It's unused |
| 84 // since these tests don't rely on the MojoWatch API. |
| 85 const RequestContext request_context_; |
| 86 |
81 static uint64_t pipe_id_generator_; | 87 static uint64_t pipe_id_generator_; |
82 DispatcherVector dispatchers_to_close_; | 88 DispatcherVector dispatchers_to_close_; |
83 | 89 |
84 DISALLOW_COPY_AND_ASSIGN(WaitSetDispatcherTest); | 90 DISALLOW_COPY_AND_ASSIGN(WaitSetDispatcherTest); |
85 }; | 91 }; |
86 | 92 |
87 // static | 93 // static |
88 uint64_t WaitSetDispatcherTest::pipe_id_generator_ = 1; | 94 uint64_t WaitSetDispatcherTest::pipe_id_generator_ = 1; |
89 | 95 |
90 TEST_F(WaitSetDispatcherTest, Basic) { | 96 TEST_F(WaitSetDispatcherTest, Basic) { |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 EXPECT_EQ(MOJO_RESULT_OK, | 463 EXPECT_EQ(MOJO_RESULT_OK, |
458 GetOneReadyDispatcher(wait_set, &woken_dispatcher, nullptr)); | 464 GetOneReadyDispatcher(wait_set, &woken_dispatcher, nullptr)); |
459 EXPECT_EQ(nested_wait_set, woken_dispatcher); | 465 EXPECT_EQ(nested_wait_set, woken_dispatcher); |
460 | 466 |
461 wait_set->RemoveAwakable(&w, nullptr); | 467 wait_set->RemoveAwakable(&w, nullptr); |
462 } | 468 } |
463 | 469 |
464 } // namespace | 470 } // namespace |
465 } // namespace edk | 471 } // namespace edk |
466 } // namespace mojo | 472 } // namespace mojo |
OLD | NEW |