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

Unified Diff: chrome/common/net/gaia/oauth2_api_call_flow_unittest.cc

Issue 10080016: Set the authorization header when calling an API. Otherwise, no API call will succeed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/net/gaia/oauth2_api_call_flow.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/net/gaia/oauth2_api_call_flow_unittest.cc
===================================================================
--- chrome/common/net/gaia/oauth2_api_call_flow_unittest.cc (revision 132216)
+++ chrome/common/net/gaia/oauth2_api_call_flow_unittest.cc (working copy)
@@ -18,6 +18,7 @@
#include "content/public/common/url_fetcher_delegate.h"
#include "content/public/common/url_fetcher_factory.h"
#include "content/test/test_url_fetcher_factory.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_status.h"
@@ -27,11 +28,15 @@
using content::URLFetcher;
using content::URLFetcherDelegate;
using content::URLFetcherFactory;
+using net::HttpRequestHeaders;
using net::URLRequestStatus;
using testing::_;
using testing::Return;
namespace {
+static std::string CreateBody() {
+ return "some body";
+}
static GURL CreateApiUrl() {
return GURL("https://www.googleapis.com/someapi");
@@ -48,7 +53,7 @@
class MockUrlFetcherFactory : public ScopedURLFetcherFactory,
public URLFetcherFactory {
-public:
+ public:
MockUrlFetcherFactory()
: ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
@@ -145,8 +150,9 @@
}
TestURLFetcher* SetupApiCall(bool succeeds, net::HttpStatusCode status) {
+ std::string body(CreateBody());
GURL url(CreateApiUrl());
- EXPECT_CALL(*flow_, CreateApiCallBody()).WillOnce(Return(""));
+ EXPECT_CALL(*flow_, CreateApiCallBody()).WillOnce(Return(body));
EXPECT_CALL(*flow_, CreateApiCallUrl()).WillOnce(Return(url));
TestURLFetcher* url_fetcher = CreateURLFetcher(
url, succeeds, status, "");
@@ -262,3 +268,22 @@
flow_->Start();
flow_->OnGetTokenFailure(error);
}
+
+TEST_F(OAuth2ApiCallFlowTest, CreateURLFetcher) {
+ std::string rt = "refresh_token";
+ std::string at = "access_token";
+ std::vector<std::string> scopes(CreateTestScopes());
+ std::string body = CreateBody();
+ GURL url(CreateApiUrl());
+
+ CreateFlow(rt, at, scopes);
+ TestURLFetcher* url_fetcher = SetupApiCall(true, net::HTTP_OK);
+ flow_->CreateURLFetcher();
+ HttpRequestHeaders headers;
+ url_fetcher->GetExtraRequestHeaders(&headers);
+ std::string auth_header;
+ EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header));
+ EXPECT_EQ("Bearer access_token", auth_header);
+ EXPECT_EQ(url, url_fetcher->GetOriginalURL());
+ EXPECT_EQ(body, url_fetcher->upload_data());
+}
« no previous file with comments | « chrome/common/net/gaia/oauth2_api_call_flow.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698