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 13 matching lines...) Expand all Loading... |
24 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { | 24 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { |
25 public: | 25 public: |
26 DistillerViewerTest(const GURL& url, | 26 DistillerViewerTest(const GURL& url, |
27 const DistillationFinishedCallback& callback, | 27 const DistillationFinishedCallback& callback, |
28 reading_list::ReadingListDistillerPageDelegate* delegate, | 28 reading_list::ReadingListDistillerPageDelegate* delegate, |
29 const std::string& html, | 29 const std::string& html, |
30 const GURL& redirect_url, | 30 const GURL& redirect_url, |
31 const std::string& mime_type) | 31 const std::string& mime_type) |
32 : dom_distiller::DistillerViewerInterface(nil) { | 32 : dom_distiller::DistillerViewerInterface(nil) { |
33 std::vector<ImageInfo> images; | 33 std::vector<ImageInfo> images; |
| 34 ImageInfo image; |
| 35 image.url = GURL("http://image"); |
| 36 image.data = "image"; |
| 37 images.push_back(image); |
| 38 |
34 if (redirect_url.is_valid()) { | 39 if (redirect_url.is_valid()) { |
35 delegate->DistilledPageRedirectedToURL(url, redirect_url); | 40 delegate->DistilledPageRedirectedToURL(url, redirect_url); |
36 } | 41 } |
37 if (!mime_type.empty()) { | 42 if (!mime_type.empty()) { |
38 delegate->DistilledPageHasMimeType(url, mime_type); | 43 delegate->DistilledPageHasMimeType(url, mime_type); |
39 } | 44 } |
40 callback.Run(url, html, images, "title"); | 45 callback.Run(url, html, images, "title"); |
41 } | 46 } |
42 | 47 |
43 void OnArticleReady( | 48 void OnArticleReady( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool fetching_pdf_; | 99 bool fetching_pdf_; |
95 | 100 |
96 private: | 101 private: |
97 void DownloadURL(const GURL& url, bool offline_url_exists) override { | 102 void DownloadURL(const GURL& url, bool offline_url_exists) override { |
98 if (offline_url_exists) { | 103 if (offline_url_exists) { |
99 DownloadCompletionHandler(url, std::string(), base::FilePath(), | 104 DownloadCompletionHandler(url, std::string(), base::FilePath(), |
100 DOWNLOAD_EXISTS); | 105 DOWNLOAD_EXISTS); |
101 return; | 106 return; |
102 } | 107 } |
103 original_url_ = url; | 108 original_url_ = url; |
| 109 saved_size_ = 0; |
104 distiller_.reset(new DistillerViewerTest( | 110 distiller_.reset(new DistillerViewerTest( |
105 url, | 111 url, |
106 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)), | 112 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)), |
107 this, html_, redirect_url_, mime_type_)); | 113 this, html_, redirect_url_, mime_type_)); |
108 } | 114 } |
109 | 115 |
110 void FetchPDFFile() override { fetching_pdf_ = true; } | 116 void FetchPDFFile() override { fetching_pdf_ = true; } |
111 | 117 |
112 void OnEndDownload(const GURL& url, | 118 void OnEndDownload(const GURL& url, |
113 const GURL& distilled_url, | 119 const GURL& distilled_url, |
114 SuccessState success, | 120 SuccessState success, |
115 const base::FilePath& distilled_path, | 121 const base::FilePath& distilled_path, |
| 122 int64_t size, |
116 const std::string& title) { | 123 const std::string& title) { |
117 downloaded_files_.push_back(url); | 124 downloaded_files_.push_back(url); |
118 DCHECK_EQ(distilled_url, redirect_url_); | 125 // Saved data is the string "html" and an image with data "image". |
| 126 EXPECT_EQ(size, 9); |
| 127 EXPECT_EQ(distilled_url, redirect_url_); |
119 } | 128 } |
120 | 129 |
121 void OnEndRemove(const GURL& url, bool success) { | 130 void OnEndRemove(const GURL& url, bool success) { |
122 removed_files_.push_back(url); | 131 removed_files_.push_back(url); |
123 } | 132 } |
124 }; | 133 }; |
125 | 134 |
126 namespace { | 135 namespace { |
127 class URLDownloaderTest : public testing::Test { | 136 class URLDownloaderTest : public testing::Test { |
128 public: | 137 public: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), | 261 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), |
253 downloader_->downloaded_files_.end(), | 262 downloader_->downloaded_files_.end(), |
254 url) != downloader_->downloaded_files_.end()); | 263 url) != downloader_->downloaded_files_.end()); |
255 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), | 264 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), |
256 downloader_->removed_files_.end(), | 265 downloader_->removed_files_.end(), |
257 url) != downloader_->removed_files_.end()); | 266 url) != downloader_->removed_files_.end()); |
258 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); | 267 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); |
259 } | 268 } |
260 | 269 |
261 } // namespace | 270 } // namespace |
OLD | NEW |