11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/bind.h"
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/message_loop/message_loop.h"
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_adapter_client.h"
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_client_helpers.h"
90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_device_client.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_manager_client.h"
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chromeos/dbus/nfc_record_client.h"
120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_tag_client.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/mock_bus.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/mock_object_proxy.h"
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h"
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using ::testing::_;
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using ::testing::Invoke;
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using ::testing::Mock;
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using ::testing::Return;
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using chromeos::nfc_client_helpers::ObjectPathVector;
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace chromeos {
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace {
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// D-Bus service name used by the test.
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char kTestServiceName[] = "test.service.name";
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Object paths that are used for testing.
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char kTestManagerPath[] = "/test/nfc/manager";
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char kTestAdapterPath0[] = "/test/nfc/adapter0";
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char kTestAdapterPath1[] = "/test/nfc/adapter1";
370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)const char kTestDevicePath0[] = "/test/nfc/device0";
380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)const char kTestDevicePath1[] = "/test/nfc/device1";
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kTestRecordPath0[] = "/test/nfc/record0";
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kTestRecordPath1[] = "/test/nfc/record1";
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kTestRecordPath2[] = "/test/nfc/record2";
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kTestRecordPath3[] = "/test/nfc/record3";
430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)const char kTestTagPath0[] = "/test/nfc/tag0";
440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)const char kTestTagPath1[] = "/test/nfc/tag1";
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class MockNfcManagerObserver : public NfcManagerClient::Observer {
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD1(AdapterAdded, void(const dbus::ObjectPath&));
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD1(AdapterRemoved, void(const dbus::ObjectPath&));
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD1(ManagerPropertyChanged, void(const std::string&));
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class MockNfcAdapterObserver : public NfcAdapterClient::Observer {
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD1(AdapterAdded, void(const dbus::ObjectPath&));
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD1(AdapterRemoved, void(const dbus::ObjectPath&));
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD2(AdapterPropertyChanged, void(const dbus::ObjectPath&,
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                            const std::string&));
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class MockNfcDeviceObserver : public NfcDeviceClient::Observer {
620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public:
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(DeviceAdded, void(const dbus::ObjectPath&));
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(DeviceRemoved, void(const dbus::ObjectPath&));
650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  MOCK_METHOD2(DevicePropertyChanged, void(const dbus::ObjectPath&,
660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                           const std::string&));
670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)};
680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class MockNfcRecordObserver : public NfcRecordClient::Observer {
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(RecordAdded, void(const dbus::ObjectPath&));
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(RecordRemoved, void(const dbus::ObjectPath&));
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD2(RecordPropertyChanged, void(const dbus::ObjectPath&,
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                           const std::string&));
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  MOCK_METHOD1(RecordPropertiesReceived, void(const dbus::ObjectPath&));
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class MockNfcTagObserver : public NfcTagClient::Observer {
790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public:
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(TagAdded, void(const dbus::ObjectPath&));
81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MOCK_METHOD1(TagRemoved, void(const dbus::ObjectPath&));
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  MOCK_METHOD2(TagPropertyChanged, void(const dbus::ObjectPath&,
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                        const std::string&));
840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)};
850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class NfcClientTest : public testing::Test {
891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  NfcClientTest() : response_(NULL) {}
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~NfcClientTest() {}
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Create the mock bus.
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::Bus::Options options;
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    options.bus_type = dbus::Bus::SYSTEM;
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mock_bus_ = new dbus::MockBus(options);
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Create the mock proxies.
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mock_manager_proxy_ = new dbus::MockObjectProxy(
1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        mock_bus_.get(),
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kTestServiceName,
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        dbus::ObjectPath(kTestManagerPath));
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mock_adapter0_proxy_ = new dbus::MockObjectProxy(
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        mock_bus_.get(),
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kTestServiceName,
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        dbus::ObjectPath(kTestAdapterPath0));
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mock_adapter1_proxy_ = new dbus::MockObjectProxy(
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        mock_bus_.get(),
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kTestServiceName,
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        dbus::ObjectPath(kTestAdapterPath1));
1120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    mock_device0_proxy_ = new dbus::MockObjectProxy(
1130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        mock_bus_.get(),
1140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        kTestServiceName,
1150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        dbus::ObjectPath(kTestDevicePath0));
1160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    mock_device1_proxy_ = new dbus::MockObjectProxy(
1170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        mock_bus_.get(),
1180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        kTestServiceName,
1190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        dbus::ObjectPath(kTestDevicePath1));
120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    mock_record0_proxy_ = new dbus::MockObjectProxy(
121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mock_bus_.get(),
122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        kTestServiceName,
123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        dbus::ObjectPath(kTestRecordPath0));
124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    mock_record1_proxy_ = new dbus::MockObjectProxy(
125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mock_bus_.get(),
126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        kTestServiceName,
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        dbus::ObjectPath(kTestRecordPath1));
128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    mock_record2_proxy_ = new dbus::MockObjectProxy(
129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mock_bus_.get(),
130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        kTestServiceName,
131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        dbus::ObjectPath(kTestRecordPath2));
132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    mock_record3_proxy_ = new dbus::MockObjectProxy(
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mock_bus_.get(),
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        kTestServiceName,
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        dbus::ObjectPath(kTestRecordPath3));
1360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    mock_tag0_proxy_ = new dbus::MockObjectProxy(
1370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        mock_bus_.get(),
1380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        kTestServiceName,
1390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        dbus::ObjectPath(kTestTagPath0));
1400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    mock_tag1_proxy_ = new dbus::MockObjectProxy(
1410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        mock_bus_.get(),
1420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        kTestServiceName,
1430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        dbus::ObjectPath(kTestTagPath1));
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Set expectations that use NfcClientTest::OnConnectToSignal when the
1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // client connect signals on the mock proxies.
1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_manager_proxy_.get(), ConnectToSignal(_, _, _, _))
1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Invoke(this, &NfcClientTest::OnConnectToSignal));
1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_adapter0_proxy_.get(), ConnectToSignal(_, _, _, _))
1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Invoke(this, &NfcClientTest::OnConnectToSignal));
1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_adapter1_proxy_.get(), ConnectToSignal(_, _, _, _))
1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Invoke(this, &NfcClientTest::OnConnectToSignal));
1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Set expectations that return our mock proxies on demand.
1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(
1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        *mock_bus_.get(),
1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        GetObjectProxy(nfc_manager::kNfcManagerServiceName,
1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                       dbus::ObjectPath(nfc_manager::kNfcManagerServicePath)))
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Return(mock_manager_proxy_.get()));
1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                GetObjectProxy(nfc_adapter::kNfcAdapterServiceName,
1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               dbus::ObjectPath(kTestAdapterPath0)))
1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Return(mock_adapter0_proxy_.get()));
1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                GetObjectProxy(nfc_adapter::kNfcAdapterServiceName,
1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               dbus::ObjectPath(kTestAdapterPath1)))
1671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        .WillRepeatedly(Return(mock_adapter1_proxy_.get()));
1680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                GetObjectProxy(nfc_device::kNfcDeviceServiceName,
1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                               dbus::ObjectPath(kTestDevicePath0)))
1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        .WillRepeatedly(Return(mock_device0_proxy_.get()));
1720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                GetObjectProxy(nfc_device::kNfcDeviceServiceName,
1740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                               dbus::ObjectPath(kTestDevicePath1)))
1750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        .WillRepeatedly(Return(mock_device1_proxy_.get()));
1760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                GetObjectProxy(nfc_record::kNfcRecordServiceName,
178f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestRecordPath0)))
179f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        .WillRepeatedly(Return(mock_record0_proxy_.get()));
180f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
181f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                GetObjectProxy(nfc_record::kNfcRecordServiceName,
182f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestRecordPath1)))
183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        .WillRepeatedly(Return(mock_record1_proxy_.get()));
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                GetObjectProxy(nfc_record::kNfcRecordServiceName,
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestRecordPath2)))
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        .WillRepeatedly(Return(mock_record2_proxy_.get()));
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                GetObjectProxy(nfc_record::kNfcRecordServiceName,
190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestRecordPath3)))
191f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        .WillRepeatedly(Return(mock_record3_proxy_.get()));
192f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                GetObjectProxy(nfc_tag::kNfcTagServiceName,
1940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                               dbus::ObjectPath(kTestTagPath0)))
1950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        .WillRepeatedly(Return(mock_tag0_proxy_.get()));
1960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(),
1970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                GetObjectProxy(nfc_tag::kNfcTagServiceName,
1980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                               dbus::ObjectPath(kTestTagPath1)))
1990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        .WillRepeatedly(Return(mock_tag1_proxy_.get()));
2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // ShutdownAndBlock will be called in TearDown.
2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Create the clients.
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    manager_client_.reset(NfcManagerClient::Create());
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    adapter_client_.reset(NfcAdapterClient::Create(manager_client_.get()));
207a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    device_client_.reset(NfcDeviceClient::Create(adapter_client_.get()));
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    tag_client_.reset(NfcTagClient::Create(adapter_client_.get()));
209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    record_client_.reset(
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        NfcRecordClient::Create(device_client_.get(), tag_client_.get()));
2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    manager_client_->Init(mock_bus_.get());
2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    adapter_client_->Init(mock_bus_.get());
2130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    device_client_->Init(mock_bus_.get());
2140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    tag_client_->Init(mock_bus_.get());
215f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    record_client_->Init(mock_bus_.get());
2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    manager_client_->AddObserver(&mock_manager_observer_);
2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    adapter_client_->AddObserver(&mock_adapter_observer_);
2180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    device_client_->AddObserver(&mock_device_observer_);
2190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    tag_client_->AddObserver(&mock_tag_observer_);
220f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    record_client_->AddObserver(&mock_record_observer_);
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    message_loop_.RunUntilIdle();
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    tag_client_->RemoveObserver(&mock_tag_observer_);
2270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    device_client_->RemoveObserver(&mock_device_observer_);
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    adapter_client_->RemoveObserver(&mock_adapter_observer_);
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    manager_client_->RemoveObserver(&mock_manager_observer_);
2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mock_bus_->ShutdownAndBlock();
2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  void SimulateAdaptersChanged(
234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ObjectPathVector& adapter_paths) {
2350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    NfcManagerClient::Properties* properties =
2360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        manager_client_->GetProperties();
2370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    ASSERT_TRUE(properties);
2380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(mock_manager_observer_,
2390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                ManagerPropertyChanged(nfc_manager::kAdaptersProperty));
2400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    SendArrayPropertyChangedSignal(
2410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        properties,
2420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_manager::kNfcManagerInterface,
2430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_manager::kAdaptersProperty,
2440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        adapter_paths);
2450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    Mock::VerifyAndClearExpectations(&mock_manager_observer_);
2460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
2470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SimulateTagsChanged(const ObjectPathVector& tag_paths,
2490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                           const dbus::ObjectPath& adapter_path) {
2500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    NfcAdapterClient::Properties* properties =
2510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        adapter_client_->GetProperties(adapter_path);
2520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    ASSERT_TRUE(properties);
2530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(mock_adapter_observer_,
2540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                AdapterPropertyChanged(adapter_path,
2550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                       nfc_adapter::kTagsProperty));
2560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    SendArrayPropertyChangedSignal(
2570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        properties,
2580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_adapter::kNfcAdapterInterface,
2590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_adapter::kTagsProperty,
2600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        tag_paths);
2610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    Mock::VerifyAndClearExpectations(&mock_adapter_observer_);
2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
264f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SimulateDevicesChanged(const ObjectPathVector& device_paths,
2650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                              const dbus::ObjectPath& adapter_path) {
2660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    NfcAdapterClient::Properties* properties =
2670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        adapter_client_->GetProperties(adapter_path);
2680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    ASSERT_TRUE(properties);
2690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    EXPECT_CALL(mock_adapter_observer_,
2700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                AdapterPropertyChanged(adapter_path,
2710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                       nfc_adapter::kDevicesProperty));
2720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    SendArrayPropertyChangedSignal(
2730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        properties,
2740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_adapter::kNfcAdapterInterface,
2750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        nfc_adapter::kDevicesProperty,
2760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        device_paths);
2770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    Mock::VerifyAndClearExpectations(&mock_adapter_observer_);
2780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
2790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
280f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SimulateDeviceRecordsChanged(
281f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ObjectPathVector& record_paths,
282f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const dbus::ObjectPath& device_path) {
283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    NfcDeviceClient::Properties* properties =
284f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        device_client_->GetProperties(device_path);
285f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ASSERT_TRUE(properties);
286f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(mock_device_observer_,
287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                DevicePropertyChanged(device_path,
288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                      nfc_device::kRecordsProperty));
289f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    SendArrayPropertyChangedSignal(
290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        properties,
291f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        nfc_device::kNfcDeviceInterface,
292f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        nfc_device::kRecordsProperty,
293f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        record_paths);
294f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Mock::VerifyAndClearExpectations(&mock_device_observer_);
295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
297f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SimulateTagRecordsChanged(
298f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ObjectPathVector& record_paths,
299f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const dbus::ObjectPath& tag_path) {
300f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    NfcTagClient::Properties* properties =
301f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        tag_client_->GetProperties(tag_path);
302f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ASSERT_TRUE(properties);
303f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    EXPECT_CALL(mock_tag_observer_,
304f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                TagPropertyChanged(tag_path,
305f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                   nfc_tag::kRecordsProperty));
306f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    SendArrayPropertyChangedSignal(
307f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        properties,
308f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        nfc_tag::kNfcTagInterface,
309f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        nfc_tag::kRecordsProperty,
310f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        record_paths);
311f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Mock::VerifyAndClearExpectations(&mock_tag_observer_);
312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
313f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  void SendArrayPropertyChangedSignal(
3150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      dbus::PropertySet* properties,
3160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const std::string& interface,
3170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const std::string& property_name,
318f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ObjectPathVector object_paths) {
3190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    dbus::Signal signal(interface, nfc_common::kPropertyChangedSignal);
3201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dbus::MessageWriter writer(&signal);
3210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    writer.AppendString(property_name);
3220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    dbus::MessageWriter variant_writer(NULL);
3230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    writer.OpenVariant("ao", &variant_writer);
3240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    variant_writer.AppendArrayOfObjectPaths(object_paths);
3250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    writer.CloseContainer(&variant_writer);
3260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    properties->ChangedReceived(&signal);
3271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
3281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD0(SuccessCallback, void(void));
3301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MOCK_METHOD2(ErrorCallback, void(const std::string& error_name,
3311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                   const std::string& error_message));
3321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
3340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // The mock object proxies.
3350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_manager_proxy_;
3360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_adapter0_proxy_;
3370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_adapter1_proxy_;
3380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_device0_proxy_;
3390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_device1_proxy_;
340f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_record0_proxy_;
341f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_record1_proxy_;
342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_record2_proxy_;
343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_record3_proxy_;
3440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_tag0_proxy_;
3450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_refptr<dbus::MockObjectProxy> mock_tag1_proxy_;
3461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The mock bus.
3471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_refptr<dbus::MockBus> mock_bus_;
3481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // A message loop to emulate asynchronous behavior.
3491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::MessageLoop message_loop_;
3501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Response returned by mock methods.
3511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  dbus::Response* response_;
3521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The D-Bus client objects under test.
3531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<NfcManagerClient> manager_client_;
3541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<NfcAdapterClient> adapter_client_;
3550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_ptr<NfcDeviceClient> device_client_;
3560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  scoped_ptr<NfcTagClient> tag_client_;
357f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<NfcRecordClient> record_client_;
3581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Mock observers.
3591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MockNfcManagerObserver mock_manager_observer_;
3601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MockNfcAdapterObserver mock_adapter_observer_;
3610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  MockNfcDeviceObserver mock_device_observer_;
3620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  MockNfcTagObserver mock_tag_observer_;
363f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  MockNfcRecordObserver mock_record_observer_;
3641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The signal callbacks used to simulate asychronous signals.
3651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  dbus::ObjectProxy::SignalCallback manager_adapter_added_signal_callback_;
3661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  dbus::ObjectProxy::SignalCallback manager_adapter_removed_signal_callback_;
3671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
3691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Used to implement the mock proxy.
3701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnConnectToSignal(
3711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const std::string& interface_name,
3721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const std::string& signal_name,
3731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const dbus::ObjectProxy::SignalCallback& signal_callback,
3741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
3751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (interface_name == nfc_manager::kNfcManagerInterface) {
3761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (signal_name == nfc_manager::kAdapterAddedSignal)
3771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        manager_adapter_added_signal_callback_ = signal_callback;
3781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      else if (signal_name == nfc_manager::kAdapterRemovedSignal)
3791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        manager_adapter_removed_signal_callback_ = signal_callback;
3801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
3811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    message_loop_.PostTask(FROM_HERE, base::Bind(on_connected_callback,
3821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                                 interface_name,
3831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                                 signal_name,
3841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                                 true));
3851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
3861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
3871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Tests that when adapters are added and removed through the manager, all
3891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// observers are notified and the proxies are created and removed
3901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// accordingly.
3911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(NfcClientTest, AdaptersAddedAndRemoved) {
3921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Invoking methods on adapters that haven't been added should fail.
3931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*this,
3941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
3951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
3961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath0),
3971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
3981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
3991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
4011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Add adapter 0.
403f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector adapter_paths;
4040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.push_back(dbus::ObjectPath(kTestAdapterPath0));
4051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
4061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath0)));
4070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
4081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Invoking methods should succeed on adapter 0 but fail on adapter 1.
4101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*mock_adapter0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
4111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath0),
4131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter0_proxy_);
4171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*this,
4181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
4190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_adapter1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
4200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
4211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath1),
4231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
4270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter1_proxy_);
4281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Add adapter 1.
4300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.push_back(dbus::ObjectPath(kTestAdapterPath1));
4311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
4321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath1)));
4330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
4341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Invoking methods should succeed on both adapters.
4361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*mock_adapter0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
4371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*mock_adapter1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
4381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath0),
4401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath1),
4451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter0_proxy_);
4490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter1_proxy_);
4501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Remove adapter 0.
4520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.erase(adapter_paths.begin());
4531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
4541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              AdapterRemoved(dbus::ObjectPath(kTestAdapterPath0)));
4550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
4561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Invoking methods should succeed on adapter 1 but fail on adapter 0.
4581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*this,
4591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
4600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_adapter0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
4610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
4621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath0),
4641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
4681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*mock_adapter1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
4701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath1),
4721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter0_proxy_);
4760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter1_proxy_);
4771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Remove adapter 1.
4790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.clear();
4801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
4811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              AdapterRemoved(dbus::ObjectPath(kTestAdapterPath1)));
4820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
4831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Invoking methods should fail on both adapters.
4851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(*this,
4861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _))
4871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      .Times(2);
4880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_adapter0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
4890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
4900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_adapter1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
491a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      .Times(0);
4921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath0),
4941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
4951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
4961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
4971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  adapter_client_->StartPollLoop(
4981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      dbus::ObjectPath(kTestAdapterPath1),
4991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      nfc_adapter::kModeInitiator,
5001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::SuccessCallback, base::Unretained(this)),
5011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::Bind(&NfcClientTest::ErrorCallback, base::Unretained(this)));
5021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
5031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Tests that when tags are added and removed through an adapter, all
5050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// observers are notified and the proxies are created and removed
5060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// accordingly.
5070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)TEST_F(NfcClientTest, TagsAddedAndRemoved) {
5080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods on tags that haven't been added should fail.
5090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
5100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
511a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::DictionaryValue write_data;
512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  write_data.SetString(nfc_record::kTypeProperty, nfc_record::kTypeText);
5130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath0), write_data,
5140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
5190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add adapter 0.
521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector adapter_paths;
5220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.push_back(dbus::ObjectPath(kTestAdapterPath0));
5230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
5240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath0)));
5250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter_observer_);
5270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add tag 0.
529f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector tag_paths;
5300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_paths.push_back(dbus::ObjectPath(kTestTagPath0));
5310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
532f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagAdded(dbus::ObjectPath(kTestTagPath0)));
5330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateTagsChanged(tag_paths, dbus::ObjectPath(kTestAdapterPath0));
5340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
5350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on tag 0 but fail on tag 1.
5370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
5380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath0), write_data,
5390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag0_proxy_);
5440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
5450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
5460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
5470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
5480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath1), write_data,
5490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
5540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag1_proxy_);
5550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add tag 1.
5570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_paths.push_back(dbus::ObjectPath(kTestTagPath1));
5580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
559f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagAdded(dbus::ObjectPath(kTestTagPath1)));
5600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateTagsChanged(tag_paths, dbus::ObjectPath(kTestAdapterPath0));
5610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
5620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on both tags.
5640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
5650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
5660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath0), write_data,
5670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath1), write_data,
5720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag0_proxy_);
5770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag1_proxy_);
5780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Remove tag 0.
5800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_paths.erase(tag_paths.begin());
5810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
582f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagRemoved(dbus::ObjectPath(kTestTagPath0)));
5830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateTagsChanged(tag_paths, dbus::ObjectPath(kTestAdapterPath0));
5840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
5850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
5860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on tag 1 but fail on tag 0.
5870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
5880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
5890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
5900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
5910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath0), write_data,
5920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
5930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
5940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
5950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
5960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
5970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag0_proxy_);
5980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
5990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath1), write_data,
6000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
6010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
6020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
6030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
6040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag1_proxy_);
6050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Remove tag 1.
6070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_paths.clear();
6080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
609f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagRemoved(dbus::ObjectPath(kTestTagPath1)));
6100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateTagsChanged(tag_paths, dbus::ObjectPath(kTestAdapterPath0));
6110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
6120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should fail on both tags.
6140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
6150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _))
6160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(2);
6170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
6180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
6190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_tag1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
6200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
6210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath0), write_data,
6220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
6230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
6240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
6250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
6260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  tag_client_->Write(dbus::ObjectPath(kTestTagPath1), write_data,
6270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::SuccessCallback,
6280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)),
6290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                     base::Bind(&NfcClientTest::ErrorCallback,
6300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                base::Unretained(this)));
6310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
6320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Tests that when devices are added and removed through an adapter, all
6340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// observers are notified and the proxies are created and removed
6350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// accordingly.
6360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)TEST_F(NfcClientTest, DevicesAddedAndRemoved) {
6370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods on devices that haven't been added should fail.
6380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
6390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
640a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::DictionaryValue write_data;
641a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  write_data.SetString(nfc_record::kTypeProperty, nfc_record::kTypeText);
6420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath0), write_data,
6430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
6440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
6450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
6460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
6470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
6480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add adapter 0.
650f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector adapter_paths;
6510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  adapter_paths.push_back(dbus::ObjectPath(kTestAdapterPath0));
6520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
6530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath0)));
6540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateAdaptersChanged(adapter_paths);
6550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add device 0.
657f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector device_paths;
6580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_paths.push_back(dbus::ObjectPath(kTestDevicePath0));
6590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
660f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceAdded(dbus::ObjectPath(kTestDevicePath0)));
6610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateDevicesChanged(device_paths, dbus::ObjectPath(kTestAdapterPath0));
6620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
6630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on device 0 but fail on device 1.
6650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
6660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath0), write_data,
6670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
6680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
6690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
6700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
6710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device0_proxy_);
6720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
6730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
6740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
6750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
6760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath1), write_data,
6770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
6780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
6790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
6800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
6810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
6820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device1_proxy_);
6830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Add device 1.
6850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_paths.push_back(dbus::ObjectPath(kTestDevicePath1));
6860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
687f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceAdded(dbus::ObjectPath(kTestDevicePath1)));
6880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateDevicesChanged(device_paths, dbus::ObjectPath(kTestAdapterPath0));
6890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
6900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on both devices.
6920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device0_proxy_, CallMethodWithErrorCallback(_, _, _, _));
6930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
6940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath0), write_data,
6950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
6960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
6970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
6980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
6990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath1), write_data,
7000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
7010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
7020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
7030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
7040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device0_proxy_);
7050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device1_proxy_);
7060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
7070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Remove device 0.
7080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_paths.erase(device_paths.begin());
7090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
710f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceRemoved(dbus::ObjectPath(kTestDevicePath0)));
7110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateDevicesChanged(device_paths, dbus::ObjectPath(kTestAdapterPath0));
7120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
7130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
7140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should succeed on device 1 but fail on device 0.
7150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
7160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _));
7170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
7180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
7190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath0), write_data,
7200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
7210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
7220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
7230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
7240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(this);
7250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device0_proxy_);
7260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device1_proxy_, CallMethodWithErrorCallback(_, _, _, _));
7270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath1), write_data,
7280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
7290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
7300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
7310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
7320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device1_proxy_);
7330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
7340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Remove device 1.
7350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_paths.clear();
7360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
737f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceRemoved(dbus::ObjectPath(kTestDevicePath1)));
7380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SimulateDevicesChanged(device_paths, dbus::ObjectPath(kTestAdapterPath0));
7390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
7400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
7410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Invoking methods should fail on both devices.
7420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*this,
7430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)              ErrorCallback(nfc_client_helpers::kUnknownObjectError, _))
7440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(2);
7450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device0_proxy_, CallMethodWithErrorCallback(_, _, _, _))
7460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
7470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  EXPECT_CALL(*mock_device1_proxy_, CallMethodWithErrorCallback(_, _, _, _))
7480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      .Times(0);
7490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath0), write_data,
7500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
7510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
7520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
7530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
7540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  device_client_->Push(dbus::ObjectPath(kTestDevicePath1), write_data,
7550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::SuccessCallback,
7560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)),
7570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                       base::Bind(&NfcClientTest::ErrorCallback,
7580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  base::Unretained(this)));
7590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
7600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
761f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(NfcClientTest, ObjectCleanup) {
762f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Tests that when an adapter gets removed, proxies that belong to the
763f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // adapter, device, tag, and record hierarchy get cleaned up properly.
764f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ObjectPathVector object_paths;
765f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
766f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Add adapters.
767f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
768f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath0)));
769f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
770f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              AdapterAdded(dbus::ObjectPath(kTestAdapterPath1)));
771f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestAdapterPath0));
772f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestAdapterPath1));
773f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateAdaptersChanged(object_paths);
774f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter_observer_);
775f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
776f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Add devices and a tags. Assign them like the following:
777f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - device 0 -> adapter 0
778f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - tag 0 -> adapter 0
779f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - device 1 -> adapter 1
780f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - tag 1 -> adapter 1
781f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
782f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceAdded(dbus::ObjectPath(kTestDevicePath0)));
783f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
784f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceAdded(dbus::ObjectPath(kTestDevicePath1)));
785f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
786f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagAdded(dbus::ObjectPath(kTestTagPath0)));
787f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
788f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagAdded(dbus::ObjectPath(kTestTagPath1)));
789f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
790f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestDevicePath0));
791f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateDevicesChanged(object_paths, dbus::ObjectPath(kTestAdapterPath0));
792f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
793f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestTagPath0));
794f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateTagsChanged(object_paths, dbus::ObjectPath(kTestAdapterPath0));
795f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
796f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestDevicePath1));
797f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateDevicesChanged(object_paths, dbus::ObjectPath(kTestAdapterPath1));
798f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
799f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestTagPath1));
800f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateTagsChanged(object_paths, dbus::ObjectPath(kTestAdapterPath1));
801f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
802f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
803f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
804f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Add records. Assign them like the following:
805f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - record 0 -> device 0
806f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - record 1 -> tag 0
807f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - record 2 -> device 1
808f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //  - record 3 -> tag 1
809f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
810f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordAdded(dbus::ObjectPath(kTestRecordPath0)));
811f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
812f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordAdded(dbus::ObjectPath(kTestRecordPath1)));
813f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
814f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordAdded(dbus::ObjectPath(kTestRecordPath2)));
815f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
816f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordAdded(dbus::ObjectPath(kTestRecordPath3)));
817f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
818f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestRecordPath0));
819f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateDeviceRecordsChanged(object_paths,
820f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestDevicePath0));
821f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
822f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestRecordPath1));
823f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateTagRecordsChanged(object_paths,
824f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            dbus::ObjectPath(kTestTagPath0));
825f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
826f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestRecordPath2));
827f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateDeviceRecordsChanged(object_paths,
828f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                               dbus::ObjectPath(kTestDevicePath1));
829f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
830f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestRecordPath3));
831f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateTagRecordsChanged(object_paths,
832f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            dbus::ObjectPath(kTestTagPath1));
833f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_record_observer_);
834f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
835f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Check that the records have been assigned to the correct device or tag.
836f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  NfcTagClient::Properties* tag_properties =
837f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      tag_client_->GetProperties(dbus::ObjectPath(kTestTagPath0));
838f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ((size_t)1, tag_properties->records.value().size());
839f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(dbus::ObjectPath(kTestRecordPath1),
840f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            tag_properties->records.value()[0]);
841f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  NfcDeviceClient::Properties* device_properties =
842f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      device_client_->GetProperties(dbus::ObjectPath(kTestDevicePath0));
843f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ((size_t)1, device_properties->records.value().size());
844f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(dbus::ObjectPath(kTestRecordPath0),
845f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            device_properties->records.value()[0]);
846f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
847f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Remove adapter 0. Make sure that all of the tag, device, and records that
848f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // are in the adapter 0 hierarchy are removed.
849f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
850f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.push_back(dbus::ObjectPath(kTestAdapterPath1));
851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
852f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              AdapterRemoved(dbus::ObjectPath(kTestAdapterPath0)));
853f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
854f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceRemoved(dbus::ObjectPath(kTestDevicePath0)));
855f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
856f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagRemoved(dbus::ObjectPath(kTestTagPath0)));
857f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
858f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordRemoved(dbus::ObjectPath(kTestRecordPath0)));
859f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
860f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordRemoved(dbus::ObjectPath(kTestRecordPath1)));
861f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateAdaptersChanged(object_paths);
862f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_adapter_observer_);
863f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_device_observer_);
864f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_tag_observer_);
865f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Mock::VerifyAndClearExpectations(&mock_record_observer_);
866f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
867f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Remove adapter 1.
868f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  object_paths.clear();
869f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_adapter_observer_,
870f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              AdapterRemoved(dbus::ObjectPath(kTestAdapterPath1)));
871f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_device_observer_,
872f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              DeviceRemoved(dbus::ObjectPath(kTestDevicePath1)));
873f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_tag_observer_,
874f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              TagRemoved(dbus::ObjectPath(kTestTagPath1)));
875f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
876f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordRemoved(dbus::ObjectPath(kTestRecordPath2)));
877f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(mock_record_observer_,
878f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              RecordRemoved(dbus::ObjectPath(kTestRecordPath3)));
879f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SimulateAdaptersChanged(object_paths);
880f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
881f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
8821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace chromeos
883