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

Side by Side Diff: remoting/host/pairing_registry_delegate_win_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_win.h" 5 #include "remoting/host/pairing_registry_delegate_win.h"
6 6
7 #include <shlwapi.h> 7 #include <shlwapi.h>
8 8
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 29 matching lines...) Expand all
40 base::UTF8ToWide(key_name_).c_str()) == ERROR_SUCCESS); 40 base::UTF8ToWide(key_name_).c_str()) == ERROR_SUCCESS);
41 } 41 }
42 42
43 protected: 43 protected:
44 std::string key_name_; 44 std::string key_name_;
45 base::win::RegKey privileged_; 45 base::win::RegKey privileged_;
46 base::win::RegKey unprivileged_; 46 base::win::RegKey unprivileged_;
47 }; 47 };
48 48
49 TEST_F(PairingRegistryDelegateWinTest, SaveAndLoad) { 49 TEST_F(PairingRegistryDelegateWinTest, SaveAndLoad) {
50 scoped_ptr<PairingRegistryDelegateWin> delegate( 50 std::unique_ptr<PairingRegistryDelegateWin> delegate(
51 new PairingRegistryDelegateWin()); 51 new PairingRegistryDelegateWin());
52 delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle()); 52 delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle());
53 53
54 // Check that registry is initially empty. 54 // Check that registry is initially empty.
55 EXPECT_TRUE(delegate->LoadAll()->empty()); 55 EXPECT_TRUE(delegate->LoadAll()->empty());
56 56
57 // Add a couple of pairings. 57 // Add a couple of pairings.
58 PairingRegistry::Pairing pairing1(base::Time::Now(), "xxx", "xxx", "xxx"); 58 PairingRegistry::Pairing pairing1(base::Time::Now(), "xxx", "xxx", "xxx");
59 PairingRegistry::Pairing pairing2(base::Time::Now(), "yyy", "yyy", "yyy"); 59 PairingRegistry::Pairing pairing2(base::Time::Now(), "yyy", "yyy", "yyy");
60 EXPECT_TRUE(delegate->Save(pairing1)); 60 EXPECT_TRUE(delegate->Save(pairing1));
61 EXPECT_TRUE(delegate->Save(pairing2)); 61 EXPECT_TRUE(delegate->Save(pairing2));
62 62
63 // Verify that there are two pairings in the store now. 63 // Verify that there are two pairings in the store now.
64 EXPECT_EQ(delegate->LoadAll()->GetSize(), 2u); 64 EXPECT_EQ(delegate->LoadAll()->GetSize(), 2u);
65 65
66 // Verify that they can be retrieved. 66 // Verify that they can be retrieved.
67 EXPECT_EQ(delegate->Load(pairing1.client_id()), pairing1); 67 EXPECT_EQ(delegate->Load(pairing1.client_id()), pairing1);
68 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2); 68 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
69 69
70 // Delete the first pairing. 70 // Delete the first pairing.
71 EXPECT_TRUE(delegate->Delete(pairing1.client_id())); 71 EXPECT_TRUE(delegate->Delete(pairing1.client_id()));
72 72
73 // Verify that there is only one pairing left. 73 // Verify that there is only one pairing left.
74 EXPECT_EQ(delegate->Load(pairing1.client_id()), PairingRegistry::Pairing()); 74 EXPECT_EQ(delegate->Load(pairing1.client_id()), PairingRegistry::Pairing());
75 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2); 75 EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
76 76
77 // Verify that the only remaining value is |pairing2|. 77 // Verify that the only remaining value is |pairing2|.
78 EXPECT_EQ(delegate->LoadAll()->GetSize(), 1u); 78 EXPECT_EQ(delegate->LoadAll()->GetSize(), 1u);
79 scoped_ptr<base::ListValue> pairings = delegate->LoadAll(); 79 std::unique_ptr<base::ListValue> pairings = delegate->LoadAll();
80 base::DictionaryValue* json; 80 base::DictionaryValue* json;
81 EXPECT_TRUE(pairings->GetDictionary(0, &json)); 81 EXPECT_TRUE(pairings->GetDictionary(0, &json));
82 EXPECT_EQ(PairingRegistry::Pairing::CreateFromValue(*json), pairing2); 82 EXPECT_EQ(PairingRegistry::Pairing::CreateFromValue(*json), pairing2);
83 83
84 // Delete the rest and verify. 84 // Delete the rest and verify.
85 EXPECT_TRUE(delegate->DeleteAll()); 85 EXPECT_TRUE(delegate->DeleteAll());
86 EXPECT_TRUE(delegate->LoadAll()->empty()); 86 EXPECT_TRUE(delegate->LoadAll()->empty());
87 } 87 }
88 88
89 // Verifies that the delegate is stateless by using two different instances. 89 // Verifies that the delegate is stateless by using two different instances.
90 TEST_F(PairingRegistryDelegateWinTest, Stateless) { 90 TEST_F(PairingRegistryDelegateWinTest, Stateless) {
91 scoped_ptr<PairingRegistryDelegateWin> load_delegate( 91 std::unique_ptr<PairingRegistryDelegateWin> load_delegate(
92 new PairingRegistryDelegateWin()); 92 new PairingRegistryDelegateWin());
93 load_delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle()); 93 load_delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle());
94 scoped_ptr<PairingRegistryDelegateWin> save_delegate( 94 std::unique_ptr<PairingRegistryDelegateWin> save_delegate(
95 new PairingRegistryDelegateWin()); 95 new PairingRegistryDelegateWin());
96 save_delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle()); 96 save_delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle());
97 97
98 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx"); 98 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx");
99 EXPECT_TRUE(save_delegate->Save(pairing)); 99 EXPECT_TRUE(save_delegate->Save(pairing));
100 EXPECT_EQ(load_delegate->Load(pairing.client_id()), pairing); 100 EXPECT_EQ(load_delegate->Load(pairing.client_id()), pairing);
101 } 101 }
102 102
103 TEST_F(PairingRegistryDelegateWinTest, Unprivileged) { 103 TEST_F(PairingRegistryDelegateWinTest, Unprivileged) {
104 scoped_ptr<PairingRegistryDelegateWin> delegate( 104 std::unique_ptr<PairingRegistryDelegateWin> delegate(
105 new PairingRegistryDelegateWin()); 105 new PairingRegistryDelegateWin());
106 delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle()); 106 delegate->SetRootKeys(privileged_.Handle(), unprivileged_.Handle());
107 107
108 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx"); 108 PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx");
109 EXPECT_TRUE(delegate->Save(pairing)); 109 EXPECT_TRUE(delegate->Save(pairing));
110 EXPECT_EQ(delegate->Load(pairing.client_id()), pairing); 110 EXPECT_EQ(delegate->Load(pairing.client_id()), pairing);
111 111
112 // Strip the delegate from write access and validate that it still can be used 112 // Strip the delegate from write access and validate that it still can be used
113 // to read the pairings. 113 // to read the pairings.
114 delegate.reset(new PairingRegistryDelegateWin()); 114 delegate.reset(new PairingRegistryDelegateWin());
115 delegate->SetRootKeys(nullptr, unprivileged_.Handle()); 115 delegate->SetRootKeys(nullptr, unprivileged_.Handle());
116 116
117 PairingRegistry::Pairing unprivileged_pairing = 117 PairingRegistry::Pairing unprivileged_pairing =
118 delegate->Load(pairing.client_id()); 118 delegate->Load(pairing.client_id());
119 EXPECT_EQ(pairing.client_id(), unprivileged_pairing.client_id()); 119 EXPECT_EQ(pairing.client_id(), unprivileged_pairing.client_id());
120 EXPECT_EQ(pairing.client_name(), unprivileged_pairing.client_name()); 120 EXPECT_EQ(pairing.client_name(), unprivileged_pairing.client_name());
121 EXPECT_EQ(pairing.created_time(), unprivileged_pairing.created_time()); 121 EXPECT_EQ(pairing.created_time(), unprivileged_pairing.created_time());
122 122
123 // Verify that the shared secret if not available. 123 // Verify that the shared secret if not available.
124 EXPECT_TRUE(unprivileged_pairing.shared_secret().empty()); 124 EXPECT_TRUE(unprivileged_pairing.shared_secret().empty());
125 125
126 // Verify that a pairing cannot be saved. 126 // Verify that a pairing cannot be saved.
127 EXPECT_FALSE(delegate->Save(pairing)); 127 EXPECT_FALSE(delegate->Save(pairing));
128 } 128 }
129 129
130 } // namespace remoting 130 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/pairing_registry_delegate_win.cc ('k') | remoting/host/pam_authorization_factory_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698