Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2192)

Unified Diff: chrome/browser/sync/glue/local_device_info_provider_unittest.cc

Issue 367153005: Sync: Refactoring of DEVICE_INFO syncable type - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed scoped_ptr issue in ProfileSyncService constructor Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bdff50b20838f3ecfb376eb07894644df7be6575
--- /dev/null
+++ b/chrome/browser/sync/glue/local_device_info_provider_unittest.cc
@@ -0,0 +1,82 @@
+// 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 {
+ public:
+ LocalDeviceInfoProviderTest()
+ : called_back_(false) {}
+ virtual ~LocalDeviceInfoProviderTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ provider_.reset(new LocalDeviceInfoProviderImpl());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ provider_.reset();
+ called_back_ = false;
+ }
+
+ protected:
+ 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(
+ base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized,
+ base::Unretained(this), &run_loop)));
+ run_loop.Run();
+ }
+
+ void QuitLoopOnInitialized(base::RunLoop* loop) {
+ called_back_ = true;
+ loop->Quit();
+ }
+
+ scoped_ptr<LocalDeviceInfoProviderImpl> provider_;
+
+ bool called_back_;
+
+ private:
+ base::MessageLoop message_loop_;
+};
+
+TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) {
+ ASSERT_FALSE(called_back_);
+
+ InitializeProvider(kLocalDeviceGuid);
+ EXPECT_TRUE(called_back_);
+}
+
+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());
+}
+
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698