- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / signed_in_devices / signed_in_devices_manager_unittest.cc
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/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"
16
17 namespace extensions {
18
19 namespace {
20 BrowserContextKeyedService* CreateProfileSyncServiceMock(
21     content::BrowserContext* profile) {
22   return NULL;
23 }
24 }  // namespace
25
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());
33
34   EventListenerInfo info(
35       api::signed_in_devices::OnDeviceInfoChange::kEventName,
36       "extension1");
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