| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #include "base/message_loop/message_loop.h" | |
| 6 #include "base/run_loop.h" | |
| 7 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace browser_sync { | |
| 11 | |
| 12 const char kLocalDeviceGuid[] = "foo"; | |
| 13 | |
| 14 class LocalDeviceInfoProviderTest : public testing::Test { | |
| 15 public: | |
| 16 LocalDeviceInfoProviderTest() | |
| 17 : called_back_(false) {} | |
| 18 virtual ~LocalDeviceInfoProviderTest() {} | |
| 19 | |
| 20 virtual void SetUp() OVERRIDE { | |
| 21 provider_.reset(new LocalDeviceInfoProviderImpl()); | |
| 22 } | |
| 23 | |
| 24 virtual void TearDown() OVERRIDE { | |
| 25 provider_.reset(); | |
| 26 called_back_ = false; | |
| 27 } | |
| 28 | |
| 29 protected: | |
| 30 void InitializeProvider(const std::string& guid) { | |
| 31 // Start initialization. | |
| 32 provider_->Initialize(guid); | |
| 33 | |
| 34 // Subscribe to the notification and wait until the callback | |
| 35 // is called. The callback will quit the loop. | |
| 36 base::RunLoop run_loop; | |
| 37 scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription( | |
| 38 provider_->RegisterOnInitializedCallback( | |
| 39 base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized, | |
| 40 base::Unretained(this), &run_loop))); | |
| 41 run_loop.Run(); | |
| 42 } | |
| 43 | |
| 44 void QuitLoopOnInitialized(base::RunLoop* loop) { | |
| 45 called_back_ = true; | |
| 46 loop->Quit(); | |
| 47 } | |
| 48 | |
| 49 scoped_ptr<LocalDeviceInfoProviderImpl> provider_; | |
| 50 | |
| 51 bool called_back_; | |
| 52 | |
| 53 private: | |
| 54 base::MessageLoop message_loop_; | |
| 55 }; | |
| 56 | |
| 57 TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) { | |
| 58 ASSERT_FALSE(called_back_); | |
| 59 | |
| 60 InitializeProvider(kLocalDeviceGuid); | |
| 61 EXPECT_TRUE(called_back_); | |
| 62 } | |
| 63 | |
| 64 TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { | |
| 65 ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo()); | |
| 66 | |
| 67 InitializeProvider(kLocalDeviceGuid); | |
| 68 | |
| 69 const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo(); | |
| 70 EXPECT_TRUE(!!local_device_info); | |
| 71 EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid()); | |
| 72 } | |
| 73 | |
| 74 TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { | |
| 75 ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID()); | |
| 76 | |
| 77 InitializeProvider(kLocalDeviceGuid); | |
| 78 | |
| 79 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID()); | |
| 80 } | |
| 81 | |
| 82 } // namespace browser_sync | |
| OLD | NEW |