1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/prefs/pref_service.h"
7 #include "base/prefs/testing_pref_store.h"
8 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager.h"
9 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "chrome/common/extensions/api/signed_in_devices.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace extensions {
20 BrowserContextKeyedService* CreateProfileSyncServiceMock(
21 content::BrowserContext* profile) {
26 // Adds a listener and removes it.
27 TEST(SignedInDevicesManager, UpdateListener) {
28 scoped_ptr<TestingProfile> profile(new TestingProfile());
29 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "foo");
30 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
31 profile.get(), CreateProfileSyncServiceMock);
32 SignedInDevicesManager manager(profile.get());
34 EventListenerInfo info(
35 api::signed_in_devices::OnDeviceInfoChange::kEventName,
39 manager.OnListenerAdded(info);
40 EXPECT_EQ(manager.change_observers_.size(), 1U);
41 EXPECT_EQ(manager.change_observers_[0]->extension_id(), info.extension_id);
43 // Remove the listener.
44 manager.OnListenerRemoved(info);
45 EXPECT_TRUE(manager.change_observers_.empty());
47 } // namespace extensions