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

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

Issue 1237883002: Added chromoting test environment for the tests to share data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittest, display connection stats ability, and error check for transition delay. Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/test/chromoting_test_driver_environment.h"
6
7 #include "base/files/file_path.h"
8 #include "remoting/test/fake_access_token_fetcher.h"
9 #include "remoting/test/fake_host_list_fetcher.h"
10 #include "remoting/test/fake_refresh_token_store.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14 const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv";
15 const char kUserNameValue[] = "remoting_user@gmail.com";
16 const char kHostNameValue[] = "remote_host_name";
17 const char kFakeHostNameValue[] = "fake_host_name";
18 const char kFakeHostIdValue[] = "fake_host_id";
19 const char kFakeHostJidValue[] = "fake_host_jid";
20 const char kFakeHostOfflineReasonValue[] = "fake_offline_reason";
21 const char kFakeHostPublicKeyValue[] = "fake_public_key";
22 const char kFakeHostFirstTokenUrlValue[] = "token_url_1";
23 const char kFakeHostSecondTokenUrlValue[] = "token_url_2";
24 const char kFakeHostThirdTokenUrlValue[] = "token_url_3";
25 const unsigned int kExpectedHostListSize = 1;
26 } // namespace
27
28 namespace remoting {
29 namespace test {
30
31 class ChromotingTestDriverEnvironmentTest : public ::testing::Test {
32 public:
33 ChromotingTestDriverEnvironmentTest();
34 ~ChromotingTestDriverEnvironmentTest() override;
35
36 protected:
37 // testing::Test interface.
38 void SetUp() override;
39
40 FakeAccessTokenFetcher fake_access_token_fetcher_;
41 FakeRefreshTokenStore fake_token_store_;
42 FakeHostListFetcher fake_host_list_fetcher_;
43
44 scoped_ptr<ChromotingTestDriverEnvironment> environment_object_;
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironmentTest);
48 };
49
50 ChromotingTestDriverEnvironmentTest::ChromotingTestDriverEnvironmentTest() {
51 }
52
53 ChromotingTestDriverEnvironmentTest::~ChromotingTestDriverEnvironmentTest() {
54 }
55
56 void ChromotingTestDriverEnvironmentTest::SetUp() {
57 ChromotingTestDriverEnvironment::EnvironmentOptions options;
58 options.user_name = kUserNameValue;
59 options.host_name = kHostNameValue;
60
61 environment_object_.reset(new ChromotingTestDriverEnvironment(options));
62
63 std::vector<HostInfo> fake_host_list;
64 HostInfo fake_host;
65 fake_host.host_id = kFakeHostIdValue;
66 fake_host.host_jid = kFakeHostJidValue;
67 fake_host.host_name = kFakeHostNameValue;
68 fake_host.offline_reason = kFakeHostOfflineReasonValue;
69 fake_host.public_key = kFakeHostPublicKeyValue;
70 fake_host.token_url_patterns.push_back(kFakeHostFirstTokenUrlValue);
71 fake_host.token_url_patterns.push_back(kFakeHostSecondTokenUrlValue);
72 fake_host.token_url_patterns.push_back(kFakeHostThirdTokenUrlValue);
73 fake_host_list.push_back(fake_host);
74
75 fake_host_list_fetcher_.set_retrieved_host_list(fake_host_list);
76
77 environment_object_->SetAccessTokenFetcherForTest(
78 &fake_access_token_fetcher_);
79 environment_object_->SetRefreshTokenStoreForTest(&fake_token_store_);
80 environment_object_->SetHostListFetcherForTest(&fake_host_list_fetcher_);
81 }
82
83 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithAuthCode) {
84 // Pass in an auth code to initialize the environment.
85 EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
86
87 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
88 EXPECT_EQ(fake_token_store_.stored_refresh_token_value(),
89 kFakeAccessTokenFetcherRefreshTokenValue);
90
91 EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
92 EXPECT_EQ(environment_object_->host_name(), kHostNameValue);
93 EXPECT_EQ(environment_object_->access_token(),
94 kFakeAccessTokenFetcherAccessTokenValue);
95
96 // Should only have one host in the list.
97 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize);
98 HostInfo fake_host = environment_object_->host_list().at(0);
99 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue);
100 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue);
101 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue);
102 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue);
103 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue);
104 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue);
105 EXPECT_EQ(fake_host.token_url_patterns.at(2), kFakeHostThirdTokenUrlValue);
106 }
107
108 TEST_F(ChromotingTestDriverEnvironmentTest,
109 InitializeObjectWithAuthCodeFailed) {
110 fake_access_token_fetcher_.set_fail_access_token_from_auth_code(true);
111
112 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
113 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
114 }
115
116 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithRefreshToken) {
117 // Pass in an empty auth code since we are using a refresh token.
118 EXPECT_TRUE(environment_object_->Initialize(std::string()));
119
120 // We should not write the refresh token a second time if we read from the
121 // disk originally.
122 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
123
124 // Verify the object was initialized correctly.
125 EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
126 EXPECT_EQ(environment_object_->host_name(), kHostNameValue);
127 EXPECT_EQ(environment_object_->access_token(),
128 kFakeAccessTokenFetcherAccessTokenValue);
129
130 // Should only have one host in the list.
131 EXPECT_EQ(environment_object_->host_list().size(), kExpectedHostListSize);
132 HostInfo fake_host = environment_object_->host_list().at(0);
133 EXPECT_EQ(fake_host.host_id, kFakeHostIdValue);
134 EXPECT_EQ(fake_host.host_jid, kFakeHostJidValue);
135 EXPECT_EQ(fake_host.host_name, kFakeHostNameValue);
136 EXPECT_EQ(fake_host.public_key, kFakeHostPublicKeyValue);
137 EXPECT_EQ(fake_host.token_url_patterns.at(0), kFakeHostFirstTokenUrlValue);
138 EXPECT_EQ(fake_host.token_url_patterns.at(1), kFakeHostSecondTokenUrlValue);
139 EXPECT_EQ(fake_host.token_url_patterns.at(2), kFakeHostThirdTokenUrlValue);
140 }
141
142 TEST_F(ChromotingTestDriverEnvironmentTest,
143 InitializeObjectWithRefreshTokenFailed) {
144 fake_access_token_fetcher_.set_fail_access_token_from_refresh_token(true);
145
146 // Pass in an empty auth code since we are using a refresh token.
147 EXPECT_FALSE(environment_object_->Initialize(std::string()));
148 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
149 }
150
151 TEST_F(ChromotingTestDriverEnvironmentTest, TearDownAfterInitializeSucceeds) {
152 // Pass in an empty auth code since we are using a refresh token.
153 EXPECT_TRUE(environment_object_->Initialize(std::string()));
154
155 // Note: We are using a static cast here because the TearDown() method is
156 // private as it is an interface method that we only want to call
157 // directly in tests or by the GTEST framework.
158 static_cast<testing::Environment*>(environment_object_.get())->TearDown();
159 }
160
161 TEST_F(ChromotingTestDriverEnvironmentTest,
162 InitializeObjectNoAuthCodeOrRefreshToken) {
163 // Clear out the 'stored' refresh token value.
164 fake_token_store_.set_refresh_token_value(std::string());
165
166 // With no auth code or refresh token, then the initialization should fail.
167 EXPECT_FALSE(environment_object_->Initialize(std::string()));
168 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
169 }
170
171 TEST_F(ChromotingTestDriverEnvironmentTest,
172 InitializeObjectWithAuthCodeWriteFailed) {
173 // Simulate a failure writing the token to the disk.
174 fake_token_store_.set_refresh_token_write_succeeded(false);
175
176 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
177 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
178 }
179
180 TEST_F(ChromotingTestDriverEnvironmentTest, HostListEmptyFromDirectory) {
181 // Set the host list fetcher to return an empty list.
182 fake_host_list_fetcher_.set_retrieved_host_list(std::vector<HostInfo>());
183
184 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
185 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
186 }
187
188 } // namespace test
189 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.cc ('k') | remoting/test/fake_host_list_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698