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

Unified Diff: chromeos/dbus/services/cros_dbus_service_unittest.cc

Issue 2693243002: chromeos: Make CrosDBusService not be a singleton. (Closed)
Patch Set: whoops, fix reversed logic in IsUsingFakes check Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/services/cros_dbus_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/services/cros_dbus_service_unittest.cc
diff --git a/chromeos/dbus/services/cros_dbus_service_unittest.cc b/chromeos/dbus/services/cros_dbus_service_unittest.cc
index a2baabc02a70a97cae93ac19d332094a6076b229..bd0470c7c95893832eef068af25105317c3bd9bb 100644
--- a/chromeos/dbus/services/cros_dbus_service_unittest.cc
+++ b/chromeos/dbus/services/cros_dbus_service_unittest.cc
@@ -4,6 +4,7 @@
#include "chromeos/dbus/services/cros_dbus_service.h"
+#include <memory>
#include <utility>
#include "base/bind.h"
@@ -19,6 +20,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
+using ::testing::_;
using ::testing::Eq;
using ::testing::Invoke;
using ::testing::Return;
@@ -34,8 +36,7 @@ class MockProxyResolutionService
class CrosDBusServiceTest : public testing::Test {
public:
- CrosDBusServiceTest() {
- }
+ CrosDBusServiceTest() = default;
// Creates an instance of CrosDBusService with mocks injected.
void SetUp() override {
@@ -47,16 +48,22 @@ class CrosDBusServiceTest : public testing::Test {
// ShutdownAndBlock() will be called in TearDown().
EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
- // Create a mock exported object that behaves as
- // org.chromium.CrosDBusService.
+ // CrosDBusService should take ownership of the service name passed to it.
+ const char kServiceName[] = "org.example.TestService";
+ EXPECT_CALL(
+ *mock_bus_.get(),
+ RequestOwnership(kServiceName,
+ dbus::Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT, _))
+ .Times(1);
+
+ // Create a mock exported object.
+ const dbus::ObjectPath kObjectPath("/org/example/TestService");
mock_exported_object_ =
- new dbus::MockExportedObject(mock_bus_.get(),
- dbus::ObjectPath(kLibCrosServicePath));
+ new dbus::MockExportedObject(mock_bus_.get(), kObjectPath);
// |mock_bus_|'s GetExportedObject() will return mock_exported_object_|
// for the given service name and the object path.
- EXPECT_CALL(*mock_bus_.get(),
- GetExportedObject(dbus::ObjectPath(kLibCrosServicePath)))
+ EXPECT_CALL(*mock_bus_.get(), GetExportedObject(kObjectPath))
.WillOnce(Return(mock_exported_object_.get()));
// Create a mock proxy resolution service.
@@ -66,25 +73,25 @@ class CrosDBusServiceTest : public testing::Test {
// Start() will be called with |mock_exported_object_|.
EXPECT_CALL(*mock_proxy_resolution_service_provider,
Start(Eq(mock_exported_object_))).WillOnce(Return());
+
// Initialize the cros service with the mocks injected.
CrosDBusService::ServiceProviderList service_providers;
service_providers.push_back(
std::move(mock_proxy_resolution_service_provider));
- CrosDBusService::InitializeForTesting(mock_bus_.get(),
- std::move(service_providers));
+ cros_dbus_service_ = CrosDBusService::CreateRealImpl(
+ mock_bus_.get(), kServiceName, kObjectPath,
+ std::move(service_providers));
}
void TearDown() override {
- // Shutdown the cros service.
- CrosDBusService::Shutdown();
-
- // Shutdown the bus.
+ cros_dbus_service_.reset();
mock_bus_->ShutdownAndBlock();
}
protected:
scoped_refptr<dbus::MockBus> mock_bus_;
scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
+ std::unique_ptr<CrosDBusService> cros_dbus_service_;
};
TEST_F(CrosDBusServiceTest, Start) {
« no previous file with comments | « chromeos/dbus/services/cros_dbus_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698