Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: mojo/public/cpp/environment/tests/async_wait_unittest.cc

Issue 703273002: Update mojo sdk to rev 04a510fb37db10642e156957f9b2c11c2f6442ac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content/child -> mojo/common linking Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "mojo/public/c/environment/async_waiter.h" 7 #include "mojo/public/c/environment/async_waiter.h"
8 #include "mojo/public/cpp/environment/environment.h" 8 #include "mojo/public/cpp/environment/environment.h"
9 #include "mojo/public/cpp/system/core.h" 9 #include "mojo/public/cpp/system/core.h"
10 #include "mojo/public/cpp/system/macros.h" 10 #include "mojo/public/cpp/system/macros.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 signals, 46 signals,
47 MOJO_DEADLINE_INDEFINITE, 47 MOJO_DEADLINE_INDEFINITE,
48 &TestAsyncWaitCallback::OnHandleReady, 48 &TestAsyncWaitCallback::OnHandleReady,
49 callback); 49 callback);
50 } 50 }
51 51
52 void CallCancelWait(MojoAsyncWaitID wait_id) { 52 void CallCancelWait(MojoAsyncWaitID wait_id) {
53 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id); 53 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id);
54 } 54 }
55 55
56 class AsyncWaiterTest : public testing::Test { 56 class AsyncWaitTest : public testing::Test {
57 public: 57 public:
58 AsyncWaiterTest() {} 58 AsyncWaitTest() {}
59 59
60 private: 60 private:
61 Environment environment_; 61 Environment environment_;
62 RunLoop run_loop_; 62 RunLoop run_loop_;
63 63
64 MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaiterTest); 64 MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaitTest);
65 }; 65 };
66 66
67 // Verifies AsyncWaitCallback is notified when pipe is ready. 67 // Verifies AsyncWaitCallback is notified when pipe is ready.
68 TEST_F(AsyncWaiterTest, CallbackNotified) { 68 TEST_F(AsyncWaitTest, CallbackNotified) {
69 TestAsyncWaitCallback callback; 69 TestAsyncWaitCallback callback;
70 MessagePipe test_pipe; 70 MessagePipe test_pipe;
71 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); 71 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
72 72
73 CallAsyncWait( 73 CallAsyncWait(
74 test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback); 74 test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback);
75 RunLoop::current()->Run(); 75 RunLoop::current()->Run();
76 EXPECT_EQ(1, callback.result_count()); 76 EXPECT_EQ(1, callback.result_count());
77 EXPECT_EQ(MOJO_RESULT_OK, callback.last_result()); 77 EXPECT_EQ(MOJO_RESULT_OK, callback.last_result());
78 } 78 }
79 79
80 // Verifies 2 AsyncWaitCallbacks are notified when there pipes are ready. 80 // Verifies 2 AsyncWaitCallbacks are notified when there pipes are ready.
81 TEST_F(AsyncWaiterTest, TwoCallbacksNotified) { 81 TEST_F(AsyncWaitTest, TwoCallbacksNotified) {
82 TestAsyncWaitCallback callback1; 82 TestAsyncWaitCallback callback1;
83 TestAsyncWaitCallback callback2; 83 TestAsyncWaitCallback callback2;
84 MessagePipe test_pipe1; 84 MessagePipe test_pipe1;
85 MessagePipe test_pipe2; 85 MessagePipe test_pipe2;
86 EXPECT_TRUE(test::WriteTextMessage(test_pipe1.handle1.get(), std::string())); 86 EXPECT_TRUE(test::WriteTextMessage(test_pipe1.handle1.get(), std::string()));
87 EXPECT_TRUE(test::WriteTextMessage(test_pipe2.handle1.get(), std::string())); 87 EXPECT_TRUE(test::WriteTextMessage(test_pipe2.handle1.get(), std::string()));
88 88
89 CallAsyncWait( 89 CallAsyncWait(
90 test_pipe1.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback1); 90 test_pipe1.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback1);
91 CallAsyncWait( 91 CallAsyncWait(
92 test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback2); 92 test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback2);
93 93
94 RunLoop::current()->Run(); 94 RunLoop::current()->Run();
95 EXPECT_EQ(1, callback1.result_count()); 95 EXPECT_EQ(1, callback1.result_count());
96 EXPECT_EQ(MOJO_RESULT_OK, callback1.last_result()); 96 EXPECT_EQ(MOJO_RESULT_OK, callback1.last_result());
97 EXPECT_EQ(1, callback2.result_count()); 97 EXPECT_EQ(1, callback2.result_count());
98 EXPECT_EQ(MOJO_RESULT_OK, callback2.last_result()); 98 EXPECT_EQ(MOJO_RESULT_OK, callback2.last_result());
99 } 99 }
100 100
101 // Verifies cancel works. 101 // Verifies cancel works.
102 TEST_F(AsyncWaiterTest, CancelCallback) { 102 TEST_F(AsyncWaitTest, CancelCallback) {
103 TestAsyncWaitCallback callback; 103 TestAsyncWaitCallback callback;
104 MessagePipe test_pipe; 104 MessagePipe test_pipe;
105 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); 105 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
106 106
107 CallCancelWait(CallAsyncWait( 107 CallCancelWait(CallAsyncWait(
108 test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback)); 108 test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback));
109 RunLoop::current()->Run(); 109 RunLoop::current()->Run();
110 EXPECT_EQ(0, callback.result_count()); 110 EXPECT_EQ(0, callback.result_count());
111 } 111 }
112 112
113 } // namespace 113 } // namespace
114 } // namespace mojo 114 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/environment/tests/BUILD.gn ('k') | mojo/public/cpp/environment/tests/async_waiter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698