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

Side by Side Diff: chromeos/dbus/services/service_provider_test_helper.cc

Issue 2824093003: chromeos: Custom services in ServiceProviderTestHelper. (Closed)
Patch Set: forward-declare dbus::ObjectPath (not that it matters) Created 3 years, 8 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 | « chromeos/dbus/services/service_provider_test_helper.h ('k') | no next file » | 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 "chromeos/dbus/services/service_provider_test_helper.h" 5 #include "chromeos/dbus/services/service_provider_test_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "dbus/message.h" 11 #include "dbus/message.h"
12 #include "dbus/mock_bus.h" 12 #include "dbus/mock_bus.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "dbus/object_path.h"
14 14
15 using ::testing::_; 15 using ::testing::_;
16 using ::testing::AllOf; 16 using ::testing::AllOf;
17 using ::testing::Invoke; 17 using ::testing::Invoke;
18 using ::testing::ResultOf; 18 using ::testing::ResultOf;
19 using ::testing::Return; 19 using ::testing::Return;
20 using ::testing::Unused; 20 using ::testing::Unused;
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 ServiceProviderTestHelper::ServiceProviderTestHelper() 24 ServiceProviderTestHelper::ServiceProviderTestHelper()
25 : response_received_(false) { 25 : response_received_(false) {
26 if (!base::MessageLoop::current()) 26 if (!base::MessageLoop::current())
27 message_loop_.reset(new base::MessageLoop()); 27 message_loop_.reset(new base::MessageLoop());
28 } 28 }
29 29
30 ServiceProviderTestHelper::~ServiceProviderTestHelper() { 30 ServiceProviderTestHelper::~ServiceProviderTestHelper() {
31 } 31 }
32 32
33 void ServiceProviderTestHelper::SetUp( 33 void ServiceProviderTestHelper::SetUp(
34 const std::string& service_name,
35 const dbus::ObjectPath& service_path,
36 const std::string& interface_name,
34 const std::string& exported_method_name, 37 const std::string& exported_method_name,
35 CrosDBusService::ServiceProviderInterface* service_provider) { 38 CrosDBusService::ServiceProviderInterface* service_provider) {
36 // Create a mock bus. 39 // Create a mock bus.
37 dbus::Bus::Options options; 40 dbus::Bus::Options options;
38 options.bus_type = dbus::Bus::SYSTEM; 41 options.bus_type = dbus::Bus::SYSTEM;
39 mock_bus_ = new dbus::MockBus(options); 42 mock_bus_ = new dbus::MockBus(options);
40 43
41 // ShutdownAndBlock() will be called in TearDown(). 44 // ShutdownAndBlock() will be called in TearDown().
42 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); 45 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
43 46
44 // Create a mock exported object that behaves as 47 // Create a mock exported object that behaves as the service.
45 // org.chromium.CrosDBusService.
46 mock_exported_object_ = 48 mock_exported_object_ =
47 new dbus::MockExportedObject(mock_bus_.get(), 49 new dbus::MockExportedObject(mock_bus_.get(), service_path);
48 dbus::ObjectPath(kLibCrosServicePath));
49 50
50 // |mock_exported_object_|'s ExportMethod() will use 51 // |mock_exported_object_|'s ExportMethod() will use
51 // |MockExportedObject(). 52 // |MockExportedObject().
52 EXPECT_CALL( 53 EXPECT_CALL(*mock_exported_object_.get(),
53 *mock_exported_object_.get(), 54 ExportMethod(interface_name, exported_method_name, _, _))
54 ExportMethod(kLibCrosServiceInterface, exported_method_name, _, _))
55 .WillOnce(Invoke(this, &ServiceProviderTestHelper::MockExportMethod)); 55 .WillOnce(Invoke(this, &ServiceProviderTestHelper::MockExportMethod));
56 56
57 // Create a mock object proxy, with which we call a method of 57 // Create a mock object proxy, with which we call a method of
58 // |mock_exported_object_|. 58 // |mock_exported_object_|.
59 mock_object_proxy_ = 59 mock_object_proxy_ =
60 new dbus::MockObjectProxy(mock_bus_.get(), 60 new dbus::MockObjectProxy(mock_bus_.get(), service_name, service_path);
61 kLibCrosServiceName,
62 dbus::ObjectPath(kLibCrosServicePath));
63 // |mock_object_proxy_|'s MockCallMethodAndBlock() will use 61 // |mock_object_proxy_|'s MockCallMethodAndBlock() will use
64 // MockCallMethodAndBlock() to return responses. 62 // MockCallMethodAndBlock() to return responses.
65 EXPECT_CALL(*mock_object_proxy_.get(), 63 EXPECT_CALL(*mock_object_proxy_.get(),
66 MockCallMethodAndBlock( 64 MockCallMethodAndBlock(
67 AllOf(ResultOf(std::mem_fun(&dbus::MethodCall::GetInterface), 65 AllOf(ResultOf(std::mem_fun(&dbus::MethodCall::GetInterface),
68 kLibCrosServiceInterface), 66 interface_name),
69 ResultOf(std::mem_fun(&dbus::MethodCall::GetMember), 67 ResultOf(std::mem_fun(&dbus::MethodCall::GetMember),
70 exported_method_name)), 68 exported_method_name)),
71 _)) 69 _))
72 .WillOnce( 70 .WillOnce(
73 Invoke(this, &ServiceProviderTestHelper::MockCallMethodAndBlock)); 71 Invoke(this, &ServiceProviderTestHelper::MockCallMethodAndBlock));
74 72
75 service_provider->Start(mock_exported_object_.get()); 73 service_provider->Start(mock_exported_object_.get());
76 } 74 }
77 75
78 void ServiceProviderTestHelper::TearDown() { 76 void ServiceProviderTestHelper::TearDown() {
79 mock_bus_->ShutdownAndBlock(); 77 mock_bus_->ShutdownAndBlock();
80 mock_exported_object_ = NULL; 78 mock_exported_object_ = NULL;
81 mock_object_proxy_ = NULL; 79 mock_object_proxy_ = NULL;
82 mock_bus_ = NULL; 80 mock_bus_ = NULL;
83 } 81 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 156
159 void ServiceProviderTestHelper::OnResponse( 157 void ServiceProviderTestHelper::OnResponse(
160 std::unique_ptr<dbus::Response> response) { 158 std::unique_ptr<dbus::Response> response) {
161 response_ = std::move(response); 159 response_ = std::move(response);
162 response_received_ = true; 160 response_received_ = true;
163 if (base::MessageLoop::current()->is_running()) 161 if (base::MessageLoop::current()->is_running())
164 base::MessageLoop::current()->QuitWhenIdle(); 162 base::MessageLoop::current()->QuitWhenIdle();
165 } 163 }
166 164
167 } // namespace chromeos 165 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/services/service_provider_test_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698