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

Side by Side Diff: google_apis/drive/test_util.cc

Issue 1873663002: Convert //google_apis from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "google_apis/drive/test_util.h" 5 #include "google_apis/drive/test_util.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (size == 0) { 70 if (size == 0) {
71 // Note: RandBytesAsString doesn't support generating an empty string. 71 // Note: RandBytesAsString doesn't support generating an empty string.
72 data->clear(); 72 data->clear();
73 return true; 73 return true;
74 } 74 }
75 75
76 *data = base::RandBytesAsString(size); 76 *data = base::RandBytesAsString(size);
77 return WriteStringToFile(*path, *data); 77 return WriteStringToFile(*path, *data);
78 } 78 }
79 79
80 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { 80 std::unique_ptr<base::Value> LoadJSONFile(const std::string& relative_path) {
81 base::FilePath path = GetTestFilePath(relative_path); 81 base::FilePath path = GetTestFilePath(relative_path);
82 82
83 std::string error; 83 std::string error;
84 JSONFileValueDeserializer deserializer(path); 84 JSONFileValueDeserializer deserializer(path);
85 scoped_ptr<base::Value> value = deserializer.Deserialize(NULL, &error); 85 std::unique_ptr<base::Value> value = deserializer.Deserialize(NULL, &error);
86 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() 86 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value()
87 << ": " << error; 87 << ": " << error;
88 return value; 88 return value;
89 } 89 }
90 90
91 // Returns a HttpResponse created from the given file path. 91 // Returns a HttpResponse created from the given file path.
92 scoped_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile( 92 std::unique_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile(
93 const base::FilePath& file_path) { 93 const base::FilePath& file_path) {
94 std::string content; 94 std::string content;
95 if (!base::ReadFileToString(file_path, &content)) 95 if (!base::ReadFileToString(file_path, &content))
96 return scoped_ptr<net::test_server::BasicHttpResponse>(); 96 return std::unique_ptr<net::test_server::BasicHttpResponse>();
97 97
98 std::string content_type = "text/plain"; 98 std::string content_type = "text/plain";
99 if (base::EndsWith(file_path.AsUTF8Unsafe(), ".json", 99 if (base::EndsWith(file_path.AsUTF8Unsafe(), ".json",
100 base::CompareCase::SENSITIVE)) 100 base::CompareCase::SENSITIVE))
101 content_type = "application/json"; 101 content_type = "application/json";
102 102
103 scoped_ptr<net::test_server::BasicHttpResponse> http_response( 103 std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
104 new net::test_server::BasicHttpResponse); 104 new net::test_server::BasicHttpResponse);
105 http_response->set_code(net::HTTP_OK); 105 http_response->set_code(net::HTTP_OK);
106 http_response->set_content(content); 106 http_response->set_content(content);
107 http_response->set_content_type(content_type); 107 http_response->set_content_type(content_type);
108 return http_response; 108 return http_response;
109 } 109 }
110 110
111 scoped_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest( 111 std::unique_ptr<net::test_server::HttpResponse> HandleDownloadFileRequest(
112 const GURL& base_url, 112 const GURL& base_url,
113 net::test_server::HttpRequest* out_request, 113 net::test_server::HttpRequest* out_request,
114 const net::test_server::HttpRequest& request) { 114 const net::test_server::HttpRequest& request) {
115 *out_request = request; 115 *out_request = request;
116 116
117 GURL absolute_url = base_url.Resolve(request.relative_url); 117 GURL absolute_url = base_url.Resolve(request.relative_url);
118 std::string remaining_path; 118 std::string remaining_path;
119 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path)) 119 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path))
120 return scoped_ptr<net::test_server::HttpResponse>(); 120 return std::unique_ptr<net::test_server::HttpResponse>();
121 return CreateHttpResponseFromFile(GetTestFilePath(remaining_path)); 121 return CreateHttpResponseFromFile(GetTestFilePath(remaining_path));
122 } 122 }
123 123
124 bool ParseContentRangeHeader(const std::string& value, 124 bool ParseContentRangeHeader(const std::string& value,
125 int64_t* start_position, 125 int64_t* start_position,
126 int64_t* end_position, 126 int64_t* end_position,
127 int64_t* length) { 127 int64_t* length) {
128 DCHECK(start_position); 128 DCHECK(start_position);
129 DCHECK(end_position); 129 DCHECK(end_position);
130 DCHECK(length); 130 DCHECK(length);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 std::string TestGetContentCallback::GetConcatenatedData() const { 167 std::string TestGetContentCallback::GetConcatenatedData() const {
168 std::string result; 168 std::string result;
169 for (size_t i = 0; i < data_.size(); ++i) { 169 for (size_t i = 0; i < data_.size(); ++i) {
170 result += *data_[i]; 170 result += *data_[i];
171 } 171 }
172 return result; 172 return result;
173 } 173 }
174 174
175 void TestGetContentCallback::OnGetContent(google_apis::DriveApiErrorCode error, 175 void TestGetContentCallback::OnGetContent(google_apis::DriveApiErrorCode error,
176 scoped_ptr<std::string> data) { 176 std::unique_ptr<std::string> data) {
177 data_.push_back(data.release()); 177 data_.push_back(data.release());
178 } 178 }
179 179
180 } // namespace test_util 180 } // namespace test_util
181 } // namespace google_apis 181 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698