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. 4 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/sync/profile_sync_service_factory.h" 10 #include "chrome/common/extensions/api/signed_in_devices.h" 11 #include "chrome/common/pref_names.h" 12 #include "chrome/test/base/testing_profile.h" 13 #include "extensions/browser/event_router.h" 14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 17 namespace extensions { 18 19 namespace { 20 KeyedService* CreateProfileSyncServiceMock(content::BrowserContext* profile) { 21 return NULL; 22 } 23 } // namespace 24 25 // Adds a listener and removes it. 26 TEST(SignedInDevicesManager, UpdateListener) { 27 scoped_ptr<TestingProfile> profile(new TestingProfile()); 28 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "foo"); 29 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( 30 profile.get(), CreateProfileSyncServiceMock); 31 SignedInDevicesManager manager(profile.get()); 32 33 EventListenerInfo info(api::signed_in_devices::OnDeviceInfoChange::kEventName, 34 "extension1", 35 GURL(), 36 profile.get()); 37 38 // Add a listener. 39 manager.OnListenerAdded(info); 40 EXPECT_EQ(manager.change_observers_.size(), 1U); 41 EXPECT_EQ(manager.change_observers_[0]->extension_id(), info.extension_id); 42 43 // Remove the listener. 44 manager.OnListenerRemoved(info); 45 EXPECT_TRUE(manager.change_observers_.empty()); 46 } 47 } // namespace extensions 48