Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / sync / glue / local_device_info_provider_unittest.cc
blob48f154c136078699de7acf6d61ed2ef4959654b7
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 "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 {
22 public:
23 LocalDeviceInfoProviderTest()
24 : called_back_(false) {}
25 ~LocalDeviceInfoProviderTest() override {}
27 void SetUp() override { provider_.reset(new LocalDeviceInfoProviderImpl()); }
29 void TearDown() override {
30 provider_.reset();
31 called_back_ = false;
34 protected:
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)));
46 run_loop.Run();
49 void QuitLoopOnInitialized(base::RunLoop* loop) {
50 called_back_ = true;
51 loop->Quit();
54 scoped_ptr<LocalDeviceInfoProviderImpl> provider_;
56 bool called_back_;
58 private:
59 base::MessageLoop message_loop_;
62 TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) {
63 ASSERT_FALSE(called_back_);
65 InitializeProvider();
66 EXPECT_TRUE(called_back_);
69 TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) {
70 ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo());
72 InitializeProvider();
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(
84 version_info),
85 local_device_info->sync_user_agent());
88 TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) {
89 ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID());
91 InitializeProvider();
93 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID());
96 } // namespace browser_sync