Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync / glue / local_device_info_provider_unittest.cc
blob9176c3070e1b2ce703e64fa19fa2a9f6979f1da3
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.
5 #include "base/bind.h"
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 "sync/util/get_session_name.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using sync_driver::DeviceInfo;
13 using sync_driver::LocalDeviceInfoProvider;
15 namespace browser_sync {
17 const char kLocalDeviceGuid[] = "foo";
18 const char kSigninScopedDeviceId[] = "device_id";
20 class LocalDeviceInfoProviderTest : public testing::Test {
21 public:
22 LocalDeviceInfoProviderTest()
23 : called_back_(false) {}
24 ~LocalDeviceInfoProviderTest() override {}
26 void SetUp() override { provider_.reset(new LocalDeviceInfoProviderImpl()); }
28 void TearDown() override {
29 provider_.reset();
30 called_back_ = false;
33 protected:
34 void InitializeProvider() {
35 // Start initialization.
36 provider_->Initialize(kLocalDeviceGuid, kSigninScopedDeviceId);
38 // Subscribe to the notification and wait until the callback
39 // is called. The callback will quit the loop.
40 base::RunLoop run_loop;
41 scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription(
42 provider_->RegisterOnInitializedCallback(
43 base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized,
44 base::Unretained(this), &run_loop)));
45 run_loop.Run();
48 void QuitLoopOnInitialized(base::RunLoop* loop) {
49 called_back_ = true;
50 loop->Quit();
53 scoped_ptr<LocalDeviceInfoProviderImpl> provider_;
55 bool called_back_;
57 private:
58 base::MessageLoop message_loop_;
61 TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) {
62 ASSERT_FALSE(called_back_);
64 InitializeProvider();
65 EXPECT_TRUE(called_back_);
68 TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) {
69 ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo());
71 InitializeProvider();
73 const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo();
74 EXPECT_TRUE(local_device_info);
75 EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid());
76 EXPECT_EQ(std::string(kSigninScopedDeviceId),
77 local_device_info->signin_scoped_device_id());
78 EXPECT_EQ(syncer::GetSessionNameSynchronouslyForTesting(),
79 local_device_info->client_name());
81 EXPECT_EQ(provider_->GetSyncUserAgent(),
82 local_device_info->sync_user_agent());
85 TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) {
86 ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID());
88 InitializeProvider();
90 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID());
93 } // namespace browser_sync