Commit 4d43c713 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Remove new usage in OAuth2ApiCallFlowTest.

Better document pointer ownership.

BUG=123762

Change-Id: I7be106bbf079ea2a30024e129d693ebe49454acf
Reviewed-on: https://chromium-review.googlesource.com/993236Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548466}
parent 02c5490c
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <utility>
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -39,6 +39,7 @@ using net::URLFetcherFactory; ...@@ -39,6 +39,7 @@ using net::URLFetcherFactory;
using net::URLRequestContextGetter; using net::URLRequestContextGetter;
using net::URLRequestStatus; using net::URLRequestStatus;
using testing::_; using testing::_;
using testing::ByMove;
using testing::Return; using testing::Return;
using testing::StrictMock; using testing::StrictMock;
...@@ -64,9 +65,9 @@ class MockUrlFetcherFactory : public ScopedURLFetcherFactory, ...@@ -64,9 +65,9 @@ class MockUrlFetcherFactory : public ScopedURLFetcherFactory,
} }
virtual ~MockUrlFetcherFactory() {} virtual ~MockUrlFetcherFactory() {}
MOCK_METHOD5( MOCK_METHOD5(CreateURLFetcherMock,
CreateURLFetcherMock, std::unique_ptr<URLFetcher>(
URLFetcher*(int id, int id,
const GURL& url, const GURL& url,
URLFetcher::RequestType request_type, URLFetcher::RequestType request_type,
URLFetcherDelegate* d, URLFetcherDelegate* d,
...@@ -78,8 +79,7 @@ class MockUrlFetcherFactory : public ScopedURLFetcherFactory, ...@@ -78,8 +79,7 @@ class MockUrlFetcherFactory : public ScopedURLFetcherFactory,
URLFetcher::RequestType request_type, URLFetcher::RequestType request_type,
URLFetcherDelegate* d, URLFetcherDelegate* d,
net::NetworkTrafficAnnotationTag traffic_annotation) override { net::NetworkTrafficAnnotationTag traffic_annotation) override {
return std::unique_ptr<URLFetcher>( return CreateURLFetcherMock(id, url, request_type, d, traffic_annotation);
CreateURLFetcherMock(id, url, request_type, d, traffic_annotation));
} }
}; };
...@@ -88,16 +88,13 @@ class MockApiCallFlow : public OAuth2ApiCallFlow { ...@@ -88,16 +88,13 @@ class MockApiCallFlow : public OAuth2ApiCallFlow {
MockApiCallFlow() {} MockApiCallFlow() {}
~MockApiCallFlow() {} ~MockApiCallFlow() {}
MOCK_METHOD0(CreateApiCallUrl, GURL ()); MOCK_METHOD0(CreateApiCallUrl, GURL());
MOCK_METHOD0(CreateApiCallBody, std::string ()); MOCK_METHOD0(CreateApiCallBody, std::string());
MOCK_METHOD1(ProcessApiCallSuccess, MOCK_METHOD1(ProcessApiCallSuccess, void(const URLFetcher* source));
void (const URLFetcher* source)); MOCK_METHOD1(ProcessApiCallFailure, void(const URLFetcher* source));
MOCK_METHOD1(ProcessApiCallFailure, MOCK_METHOD1(ProcessNewAccessToken, void(const std::string& access_token));
void (const URLFetcher* source));
MOCK_METHOD1(ProcessNewAccessToken,
void (const std::string& access_token));
MOCK_METHOD1(ProcessMintAccessTokenFailure, MOCK_METHOD1(ProcessMintAccessTokenFailure,
void (const GoogleServiceAuthError& error)); void(const GoogleServiceAuthError& error));
net::PartialNetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTag() { net::PartialNetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTag() {
return PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS; return PARTIAL_TRAFFIC_ANNOTATION_FOR_TESTS;
...@@ -109,13 +106,15 @@ class MockApiCallFlow : public OAuth2ApiCallFlow { ...@@ -109,13 +106,15 @@ class MockApiCallFlow : public OAuth2ApiCallFlow {
class OAuth2ApiCallFlowTest : public testing::Test { class OAuth2ApiCallFlowTest : public testing::Test {
protected: protected:
OAuth2ApiCallFlowTest() OAuth2ApiCallFlowTest()
: request_context_getter_(new net::TestURLRequestContextGetter( : request_context_getter_(
base::MakeRefCounted<net::TestURLRequestContextGetter>(
message_loop_.task_runner())) {} message_loop_.task_runner())) {}
TestURLFetcher* CreateURLFetcher( std::unique_ptr<TestURLFetcher> CreateURLFetcher(const GURL& url,
const GURL& url, bool fetch_succeeds, bool fetch_succeeds,
int response_code, const std::string& body) { int response_code,
TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &flow_); const std::string& body) {
auto url_fetcher = std::make_unique<TestURLFetcher>(0, url, &flow_);
net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED; net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED;
url_fetcher->set_status(URLRequestStatus::FromError(error)); url_fetcher->set_status(URLRequestStatus::FromError(error));
...@@ -133,11 +132,12 @@ class OAuth2ApiCallFlowTest : public testing::Test { ...@@ -133,11 +132,12 @@ class OAuth2ApiCallFlowTest : public testing::Test {
GURL url(CreateApiUrl()); GURL url(CreateApiUrl());
EXPECT_CALL(flow_, CreateApiCallBody()).WillOnce(Return(body)); EXPECT_CALL(flow_, CreateApiCallBody()).WillOnce(Return(body));
EXPECT_CALL(flow_, CreateApiCallUrl()).WillOnce(Return(url)); EXPECT_CALL(flow_, CreateApiCallUrl()).WillOnce(Return(url));
TestURLFetcher* url_fetcher = std::unique_ptr<TestURLFetcher> url_fetcher =
CreateURLFetcher(url, succeeds, status, std::string()); CreateURLFetcher(url, succeeds, status, std::string());
TestURLFetcher* url_fetcher_ptr = url_fetcher.get();
EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _, _)) EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _, _))
.WillOnce(Return(url_fetcher)); .WillOnce(Return(ByMove(std::move(url_fetcher))));
return url_fetcher; return url_fetcher_ptr;
} }
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment