Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / dbus / services / cros_dbus_service_unittest.cc
blob1a0a25f28e0ade0e4d7d24fea1767966f6f89606
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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/services/cros_dbus_service.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h"
10 #include "dbus/message.h"
11 #include "dbus/mock_bus.h"
12 #include "dbus/mock_exported_object.h"
13 #include "dbus/mock_object_proxy.h"
14 #include "dbus/object_path.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
19 using ::testing::Eq;
20 using ::testing::Invoke;
21 using ::testing::Return;
23 namespace chromeos {
25 class MockProxyResolutionService
26 : public CrosDBusService::ServiceProviderInterface {
27 public:
28 MOCK_METHOD1(Start, void(scoped_refptr<dbus::ExportedObject>
29 exported_object));
32 class CrosDBusServiceTest : public testing::Test {
33 public:
34 CrosDBusServiceTest() {
37 // Creates an instance of CrosDBusService with mocks injected.
38 void SetUp() override {
39 // Create a mock bus.
40 dbus::Bus::Options options;
41 options.bus_type = dbus::Bus::SYSTEM;
42 mock_bus_ = new dbus::MockBus(options);
44 // ShutdownAndBlock() will be called in TearDown().
45 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
47 // Create a mock exported object that behaves as
48 // org.chromium.CrosDBusService.
49 mock_exported_object_ =
50 new dbus::MockExportedObject(mock_bus_.get(),
51 dbus::ObjectPath(kLibCrosServicePath));
53 // |mock_bus_|'s GetExportedObject() will return mock_exported_object_|
54 // for the given service name and the object path.
55 EXPECT_CALL(*mock_bus_.get(),
56 GetExportedObject(dbus::ObjectPath(kLibCrosServicePath)))
57 .WillOnce(Return(mock_exported_object_.get()));
59 // Create a mock proxy resolution service.
60 MockProxyResolutionService* mock_proxy_resolution_service_provider =
61 new MockProxyResolutionService;
63 // Start() will be called with |mock_exported_object_|.
64 EXPECT_CALL(*mock_proxy_resolution_service_provider,
65 Start(Eq(mock_exported_object_))).WillOnce(Return());
66 // Initialize the cros service with the mocks injected.
67 ScopedVector<CrosDBusService::ServiceProviderInterface> service_providers;
68 service_providers.push_back(mock_proxy_resolution_service_provider);
69 CrosDBusService::InitializeForTesting(
70 mock_bus_.get(), service_providers.Pass());
73 void TearDown() override {
74 // Shutdown the cros service.
75 CrosDBusService::Shutdown();
77 // Shutdown the bus.
78 mock_bus_->ShutdownAndBlock();
81 protected:
82 scoped_refptr<dbus::MockBus> mock_bus_;
83 scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
86 TEST_F(CrosDBusServiceTest, Start) {
87 // Simply start the service and see if mock expectations are met:
88 // - The service object is exported by GetExportedObject()
89 // - The proxy resolution service is started.
92 } // namespace chromeos