Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <algorithm> | |
|
joedow
2015/07/16 03:00:38
I used algorithm for sorting the list of hosts to
tonychun
2015/07/16 18:46:53
Done.
| |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "remoting/test/fake_access_token_fetcher.h" | |
| 11 #include "remoting/test/fake_app_remoting_report_issue_request.h" | |
|
joedow
2015/07/16 03:00:38
Pretty sure you don't need this file...please remo
tonychun
2015/07/16 18:46:53
Done.
| |
| 12 #include "remoting/test/fake_host_list_fetcher.h" | |
| 13 #include "remoting/test/fake_refresh_token_store.h" | |
| 14 #include "remoting/test/refresh_token_store.h" | |
|
joedow
2015/07/16 03:00:38
I don't think this header is needed since you only
tonychun
2015/07/16 18:46:53
Done.
| |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace { | |
| 18 const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv"; | |
| 19 const char kUserNameValue[] = "remoting_user@gmail.com"; | |
| 20 const char kHostNameValue[] = "remote_host_name"; | |
| 21 const char kFakeHostNameValue[] = "fake_host_name"; | |
| 22 const char kFakeHostIdValue[] = "fake_host_id"; | |
| 23 const char kFakeHostJidValue[] = "fake_host_jid"; | |
| 24 const char kFakeHostOfflineReasonValue[] = "fake_offline_reason"; | |
| 25 const char kFakeHostPublicKeyValue[] = "fake_public_key"; | |
| 26 const char kFakeHostFirstTokenUrlValue[] = "token_url_1"; | |
| 27 const char kFakeHostSecondTokenUrlValue[] = "token_url_2"; | |
| 28 const char kFakeHostThirdTokenUrlValue[] = "token_url_3"; | |
| 29 } // namespace | |
| 30 | |
| 31 namespace remoting { | |
| 32 namespace test { | |
| 33 | |
| 34 class ChromotingTestDriverEnvironmentTest : public ::testing::Test { | |
| 35 public: | |
| 36 ChromotingTestDriverEnvironmentTest(); | |
| 37 ~ChromotingTestDriverEnvironmentTest() override; | |
| 38 | |
| 39 protected: | |
| 40 // testing::Test interface. | |
| 41 void SetUp() override; | |
| 42 | |
| 43 FakeAccessTokenFetcher fake_access_token_fetcher_; | |
| 44 FakeRefreshTokenStore fake_token_store_; | |
| 45 FakeHostListFetcher fake_host_list_fetcher_; | |
| 46 | |
| 47 scoped_ptr<ChromotingTestDriverEnvironment> environment_object_; | |
| 48 | |
| 49 private: | |
| 50 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironmentTest); | |
| 51 }; | |
| 52 | |
| 53 void ChromotingTestDriverEnvironmentTest::SetUp() { | |
| 54 ChromotingTestDriverEnvironment::EnvironmentOptions options; | |
| 55 options.user_name = kUserNameValue; | |
| 56 options.host_name = kHostNameValue; | |
| 57 | |
| 58 environment_object_.reset(new ChromotingTestDriverEnvironment(options)); | |
| 59 | |
| 60 std::vector<HostInfo> fake_host_list; | |
| 61 HostInfo fake_host; | |
| 62 fake_host.host_id = kFakeHostIdValue; | |
| 63 fake_host.host_jid = kFakeHostJidValue; | |
| 64 fake_host.host_name = kFakeHostNameValue; | |
| 65 fake_host.offline_reason = kFakeHostOfflineReasonValue; | |
| 66 fake_host.public_key = kFakeHostPublicKeyValue; | |
| 67 fake_host.token_url_patterns.push_back(kFakeHostFirstTokenUrlValue); | |
| 68 fake_host.token_url_patterns.push_back(kFakeHostSecondTokenUrlValue); | |
| 69 fake_host.token_url_patterns.push_back(kFakeHostThirdTokenUrlValue); | |
| 70 fake_host_list.push_back(fake_host); | |
| 71 | |
| 72 fake_host_list_fetcher_.set_retrieved_host_list(fake_host_list); | |
| 73 | |
| 74 environment_object_->SetAccessTokenFetcherForTest( | |
| 75 &fake_access_token_fetcher_); | |
| 76 environment_object_->SetRefreshTokenStoreForTest(&fake_token_store_); | |
| 77 environment_object_->SetHostListFetcherForTest(&fake_host_list_fetcher_); | |
| 78 } | |
| 79 | |
| 80 ChromotingTestDriverEnvironmentTest::ChromotingTestDriverEnvironmentTest() { | |
| 81 } | |
| 82 | |
| 83 ChromotingTestDriverEnvironmentTest::~ChromotingTestDriverEnvironmentTest() { | |
| 84 } | |
| 85 | |
| 86 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithAuthCode) { | |
| 87 EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue)); | |
|
joedow
2015/07/16 03:00:39
some newlines here would make this much more reada
tonychun
2015/07/16 18:46:53
Done.
| |
| 88 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); | |
| 89 EXPECT_EQ(fake_token_store_.stored_refresh_token_value(), | |
| 90 kFakeAccessTokenFetcherRefreshTokenValue); | |
| 91 EXPECT_EQ(environment_object_->user_name(), kUserNameValue); | |
| 92 EXPECT_EQ(environment_object_->host_name(), kHostNameValue); | |
| 93 EXPECT_FALSE(environment_object_->host_list().empty()); | |
|
joedow
2015/07/16 03:00:39
Should be validating that the data in the host_lis
tonychun
2015/07/16 18:46:53
Done.
| |
| 94 EXPECT_EQ(environment_object_->access_token(), | |
| 95 kFakeAccessTokenFetcherAccessTokenValue); | |
| 96 } | |
| 97 | |
| 98 TEST_F(ChromotingTestDriverEnvironmentTest, | |
| 99 InitializeObjectWithAuthCodeFailed) { | |
| 100 fake_access_token_fetcher_.set_fail_access_token_from_auth_code(true); | |
| 101 | |
| 102 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue)); | |
| 103 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted()); | |
| 104 } | |
| 105 | |
| 106 TEST_F(ChromotingTestDriverEnvironmentTest, InitializeObjectWithRefreshToken) { | |
| 107 // Pass in an empty auth code since we are using a refresh token. | |
| 108 EXPECT_TRUE(environment_object_->Initialize(std::string())); | |
| 109 | |
| 110 // We should not write the refresh token a second time if we read from the | |
| 111 // disk originally. | |
| 112 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted()); | |
| 113 | |
| 114 // Verify the object was initialized correctly. | |
| 115 EXPECT_EQ(environment_object_->user_name(), kUserNameValue); | |
| 116 EXPECT_EQ(environment_object_->host_name(), kHostNameValue); | |
| 117 EXPECT_FALSE(environment_object_->host_list().empty()); | |
| 118 EXPECT_EQ(environment_object_->access_token(), | |
| 119 kFakeAccessTokenFetcherAccessTokenValue); | |
| 120 } | |
| 121 | |
| 122 TEST_F(ChromotingTestDriverEnvironmentTest, | |
| 123 InitializeObjectWithRefreshTokenFailed) { | |
| 124 fake_access_token_fetcher_.set_fail_access_token_from_refresh_token(true); | |
| 125 | |
| 126 // Pass in an empty auth code since we are using a refresh token. | |
| 127 EXPECT_FALSE(environment_object_->Initialize(std::string())); | |
| 128 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted()); | |
| 129 } | |
| 130 | |
| 131 TEST_F(ChromotingTestDriverEnvironmentTest, TearDownAfterInitializeSucceeds) { | |
| 132 // Pass in an empty auth code since we are using a refresh token. | |
| 133 EXPECT_TRUE(environment_object_->Initialize(std::string())); | |
| 134 | |
| 135 // Note: We are using a static cast here because the TearDown() method is | |
| 136 // private as it is an interface method that we only want to call | |
| 137 // directly in tests or by the GTEST framework. | |
| 138 static_cast<testing::Environment*>(environment_object_.get())->TearDown(); | |
| 139 } | |
| 140 | |
| 141 TEST_F(ChromotingTestDriverEnvironmentTest, | |
| 142 InitializeObjectNoAuthCodeOrRefreshToken) { | |
| 143 // Clear out the 'stored' refresh token value. | |
| 144 fake_token_store_.set_refresh_token_value(std::string()); | |
| 145 | |
| 146 // With no auth code or refresh token, then the initialization should fail. | |
| 147 EXPECT_FALSE(environment_object_->Initialize(std::string())); | |
| 148 EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted()); | |
| 149 } | |
| 150 | |
| 151 TEST_F(ChromotingTestDriverEnvironmentTest, | |
| 152 InitializeObjectWithAuthCodeWriteFailed) { | |
| 153 // Simulate a failure writing the token to the disk. | |
| 154 fake_token_store_.set_refresh_token_write_succeeded(false); | |
| 155 | |
| 156 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue)); | |
| 157 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); | |
| 158 } | |
| 159 | |
| 160 TEST_F(ChromotingTestDriverEnvironmentTest, HostListEmptyFromDirectory) { | |
| 161 // Set the host list fetcher to return an empty list. | |
| 162 fake_host_list_fetcher_.set_retrieved_host_list(std::vector<HostInfo>()); | |
| 163 | |
| 164 EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue)); | |
| 165 EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted()); | |
| 166 } | |
| 167 | |
| 168 } // namespace test | |
| 169 } // namespace remoting | |
| OLD | NEW |