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 protected: | |
16 virtual void SetUp() { | |
17 provider_.reset(new LocalDeviceInfoProviderImpl()); | |
18 } | |
19 | |
20 virtual void TearDown() { | |
21 provider_.reset(); | |
22 } | |
23 | |
24 void InitializeProvider(const std::string& guid) { | |
25 // Start initialization. | |
26 provider_->Initialize(guid); | |
27 | |
28 // Subscribe to the notification and wait until the callback | |
29 // is called. The callback will quit the loop. | |
30 base::RunLoop run_loop; | |
31 scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription = | |
32 provider_->RegisterOnInitializedCallback(run_loop.QuitClosure()); | |
33 run_loop.Run(); | |
34 } | |
35 | |
36 scoped_ptr<LocalDeviceInfoProviderImpl> provider_; | |
37 | |
38 private: | |
39 base::MessageLoop message_loop_; | |
40 }; | |
41 | |
42 TEST_F(LocalDeviceInfoProviderTest, Initialize) { | |
43 ASSERT_FALSE(provider_->IsInitialized()); | |
44 | |
45 InitializeProvider(kLocalDeviceGuid); | |
46 | |
47 EXPECT_TRUE(provider_->IsInitialized()); | |
48 } | |
49 | |
50 TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { | |
51 ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo()); | |
52 | |
53 InitializeProvider(kLocalDeviceGuid); | |
54 | |
55 const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo(); | |
56 EXPECT_TRUE(!!local_device_info); | |
57 EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid()); | |
58 } | |
59 | |
60 TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { | |
61 ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID()); | |
62 | |
63 InitializeProvider(kLocalDeviceGuid); | |
64 | |
65 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID()); | |
66 } | |
67 | |
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
| |
68 } // namespace browser_sync | |
OLD | NEW |