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

Side by Side Diff: remoting/host/gcd_rest_client_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
« no previous file with comments | « remoting/host/gcd_rest_client.cc ('k') | remoting/host/gcd_state_updater.h » ('j') | 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/host/gcd_rest_client.h" 5 #include "remoting/host/gcd_rest_client.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/test/simple_test_clock.h" 9 #include "base/test/simple_test_clock.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "net/url_request/test_url_fetcher_factory.h" 11 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "remoting/host/fake_oauth_token_getter.h" 12 #include "remoting/host/fake_oauth_token_getter.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace remoting { 15 namespace remoting {
15 16
16 class GcdRestClientTest : public testing::Test { 17 class GcdRestClientTest : public testing::Test {
17 public: 18 public:
18 GcdRestClientTest() 19 GcdRestClientTest()
19 : default_token_getter_(OAuthTokenGetter::SUCCESS, 20 : default_token_getter_(OAuthTokenGetter::SUCCESS,
20 "<fake_user_email>", 21 "<fake_user_email>",
21 "<fake_access_token>") {} 22 "<fake_access_token>") {}
22 23
23 void OnRequestComplete(GcdRestClient::Result result) { 24 void OnRequestComplete(GcdRestClient::Result result) {
24 ++counter_; 25 ++counter_;
25 last_result_ = result; 26 last_result_ = result;
26 } 27 }
27 28
28 scoped_ptr<base::DictionaryValue> MakePatchDetails(int id) { 29 std::unique_ptr<base::DictionaryValue> MakePatchDetails(int id) {
29 scoped_ptr<base::DictionaryValue> patch_details(new base::DictionaryValue); 30 std::unique_ptr<base::DictionaryValue> patch_details(
31 new base::DictionaryValue);
30 patch_details->SetInteger("id", id); 32 patch_details->SetInteger("id", id);
31 return patch_details; 33 return patch_details;
32 } 34 }
33 35
34 void CreateClient(OAuthTokenGetter* token_getter = nullptr) { 36 void CreateClient(OAuthTokenGetter* token_getter = nullptr) {
35 if (!token_getter) { 37 if (!token_getter) {
36 token_getter = &default_token_getter_; 38 token_getter = &default_token_getter_;
37 } 39 }
38 client_.reset(new GcdRestClient("http://gcd_base_url", "<gcd_device_id>", 40 client_.reset(new GcdRestClient("http://gcd_base_url", "<gcd_device_id>",
39 nullptr, token_getter)); 41 nullptr, token_getter));
40 client_->SetClockForTest(make_scoped_ptr(new base::SimpleTestClock)); 42 client_->SetClockForTest(base::WrapUnique(new base::SimpleTestClock));
41 } 43 }
42 44
43 protected: 45 protected:
44 net::TestURLFetcherFactory url_fetcher_factory_; 46 net::TestURLFetcherFactory url_fetcher_factory_;
45 FakeOAuthTokenGetter default_token_getter_; 47 FakeOAuthTokenGetter default_token_getter_;
46 scoped_ptr<GcdRestClient> client_; 48 std::unique_ptr<GcdRestClient> client_;
47 int counter_ = 0; 49 int counter_ = 0;
48 GcdRestClient::Result last_result_ = GcdRestClient::OTHER_ERROR; 50 GcdRestClient::Result last_result_ = GcdRestClient::OTHER_ERROR;
49 51
50 private: 52 private:
51 base::MessageLoop message_loop_; 53 base::MessageLoop message_loop_;
52 }; 54 };
53 55
54 TEST_F(GcdRestClientTest, NetworkErrorGettingToken) { 56 TEST_F(GcdRestClientTest, NetworkErrorGettingToken) {
55 FakeOAuthTokenGetter token_getter(OAuthTokenGetter::NETWORK_ERROR, "", ""); 57 FakeOAuthTokenGetter token_getter(OAuthTokenGetter::NETWORK_ERROR, "", "");
56 CreateClient(&token_getter); 58 CreateClient(&token_getter);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 "\"requestTimeMs\":0.0}", 148 "\"requestTimeMs\":0.0}",
147 fetcher->upload_data()); 149 fetcher->upload_data());
148 EXPECT_EQ("application/json", fetcher->upload_content_type()); 150 EXPECT_EQ("application/json", fetcher->upload_content_type());
149 fetcher->set_response_code(200); 151 fetcher->set_response_code(200);
150 fetcher->delegate()->OnURLFetchComplete(fetcher); 152 fetcher->delegate()->OnURLFetchComplete(fetcher);
151 EXPECT_EQ(1, counter_); 153 EXPECT_EQ(1, counter_);
152 EXPECT_EQ(GcdRestClient::SUCCESS, last_result_); 154 EXPECT_EQ(GcdRestClient::SUCCESS, last_result_);
153 } 155 }
154 156
155 } // namespace remoting 157 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/gcd_rest_client.cc ('k') | remoting/host/gcd_state_updater.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698