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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/download_metadata_manager_unittest.cc

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 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 "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 base::FilePath GetMetadataPath() const { 115 base::FilePath GetMetadataPath() const {
116 return profile_.GetPath().Append(FILE_PATH_LITERAL("DownloadMetadata")); 116 return profile_.GetPath().Append(FILE_PATH_LITERAL("DownloadMetadata"));
117 } 117 }
118 118
119 // Returns a new ClientDownloadRequest for the given download URL. 119 // Returns a new ClientDownloadRequest for the given download URL.
120 static scoped_ptr<ClientDownloadRequest> MakeTestRequest(const char* url) { 120 static scoped_ptr<ClientDownloadRequest> MakeTestRequest(const char* url) {
121 scoped_ptr<ClientDownloadRequest> request(new ClientDownloadRequest()); 121 scoped_ptr<ClientDownloadRequest> request(new ClientDownloadRequest());
122 request->set_url(url); 122 request->set_url(url);
123 request->mutable_digests(); 123 request->mutable_digests();
124 request->set_length(kTestDownloadLength); 124 request->set_length(kTestDownloadLength);
125 return request.Pass(); 125 return request;
126 } 126 }
127 127
128 // Returns a new DownloadMetdata for the given download id. 128 // Returns a new DownloadMetdata for the given download id.
129 static scoped_ptr<DownloadMetadata> GetTestMetadata(uint32_t download_id) { 129 static scoped_ptr<DownloadMetadata> GetTestMetadata(uint32_t download_id) {
130 scoped_ptr<DownloadMetadata> metadata(new DownloadMetadata()); 130 scoped_ptr<DownloadMetadata> metadata(new DownloadMetadata());
131 metadata->set_download_id(download_id); 131 metadata->set_download_id(download_id);
132 ClientIncidentReport_DownloadDetails* details = 132 ClientIncidentReport_DownloadDetails* details =
133 metadata->mutable_download(); 133 metadata->mutable_download();
134 details->set_download_time_msec(kTestDownloadTimeMsec); 134 details->set_download_time_msec(kTestDownloadTimeMsec);
135 details->set_allocated_download(MakeTestRequest(kTestUrl).release()); 135 details->set_allocated_download(MakeTestRequest(kTestUrl).release());
136 return metadata.Pass(); 136 return metadata;
137 } 137 }
138 138
139 // Writes a test DownloadMetadata file for the given download id to the 139 // Writes a test DownloadMetadata file for the given download id to the
140 // test profile directory. 140 // test profile directory.
141 void WriteTestMetadataFileForItem(uint32_t download_id) { 141 void WriteTestMetadataFileForItem(uint32_t download_id) {
142 std::string data; 142 std::string data;
143 ASSERT_TRUE(GetTestMetadata(download_id)->SerializeToString(&data)); 143 ASSERT_TRUE(GetTestMetadata(download_id)->SerializeToString(&data));
144 ASSERT_TRUE(base::WriteFile(GetMetadataPath(), data.data(), data.size())); 144 ASSERT_TRUE(base::WriteFile(GetMetadataPath(), data.data(), data.size()));
145 } 145 }
146 146
147 // Writes a test DownloadMetadata file for kTestDownloadId to the test profile 147 // Writes a test DownloadMetadata file for kTestDownloadId to the test profile
148 // directory. 148 // directory.
149 void WriteTestMetadataFile() { 149 void WriteTestMetadataFile() {
150 WriteTestMetadataFileForItem(kTestDownloadId); 150 WriteTestMetadataFileForItem(kTestDownloadId);
151 } 151 }
152 152
153 // Returns the DownloadMetadata read from the test profile's directory. 153 // Returns the DownloadMetadata read from the test profile's directory.
154 scoped_ptr<DownloadMetadata> ReadTestMetadataFile() const { 154 scoped_ptr<DownloadMetadata> ReadTestMetadataFile() const {
155 std::string data; 155 std::string data;
156 if (!base::ReadFileToString(GetMetadataPath(), &data)) 156 if (!base::ReadFileToString(GetMetadataPath(), &data))
157 return scoped_ptr<DownloadMetadata>(); 157 return scoped_ptr<DownloadMetadata>();
158 scoped_ptr<DownloadMetadata> result(new DownloadMetadata); 158 scoped_ptr<DownloadMetadata> result(new DownloadMetadata);
159 EXPECT_TRUE(result->ParseFromString(data)); 159 EXPECT_TRUE(result->ParseFromString(data));
160 return result.Pass(); 160 return result;
161 } 161 }
162 162
163 // Runs all tasks posted to the test thread's message loop. 163 // Runs all tasks posted to the test thread's message loop.
164 void RunAllTasks() { base::MessageLoop::current()->RunUntilIdle(); } 164 void RunAllTasks() { base::MessageLoop::current()->RunUntilIdle(); }
165 165
166 // Adds a DownloadManager for the test profile. The DownloadMetadataManager's 166 // Adds a DownloadManager for the test profile. The DownloadMetadataManager's
167 // observer is stashed for later use. Only call once per call to 167 // observer is stashed for later use. Only call once per call to
168 // ShutdownDownloadManager. 168 // ShutdownDownloadManager.
169 void AddDownloadManager() { 169 void AddDownloadManager() {
170 ASSERT_EQ(nullptr, dm_observer_); 170 ASSERT_EQ(nullptr, dm_observer_);
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // Allow everything to load into steady-state. 609 // Allow everything to load into steady-state.
610 RunAllTasks(); 610 RunAllTasks();
611 611
612 // Open the zero-id item. 612 // Open the zero-id item.
613 zero_item_->NotifyObserversDownloadOpened(); 613 zero_item_->NotifyObserversDownloadOpened();
614 614
615 ShutdownDownloadManager(); 615 ShutdownDownloadManager();
616 } 616 }
617 617
618 } // namespace safe_browsing 618 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698