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

Side by Side Diff: dbus/end_to_end_async_unittest.cc

Issue 1559873005: dbus: Use randomly generated string as a TestService's service name (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
« no previous file with comments | « no previous file | dbus/end_to_end_sync_unittest.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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); 56 ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted());
57 ASSERT_TRUE(test_service_->HasDBusThread()); 57 ASSERT_TRUE(test_service_->HasDBusThread());
58 58
59 // Create the client, using the D-Bus thread. 59 // Create the client, using the D-Bus thread.
60 Bus::Options bus_options; 60 Bus::Options bus_options;
61 bus_options.bus_type = Bus::SESSION; 61 bus_options.bus_type = Bus::SESSION;
62 bus_options.connection_type = Bus::PRIVATE; 62 bus_options.connection_type = Bus::PRIVATE;
63 bus_options.dbus_task_runner = dbus_thread_->task_runner(); 63 bus_options.dbus_task_runner = dbus_thread_->task_runner();
64 bus_ = new Bus(bus_options); 64 bus_ = new Bus(bus_options);
65 object_proxy_ = bus_->GetObjectProxy( 65 object_proxy_ = bus_->GetObjectProxy(
66 "org.chromium.TestService", 66 test_service_->service_name(),
67 ObjectPath("/org/chromium/TestObject")); 67 ObjectPath("/org/chromium/TestObject"));
68 ASSERT_TRUE(bus_->HasDBusThread()); 68 ASSERT_TRUE(bus_->HasDBusThread());
69 69
70 // Connect to the "Test" signal of "org.chromium.TestInterface" from 70 // Connect to the "Test" signal of "org.chromium.TestInterface" from
71 // the remote object. 71 // the remote object.
72 object_proxy_->ConnectToSignal( 72 object_proxy_->ConnectToSignal(
73 "org.chromium.TestInterface", 73 "org.chromium.TestInterface",
74 "Test", 74 "Test",
75 base::Bind(&EndToEndAsyncTest::OnTestSignal, 75 base::Bind(&EndToEndAsyncTest::OnTestSignal,
76 base::Unretained(this)), 76 base::Unretained(this)),
(...skipping 13 matching lines...) Expand all
90 "Test2", 90 "Test2",
91 base::Bind(&EndToEndAsyncTest::OnTest2Signal, 91 base::Bind(&EndToEndAsyncTest::OnTest2Signal,
92 base::Unretained(this)), 92 base::Unretained(this)),
93 base::Bind(&EndToEndAsyncTest::OnConnected, 93 base::Bind(&EndToEndAsyncTest::OnConnected,
94 base::Unretained(this))); 94 base::Unretained(this)));
95 // Wait until the object proxy is connected to the signal. 95 // Wait until the object proxy is connected to the signal.
96 run_loop_.reset(new base::RunLoop()); 96 run_loop_.reset(new base::RunLoop());
97 run_loop_->Run(); 97 run_loop_->Run();
98 98
99 // Create a second object proxy for the root object. 99 // Create a second object proxy for the root object.
100 root_object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", 100 root_object_proxy_ = bus_->GetObjectProxy(test_service_->service_name(),
101 ObjectPath("/")); 101 ObjectPath("/"));
102 ASSERT_TRUE(bus_->HasDBusThread()); 102 ASSERT_TRUE(bus_->HasDBusThread());
103 103
104 // Connect to the "Test" signal of "org.chromium.TestInterface" from 104 // Connect to the "Test" signal of "org.chromium.TestInterface" from
105 // the root remote object too. 105 // the root remote object too.
106 root_object_proxy_->ConnectToSignal( 106 root_object_proxy_->ConnectToSignal(
107 "org.chromium.TestInterface", 107 "org.chromium.TestInterface",
108 "Test", 108 "Test",
109 base::Bind(&EndToEndAsyncTest::OnRootTestSignal, 109 base::Bind(&EndToEndAsyncTest::OnRootTestSignal,
110 base::Unretained(this)), 110 base::Unretained(this)),
(...skipping 29 matching lines...) Expand all
140 Bus::Options bus_options; 140 Bus::Options bus_options;
141 bus_options.bus_type = Bus::CUSTOM_ADDRESS; 141 bus_options.bus_type = Bus::CUSTOM_ADDRESS;
142 bus_options.address = kInvalidAddress; 142 bus_options.address = kInvalidAddress;
143 bus_options.connection_type = Bus::PRIVATE; 143 bus_options.connection_type = Bus::PRIVATE;
144 bus_options.dbus_task_runner = dbus_thread_->task_runner(); 144 bus_options.dbus_task_runner = dbus_thread_->task_runner();
145 bus_ = new Bus(bus_options); 145 bus_ = new Bus(bus_options);
146 ASSERT_TRUE(bus_->HasDBusThread()); 146 ASSERT_TRUE(bus_->HasDBusThread());
147 147
148 // Create new object proxy. 148 // Create new object proxy.
149 object_proxy_ = bus_->GetObjectProxy( 149 object_proxy_ = bus_->GetObjectProxy(
150 "org.chromium.TestService", 150 test_service_->service_name(),
151 ObjectPath("/org/chromium/TestObject")); 151 ObjectPath("/org/chromium/TestObject"));
152 } 152 }
153 153
154 // Calls the method asynchronously. OnResponse() will be called once the 154 // Calls the method asynchronously. OnResponse() will be called once the
155 // response is received. 155 // response is received.
156 void CallMethod(MethodCall* method_call, 156 void CallMethod(MethodCall* method_call,
157 int timeout_ms) { 157 int timeout_ms) {
158 object_proxy_->CallMethod(method_call, 158 object_proxy_->CallMethod(method_call,
159 timeout_ms, 159 timeout_ms,
160 base::Bind(&EndToEndAsyncTest::OnResponse, 160 base::Bind(&EndToEndAsyncTest::OnResponse,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 MethodCall method_call("org.chromium.TestInterface", "Echo"); 428 MethodCall method_call("org.chromium.TestInterface", "Echo");
429 MessageWriter writer(&method_call); 429 MessageWriter writer(&method_call);
430 writer.AppendString(kHello); 430 writer.AppendString(kHello);
431 431
432 // Call the method. 432 // Call the method.
433 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; 433 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
434 CallMethod(&method_call, timeout_ms); 434 CallMethod(&method_call, timeout_ms);
435 435
436 // Remove the object proxy before receiving the result. 436 // Remove the object proxy before receiving the result.
437 // This results in cancelling the pending method call. 437 // This results in cancelling the pending method call.
438 bus_->RemoveObjectProxy("org.chromium.TestService", 438 bus_->RemoveObjectProxy(test_service_->service_name(),
439 ObjectPath("/org/chromium/TestObject"), 439 ObjectPath("/org/chromium/TestObject"),
440 base::Bind(&base::DoNothing)); 440 base::Bind(&base::DoNothing));
441 441
442 // We shouldn't receive any responses. Wait for a while just to make sure. 442 // We shouldn't receive any responses. Wait for a while just to make sure.
443 run_loop_.reset(new base::RunLoop); 443 run_loop_.reset(new base::RunLoop);
444 message_loop_.PostDelayedTask(FROM_HERE, 444 message_loop_.PostDelayedTask(FROM_HERE,
445 run_loop_->QuitClosure(), 445 run_loop_->QuitClosure(),
446 TestTimeouts::tiny_timeout()); 446 TestTimeouts::tiny_timeout());
447 run_loop_->Run(); 447 run_loop_->Run();
448 EXPECT_TRUE(response_strings_.empty()); 448 EXPECT_TRUE(response_strings_.empty());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // Should fail because the method is broken. 510 // Should fail because the method is broken.
511 ASSERT_TRUE(response_strings_.empty()); 511 ASSERT_TRUE(response_strings_.empty());
512 ASSERT_EQ(DBUS_ERROR_FAILED, error_names_[0]); 512 ASSERT_EQ(DBUS_ERROR_FAILED, error_names_[0]);
513 } 513 }
514 514
515 TEST_F(EndToEndAsyncTest, InvalidObjectPath) { 515 TEST_F(EndToEndAsyncTest, InvalidObjectPath) {
516 // Trailing '/' is only allowed for the root path. 516 // Trailing '/' is only allowed for the root path.
517 const ObjectPath invalid_object_path("/org/chromium/TestObject/"); 517 const ObjectPath invalid_object_path("/org/chromium/TestObject/");
518 518
519 // Replace object proxy with new one. 519 // Replace object proxy with new one.
520 object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", 520 object_proxy_ = bus_->GetObjectProxy(test_service_->service_name(),
521 invalid_object_path); 521 invalid_object_path);
522 522
523 MethodCall method_call("org.chromium.TestInterface", "Echo"); 523 MethodCall method_call("org.chromium.TestInterface", "Echo");
524 524
525 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; 525 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
526 CallMethodWithErrorCallback(&method_call, timeout_ms); 526 CallMethodWithErrorCallback(&method_call, timeout_ms);
527 WaitForErrors(1); 527 WaitForErrors(1);
528 528
529 // Should fail because of the invalid path. 529 // Should fail because of the invalid path.
530 ASSERT_TRUE(response_strings_.empty()); 530 ASSERT_TRUE(response_strings_.empty());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 test_service_->SendTestSignal(kMessage); 658 test_service_->SendTestSignal(kMessage);
659 // Receive the signal with the object proxy. 659 // Receive the signal with the object proxy.
660 WaitForTestSignal(); 660 WaitForTestSignal();
661 // Verify the string WAS received by the original handler. 661 // Verify the string WAS received by the original handler.
662 ASSERT_EQ(kMessage, test_signal_string_); 662 ASSERT_EQ(kMessage, test_signal_string_);
663 // Verify the signal WAS ALSO received by the additional handler. 663 // Verify the signal WAS ALSO received by the additional handler.
664 ASSERT_EQ(kMessage, additional_test_signal_string_); 664 ASSERT_EQ(kMessage, additional_test_signal_string_);
665 } 665 }
666 666
667 } // namespace dbus 667 } // namespace dbus
OLDNEW
« no previous file with comments | « no previous file | dbus/end_to_end_sync_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698