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

Side by Side Diff: dbus/end_to_end_async_unittest.cc

Issue 9508005: dbus: verify object path of incoming signals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adjust unit test to test the new behavior, reather than removing Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ASSERT_TRUE(success); 153 ASSERT_TRUE(success);
154 message_loop_.Quit(); 154 message_loop_.Quit();
155 } 155 }
156 156
157 // Wait for the hey signal to be received. 157 // Wait for the hey signal to be received.
158 void WaitForTestSignal() { 158 void WaitForTestSignal() {
159 // OnTestSignal() will quit the message loop. 159 // OnTestSignal() will quit the message loop.
160 message_loop_.Run(); 160 message_loop_.Run();
161 } 161 }
162 162
163 // Wait for the hey signal to be received, or a timeout.
164 void WaitForTestSignalOrTimeout(int timeout_ms) {
165 // OnTestSignal() will quit the message loop, we don't expect that
166 // to be called, so post a delayed task to quit the message loop
167 // for when it isn't.
168 message_loop_.PostDelayedTask(FROM_HERE,
169 MessageLoop::QuitClosure(),
170 timeout_ms);
171 message_loop_.Run();
172 }
173
163 MessageLoop message_loop_; 174 MessageLoop message_loop_;
164 std::vector<std::string> response_strings_; 175 std::vector<std::string> response_strings_;
165 scoped_ptr<base::Thread> dbus_thread_; 176 scoped_ptr<base::Thread> dbus_thread_;
166 scoped_refptr<dbus::Bus> bus_; 177 scoped_refptr<dbus::Bus> bus_;
167 dbus::ObjectProxy* object_proxy_; 178 dbus::ObjectProxy* object_proxy_;
168 scoped_ptr<dbus::TestService> test_service_; 179 scoped_ptr<dbus::TestService> test_service_;
169 // Text message from "Test" signal. 180 // Text message from "Test" signal.
170 std::string test_signal_string_; 181 std::string test_signal_string_;
171 }; 182 };
172 183
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Send the test signal from the exported object. 306 // Send the test signal from the exported object.
296 test_service_->SendTestSignal(kMessage); 307 test_service_->SendTestSignal(kMessage);
297 // Receive the signal with the object proxy. The signal is handled in 308 // Receive the signal with the object proxy. The signal is handled in
298 // EndToEndAsyncTest::OnTestSignal() in the main thread. 309 // EndToEndAsyncTest::OnTestSignal() in the main thread.
299 WaitForTestSignal(); 310 WaitForTestSignal();
300 ASSERT_EQ(kMessage, test_signal_string_); 311 ASSERT_EQ(kMessage, test_signal_string_);
301 } 312 }
302 313
303 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) { 314 TEST_F(EndToEndAsyncTest, TestSignalFromRoot) {
304 const char kMessage[] = "hello, world"; 315 const char kMessage[] = "hello, world";
305 // Send the test signal from the root object path, to see if we can 316 // Object proxies are tied to a particular object path, if a signal
306 // handle signals sent from "/", like dbus-send does. 317 // arrives from a different object path like "/" the proxy should not
318 // handle it, and should leave it for another.
307 test_service_->SendTestSignalFromRoot(kMessage); 319 test_service_->SendTestSignalFromRoot(kMessage);
308 // Receive the signal with the object proxy. The signal is handled in 320 // Timeout while waiting to receive the signal, failing if we received it.
309 // EndToEndAsyncTest::OnTestSignal() in the main thread. 321 const int timeout_ms = 5000;
310 WaitForTestSignal(); 322 WaitForTestSignalOrTimeout(timeout_ms);
satorux1 2012/03/01 00:14:32 Does this mean the test takes 5 seconds to perform
keybuk 2012/03/01 00:15:22 yes. action_timeout_ms is 10s, which is even long
satorux1 2012/03/01 00:23:46 I see. Then let's remove this test. A better way
311 ASSERT_EQ(kMessage, test_signal_string_); 323 // Verify the signal was not received
324 ASSERT_TRUE(test_signal_string_.empty());
312 } 325 }
OLDNEW
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698