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

Side by Side Diff: remoting/test/chromoting_test_driver_environment_unittest.cc

Issue 1864433005: Fixing the Chromoting Test Driver host online retry logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up HostInfo creation in the unit tests. 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
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/test/chromoting_test_driver_environment.h" 5 #include "remoting/test/chromoting_test_driver_environment.h"
6 6
7 #include <string>
8 #include <utility>
9
7 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
8 #include "base/macros.h" 11 #include "base/macros.h"
9 #include "remoting/test/fake_access_token_fetcher.h" 12 #include "remoting/test/fake_access_token_fetcher.h"
10 #include "remoting/test/fake_host_list_fetcher.h" 13 #include "remoting/test/fake_host_list_fetcher.h"
11 #include "remoting/test/fake_refresh_token_store.h" 14 #include "remoting/test/fake_refresh_token_store.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 16
14 namespace { 17 namespace {
15 const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv"; 18 const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv";
16 const char kUserNameValue[] = "remoting_user@gmail.com"; 19 const char kUserNameValue[] = "remoting_user@gmail.com";
(...skipping 14 matching lines...) Expand all
31 34
32 class ChromotingTestDriverEnvironmentTest : public ::testing::Test { 35 class ChromotingTestDriverEnvironmentTest : public ::testing::Test {
33 public: 36 public:
34 ChromotingTestDriverEnvironmentTest(); 37 ChromotingTestDriverEnvironmentTest();
35 ~ChromotingTestDriverEnvironmentTest() override; 38 ~ChromotingTestDriverEnvironmentTest() override;
36 39
37 protected: 40 protected:
38 // testing::Test interface. 41 // testing::Test interface.
39 void SetUp() override; 42 void SetUp() override;
40 43
44 // Helper method which has access to private method in class under test.
45 bool RefreshHostList();
46
47 HostInfo CreateFakeHostInfo();
48
41 FakeAccessTokenFetcher fake_access_token_fetcher_; 49 FakeAccessTokenFetcher fake_access_token_fetcher_;
42 FakeRefreshTokenStore fake_token_store_; 50 FakeRefreshTokenStore fake_token_store_;
43 FakeHostListFetcher fake_host_list_fetcher_; 51 FakeHostListFetcher fake_host_list_fetcher_;
44 52
45 scoped_ptr<ChromotingTestDriverEnvironment> environment_object_; 53 scoped_ptr<ChromotingTestDriverEnvironment> environment_object_;
46 54
47 private: 55 private:
48 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironmentTest); 56 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironmentTest);
49 }; 57 };
50 58
51 ChromotingTestDriverEnvironmentTest::ChromotingTestDriverEnvironmentTest() { 59 ChromotingTestDriverEnvironmentTest::ChromotingTestDriverEnvironmentTest() {
52 } 60 }
53 61
54 ChromotingTestDriverEnvironmentTest::~ChromotingTestDriverEnvironmentTest() { 62 ChromotingTestDriverEnvironmentTest::~ChromotingTestDriverEnvironmentTest() {
55 } 63 }
56 64
57 void ChromotingTestDriverEnvironmentTest::SetUp() { 65 void ChromotingTestDriverEnvironmentTest::SetUp() {
58 ChromotingTestDriverEnvironment::EnvironmentOptions options; 66 ChromotingTestDriverEnvironment::EnvironmentOptions options;
59 options.user_name = kUserNameValue; 67 options.user_name = kUserNameValue;
60 options.host_name = kHostNameValue; 68 options.host_name = kHostNameValue;
61 69
62 environment_object_.reset(new ChromotingTestDriverEnvironment(options)); 70 environment_object_.reset(new ChromotingTestDriverEnvironment(options));
63 71
64 std::vector<HostInfo> fake_host_list; 72 std::vector<HostInfo> fake_host_list;
65 HostInfo fake_host; 73 fake_host_list.push_back(CreateFakeHostInfo());
66 fake_host.host_id = kFakeHostIdValue;
67 fake_host.host_jid = kFakeHostJidValue;
68 fake_host.host_name = kFakeHostNameValue;
69 fake_host.offline_reason = kFakeHostOfflineReasonValue;
70 fake_host.public_key = kFakeHostPublicKeyValue;
71 fake_host.status = kHostStatusOnline;
72 fake_host.token_url_patterns.push_back(kFakeHostFirstTokenUrlValue);
73 fake_host.token_url_patterns.push_back(kFakeHostSecondTokenUrlValue);
74 fake_host.token_url_patterns.push_back(kFakeHostThirdTokenUrlValue);
75 fake_host_list.push_back(fake_host);
76 74
77 fake_host_list_fetcher_.set_retrieved_host_list(fake_host_list); 75 fake_host_list_fetcher_.set_retrieved_host_list(fake_host_list);
78 76
79 environment_object_->SetAccessTokenFetcherForTest( 77 environment_object_->SetAccessTokenFetcherForTest(
80 &fake_access_token_fetcher_); 78 &fake_access_token_fetcher_);
81 environment_object_->SetRefreshTokenStoreForTest(&fake_token_store_); 79 environment_object_->SetRefreshTokenStoreForTest(&fake_token_store_);
82 environment_object_->SetHostListFetcherForTest(&fake_host_list_fetcher_); 80 environment_object_->SetHostListFetcherForTest(&fake_host_list_fetcher_);
83 } 81 }
84 82
83 bool ChromotingTestDriverEnvironmentTest::RefreshHostList() {
84 return environment_object_->RefreshHostList();
85 }
86
87 HostInfo ChromotingTestDriverEnvironmentTest::CreateFakeHostInfo() {
88 HostInfo host_info;
89 host_info.host_id = kFakeHostIdValue;
90 host_info.host_jid = kFakeHostJidValue;
91 host_info.host_name = kFakeHostNameValue;
92 host_info.offline_reason = kFakeHostOfflineReasonValue;
93 host_info.public_key = kFakeHostPublicKeyValue;
94 host_info.status = kHostStatusOnline;
95 host_info.token_url_patterns.push_back(kFakeHostFirstTokenUrlValue);
96 host_info.token_url_patterns.push_back(kFakeHostSecondTokenUrlValue);
97 host_info.token_url_patterns.push_back(kFakeHostThirdTokenUrlValue);
98
99 return host_info;
100 }
101
85 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithAuthCode) { 102 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithAuthCode) {
86 // Pass in an auth code to initialize the environment. 103 // Pass in an auth code to initialize the environment.
87 EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue)); 104 EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
88 105
89 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); 106 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
90 EXPECT_EQ(fake_token_store_.stored_refresh_token_value(), 107 EXPECT_EQ(fake_token_store_.stored_refresh_token_value(),
91 kFakeAccessTokenFetcherRefreshTokenValue); 108 kFakeAccessTokenFetcherRefreshTokenValue);
92 109
93 EXPECT_EQ(environment_object_->user_name(), kUserNameValue); 110 EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
94 EXPECT_EQ(environment_object_->host_name(), kHostNameValue); 111 EXPECT_EQ(environment_object_->host_name(), kHostNameValue);
95 EXPECT_EQ(environment_object_->access_token(), 112 EXPECT_EQ(environment_object_->access_token(),
96 kFakeAccessTokenFetcherAccessTokenValue); 113 kFakeAccessTokenFetcherAccessTokenValue);
114 EXPECT_EQ(environment_object_->host_list().size(), 0u);
115
116 // Now Retrieve the host list.
117 EXPECT_TRUE(environment_object_->WaitForHostOnline(kFakeHostJidValue,
118 kFakeHostNameValue));
97 119
98 // Should only have one host in the list. 120 // Should only have one host in the list.
99 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize); 121 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize);
100 HostInfo fake_host = environment_object_->host_list().at(0); 122 HostInfo fake_host = environment_object_->host_list().at(0);
101 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue); 123 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue);
102 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue); 124 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue);
103 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue); 125 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue);
104 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue); 126 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue);
105 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue); 127 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue);
106 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue); 128 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue);
(...skipping 14 matching lines...) Expand all
121 143
122 // We should not write the refresh token a second time if we read from the 144 // We should not write the refresh token a second time if we read from the
123 // disk originally. 145 // disk originally.
124 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted()); 146 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
125 147
126 // Verify the object was initialized correctly. 148 // Verify the object was initialized correctly.
127 EXPECT_EQ(environment_object_->user_name(), kUserNameValue); 149 EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
128 EXPECT_EQ(environment_object_->host_name(), kHostNameValue); 150 EXPECT_EQ(environment_object_->host_name(), kHostNameValue);
129 EXPECT_EQ(environment_object_->access_token(), 151 EXPECT_EQ(environment_object_->access_token(),
130 kFakeAccessTokenFetcherAccessTokenValue); 152 kFakeAccessTokenFetcherAccessTokenValue);
153 EXPECT_EQ(environment_object_->host_list().size(), 0u);
154
155 // Now Retrieve the host list.
156 EXPECT_TRUE(environment_object_->WaitForHostOnline(kFakeHostJidValue,
157 kFakeHostNameValue));
131 158
132 // Should only have one host in the list. 159 // Should only have one host in the list.
133 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize); 160 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize);
161
134 HostInfo fake_host = environment_object_->host_list().at(0); 162 HostInfo fake_host = environment_object_->host_list().at(0);
135 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue); 163 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue);
136 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue); 164 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue);
137 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue); 165 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue);
138 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue); 166 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue);
139 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue); 167 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue);
140 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue); 168 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue);
141 EXPECT_EQ(fake_host.token_url_patterns.at(2), kFakeHostThirdTokenUrlValue); 169 EXPECT_EQ(fake_host.token_url_patterns.at(2), kFakeHostThirdTokenUrlValue);
142 } 170 }
143 171
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 fake_token_store_.set_refresh_token_write_succeeded(false); 204 fake_token_store_.set_refresh_token_write_succeeded(false);
177 205
178 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue)); 206 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
179 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); 207 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
180 } 208 }
181 209
182 TEST_F(ChromotingTestDriverEnvironmentTest, HostListEmptyFromDirectory) { 210 TEST_F(ChromotingTestDriverEnvironmentTest, HostListEmptyFromDirectory) {
183 // Set the host list fetcher to return an empty list. 211 // Set the host list fetcher to return an empty list.
184 fake_host_list_fetcher_.set_retrieved_host_list(std::vector<HostInfo>()); 212 fake_host_list_fetcher_.set_retrieved_host_list(std::vector<HostInfo>());
185 213
186 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue)); 214 EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
187 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); 215 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
188 } 216 }
189 217
218 TEST_F(ChromotingTestDriverEnvironmentTest, RefreshHostList_HostOnline) {
219 EXPECT_TRUE(environment_object_->Initialize(std::string()));
220 environment_object_->SetHostNameForTest(kFakeHostNameValue);
221 environment_object_->SetHostJidForTest(kFakeHostJidValue);
222 EXPECT_TRUE(RefreshHostList());
223 EXPECT_TRUE(environment_object_->host_info().IsReadyForConnection());
224 }
225
226 TEST_F(ChromotingTestDriverEnvironmentTest,
227 RefreshHostList_HostOnline_NoJidPassed) {
228 EXPECT_TRUE(environment_object_->Initialize(std::string()));
229
230 environment_object_->SetHostNameForTest(kFakeHostNameValue);
231 environment_object_->SetHostJidForTest(std::string());
232 EXPECT_TRUE(RefreshHostList());
233 EXPECT_TRUE(environment_object_->host_info().IsReadyForConnection());
234 }
235
236 TEST_F(ChromotingTestDriverEnvironmentTest, RefreshHostList_NameMismatch) {
237 EXPECT_TRUE(environment_object_->Initialize(std::string()));
238
239 environment_object_->SetHostNameForTest("Ficticious_host");
240 environment_object_->SetHostJidForTest(kFakeHostJidValue);
241 EXPECT_FALSE(RefreshHostList());
242 EXPECT_FALSE(environment_object_->host_info().IsReadyForConnection());
243 }
244
245 TEST_F(ChromotingTestDriverEnvironmentTest, RefreshHostList_JidMismatch) {
246 EXPECT_TRUE(environment_object_->Initialize(std::string()));
247
248 environment_object_->SetHostNameForTest(kFakeHostNameValue);
249 environment_object_->SetHostJidForTest("Ficticious_jid");
250 EXPECT_FALSE(RefreshHostList());
251 EXPECT_FALSE(environment_object_->host_info().IsReadyForConnection());
252 }
253
254 TEST_F(ChromotingTestDriverEnvironmentTest, RefreshHostList_HostOffline) {
255 EXPECT_TRUE(environment_object_->Initialize(std::string()));
256
257 HostInfo fake_host(CreateFakeHostInfo());
258 fake_host.status = kHostStatusOffline;
259
260 std::vector<HostInfo> fake_host_list(1, fake_host);
261 fake_host_list_fetcher_.set_retrieved_host_list(fake_host_list);
262
263 environment_object_->SetHostNameForTest(kFakeHostNameValue);
264 environment_object_->SetHostJidForTest(kFakeHostJidValue);
265 EXPECT_FALSE(RefreshHostList());
266 EXPECT_FALSE(environment_object_->host_info().IsReadyForConnection());
267 }
268
269 TEST_F(ChromotingTestDriverEnvironmentTest, RefreshHostList_HostListEmpty) {
270 EXPECT_TRUE(environment_object_->Initialize(std::string()));
271
272 // Set the host list fetcher to return an empty list.
273 fake_host_list_fetcher_.set_retrieved_host_list(std::vector<HostInfo>());
274 environment_object_->SetHostNameForTest(kFakeHostNameValue);
275 environment_object_->SetHostJidForTest(kFakeHostJidValue);
276 EXPECT_FALSE(RefreshHostList());
277 EXPECT_FALSE(environment_object_->host_info().IsReadyForConnection());
278 }
279
190 } // namespace test 280 } // namespace test
191 } // namespace remoting 281 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698