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

Side by Side Diff: remoting/host/pairing_registry_delegate_linux_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/pairing_registry_delegate_linux.h" 5 #include "remoting/host/pairing_registry_delegate_linux.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 24
25 void TearDown() override { base::DeleteFile(temp_dir_, true); } 25 void TearDown() override { base::DeleteFile(temp_dir_, true); }
26 26
27 protected: 27 protected:
28 base::FilePath temp_dir_; 28 base::FilePath temp_dir_;
29 base::FilePath temp_registry_; 29 base::FilePath temp_registry_;
30 }; 30 };
31 31
32 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) { 32 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
33 scoped_ptr<PairingRegistryDelegateLinux> delegate( 33 std::unique_ptr<PairingRegistryDelegateLinux> delegate(
34 new PairingRegistryDelegateLinux()); 34 new PairingRegistryDelegateLinux());
35 delegate->SetRegistryPathForTesting(temp_registry_); 35 delegate->SetRegistryPathForTesting(temp_registry_);
36 36
37 // Check that registry is initially empty. 37 // Check that registry is initially empty.
38 EXPECT_TRUE(delegate->LoadAll()->empty()); 38 EXPECT_TRUE(delegate->LoadAll()->empty());
39 39
40 // Add a couple of pairings. 40 // Add a couple of pairings.
41 PairingRegistry::Pairing pairing1(base::Time::Now(), "xxx", "xxx", "xxx"); 41 PairingRegistry::Pairing pairing1(base::Time::Now(), "xxx", "xxx", "xxx");
42 PairingRegistry::Pairing pairing2(base::Time::Now(), "yyy", "yyy", "yyy"); 42 PairingRegistry::Pairing pairing2(base::Time::Now(), "yyy", "yyy", "yyy");
43 EXPECT_TRUE(delegate->Save(pairing1)); 43 EXPECT_TRUE(delegate->Save(pairing1));
44 EXPECT_TRUE(delegate->Save(pairing2)); 44 EXPECT_TRUE(delegate->Save(pairing2));
45 45
46 // Verify that there are two pairings in the store now. 46 // Verify that there are two pairings in the store now.
47 EXPECT_EQ(delegate->LoadAll()->GetSize(), 2u); 47 EXPECT_EQ(delegate->LoadAll()->GetSize(), 2u);
48 48
49 // Verify that they can be retrieved. 49 // Verify that they can be retrieved.
50 EXPECT_EQ(delegate->Load(pairing1.client_id()), pairing1); 50 EXPECT_EQ(delegate->Load(pairing1.client_id()), pairing1);
51 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2); 51 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
52 52
53 // Delete the first pairing. 53 // Delete the first pairing.
54 EXPECT_TRUE(delegate->Delete(pairing1.client_id())); 54 EXPECT_TRUE(delegate->Delete(pairing1.client_id()));
55 55
56 // Verify that there is only one pairing left. 56 // Verify that there is only one pairing left.
57 EXPECT_EQ(delegate->Load(pairing1.client_id()), PairingRegistry::Pairing()); 57 EXPECT_EQ(delegate->Load(pairing1.client_id()), PairingRegistry::Pairing());
58 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2); 58 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
59 59
60 // Verify that the only value that left is |pairing2|. 60 // Verify that the only value that left is |pairing2|.
61 EXPECT_EQ(delegate->LoadAll()->GetSize(), 1u); 61 EXPECT_EQ(delegate->LoadAll()->GetSize(), 1u);
62 scoped_ptr<base::ListValue> pairings = delegate->LoadAll(); 62 std::unique_ptr<base::ListValue> pairings = delegate->LoadAll();
63 base::DictionaryValue* json; 63 base::DictionaryValue* json;
64 EXPECT_TRUE(pairings->GetDictionary(0, &json)); 64 EXPECT_TRUE(pairings->GetDictionary(0, &json));
65 EXPECT_EQ(PairingRegistry::Pairing::CreateFromValue(*json), pairing2); 65 EXPECT_EQ(PairingRegistry::Pairing::CreateFromValue(*json), pairing2);
66 66
67 // Delete the rest and verify. 67 // Delete the rest and verify.
68 EXPECT_TRUE(delegate->DeleteAll()); 68 EXPECT_TRUE(delegate->DeleteAll());
69 EXPECT_TRUE(delegate->LoadAll()->empty()); 69 EXPECT_TRUE(delegate->LoadAll()->empty());
70 } 70 }
71 71
72 // Verifies that the delegate is stateless by using two different instances. 72 // Verifies that the delegate is stateless by using two different instances.
73 TEST_F(PairingRegistryDelegateLinuxTest, Stateless) { 73 TEST_F(PairingRegistryDelegateLinuxTest, Stateless) {
74 scoped_ptr<PairingRegistryDelegateLinux> save_delegate( 74 std::unique_ptr<PairingRegistryDelegateLinux> save_delegate(
75 new PairingRegistryDelegateLinux()); 75 new PairingRegistryDelegateLinux());
76 scoped_ptr<PairingRegistryDelegateLinux> load_delegate( 76 std::unique_ptr<PairingRegistryDelegateLinux> load_delegate(
77 new PairingRegistryDelegateLinux()); 77 new PairingRegistryDelegateLinux());
78 save_delegate->SetRegistryPathForTesting(temp_registry_); 78 save_delegate->SetRegistryPathForTesting(temp_registry_);
79 load_delegate->SetRegistryPathForTesting(temp_registry_); 79 load_delegate->SetRegistryPathForTesting(temp_registry_);
80 80
81 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx"); 81 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx");
82 EXPECT_TRUE(save_delegate->Save(pairing)); 82 EXPECT_TRUE(save_delegate->Save(pairing));
83 EXPECT_EQ(load_delegate->Load(pairing.client_id()), pairing); 83 EXPECT_EQ(load_delegate->Load(pairing.client_id()), pairing);
84 } 84 }
85 85
86 } // namespace remoting 86 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/pairing_registry_delegate_linux.cc ('k') | remoting/host/pairing_registry_delegate_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698