| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/single_thread_task_runner.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 #include "components/offline_pages/offline_page_archiver.h" | |
| 16 | |
| 17 class GURL; | |
| 18 | |
| 19 namespace base { | |
| 20 class FilePath; | |
| 21 } // namespace | |
| 22 | |
| 23 namespace offline_pages { | |
| 24 | |
| 25 // A test archiver class, which allows for testing offline pages without a need | |
| 26 // for an actual web contents. | |
| 27 class OfflinePageTestArchiver : public OfflinePageArchiver { | |
| 28 public: | |
| 29 // TODO(fgorski): Try refactoring the observer out and replace it with a | |
| 30 // callback, or completely remove the call to |SetLastPathCreatedByArchiver|. | |
| 31 class Observer { | |
| 32 public: | |
| 33 virtual ~Observer() {} | |
| 34 virtual void SetLastPathCreatedByArchiver( | |
| 35 const base::FilePath& file_path) = 0; | |
| 36 }; | |
| 37 | |
| 38 OfflinePageTestArchiver( | |
| 39 Observer* observer, | |
| 40 const GURL& url, | |
| 41 ArchiverResult result, | |
| 42 const base::string16& result_title, | |
| 43 int64_t size_to_report, | |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
| 45 ~OfflinePageTestArchiver() override; | |
| 46 | |
| 47 // OfflinePageArchiver implementation: | |
| 48 void CreateArchive(const base::FilePath& archives_dir, | |
| 49 int64_t archive_id, | |
| 50 const CreateArchiveCallback& callback) override; | |
| 51 | |
| 52 // Completes the creation of archive. Should be used with |set_delayed| set to | |
| 53 // ture. | |
| 54 void CompleteCreateArchive(); | |
| 55 | |
| 56 // When set to true, |CompleteCreateArchive| should be called explicitly for | |
| 57 // the process to finish. | |
| 58 // TODO(fgorski): See if we can move this to the constructor. | |
| 59 void set_delayed(bool delayed) { delayed_ = delayed; } | |
| 60 | |
| 61 // Allows to explicitly specify a file name for the tests. | |
| 62 // TODO(fgorski): See if we can move this to the constructor. | |
| 63 void set_filename(const base::FilePath& filename) { filename_ = filename; } | |
| 64 | |
| 65 bool create_archive_called() const { return create_archive_called_; } | |
| 66 | |
| 67 private: | |
| 68 // Not owned. Outlives OfflinePageTestArchiver. | |
| 69 Observer* observer_; | |
| 70 GURL url_; | |
| 71 base::FilePath archives_dir_; | |
| 72 base::FilePath filename_; | |
| 73 ArchiverResult result_; | |
| 74 int64_t size_to_report_; | |
| 75 bool create_archive_called_; | |
| 76 bool delayed_; | |
| 77 base::string16 result_title_; | |
| 78 CreateArchiveCallback callback_; | |
| 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(OfflinePageTestArchiver); | |
| 82 }; | |
| 83 | |
| 84 } // namespace offline_pages | |
| 85 | |
| 86 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | |
| OLD | NEW |