| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/prefs/testing_pref_store.h" | 7 #include "base/prefs/testing_pref_store.h" |
| 8 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_mana
ger.h" | 8 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_mana
ger.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 9 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 11 #include "chrome/common/extensions/api/signed_in_devices.h" | 11 #include "chrome/common/extensions/api/signed_in_devices.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/signin/core/browser/signin_manager.h" | 14 #include "components/signin/core/browser/signin_manager.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 KeyedService* CreateProfileSyncServiceMock(content::BrowserContext* profile) { | 23 KeyedService* CreateProfileSyncServiceMock(content::BrowserContext* profile) { |
| 23 return NULL; | 24 return NULL; |
| 24 } | 25 } |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 // Adds a listener and removes it. | 28 // Adds a listener and removes it. |
| 28 TEST(SignedInDevicesManager, UpdateListener) { | 29 TEST(SignedInDevicesManager, UpdateListener) { |
| 30 content::TestBrowserThreadBundle thread_bundle; |
| 29 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 31 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 30 SigninManagerFactory::GetForProfile(profile.get())-> | 32 SigninManagerFactory::GetForProfile(profile.get())-> |
| 31 SetAuthenticatedAccountInfo("gaia_id", "foo"); | 33 SetAuthenticatedAccountInfo("gaia_id", "foo"); |
| 32 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( | 34 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( |
| 33 profile.get(), CreateProfileSyncServiceMock); | 35 profile.get(), CreateProfileSyncServiceMock); |
| 34 SignedInDevicesManager manager(profile.get()); | 36 SignedInDevicesManager manager(profile.get()); |
| 35 | 37 |
| 36 EventListenerInfo info(api::signed_in_devices::OnDeviceInfoChange::kEventName, | 38 EventListenerInfo info(api::signed_in_devices::OnDeviceInfoChange::kEventName, |
| 37 "extension1", | 39 "extension1", |
| 38 GURL(), | 40 GURL(), |
| 39 profile.get()); | 41 profile.get()); |
| 40 | 42 |
| 41 // Add a listener. | 43 // Add a listener. |
| 42 manager.OnListenerAdded(info); | 44 manager.OnListenerAdded(info); |
| 43 EXPECT_EQ(manager.change_observers_.size(), 1U); | 45 EXPECT_EQ(manager.change_observers_.size(), 1U); |
| 44 EXPECT_EQ(manager.change_observers_[0]->extension_id(), info.extension_id); | 46 EXPECT_EQ(manager.change_observers_[0]->extension_id(), info.extension_id); |
| 45 | 47 |
| 46 // Remove the listener. | 48 // Remove the listener. |
| 47 manager.OnListenerRemoved(info); | 49 manager.OnListenerRemoved(info); |
| 48 EXPECT_TRUE(manager.change_observers_.empty()); | 50 EXPECT_TRUE(manager.change_observers_.empty()); |
| 49 } | 51 } |
| 50 } // namespace extensions | 52 } // namespace extensions |
| OLD | NEW |