1 // Copyright 2014 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.
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
9 #include "chrome/common/chrome_version_info.h"
10 #include "sync/util/get_session_name.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using sync_driver::DeviceInfo
;
14 using sync_driver::LocalDeviceInfoProvider
;
16 namespace browser_sync
{
18 const char kLocalDeviceGuid
[] = "foo";
19 const char kSigninScopedDeviceId
[] = "device_id";
21 class LocalDeviceInfoProviderTest
: public testing::Test
{
23 LocalDeviceInfoProviderTest()
24 : called_back_(false) {}
25 ~LocalDeviceInfoProviderTest() override
{}
27 void SetUp() override
{ provider_
.reset(new LocalDeviceInfoProviderImpl()); }
29 void TearDown() override
{
35 void InitializeProvider() {
36 // Start initialization.
37 provider_
->Initialize(kLocalDeviceGuid
, kSigninScopedDeviceId
);
39 // Subscribe to the notification and wait until the callback
40 // is called. The callback will quit the loop.
41 base::RunLoop run_loop
;
42 scoped_ptr
<LocalDeviceInfoProvider::Subscription
> subscription(
43 provider_
->RegisterOnInitializedCallback(
44 base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized
,
45 base::Unretained(this), &run_loop
)));
49 void QuitLoopOnInitialized(base::RunLoop
* loop
) {
54 scoped_ptr
<LocalDeviceInfoProviderImpl
> provider_
;
59 base::MessageLoop message_loop_
;
62 TEST_F(LocalDeviceInfoProviderTest
, OnInitializedCallback
) {
63 ASSERT_FALSE(called_back_
);
66 EXPECT_TRUE(called_back_
);
69 TEST_F(LocalDeviceInfoProviderTest
, GetLocalDeviceInfo
) {
70 ASSERT_EQ(NULL
, provider_
->GetLocalDeviceInfo());
74 const DeviceInfo
* local_device_info
= provider_
->GetLocalDeviceInfo();
75 EXPECT_TRUE(!!local_device_info
);
76 EXPECT_EQ(std::string(kLocalDeviceGuid
), local_device_info
->guid());
77 EXPECT_EQ(std::string(kSigninScopedDeviceId
),
78 local_device_info
->signin_scoped_device_id());
79 EXPECT_EQ(syncer::GetSessionNameSynchronouslyForTesting(),
80 local_device_info
->client_name());
82 chrome::VersionInfo version_info
;
83 EXPECT_EQ(browser_sync::LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi(
85 local_device_info
->sync_user_agent());
88 TEST_F(LocalDeviceInfoProviderTest
, GetLocalSyncCacheGUID
) {
89 ASSERT_EQ(std::string(), provider_
->GetLocalSyncCacheGUID());
93 EXPECT_EQ(std::string(kLocalDeviceGuid
), provider_
->GetLocalSyncCacheGUID());
96 } // namespace browser_sync