Chromium Code Reviews| Index: chrome/browser/sync/glue/local_device_info_provider_unittest.cc |
| diff --git a/chrome/browser/sync/glue/local_device_info_provider_unittest.cc b/chrome/browser/sync/glue/local_device_info_provider_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8595ce506a93a488f6136260460c1fbfbecaf074 |
| --- /dev/null |
| +++ b/chrome/browser/sync/glue/local_device_info_provider_unittest.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace browser_sync { |
| + |
| +const char kLocalDeviceGuid[] = "foo"; |
| + |
| +class LocalDeviceInfoProviderTest : public testing::Test { |
| + protected: |
| + virtual void SetUp() { |
| + provider_.reset(new LocalDeviceInfoProviderImpl()); |
| + } |
| + |
| + virtual void TearDown() { |
| + provider_.reset(); |
| + } |
| + |
| + void InitializeProvider(const std::string& guid) { |
| + // Start initialization. |
| + provider_->Initialize(guid); |
| + |
| + // Subscribe to the notification and wait until the callback |
| + // is called. The callback will quit the loop. |
| + base::RunLoop run_loop; |
| + scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription = |
| + provider_->RegisterOnInitializedCallback(run_loop.QuitClosure()); |
| + run_loop.Run(); |
| + } |
| + |
| + scoped_ptr<LocalDeviceInfoProviderImpl> provider_; |
| + |
| + private: |
| + base::MessageLoop message_loop_; |
| +}; |
| + |
| +TEST_F(LocalDeviceInfoProviderTest, Initialize) { |
| + ASSERT_FALSE(provider_->IsInitialized()); |
| + |
| + InitializeProvider(kLocalDeviceGuid); |
| + |
| + EXPECT_TRUE(provider_->IsInitialized()); |
| +} |
| + |
| +TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { |
| + ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo()); |
| + |
| + InitializeProvider(kLocalDeviceGuid); |
| + |
| + const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo(); |
| + EXPECT_TRUE(!!local_device_info); |
| + EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid()); |
| +} |
| + |
| +TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { |
| + ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID()); |
| + |
| + InitializeProvider(kLocalDeviceGuid); |
| + |
| + EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID()); |
| +} |
| + |
|
rlarocque
2014/07/08 18:25:38
Maybe add a test for the callback registration, to
stanisc
2014/07/09 21:58:36
I had a test for this in InitializeProvider method
|
| +} // namespace browser_sync |