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

Side by Side Diff: ios/chrome/browser/reading_list/url_downloader_unittest.mm

Issue 2945803002: Use ContainsValue() instead of std::find() in ios/ (Closed)
Patch Set: Fixed compilation error. Created 3 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ios/chrome/browser/reading_list/url_downloader.h" 5 #include "ios/chrome/browser/reading_list/url_downloader.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #import "base/mac/bind_objc_block.h" 10 #import "base/mac/bind_objc_block.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stl_util.h"
13 #import "base/test/ios/wait_util.h" 14 #import "base/test/ios/wait_util.h"
14 #include "components/reading_list/core/offline_url_utils.h" 15 #include "components/reading_list/core/offline_url_utils.h"
15 #include "ios/chrome/browser/chrome_paths.h" 16 #include "ios/chrome/browser/chrome_paths.h"
16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" 17 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h"
17 #include "ios/chrome/browser/reading_list/offline_url_utils.h" 18 #include "ios/chrome/browser/reading_list/offline_url_utils.h"
18 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" 19 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h"
19 #include "ios/web/public/test/test_web_thread_bundle.h" 20 #include "ios/web/public/test/test_web_thread_bundle.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace { 23 namespace {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 162
162 TEST_F(URLDownloaderTest, SingleDownload) { 163 TEST_F(URLDownloaderTest, SingleDownload) {
163 GURL url = GURL("http://test.com"); 164 GURL url = GURL("http://test.com");
164 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 165 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
165 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); 166 ASSERT_EQ(0ul, downloader_->downloaded_files_.size());
166 ASSERT_EQ(0ul, downloader_->removed_files_.size()); 167 ASSERT_EQ(0ul, downloader_->removed_files_.size());
167 168
168 downloader_->DownloadOfflineURL(url); 169 downloader_->DownloadOfflineURL(url);
169 170
170 WaitUntilCondition(^bool { 171 WaitUntilCondition(^bool {
171 return std::find(downloader_->downloaded_files_.begin(), 172 return base::ContainsValue(downloader_->downloaded_files_, url);
172 downloader_->downloaded_files_.end(),
173 url) != downloader_->downloaded_files_.end();
174 }); 173 });
175 174
176 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 175 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
177 } 176 }
178 177
179 TEST_F(URLDownloaderTest, SingleDownloadRedirect) { 178 TEST_F(URLDownloaderTest, SingleDownloadRedirect) {
180 GURL url = GURL("http://test.com"); 179 GURL url = GURL("http://test.com");
181 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 180 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
182 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); 181 ASSERT_EQ(0ul, downloader_->downloaded_files_.size());
183 ASSERT_EQ(0ul, downloader_->removed_files_.size()); 182 ASSERT_EQ(0ul, downloader_->removed_files_.size());
184 183
185 // The DCHECK in OnEndDownload will verify that the redirection was handled 184 // The DCHECK in OnEndDownload will verify that the redirection was handled
186 // correctly. 185 // correctly.
187 downloader_->redirect_url_ = GURL("http://test.com/redirected"); 186 downloader_->redirect_url_ = GURL("http://test.com/redirected");
188 187
189 downloader_->DownloadOfflineURL(url); 188 downloader_->DownloadOfflineURL(url);
190 189
191 WaitUntilCondition(^bool { 190 WaitUntilCondition(^bool {
192 return std::find(downloader_->downloaded_files_.begin(), 191 return base::ContainsValue(downloader_->downloaded_files_, url);
193 downloader_->downloaded_files_.end(),
194 url) != downloader_->downloaded_files_.end();
195 }); 192 });
196 193
197 EXPECT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 194 EXPECT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
198 } 195 }
199 196
200 TEST_F(URLDownloaderTest, SingleDownloadPDF) { 197 TEST_F(URLDownloaderTest, SingleDownloadPDF) {
201 GURL url = GURL("http://test.com"); 198 GURL url = GURL("http://test.com");
202 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 199 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
203 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); 200 ASSERT_EQ(0ul, downloader_->downloaded_files_.size());
204 ASSERT_EQ(0ul, downloader_->removed_files_.size()); 201 ASSERT_EQ(0ul, downloader_->removed_files_.size());
(...skipping 17 matching lines...) Expand all
222 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url2)); 219 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url2));
223 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); 220 ASSERT_EQ(0ul, downloader_->downloaded_files_.size());
224 ASSERT_EQ(0ul, downloader_->removed_files_.size()); 221 ASSERT_EQ(0ul, downloader_->removed_files_.size());
225 downloader_->FakeWorking(); 222 downloader_->FakeWorking();
226 downloader_->DownloadOfflineURL(url); 223 downloader_->DownloadOfflineURL(url);
227 downloader_->DownloadOfflineURL(url2); 224 downloader_->DownloadOfflineURL(url2);
228 downloader_->RemoveOfflineURL(url); 225 downloader_->RemoveOfflineURL(url);
229 downloader_->FakeEndWorking(); 226 downloader_->FakeEndWorking();
230 227
231 WaitUntilCondition(^bool { 228 WaitUntilCondition(^bool {
232 return std::find(downloader_->removed_files_.begin(), 229 return base::ContainsValue(downloader_->removed_files_, url);
233 downloader_->removed_files_.end(),
234 url) != downloader_->removed_files_.end();
235 }); 230 });
236 231
237 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), 232 ASSERT_TRUE(!base::ContainsValue(downloader_->downloaded_files_, url));
238 downloader_->downloaded_files_.end(),
239 url) == downloader_->downloaded_files_.end());
240 ASSERT_EQ(1ul, downloader_->downloaded_files_.size()); 233 ASSERT_EQ(1ul, downloader_->downloaded_files_.size());
241 ASSERT_EQ(1ul, downloader_->removed_files_.size()); 234 ASSERT_EQ(1ul, downloader_->removed_files_.size());
242 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 235 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
243 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url2)); 236 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url2));
244 } 237 }
245 238
246 TEST_F(URLDownloaderTest, DownloadAndRemoveAndRedownload) { 239 TEST_F(URLDownloaderTest, DownloadAndRemoveAndRedownload) {
247 GURL url = GURL("http://test.com"); 240 GURL url = GURL("http://test.com");
248 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 241 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
249 downloader_->FakeWorking(); 242 downloader_->FakeWorking();
250 downloader_->DownloadOfflineURL(url); 243 downloader_->DownloadOfflineURL(url);
251 downloader_->RemoveOfflineURL(url); 244 downloader_->RemoveOfflineURL(url);
252 downloader_->DownloadOfflineURL(url); 245 downloader_->DownloadOfflineURL(url);
253 downloader_->FakeEndWorking(); 246 downloader_->FakeEndWorking();
254 247
255 WaitUntilCondition(^bool { 248 WaitUntilCondition(^bool {
256 return std::find(downloader_->removed_files_.begin(), 249 return base::ContainsValue(downloader_->removed_files_, url);
257 downloader_->removed_files_.end(),
258 url) != downloader_->removed_files_.end();
259 }); 250 });
260 251
261 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), 252 ASSERT_TRUE(base::ContainsValue(downloader_->downloaded_files_, url));
262 downloader_->downloaded_files_.end(), 253 ASSERT_TRUE(base::ContainsValue(downloader_->removed_files_, url));
263 url) != downloader_->downloaded_files_.end());
264 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(),
265 downloader_->removed_files_.end(),
266 url) != downloader_->removed_files_.end());
267 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); 254 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url));
268 } 255 }
269 256
270 } // namespace 257 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/url_downloader.cc ('k') | ios/chrome/browser/ui/bookmarks/bookmark_collection_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698