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" |
| 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 #import "base/test/ios/wait_util.h" | 13 #import "base/test/ios/wait_util.h" |
| 14 #include "ios/chrome/browser/chrome_paths.h" | 14 #include "ios/chrome/browser/chrome_paths.h" |
| 15 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" | 15 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 16 #include "ios/chrome/browser/reading_list/offline_url_utils.h" | |
| 16 #include "ios/web/public/test/test_web_thread_bundle.h" | 17 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { | 22 class DistillerViewerTest : public dom_distiller::DistillerViewerInterface { |
| 22 public: | 23 public: |
| 23 DistillerViewerTest(const GURL& url, | 24 DistillerViewerTest(const GURL& url, |
| 24 const DistillationFinishedCallback& callback) | 25 const DistillationFinishedCallback& callback) |
| 25 : dom_distiller::DistillerViewerInterface(nil, nil) { | 26 : dom_distiller::DistillerViewerInterface(nil, nil) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 | 38 |
| 38 class MockURLDownloader : public URLDownloader { | 39 class MockURLDownloader : public URLDownloader { |
| 39 public: | 40 public: |
| 40 MockURLDownloader(base::FilePath path) | 41 MockURLDownloader(base::FilePath path) |
| 41 : URLDownloader(nil, | 42 : URLDownloader(nil, |
| 42 nil, | 43 nil, |
| 43 path, | 44 path, |
| 44 base::Bind(&MockURLDownloader::OnEndDownload, | 45 base::Bind(&MockURLDownloader::OnEndDownload, |
| 45 base::Unretained(this)), | 46 base::Unretained(this)), |
| 46 base::Bind(&MockURLDownloader::OnEndRemove, | 47 base::Bind(&MockURLDownloader::OnEndRemove, |
| 47 base::Unretained(this))) {} | 48 base::Unretained(this))), |
| 49 base_path_(path) {} | |
| 48 | 50 |
| 49 void RemoveOfflineFilesDirectory() { | 51 void RemoveOfflineFilesDirectory() { |
| 50 base::DeleteFile(OfflineRootDirectoryPath(), true); | 52 base::DeleteFile(reading_list::OfflineRootDirectoryPath(base_path_), true); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void ClearCompletionTrackers() { | 55 void ClearCompletionTrackers() { |
| 54 downloaded_files_.clear(); | 56 downloaded_files_.clear(); |
| 55 removed_files_.clear(); | 57 removed_files_.clear(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 bool CheckExistenceOfOfflineURLPagePath(const GURL& url) { | 60 bool CheckExistenceOfOfflineURLPagePath(const GURL& url) { |
| 59 return base::PathExists(OfflinePageAbsolutePath(url)); | 61 return base::PathExists( |
| 62 reading_list::OfflinePageAbsolutePath(base_directory_, url)); | |
|
gambard
2016/11/16 12:44:20
base_directory_ or base_path_?
Olivier
2016/11/16 13:36:27
Actually MockURLDownloader is friend of URLDownloa
| |
| 60 } | 63 } |
| 61 | 64 |
| 62 void FakeWorking() { working_ = true; } | 65 void FakeWorking() { working_ = true; } |
| 63 | 66 |
| 64 void FakeEndWorking() { | 67 void FakeEndWorking() { |
| 65 working_ = false; | 68 working_ = false; |
| 66 HandleNextTask(); | 69 HandleNextTask(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 std::vector<GURL> downloaded_files_; | 72 std::vector<GURL> downloaded_files_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 83 void OnEndDownload(const GURL& url, | 86 void OnEndDownload(const GURL& url, |
| 84 SuccessState success, | 87 SuccessState success, |
| 85 const base::FilePath& distilled_path, | 88 const base::FilePath& distilled_path, |
| 86 const std::string& title) { | 89 const std::string& title) { |
| 87 downloaded_files_.push_back(url); | 90 downloaded_files_.push_back(url); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void OnEndRemove(const GURL& url, bool success) { | 93 void OnEndRemove(const GURL& url, bool success) { |
| 91 removed_files_.push_back(url); | 94 removed_files_.push_back(url); |
| 92 } | 95 } |
| 96 | |
| 97 base::FilePath base_path_; | |
| 93 }; | 98 }; |
| 94 | 99 |
| 95 namespace { | 100 namespace { |
| 96 class URLDownloaderTest : public testing::Test { | 101 class URLDownloaderTest : public testing::Test { |
| 97 public: | 102 public: |
| 98 std::unique_ptr<MockURLDownloader> downloader_; | 103 std::unique_ptr<MockURLDownloader> downloader_; |
| 99 web::TestWebThreadBundle bundle_; | 104 web::TestWebThreadBundle bundle_; |
| 100 | 105 |
| 101 URLDownloaderTest() { | 106 URLDownloaderTest() { |
| 102 base::FilePath data_dir; | 107 base::FilePath data_dir; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), | 184 ASSERT_TRUE(std::find(downloader_->downloaded_files_.begin(), |
| 180 downloader_->downloaded_files_.end(), | 185 downloader_->downloaded_files_.end(), |
| 181 url) != downloader_->downloaded_files_.end()); | 186 url) != downloader_->downloaded_files_.end()); |
| 182 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), | 187 ASSERT_TRUE(std::find(downloader_->removed_files_.begin(), |
| 183 downloader_->removed_files_.end(), | 188 downloader_->removed_files_.end(), |
| 184 url) != downloader_->removed_files_.end()); | 189 url) != downloader_->removed_files_.end()); |
| 185 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); | 190 ASSERT_TRUE(downloader_->CheckExistenceOfOfflineURLPagePath(url)); |
| 186 } | 191 } |
| 187 | 192 |
| 188 } // namespace | 193 } // namespace |
| OLD | NEW |