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

Side by Side Diff: mojo/message_pump/message_pump_mojo_unittest.cc

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_pump/message_pump_mojo.h" 5 #include "mojo/message_pump/message_pump_mojo.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop_test.h" 8 #include "base/message_loop/message_loop_test.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/message_pump/message_pump_mojo_handler.h" 10 #include "mojo/message_pump/message_pump_mojo_handler.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 CountingMojoHandler handler; 62 CountingMojoHandler handler;
63 MessagePipe handles; 63 MessagePipe handles;
64 MessagePumpMojo::current()->AddHandler(&handler, 64 MessagePumpMojo::current()->AddHandler(&handler,
65 handles.handle0.get(), 65 handles.handle0.get(),
66 MOJO_HANDLE_SIGNAL_READABLE, 66 MOJO_HANDLE_SIGNAL_READABLE,
67 base::TimeTicks()); 67 base::TimeTicks());
68 WriteMessageRaw( 68 WriteMessageRaw(
69 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); 69 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
70 WriteMessageRaw( 70 WriteMessageRaw(
71 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); 71 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
72 MojoHandleSignalsState hss;
73 ASSERT_EQ(MOJO_RESULT_OK,
74 MojoWait(handles.handle0.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
75 MOJO_DEADLINE_INDEFINITE, &hss));
72 base::RunLoop run_loop; 76 base::RunLoop run_loop;
73 run_loop.RunUntilIdle(); 77 run_loop.RunUntilIdle();
yzshen1 2016/01/04 18:54:25 Even when we wait till the handle is readable, it
jam 2016/01/04 21:00:06 good point. I've switched these tests to use callb
74 EXPECT_EQ(2, handler.success_count()); 78 EXPECT_EQ(2, handler.success_count());
75 } 79 }
76 80
77 TEST(MessagePumpMojo, Observer) { 81 TEST(MessagePumpMojo, Observer) {
78 base::MessageLoop message_loop(MessagePumpMojo::Create()); 82 base::MessageLoop message_loop(MessagePumpMojo::Create());
79 83
80 CountingObserver observer; 84 CountingObserver observer;
81 MessagePumpMojo::current()->AddObserver(&observer); 85 MessagePumpMojo::current()->AddObserver(&observer);
82 86
83 CountingMojoHandler handler; 87 CountingMojoHandler handler;
84 MessagePipe handles; 88 MessagePipe handles;
85 MessagePumpMojo::current()->AddHandler(&handler, 89 MessagePumpMojo::current()->AddHandler(&handler,
86 handles.handle0.get(), 90 handles.handle0.get(),
87 MOJO_HANDLE_SIGNAL_READABLE, 91 MOJO_HANDLE_SIGNAL_READABLE,
88 base::TimeTicks()); 92 base::TimeTicks());
89 WriteMessageRaw( 93 WriteMessageRaw(
90 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); 94 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
95
96 MojoHandleSignalsState hss;
97 ASSERT_EQ(MOJO_RESULT_OK,
98 MojoWait(handles.handle0.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
99 MOJO_DEADLINE_INDEFINITE, &hss));
91 base::RunLoop run_loop; 100 base::RunLoop run_loop;
92 run_loop.RunUntilIdle(); 101 run_loop.RunUntilIdle();
93 EXPECT_EQ(1, handler.success_count()); 102 EXPECT_EQ(1, handler.success_count());
94 EXPECT_EQ(1, observer.will_signal_handler_count); 103 EXPECT_EQ(1, observer.will_signal_handler_count);
95 EXPECT_EQ(1, observer.did_signal_handler_count); 104 EXPECT_EQ(1, observer.did_signal_handler_count);
96 MessagePumpMojo::current()->RemoveObserver(&observer); 105 MessagePumpMojo::current()->RemoveObserver(&observer);
97 106
98 WriteMessageRaw( 107 WriteMessageRaw(
99 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); 108 handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
109 ASSERT_EQ(MOJO_RESULT_OK,
110 MojoWait(handles.handle0.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
111 MOJO_DEADLINE_INDEFINITE, &hss));
100 base::RunLoop run_loop2; 112 base::RunLoop run_loop2;
101 run_loop2.RunUntilIdle(); 113 run_loop2.RunUntilIdle();
102 EXPECT_EQ(2, handler.success_count()); 114 EXPECT_EQ(2, handler.success_count());
103 EXPECT_EQ(1, observer.will_signal_handler_count); 115 EXPECT_EQ(1, observer.will_signal_handler_count);
104 EXPECT_EQ(1, observer.did_signal_handler_count); 116 EXPECT_EQ(1, observer.did_signal_handler_count);
105 } 117 }
106 118
107 TEST(MessagePumpMojo, UnregisterAfterDeadline) { 119 TEST(MessagePumpMojo, UnregisterAfterDeadline) {
108 base::MessageLoop message_loop(MessagePumpMojo::Create()); 120 base::MessageLoop message_loop(MessagePumpMojo::Create());
109 CountingMojoHandler handler; 121 CountingMojoHandler handler;
110 MessagePipe handles; 122 MessagePipe handles;
111 MessagePumpMojo::current()->AddHandler( 123 MessagePumpMojo::current()->AddHandler(
112 &handler, 124 &handler,
113 handles.handle0.get(), 125 handles.handle0.get(),
114 MOJO_HANDLE_SIGNAL_READABLE, 126 MOJO_HANDLE_SIGNAL_READABLE,
115 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1)); 127 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1));
116 for (int i = 0; i < 2; ++i) { 128 for (int i = 0; i < 2; ++i) {
117 base::RunLoop run_loop; 129 base::RunLoop run_loop;
118 run_loop.RunUntilIdle(); 130 run_loop.RunUntilIdle();
119 } 131 }
120 EXPECT_EQ(1, handler.error_count()); 132 EXPECT_EQ(1, handler.error_count());
121 } 133 }
122 134
123 } // namespace test 135 } // namespace test
124 } // namespace common 136 } // namespace common
125 } // namespace mojo 137 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698