1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// found in the LICENSE file.
4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
5a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <string>
6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <vector>
8a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/guid.h"
10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/message_loop/message_loop.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/prefs/pref_service.h"
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/values.h"
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/extension_api_unittest.h"
15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/extensions/test_extension_prefs.h"
163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/sync/profile_sync_service_factory.h"
18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/sync/profile_sync_service_mock.h"
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/common/pref_names.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/sync_driver/device_info.h"
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h"
22a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciusing sync_driver::DeviceInfo;
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciusing sync_driver::DeviceInfoTracker;
27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using testing::Return;
28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace extensions {
30a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass MockDeviceInfoTracker : public DeviceInfoTracker {
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public:
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ~MockDeviceInfoTracker() {}
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual scoped_ptr<DeviceInfo> GetDeviceInfo(
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const std::string& client_id) const OVERRIDE {
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    NOTREACHED();
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return scoped_ptr<DeviceInfo>();
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static DeviceInfo* CloneDeviceInfo(const DeviceInfo* device_info) {
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return new DeviceInfo(device_info->guid(),
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          device_info->client_name(),
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          device_info->chrome_version(),
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          device_info->sync_user_agent(),
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          device_info->device_type(),
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          device_info->signin_scoped_device_id());
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ScopedVector<DeviceInfo> GetAllDeviceInfo() const OVERRIDE {
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ScopedVector<DeviceInfo> list;
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    for (std::vector<const DeviceInfo*>::const_iterator iter = devices_.begin();
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci         iter != devices_.end();
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci         ++iter) {
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      list.push_back(CloneDeviceInfo(*iter));
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    }
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return list.Pass();
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void AddObserver(Observer* observer) OVERRIDE { NOTREACHED(); }
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void RemoveObserver(Observer* observer) OVERRIDE { NOTREACHED(); }
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Add(const DeviceInfo* device) { devices_.push_back(device); }
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // DeviceInfo stored here are not owned.
701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::vector<const DeviceInfo*> devices_;
711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci};
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST(SignedInDevicesAPITest, GetSignedInDevices) {
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  TestingProfile profile;
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  MockDeviceInfoTracker device_tracker;
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::MessageLoop message_loop_;
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  TestExtensionPrefs extension_prefs(
78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      message_loop_.message_loop_proxy().get());
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Add a couple of devices and make sure we get back public ids for them.
81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  std::string extension_name = "test";
82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_refptr<Extension> extension_test =
83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      extension_prefs.AddExtension(extension_name);
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DeviceInfo device_info1(base::GenerateGUID(),
865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "abc Device",
875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ v1",
885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ SyncAgent v1",
895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "device_id");
915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DeviceInfo device_info2(base::GenerateGUID(),
935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "def Device",
945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ v2",
955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ SyncAgent v2",
965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "device_id");
98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  device_tracker.Add(&device_info1);
1001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  device_tracker.Add(&device_info2);
101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
10258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ScopedVector<DeviceInfo> output1 = GetAllSignedInDevices(
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      extension_test.get()->id(), &device_tracker, extension_prefs.prefs());
104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::string public_id1 = output1[0]->public_id();
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::string public_id2 = output1[1]->public_id();
107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(public_id1.empty());
109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(public_id2.empty());
110a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_NE(public_id1, public_id2);
111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Add a third device and make sure the first 2 ids are retained and a new
113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // id is generated for the third device.
1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DeviceInfo device_info3(base::GenerateGUID(),
1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "def Device",
1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "jkl v2",
1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ SyncAgent v2",
1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "device_id");
120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  device_tracker.Add(&device_info3);
122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
12358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ScopedVector<DeviceInfo> output2 = GetAllSignedInDevices(
1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      extension_test.get()->id(), &device_tracker, extension_prefs.prefs());
125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(output2[0]->public_id(), public_id1);
1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(output2[1]->public_id(), public_id2);
128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::string public_id3 = output2[2]->public_id();
130a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(public_id3.empty());
131a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_NE(public_id3, public_id1);
132a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_NE(public_id3, public_id2);
133a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
134a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ProfileSyncServiceMockForExtensionTests:
1363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    public ProfileSyncServiceMock {
1373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  explicit ProfileSyncServiceMockForExtensionTests(Profile* p)
139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      : ProfileSyncServiceMock(p) {}
1403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ~ProfileSyncServiceMockForExtensionTests() {}
141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  MOCK_METHOD0(Shutdown, void());
1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  MOCK_CONST_METHOD0(GetDeviceInfoTracker, DeviceInfoTracker*());
1443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
146a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* CreateProfileSyncServiceMock(content::BrowserContext* profile) {
147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return new ProfileSyncServiceMockForExtensionTests(
148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      Profile::FromBrowserContext(profile));
1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ExtensionSignedInDevicesTest : public ExtensionApiUnittest {
1523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
1533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void SetUp() {
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtensionApiUnittest::SetUp();
1553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
1573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)        profile(), CreateProfileSyncServiceMock);
1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
1593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
1603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)std::string GetPublicId(const base::DictionaryValue* dictionary) {
1623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string public_id;
1633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (!dictionary->GetString("id", &public_id)) {
1643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ADD_FAILURE() << "Not able to find public id in the dictionary";
1653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
1663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return public_id;
1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
1693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void VerifyDictionaryWithDeviceInfo(const base::DictionaryValue* actual_value,
1713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                    DeviceInfo* device_info) {
1723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string public_id = GetPublicId(actual_value);
1733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  device_info->set_public_id(public_id);
1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<base::DictionaryValue> expected_value(device_info->ToValue());
1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(expected_value->Equals(actual_value));
1773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
1783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)base::DictionaryValue* GetDictionaryFromList(int index,
1803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                             base::ListValue* value) {
1813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::DictionaryValue* dictionary;
1823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (!value->GetDictionary(index, &dictionary)) {
1833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ADD_FAILURE() << "Expected a list of dictionaries";
1843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return NULL;
1853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
1863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return dictionary;
1873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
1883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ExtensionSignedInDevicesTest, GetAll) {
1903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ProfileSyncServiceMockForExtensionTests* pss_mock =
1913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      static_cast<ProfileSyncServiceMockForExtensionTests*>(
1923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)          ProfileSyncServiceFactory::GetForProfile(profile()));
1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  MockDeviceInfoTracker device_tracker;
1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DeviceInfo device_info1(base::GenerateGUID(),
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "abc Device",
1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ v1",
1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ SyncAgent v1",
1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "device_id");
2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DeviceInfo device_info2(base::GenerateGUID(),
2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "def Device",
2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ v2",
2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "XYZ SyncAgent v2",
2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                          "device_id");
2083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  device_tracker.Add(&device_info1);
2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  device_tracker.Add(&device_info2);
2113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_CALL(*pss_mock, GetDeviceInfoTracker())
2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      .WillOnce(Return(&device_tracker));
2143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_CALL(*pss_mock, Shutdown());
2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<base::ListValue> result(RunFunctionAndReturnList(
21858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      new SignedInDevicesGetFunction(), "[null]"));
2193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Ensure dictionary matches device info.
2213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  VerifyDictionaryWithDeviceInfo(GetDictionaryFromList(0, result.get()),
2223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                 &device_info1);
2233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  VerifyDictionaryWithDeviceInfo(GetDictionaryFromList(1, result.get()),
2243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                 &device_info2);
2253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Ensure public ids are set and unique.
2273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string public_id1 = GetPublicId(GetDictionaryFromList(0, result.get()));
2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string public_id2 = GetPublicId(GetDictionaryFromList(1, result.get()));
2293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(public_id1.empty());
2313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(public_id2.empty());
2323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_NE(public_id1, public_id2);
2333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
2343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(ExtensionSignedInDevicesTest, DeviceInfoTrackerNotInitialized) {
2361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ProfileSyncServiceMockForExtensionTests* pss_mock =
2371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      static_cast<ProfileSyncServiceMockForExtensionTests*>(
2381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          ProfileSyncServiceFactory::GetForProfile(profile()));
2391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_CALL(*pss_mock, GetDeviceInfoTracker())
2411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    .WillOnce(Return((DeviceInfoTracker*)NULL));
2421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_CALL(*pss_mock, Shutdown());
2431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ScopedVector<DeviceInfo> output = GetAllSignedInDevices(
2451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      extension()->id(), profile());
2461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(output.empty());
2481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
250a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}  // namespace extensions
251