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

Side by Side Diff: sync/internal_api/attachments/attachment_downloader_impl_unittest.cc

Issue 2007373004: Fix test expectations to use bool checks rather than null compares (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/protocol/fake_datagram_socket.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sync/internal_api/public/attachments/attachment_downloader_impl.h" 5 #include "sync/internal_api/public/attachments/attachment_downloader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const ScopeSet& scopes, 63 const ScopeSet& scopes,
64 const std::string& access_token) override; 64 const std::string& access_token) override;
65 65
66 private: 66 private:
67 base::WeakPtr<RequestImpl> last_request_; 67 base::WeakPtr<RequestImpl> last_request_;
68 int num_invalidate_token_; 68 int num_invalidate_token_;
69 }; 69 };
70 70
71 void MockOAuth2TokenService::RespondToAccessTokenRequest( 71 void MockOAuth2TokenService::RespondToAccessTokenRequest(
72 GoogleServiceAuthError error) { 72 GoogleServiceAuthError error) {
73 EXPECT_TRUE(last_request_ != NULL); 73 EXPECT_TRUE(last_request_);
74 std::string access_token; 74 std::string access_token;
75 base::Time expiration_time; 75 base::Time expiration_time;
76 if (error == GoogleServiceAuthError::AuthErrorNone()) { 76 if (error == GoogleServiceAuthError::AuthErrorNone()) {
77 access_token = kAccessToken; 77 access_token = kAccessToken;
78 expiration_time = base::Time::Max(); 78 expiration_time = base::Time::Max();
79 } 79 }
80 base::MessageLoop::current()->PostTask( 80 base::MessageLoop::current()->PostTask(
81 FROM_HERE, 81 FROM_HERE,
82 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer, 82 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer,
83 last_request_, 83 last_request_,
84 error, 84 error,
85 access_token, 85 access_token,
86 expiration_time)); 86 expiration_time));
87 } 87 }
88 88
89 void MockOAuth2TokenService::FetchOAuth2Token( 89 void MockOAuth2TokenService::FetchOAuth2Token(
90 RequestImpl* request, 90 RequestImpl* request,
91 const std::string& account_id, 91 const std::string& account_id,
92 net::URLRequestContextGetter* getter, 92 net::URLRequestContextGetter* getter,
93 const std::string& client_id, 93 const std::string& client_id,
94 const std::string& client_secret, 94 const std::string& client_secret,
95 const ScopeSet& scopes) { 95 const ScopeSet& scopes) {
96 // Only one request at a time is allowed. 96 // Only one request at a time is allowed.
97 EXPECT_TRUE(last_request_ == NULL); 97 EXPECT_FALSE(last_request_);
98 last_request_ = request->AsWeakPtr(); 98 last_request_ = request->AsWeakPtr();
99 } 99 }
100 100
101 void MockOAuth2TokenService::InvalidateAccessTokenImpl( 101 void MockOAuth2TokenService::InvalidateAccessTokenImpl(
102 const std::string& account_id, 102 const std::string& account_id,
103 const std::string& client_id, 103 const std::string& client_id,
104 const ScopeSet& scopes, 104 const ScopeSet& scopes,
105 const std::string& access_token) { 105 const std::string& access_token) {
106 ++num_invalidate_token_; 106 ++num_invalidate_token_;
107 } 107 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void AttachmentDownloaderImplTest::TearDown() { 226 void AttachmentDownloaderImplTest::TearDown() {
227 RunMessageLoop(); 227 RunMessageLoop();
228 } 228 }
229 229
230 void AttachmentDownloaderImplTest::CompleteDownload( 230 void AttachmentDownloaderImplTest::CompleteDownload(
231 int response_code, 231 int response_code,
232 HashHeaderType hash_header_type) { 232 HashHeaderType hash_header_type) {
233 // TestURLFetcherFactory remembers last active URLFetcher. 233 // TestURLFetcherFactory remembers last active URLFetcher.
234 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 234 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
235 // There should be outstanding url fetch request. 235 // There should be outstanding url fetch request.
236 EXPECT_TRUE(fetcher != NULL); 236 EXPECT_TRUE(fetcher);
237 fetcher->set_status(net::URLRequestStatus()); 237 fetcher->set_status(net::URLRequestStatus());
238 fetcher->set_response_code(response_code); 238 fetcher->set_response_code(response_code);
239 if (response_code == net::HTTP_OK) { 239 if (response_code == net::HTTP_OK) {
240 fetcher->SetResponseString(kAttachmentContent); 240 fetcher->SetResponseString(kAttachmentContent);
241 } 241 }
242 AddHashHeader(hash_header_type, fetcher); 242 AddHashHeader(hash_header_type, fetcher);
243 243
244 // Call URLFetcherDelegate. 244 // Call URLFetcherDelegate.
245 net::URLFetcherDelegate* delegate = fetcher->delegate(); 245 net::URLFetcherDelegate* delegate = fetcher->delegate();
246 delegate->OnURLFetchComplete(fetcher); 246 delegate->OnURLFetchComplete(fetcher);
247 RunMessageLoop(); 247 RunMessageLoop();
248 // Once result is processed URLFetcher should be deleted. 248 // Once result is processed URLFetcher should be deleted.
249 fetcher = url_fetcher_factory_.GetFetcherByID(0); 249 fetcher = url_fetcher_factory_.GetFetcherByID(0);
250 EXPECT_TRUE(fetcher == NULL); 250 EXPECT_FALSE(fetcher);
251 } 251 }
252 252
253 void AttachmentDownloaderImplTest::DownloadDone( 253 void AttachmentDownloaderImplTest::DownloadDone(
254 const AttachmentId& attachment_id, 254 const AttachmentId& attachment_id,
255 const AttachmentDownloader::DownloadResult& result, 255 const AttachmentDownloader::DownloadResult& result,
256 std::unique_ptr<Attachment> attachment) { 256 std::unique_ptr<Attachment> attachment) {
257 download_results_.insert(std::make_pair(attachment_id, result)); 257 download_results_.insert(std::make_pair(attachment_id, result));
258 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) { 258 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) {
259 // Successful download should be accompanied by valid attachment with 259 // Successful download should be accompanied by valid attachment with
260 // matching id and valid data. 260 // matching id and valid data.
261 EXPECT_TRUE(attachment != NULL); 261 EXPECT_TRUE(attachment);
262 EXPECT_EQ(attachment_id, attachment->GetId()); 262 EXPECT_EQ(attachment_id, attachment->GetId());
263 263
264 scoped_refptr<base::RefCountedMemory> data = attachment->GetData(); 264 scoped_refptr<base::RefCountedMemory> data = attachment->GetData();
265 std::string data_as_string(data->front_as<char>(), data->size()); 265 std::string data_as_string(data->front_as<char>(), data->size());
266 EXPECT_EQ(data_as_string, kAttachmentContent); 266 EXPECT_EQ(data_as_string, kAttachmentContent);
267 } else { 267 } else {
268 EXPECT_TRUE(attachment == NULL); 268 EXPECT_FALSE(attachment);
269 } 269 }
270 ++num_completed_downloads_; 270 ++num_completed_downloads_;
271 } 271 }
272 272
273 void AttachmentDownloaderImplTest::VerifyDownloadResult( 273 void AttachmentDownloaderImplTest::VerifyDownloadResult(
274 const AttachmentId& attachment_id, 274 const AttachmentId& attachment_id,
275 const AttachmentDownloader::DownloadResult& result) { 275 const AttachmentDownloader::DownloadResult& result) {
276 ResultsMap::const_iterator iter = download_results_.find(attachment_id); 276 ResultsMap::const_iterator iter = download_results_.find(attachment_id);
277 EXPECT_TRUE(iter != download_results_.end()); 277 EXPECT_TRUE(iter != download_results_.end());
278 EXPECT_EQ(iter->second, result); 278 EXPECT_EQ(iter->second, result);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 raw += "\n"; 532 raw += "\n";
533 std::replace(raw.begin(), raw.end(), '\n', '\0'); 533 std::replace(raw.begin(), raw.end(), '\n', '\0');
534 scoped_refptr<net::HttpResponseHeaders> headers( 534 scoped_refptr<net::HttpResponseHeaders> headers(
535 new net::HttpResponseHeaders(raw)); 535 new net::HttpResponseHeaders(raw));
536 uint32_t extracted; 536 uint32_t extracted;
537 ASSERT_FALSE( 537 ASSERT_FALSE(
538 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted)); 538 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted));
539 } 539 }
540 540
541 } // namespace syncer 541 } // namespace syncer
OLDNEW
« no previous file with comments | « remoting/protocol/fake_datagram_socket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698