| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #import "base/test/ios/wait_util.h" | 14 #import "base/test/ios/wait_util.h" |
| 15 #include "ios/chrome/browser/chrome_paths.h" | 15 #include "ios/chrome/browser/chrome_paths.h" |
| 16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" | 16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 17 #include "ios/web/public/test/test_web_thread_bundle.h" | 17 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { | 22 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { |
| 23 public: | 23 public: |
| 24 DistillerViewerTest(const GURL& url, | 24 DistillerViewerTest(const GURL& url, |
| 25 const DistillationFinishedCallback& callback) | 25 const DistillationFinishedCallback& callback) |
| 26 : dom_distiller::DistillerViewerInterface(nil, nil) { | 26 : dom_distiller::DistillerViewerInterface(nil, nil) { |
| 27 std::vector<ImageInfo> images; | 27 std::vector<ImageInfo> images; |
| 28 callback.Run(url, "html", images); | 28 callback.Run(url, "html", images, "title"); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void OnArticleReady( | 31 void OnArticleReady( |
| 32 const dom_distiller::DistilledArticleProto* article_proto) override {} | 32 const dom_distiller::DistilledArticleProto* article_proto) override {} |
| 33 | 33 |
| 34 void SendJavaScript(const std::string& buffer) override {} | 34 void SendJavaScript(const std::string& buffer) override {} |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 working_ = false; | 66 working_ = false; |
| 67 HandleNextTask(); | 67 HandleNextTask(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 std::vector<GURL> downloaded_files_; | 70 std::vector<GURL> downloaded_files_; |
| 71 std::vector<GURL> removed_files_; | 71 std::vector<GURL> removed_files_; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 void DownloadURL(GURL url, bool offlineURLExists) override { | 74 void DownloadURL(GURL url, bool offlineURLExists) override { |
| 75 if (offlineURLExists) { | 75 if (offlineURLExists) { |
| 76 DownloadCompletionHandler(url, false); | 76 DownloadCompletionHandler(url, std::string(), DOWNLOAD_EXISTS); |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 distiller_.reset(new DistillerViewerTest( | 79 distiller_.reset(new DistillerViewerTest( |
| 80 url, | 80 url, |
| 81 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); | 81 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void OnEndDownload(const GURL& url, bool success) { | 84 void OnEndDownload(const GURL& url, |
| 85 SuccessState success, |
| 86 const GURL& distilledURL, |
| 87 const std::string& title) { |
| 85 downloaded_files_.push_back(url); | 88 downloaded_files_.push_back(url); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void OnEndRemove(const GURL& url, bool success) { | 91 void OnEndRemove(const GURL& url, bool success) { |
| 89 removed_files_.push_back(url); | 92 removed_files_.push_back(url); |
| 90 } | 93 } |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 namespace { | 96 namespace { |
| 94 class URLDownloaderTest : public testing::Test { | 97 class URLDownloaderTest : public testing::Test { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), | 182 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), |
| 180 downloader_->downloaded_files_.end(), | 183 downloader_->downloaded_files_.end(), |
| 181 url) != downloader_->downloaded_files_.end()); | 184 url) != downloader_->downloaded_files_.end()); |
| 182 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), | 185 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), |
| 183 downloader_->removed_files_.end(), | 186 downloader_->removed_files_.end(), |
| 184 url) != downloader_->removed_files_.end()); | 187 url) != downloader_->removed_files_.end()); |
| 185 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); | 188 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); |
| 186 } | 189 } |
| 187 | 190 |
| 188 } // namespace | 191 } // namespace |
| OLD | NEW |