summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authortimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 08:51:18 +0000
committertimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 08:51:18 +0000
commitc05c390fce9cb137c0557e374832c45d01a657be (patch)
tree1ae0affdba0b1a1e5f67287f016ad6da8af64f6c /sync
parent4045fe832225bc2e646329165f3cf48e932ec6d8 (diff)
downloadchromium_src-c05c390fce9cb137c0557e374832c45d01a657be.zip
chromium_src-c05c390fce9cb137c0557e374832c45d01a657be.tar.gz
chromium_src-c05c390fce9cb137c0557e374832c45d01a657be.tar.bz2
Revert 275293 "Add authentication support to AttachmentUploaderI..."
BUG=381581 > Add authentication support to AttachmentUploaderImpl. > > Update AUI to request an access token and send an Authorization header > with each requests. If the server responds with 401, AUI invalidates > its token, but does not retry. Retries will be implemented in a future > CL, probably at a higher level. > > BUG=371516 > > Review URL: https://codereview.chromium.org/304253010 TBR=maniscalco@chromium.org Review URL: https://codereview.chromium.org/316413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/attachments/attachment_uploader_impl.cc158
-rw-r--r--sync/internal_api/attachments/attachment_uploader_impl_unittest.cc346
-rw-r--r--sync/internal_api/public/attachments/attachment_uploader_impl.h26
-rw-r--r--sync/sync_tests.gypi1
4 files changed, 58 insertions, 473 deletions
diff --git a/sync/internal_api/attachments/attachment_uploader_impl.cc b/sync/internal_api/attachments/attachment_uploader_impl.cc
index 90c620e5..25630dc 100644
--- a/sync/internal_api/attachments/attachment_uploader_impl.cc
+++ b/sync/internal_api/attachments/attachment_uploader_impl.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/non_thread_safe.h"
-#include "google_apis/gaia/gaia_constants.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
@@ -26,23 +25,18 @@ namespace syncer {
// Encapsulates all the state associated with a single upload.
class AttachmentUploaderImpl::UploadState : public net::URLFetcherDelegate,
- public OAuth2TokenService::Consumer,
public base::NonThreadSafe {
public:
// Construct an UploadState.
//
// |owner| is a pointer to the object that will own (and must outlive!) this
// |UploadState.
- UploadState(
- const GURL& upload_url,
- const scoped_refptr<net::URLRequestContextGetter>&
- url_request_context_getter,
- const Attachment& attachment,
- const UploadCallback& user_callback,
- const std::string& account_id,
- const OAuth2TokenService::ScopeSet& scopes,
- OAuth2TokenServiceRequest::TokenServiceProvider* token_service_provider,
- AttachmentUploaderImpl* owner);
+ UploadState(const GURL& upload_url,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter,
+ const Attachment& attachment,
+ const UploadCallback& user_callback,
+ AttachmentUploaderImpl* owner);
virtual ~UploadState();
@@ -56,34 +50,17 @@ class AttachmentUploaderImpl::UploadState : public net::URLFetcherDelegate,
// URLFetcher implementation.
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
- // OAuth2TokenService::Consumer.
- virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) OVERRIDE;
- virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) OVERRIDE;
-
private:
typedef std::vector<UploadCallback> UploadCallbackList;
- void GetToken();
-
- void ReportResult(const UploadResult& result,
- const AttachmentId& attachment_id);
-
GURL upload_url_;
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter_;
Attachment attachment_;
UploadCallbackList user_callbacks_;
scoped_ptr<net::URLFetcher> fetcher_;
- std::string account_id_;
- OAuth2TokenService::ScopeSet scopes_;
- std::string access_token_;
- OAuth2TokenServiceRequest::TokenServiceProvider* token_service_provider_;
// Pointer to the AttachmentUploaderImpl that owns this object.
AttachmentUploaderImpl* owner_;
- scoped_ptr<OAuth2TokenServiceRequest> access_token_request_;
DISALLOW_COPY_AND_ASSIGN(UploadState);
};
@@ -94,26 +71,33 @@ AttachmentUploaderImpl::UploadState::UploadState(
url_request_context_getter,
const Attachment& attachment,
const UploadCallback& user_callback,
- const std::string& account_id,
- const OAuth2TokenService::ScopeSet& scopes,
- OAuth2TokenServiceRequest::TokenServiceProvider* token_service_provider,
AttachmentUploaderImpl* owner)
- : OAuth2TokenService::Consumer("attachment-uploader-impl"),
- upload_url_(upload_url),
+ : upload_url_(upload_url),
url_request_context_getter_(url_request_context_getter),
attachment_(attachment),
user_callbacks_(1, user_callback),
- account_id_(account_id),
- scopes_(scopes),
- token_service_provider_(token_service_provider),
owner_(owner) {
- DCHECK(upload_url_.is_valid());
DCHECK(url_request_context_getter_);
- DCHECK(!account_id_.empty());
- DCHECK(!scopes_.empty());
- DCHECK(token_service_provider_);
+ DCHECK(upload_url_.is_valid());
DCHECK(owner_);
- GetToken();
+ fetcher_.reset(
+ net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this));
+ fetcher_->SetRequestContext(url_request_context_getter_.get());
+ // TODO(maniscalco): Is there a better way? Copying the attachment data into
+ // a string feels wrong given how large attachments may be (several MBs). If
+ // we may end up switching from URLFetcher to URLRequest, this copy won't be
+ // necessary.
+ scoped_refptr<base::RefCountedMemory> memory = attachment.GetData();
+ const std::string upload_content(memory->front_as<char>(), memory->size());
+ fetcher_->SetUploadData(kContentType, upload_content);
+ // TODO(maniscalco): Add authentication support (bug 371516).
+ fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
+ net::LOAD_DO_NOT_SEND_COOKIES |
+ net::LOAD_DISABLE_CACHE);
+ // TODO(maniscalco): Set an appropriate headers (User-Agent, Content-type, and
+ // Content-length) on the request and include the content's MD5,
+ // AttachmentId's unique_id and the "sync birthday" (bug 371521).
+ fetcher_->Start();
}
AttachmentUploaderImpl::UploadState::~UploadState() {
@@ -133,75 +117,20 @@ const Attachment& AttachmentUploaderImpl::UploadState::GetAttachment() {
void AttachmentUploaderImpl::UploadState::OnURLFetchComplete(
const net::URLFetcher* source) {
DCHECK(CalledOnValidThread());
+ // TODO(maniscalco): Once the protocol is better defined, deal with the
+ // various HTTP response code we may encounter.
UploadResult result = UPLOAD_UNSPECIFIED_ERROR;
- AttachmentId attachment_id = attachment_.GetId();
if (source->GetResponseCode() == net::HTTP_OK) {
result = UPLOAD_SUCCESS;
- // TODO(maniscalco): Update the attachment id with server address
- // information before passing it to the callback (bug 371522).
- } else if (source->GetResponseCode() == net::HTTP_UNAUTHORIZED) {
- // TODO(maniscalco): One possibility is that we received a 401 because our
- // access token has expired. We should probably fetch a new access token
- // and retry this upload before giving up and reporting failure to our
- // caller (bug 380437).
- OAuth2TokenServiceRequest::InvalidateToken(
- token_service_provider_, account_id_, scopes_, access_token_);
- } else {
- // TODO(maniscalco): Once the protocol is better defined, deal with the
- // various HTTP response codes we may encounter.
}
- ReportResult(result, attachment_id);
-}
-
-void AttachmentUploaderImpl::UploadState::OnGetTokenSuccess(
- const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) {
- DCHECK_EQ(access_token_request_.get(), request);
- access_token_request_.reset();
- access_token_ = access_token;
- fetcher_.reset(
- net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this));
- fetcher_->SetRequestContext(url_request_context_getter_.get());
- // TODO(maniscalco): Is there a better way? Copying the attachment data into
- // a string feels wrong given how large attachments may be (several MBs). If
- // we may end up switching from URLFetcher to URLRequest, this copy won't be
- // necessary.
- scoped_refptr<base::RefCountedMemory> memory = attachment_.GetData();
- const std::string upload_content(memory->front_as<char>(), memory->size());
- fetcher_->SetUploadData(kContentType, upload_content);
- const std::string auth_header("Authorization: Bearer " + access_token_);
- fetcher_->AddExtraRequestHeader(auth_header);
- fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
- net::LOAD_DO_NOT_SEND_COOKIES |
- net::LOAD_DISABLE_CACHE);
- // TODO(maniscalco): Set an appropriate headers (User-Agent, Content-type, and
- // Content-length) on the request and include the content's MD5,
- // AttachmentId's unique_id and the "sync birthday" (bug 371521).
- fetcher_->Start();
-}
-
-void AttachmentUploaderImpl::UploadState::OnGetTokenFailure(
- const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) {
- DCHECK_EQ(access_token_request_.get(), request);
- access_token_request_.reset();
- ReportResult(UPLOAD_UNSPECIFIED_ERROR, attachment_.GetId());
-}
-
-void AttachmentUploaderImpl::UploadState::GetToken() {
- access_token_request_ = OAuth2TokenServiceRequest::CreateAndStart(
- token_service_provider_, account_id_, scopes_, this);
-}
-
-void AttachmentUploaderImpl::UploadState::ReportResult(
- const UploadResult& result,
- const AttachmentId& attachment_id) {
+ // TODO(maniscalco): Update the attachment id with server address information
+ // before passing it to the callback (bug 371522).
+ AttachmentId updated_id = attachment_.GetId();
UploadCallbackList::const_iterator iter = user_callbacks_.begin();
UploadCallbackList::const_iterator end = user_callbacks_.end();
for (; iter != end; ++iter) {
base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(*iter, result, attachment_id));
+ FROM_HERE, base::Bind(*iter, result, updated_id));
}
// Destroy this object and return immediately.
owner_->DeleteUploadStateFor(attachment_.GetId().GetProto().unique_id());
@@ -211,18 +140,10 @@ void AttachmentUploaderImpl::UploadState::ReportResult(
AttachmentUploaderImpl::AttachmentUploaderImpl(
const std::string& url_prefix,
const scoped_refptr<net::URLRequestContextGetter>&
- url_request_context_getter,
- const std::string& account_id,
- const OAuth2TokenService::ScopeSet& scopes,
- scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
- token_service_provider)
+ url_request_context_getter)
: url_prefix_(url_prefix),
- url_request_context_getter_(url_request_context_getter),
- account_id_(account_id),
- scopes_(scopes),
- token_service_provider_(token_service_provider.Pass()) {
+ url_request_context_getter_(url_request_context_getter) {
DCHECK(CalledOnValidThread());
- DCHECK(token_service_provider_);
}
AttachmentUploaderImpl::~AttachmentUploaderImpl() {
@@ -238,15 +159,8 @@ void AttachmentUploaderImpl::UploadAttachment(const Attachment& attachment,
StateMap::iterator iter = state_map_.find(unique_id);
if (iter == state_map_.end()) {
const GURL url = GetUploadURLForAttachmentId(attachment_id);
- scoped_ptr<UploadState> upload_state(
- new UploadState(url,
- url_request_context_getter_,
- attachment,
- callback,
- account_id_,
- scopes_,
- token_service_provider_.get(),
- this));
+ scoped_ptr<UploadState> upload_state(new UploadState(
+ url, url_request_context_getter_, attachment, callback, this));
state_map_.add(unique_id, upload_state.Pass());
} else {
DCHECK(
diff --git a/sync/internal_api/attachments/attachment_uploader_impl_unittest.cc b/sync/internal_api/attachments/attachment_uploader_impl_unittest.cc
index f2ad7ce..99c2247 100644
--- a/sync/internal_api/attachments/attachment_uploader_impl_unittest.cc
+++ b/sync/internal_api/attachments/attachment_uploader_impl_unittest.cc
@@ -11,28 +11,19 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
-#include "base/synchronization/lock.h"
-#include "base/thread_task_runner_handle.h"
#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
-#include "google_apis/gaia/fake_oauth2_token_service.h"
-#include "google_apis/gaia/gaia_constants.h"
-#include "google_apis/gaia/oauth2_token_service_request.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/url_request/url_request_test_util.h"
#include "sync/api/attachments/attachment.h"
#include "sync/protocol/sync.pb.h"
-#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kAttachmentData[] = "some data";
-const char kAccountId[] = "some-account-id";
-const char kAccessToken[] = "some-access-token";
-const char kAuthorization[] = "Authorization";
} // namespace
@@ -44,131 +35,10 @@ using net::test_server::HttpResponse;
class RequestHandler;
-// A mock implementation of an OAuth2TokenService.
-//
-// Use |SetResponse| to vary the response to token requests.
-//
-// Use |num_invalidate_token| and |last_token_invalidated| to check the number
-// of invalidate token operations performed and the last token invalidated.
-class MockOAuth2TokenService : public FakeOAuth2TokenService {
- public:
- MockOAuth2TokenService();
- virtual ~MockOAuth2TokenService();
-
- void SetResponse(const GoogleServiceAuthError& error,
- const std::string& access_token,
- const base::Time& expiration);
-
- int num_invalidate_token() const { return num_invalidate_token_; }
-
- const std::string& last_token_invalidated() const {
- return last_token_invalidated_;
- }
-
- protected:
- virtual void FetchOAuth2Token(RequestImpl* request,
- const std::string& account_id,
- net::URLRequestContextGetter* getter,
- const std::string& client_id,
- const std::string& client_secret,
- const ScopeSet& scopes) OVERRIDE;
-
- virtual void InvalidateOAuth2Token(const std::string& account_id,
- const std::string& client_id,
- const ScopeSet& scopes,
- const std::string& access_token) OVERRIDE;
-
- private:
- GoogleServiceAuthError response_error_;
- std::string response_access_token_;
- base::Time response_expiration_;
- int num_invalidate_token_;
- std::string last_token_invalidated_;
-};
-
-MockOAuth2TokenService::MockOAuth2TokenService()
- : response_error_(GoogleServiceAuthError::AuthErrorNone()),
- response_access_token_(kAccessToken),
- response_expiration_(base::Time::Max()),
- num_invalidate_token_(0) {
-}
-
-MockOAuth2TokenService::~MockOAuth2TokenService() {
-}
-
-void MockOAuth2TokenService::SetResponse(const GoogleServiceAuthError& error,
- const std::string& access_token,
- const base::Time& expiration) {
- response_error_ = error;
- response_access_token_ = access_token;
- response_expiration_ = expiration;
-}
-
-void MockOAuth2TokenService::FetchOAuth2Token(
- RequestImpl* request,
- const std::string& account_id,
- net::URLRequestContextGetter* getter,
- const std::string& client_id,
- const std::string& client_secret,
- const ScopeSet& scopes) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer,
- request->AsWeakPtr(),
- response_error_,
- response_access_token_,
- response_expiration_));
-}
-
-void MockOAuth2TokenService::InvalidateOAuth2Token(
- const std::string& account_id,
- const std::string& client_id,
- const ScopeSet& scopes,
- const std::string& access_token) {
- ++num_invalidate_token_;
- last_token_invalidated_ = access_token;
-}
-
-class TokenServiceProvider
- : public OAuth2TokenServiceRequest::TokenServiceProvider,
- base::NonThreadSafe {
- public:
- TokenServiceProvider(OAuth2TokenService* token_service);
- virtual ~TokenServiceProvider();
-
- // OAuth2TokenService::TokenServiceProvider implementation.
- virtual scoped_refptr<base::SingleThreadTaskRunner>
- GetTokenServiceTaskRunner() OVERRIDE;
- virtual OAuth2TokenService* GetTokenService() OVERRIDE;
-
- private:
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
- OAuth2TokenService* token_service_;
-};
-
-TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service)
- : task_runner_(base::ThreadTaskRunnerHandle::Get()),
- token_service_(token_service) {
- DCHECK(token_service_);
-}
-
-TokenServiceProvider::~TokenServiceProvider() {
-}
-
-scoped_refptr<base::SingleThreadTaskRunner>
-TokenServiceProvider::GetTokenServiceTaskRunner() {
- return task_runner_;
-}
-
-OAuth2TokenService* TokenServiceProvider::GetTokenService() {
- DCHECK(task_runner_->BelongsToCurrentThread());
- return token_service_;
-}
-
// Text fixture for AttachmentUploaderImpl test.
//
-// This fixture provides an embedded HTTP server and a mock OAuth2 token service
-// for interacting with AttachmentUploaderImpl
+// This fixture provides an embedded HTTP server for interacting with
+// AttachmentUploaderImpl.
class AttachmentUploaderImplTest : public testing::Test,
public base::NonThreadSafe {
public:
@@ -177,7 +47,6 @@ class AttachmentUploaderImplTest : public testing::Test,
protected:
AttachmentUploaderImplTest();
virtual void SetUp();
- virtual void TearDown();
// Run the message loop until UploadDone has been invoked |num_uploads| times.
void RunAndWaitFor(int num_uploads);
@@ -187,9 +56,6 @@ class AttachmentUploaderImplTest : public testing::Test,
std::vector<HttpRequest>& http_requests_received();
std::vector<AttachmentUploader::UploadResult>& upload_results();
std::vector<AttachmentId>& updated_attachment_ids();
- MockOAuth2TokenService& token_service();
- base::MessageLoopForIO& message_loop();
- RequestHandler& request_handler();
private:
// An UploadCallback invoked by AttachmentUploaderImpl.
@@ -202,20 +68,18 @@ class AttachmentUploaderImplTest : public testing::Test,
scoped_ptr<AttachmentUploader> uploader_;
AttachmentUploader::UploadCallback upload_callback_;
net::test_server::EmbeddedTestServer server_;
+
// A closure that signals an upload has finished.
base::Closure signal_upload_done_;
std::vector<HttpRequest> http_requests_received_;
std::vector<AttachmentUploader::UploadResult> upload_results_;
std::vector<AttachmentId> updated_attachment_ids_;
- scoped_ptr<MockOAuth2TokenService> token_service_;
// Must be last data member.
base::WeakPtrFactory<AttachmentUploaderImplTest> weak_ptr_factory_;
};
// Handles HTTP requests received by the EmbeddedTestServer.
-//
-// Responds with HTTP_OK by default. See |SetStatusCode|.
class RequestHandler : public base::NonThreadSafe {
public:
// Construct a RequestHandler that will PostTask to |test| using
@@ -228,17 +92,7 @@ class RequestHandler : public base::NonThreadSafe {
scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request);
- // Set the HTTP status code to respond with.
- void SetStatusCode(const net::HttpStatusCode& status_code);
-
- // Returns the HTTP status code that will be used in responses.
- net::HttpStatusCode GetStatusCode() const;
-
private:
- // Protects status_code_.
- mutable base::Lock mutex_;
- net::HttpStatusCode status_code_;
-
scoped_refptr<base::SingleThreadTaskRunner> test_task_runner_;
base::WeakPtr<AttachmentUploaderImplTest> test_;
};
@@ -267,26 +121,12 @@ void AttachmentUploaderImplTest::SetUp() {
std::string url_prefix(
base::StringPrintf("http://localhost:%d/uploads/", server_.port()));
- token_service_.reset(new MockOAuth2TokenService);
- scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
- token_service_provider(new TokenServiceProvider(token_service_.get()));
-
- OAuth2TokenService::ScopeSet scopes;
- scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
- uploader().reset(new AttachmentUploaderImpl(url_prefix,
- url_request_context_getter_,
- kAccountId,
- scopes,
- token_service_provider.Pass()));
-
+ uploader().reset(
+ new AttachmentUploaderImpl(url_prefix, url_request_context_getter_));
upload_callback_ = base::Bind(&AttachmentUploaderImplTest::UploadDone,
base::Unretained(this));
}
-void AttachmentUploaderImplTest::TearDown() {
- base::RunLoop().RunUntilIdle();
-}
-
void AttachmentUploaderImplTest::RunAndWaitFor(int num_uploads) {
for (int i = 0; i < num_uploads; ++i) {
// Run the loop until one upload completes.
@@ -319,18 +159,6 @@ AttachmentUploaderImplTest::updated_attachment_ids() {
return updated_attachment_ids_;
}
-MockOAuth2TokenService& AttachmentUploaderImplTest::token_service() {
- return *token_service_;
-}
-
-base::MessageLoopForIO& AttachmentUploaderImplTest::message_loop() {
- return message_loop_;
-}
-
-RequestHandler& AttachmentUploaderImplTest::request_handler() {
- return *request_handler_;
-}
-
void AttachmentUploaderImplTest::UploadDone(
const AttachmentUploader::UploadResult& result,
const AttachmentId& updated_attachment_id) {
@@ -343,9 +171,7 @@ void AttachmentUploaderImplTest::UploadDone(
RequestHandler::RequestHandler(
const scoped_refptr<base::SingleThreadTaskRunner>& test_task_runner,
const base::WeakPtr<AttachmentUploaderImplTest>& test)
- : status_code_(net::HTTP_OK),
- test_task_runner_(test_task_runner),
- test_(test) {
+ : test_task_runner_(test_task_runner), test_(test) {
DetachFromThread();
}
@@ -360,46 +186,23 @@ scoped_ptr<HttpResponse> RequestHandler::HandleRequest(
FROM_HERE,
base::Bind(
&AttachmentUploaderImplTest::OnRequestReceived, test_, request));
- scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
- response->set_code(GetStatusCode());
- response->set_content_type("text/plain");
- return response.PassAs<HttpResponse>();
-}
-
-void RequestHandler::SetStatusCode(const net::HttpStatusCode& status_code) {
- base::AutoLock lock(mutex_);
- status_code_ = status_code;
-}
-
-net::HttpStatusCode RequestHandler::GetStatusCode() const {
- base::AutoLock lock(mutex_);
- return status_code_;
+ scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
+ http_response->set_code(net::HTTP_OK);
+ http_response->set_content("hello");
+ http_response->set_content_type("text/plain");
+ return http_response.PassAs<HttpResponse>();
}
// Verify the "happy case" of uploading an attachment.
-//
-// Token is requested, token is returned, HTTP request is made, attachment is
-// received by server.
TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) {
- token_service().AddAccount(kAccountId);
- request_handler().SetStatusCode(net::HTTP_OK);
-
scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
some_data->data() = kAttachmentData;
Attachment attachment = Attachment::Create(some_data);
uploader()->UploadAttachment(attachment, upload_callback());
-
- // Run until the done callback is invoked.
RunAndWaitFor(1);
- // See that the done callback was invoked with the right arguments.
- ASSERT_EQ(1U, upload_results().size());
- EXPECT_EQ(AttachmentUploader::UPLOAD_SUCCESS, upload_results()[0]);
- ASSERT_EQ(1U, updated_attachment_ids().size());
- EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]);
-
// See that the HTTP server received one request.
- ASSERT_EQ(1U, http_requests_received().size());
+ EXPECT_EQ(1U, http_requests_received().size());
const HttpRequest& http_request = http_requests_received().front();
EXPECT_EQ(net::test_server::METHOD_POST, http_request.method);
std::string expected_relative_url("/uploads/" +
@@ -407,11 +210,12 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) {
EXPECT_EQ(expected_relative_url, http_request.relative_url);
EXPECT_TRUE(http_request.has_content);
EXPECT_EQ(kAttachmentData, http_request.content);
- const std::string header_name(kAuthorization);
- const std::string header_value(std::string("Bearer ") + kAccessToken);
- EXPECT_THAT(http_request.headers,
- testing::Contains(testing::Pair(header_name, header_value)));
+ // See that the UploadCallback received a result and updated AttachmentId.
+ EXPECT_EQ(1U, upload_results().size());
+ EXPECT_EQ(1U, updated_attachment_ids().size());
+ EXPECT_EQ(AttachmentUploader::UPLOAD_SUCCESS, upload_results().front());
+ EXPECT_EQ(attachment.GetId(), updated_attachment_ids().front());
// TODO(maniscalco): Once AttachmentUploaderImpl is capable of updating the
// AttachmentId with server address information about the attachment, add some
// checks here to verify it works properly (bug 371522).
@@ -420,17 +224,12 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) {
// Verify two overlapping calls to upload the same attachment result in only one
// HTTP request.
TEST_F(AttachmentUploaderImplTest, UploadAttachment_Collapse) {
- token_service().AddAccount(kAccountId);
- request_handler().SetStatusCode(net::HTTP_OK);
-
scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
some_data->data() = kAttachmentData;
Attachment attachment1 = Attachment::Create(some_data);
Attachment attachment2 = attachment1;
uploader()->UploadAttachment(attachment1, upload_callback());
uploader()->UploadAttachment(attachment2, upload_callback());
- base::RunLoop().RunUntilIdle();
-
// Wait for upload_callback() to be invoked twice.
RunAndWaitFor(2);
// See there was only one request.
@@ -441,127 +240,18 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_Collapse) {
// uplaod finishes. We do this by issuing two non-overlapping uploads for the
// same attachment and see that it results in two HTTP requests.
TEST_F(AttachmentUploaderImplTest, UploadAttachment_CleanUpAfterUpload) {
- token_service().AddAccount(kAccountId);
- request_handler().SetStatusCode(net::HTTP_OK);
-
scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
some_data->data() = kAttachmentData;
Attachment attachment1 = Attachment::Create(some_data);
Attachment attachment2 = attachment1;
uploader()->UploadAttachment(attachment1, upload_callback());
- base::RunLoop().RunUntilIdle();
-
// Wait for upload_callback() to be invoked before starting the second upload.
RunAndWaitFor(1);
uploader()->UploadAttachment(attachment2, upload_callback());
- base::RunLoop().RunUntilIdle();
-
// Wait for upload_callback() to be invoked a second time.
RunAndWaitFor(1);
// See there were two requests.
- ASSERT_EQ(2U, http_requests_received().size());
-}
-
-// Verify that we do not issue an HTTP request when we fail to receive an access
-// token.
-//
-// Token is requested, no token is returned, no HTTP request is made
-TEST_F(AttachmentUploaderImplTest, UploadAttachment_FailToGetToken) {
- // Note, we won't receive a token because we did not add kAccountId to the
- // token service.
- scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
- some_data->data() = kAttachmentData;
- Attachment attachment = Attachment::Create(some_data);
- uploader()->UploadAttachment(attachment, upload_callback());
-
- RunAndWaitFor(1);
-
- // See that the done callback was invoked.
- ASSERT_EQ(1U, upload_results().size());
- EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
- ASSERT_EQ(1U, updated_attachment_ids().size());
- EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]);
-
- // See that no HTTP request was received.
- ASSERT_EQ(0U, http_requests_received().size());
-}
-
-// Verify behavior when the server returns "503 Service Unavailable".
-TEST_F(AttachmentUploaderImplTest, UploadAttachment_ServiceUnavilable) {
- token_service().AddAccount(kAccountId);
- request_handler().SetStatusCode(net::HTTP_SERVICE_UNAVAILABLE);
-
- scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
- some_data->data() = kAttachmentData;
- Attachment attachment = Attachment::Create(some_data);
- uploader()->UploadAttachment(attachment, upload_callback());
-
- RunAndWaitFor(1);
-
- // See that the done callback was invoked.
- ASSERT_EQ(1U, upload_results().size());
- EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
- ASSERT_EQ(1U, updated_attachment_ids().size());
- EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]);
-
- // See that the HTTP server received one request.
- ASSERT_EQ(1U, http_requests_received().size());
- const HttpRequest& http_request = http_requests_received().front();
- EXPECT_EQ(net::test_server::METHOD_POST, http_request.method);
- std::string expected_relative_url("/uploads/" +
- attachment.GetId().GetProto().unique_id());
- EXPECT_EQ(expected_relative_url, http_request.relative_url);
- EXPECT_TRUE(http_request.has_content);
- EXPECT_EQ(kAttachmentData, http_request.content);
- std::string expected_header(kAuthorization);
- const std::string header_name(kAuthorization);
- const std::string header_value(std::string("Bearer ") + kAccessToken);
- EXPECT_THAT(http_request.headers,
- testing::Contains(testing::Pair(header_name, header_value)));
-
- // See that we did not invalidate the token.
- ASSERT_EQ(0, token_service().num_invalidate_token());
+ EXPECT_EQ(2U, http_requests_received().size());
}
-// Verify that when we receive an "401 Unauthorized" we invalidate the access
-// token.
-TEST_F(AttachmentUploaderImplTest, UploadAttachment_BadToken) {
- token_service().AddAccount(kAccountId);
- request_handler().SetStatusCode(net::HTTP_UNAUTHORIZED);
-
- scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
- some_data->data() = kAttachmentData;
- Attachment attachment = Attachment::Create(some_data);
- uploader()->UploadAttachment(attachment, upload_callback());
-
- RunAndWaitFor(1);
-
- // See that the done callback was invoked.
- ASSERT_EQ(1U, upload_results().size());
- EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
- ASSERT_EQ(1U, updated_attachment_ids().size());
- EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]);
-
- // See that the HTTP server received one request.
- ASSERT_EQ(1U, http_requests_received().size());
- const HttpRequest& http_request = http_requests_received().front();
- EXPECT_EQ(net::test_server::METHOD_POST, http_request.method);
- std::string expected_relative_url("/uploads/" +
- attachment.GetId().GetProto().unique_id());
- EXPECT_EQ(expected_relative_url, http_request.relative_url);
- EXPECT_TRUE(http_request.has_content);
- EXPECT_EQ(kAttachmentData, http_request.content);
- std::string expected_header(kAuthorization);
- const std::string header_name(kAuthorization);
- const std::string header_value(std::string("Bearer ") + kAccessToken);
- EXPECT_THAT(http_request.headers,
- testing::Contains(testing::Pair(header_name, header_value)));
-
- // See that we invalidated the token.
- ASSERT_EQ(1, token_service().num_invalidate_token());
-}
-
-// TODO(maniscalco): Add test case for when we are uploading an attachment that
-// already exists. 409 Conflict? (bug 379825)
-
} // namespace syncer
diff --git a/sync/internal_api/public/attachments/attachment_uploader_impl.h b/sync/internal_api/public/attachments/attachment_uploader_impl.h
index 8604415..0720bcb 100644
--- a/sync/internal_api/public/attachments/attachment_uploader_impl.h
+++ b/sync/internal_api/public/attachments/attachment_uploader_impl.h
@@ -7,7 +7,6 @@
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/threading/non_thread_safe.h"
-#include "google_apis/gaia/oauth2_token_service_request.h"
#include "net/url_request/url_request_context_getter.h"
#include "sync/api/attachments/attachment_uploader.h"
@@ -24,23 +23,10 @@ class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader,
public base::NonThreadSafe {
public:
// |url_prefix| is the URL prefix (including trailing slash) to be used when
- // uploading attachments.
- //
- // |url_request_context_getter| provides a URLRequestContext.
- //
- // |account_id| is the account id to use for uploads.
- //
- // |scopes| is the set of scopes to use for uploads.
- //
- // |token_service_provider| provides an OAuth2 token service.
- AttachmentUploaderImpl(
- const std::string& url_prefix,
- const scoped_refptr<net::URLRequestContextGetter>&
- url_request_context_getter,
- const std::string& account_id,
- const OAuth2TokenService::ScopeSet& scopes,
- scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
- token_service_provider);
+ // |uploading attachments.
+ AttachmentUploaderImpl(const std::string& url_prefix,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter);
virtual ~AttachmentUploaderImpl();
// AttachmentUploader implementation.
@@ -57,10 +43,6 @@ class SYNC_EXPORT AttachmentUploaderImpl : public AttachmentUploader,
std::string url_prefix_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
- std::string account_id_;
- OAuth2TokenService::ScopeSet scopes_;
- scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider>
- token_service_provider_;
StateMap state_map_;
DISALLOW_COPY_AND_ASSIGN(AttachmentUploaderImpl);
};
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index d11dbde..b7614d5 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -389,7 +389,6 @@
'suppress_wildcard': 1,
'dependencies': [
'../base/base.gyp:base',
- '../google_apis/google_apis.gyp:google_apis_test_support',
'../net/net.gyp:net',
'../net/net.gyp:net_test_support',
'../testing/gmock.gyp:gmock',