Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 if (offlineURLExists) { | 79 if (offlineURLExists) { |
| 80 DownloadCompletionHandler(url, std::string(), DOWNLOAD_EXISTS); | 80 DownloadCompletionHandler(url, std::string(), DOWNLOAD_EXISTS); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 distiller_.reset(new DistillerViewerTest( | 83 distiller_.reset(new DistillerViewerTest( |
| 84 url, | 84 url, |
| 85 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); | 85 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void OnEndDownload(const GURL& url, | 88 void OnEndDownload(const GURL& url, |
| 89 const GURL& distilled_url, | |
| 89 SuccessState success, | 90 SuccessState success, |
| 90 const base::FilePath& distilled_path, | 91 const base::FilePath& distilled_path, |
| 91 const std::string& title) { | 92 const std::string& title) { |
| 92 downloaded_files_.push_back(url); | 93 downloaded_files_.push_back(url); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void OnEndRemove(const GURL& url, bool success) { | 96 void OnEndRemove(const GURL& url, bool success) { |
| 96 removed_files_.push_back(url); | 97 removed_files_.push_back(url); |
| 97 } | 98 } |
| 98 }; | 99 }; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 114 downloader_->RemoveOfflineFilesDirectory(); | 115 downloader_->RemoveOfflineFilesDirectory(); |
| 115 downloader_->ClearCompletionTrackers(); | 116 downloader_->ClearCompletionTrackers(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void WaitUntilCondition(ConditionBlock condition) { | 119 void WaitUntilCondition(ConditionBlock condition) { |
| 119 base::test::ios::WaitUntilCondition(condition, true, | 120 base::test::ios::WaitUntilCondition(condition, true, |
| 120 base::TimeDelta::FromSeconds(1)); | 121 base::TimeDelta::FromSeconds(1)); |
| 121 } | 122 } |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 TEST_F(URLDownloaderTest, SingleDownload) { | 125 TEST_F(URLDownloaderTest, SingleDownload) { |
|
gambard
2017/01/20 14:15:14
Maybe you can add to this test the redirection url
Olivier
2017/01/20 15:31:16
Not easy because all the calls here are synchronou
| |
| 125 GURL url = GURL("http://test.com"); | 126 GURL url = GURL("http://test.com"); |
| 126 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); | 127 ASSERT_FALSE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); |
| 127 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); | 128 ASSERT_EQ(0ul, downloader_->downloaded_files_.size()); |
| 128 ASSERT_EQ(0ul, downloader_->removed_files_.size()); | 129 ASSERT_EQ(0ul, downloader_->removed_files_.size()); |
| 129 | 130 |
| 130 downloader_->DownloadOfflineURL(url); | 131 downloader_->DownloadOfflineURL(url); |
| 131 | 132 |
| 132 WaitUntilCondition(^bool { | 133 WaitUntilCondition(^bool { |
| 133 return std::find(downloader_->downloaded_files_.begin(), | 134 return std::find(downloader_->downloaded_files_.begin(), |
| 134 downloader_->downloaded_files_.end(), | 135 downloader_->downloaded_files_.end(), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), | 185 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), |
| 185 downloader_->downloaded_files_.end(), | 186 downloader_->downloaded_files_.end(), |
| 186 url) != downloader_->downloaded_files_.end()); | 187 url) != downloader_->downloaded_files_.end()); |
| 187 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), | 188 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), |
| 188 downloader_->removed_files_.end(), | 189 downloader_->removed_files_.end(), |
| 189 url) != downloader_->removed_files_.end()); | 190 url) != downloader_->removed_files_.end()); |
| 190 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); | 191 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace | 194 } // namespace |
| OLD | NEW |