OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "components/open_from_clipboard/clipboard_recent_content_generic.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/base/clipboard/clipboard.h" |
| 11 |
| 12 class MockClipboard : public base::Clipboard { |
| 13 public: |
| 14 void ReadText(ClipboardType type, base::string16* result) const override; |
| 15 base::Time GetClipboardLastModifiedTime() const override; |
| 16 |
| 17 // Empty required implementations of Clipboard. |
| 18 void OnPreShutdown() override {} |
| 19 uint64_t GetSequenceNumber(ClipboardType type) const override {} |
| 20 bool IsFormatAvailable(const FormatType& format, |
| 21 ClipboardType type) const override {} |
| 22 void Clear(ClipboardType type) override {} |
| 23 void ReadAvailableTypes(ClipboardType type, |
| 24 std::vector<base::string16>* types, |
| 25 bool* contains_filenames) const override {} |
| 26 void ReadAsciiText(ClipboardType type, std::string* result) const override {} |
| 27 void ReadHTML(ClipboardType type, |
| 28 base::string16* markup, |
| 29 std::string* src_url, |
| 30 uint32_t* fragment_start, |
| 31 uint32_t* fragment_end) const override {} |
| 32 void ReadRTF(ClipboardType type, std::string* result) const override {} |
| 33 SkBitmap ReadImage(ClipboardType type) const override {} |
| 34 void ReadCustomData(ClipboardType clipboard_type, |
| 35 const base::string16& type, |
| 36 base::string16* result) const override {} |
| 37 void ReadBookmark(base::string16* title, std::string* url) const override {} |
| 38 void ReadData(const FormatType& format, std::string* result) const override {} |
| 39 |
| 40 protected: |
| 41 void WriteText(const char* text_data, size_t text_len) override; |
| 42 void SetClipboardLastModifiedTime(const base::Time& time); |
| 43 |
| 44 // Empty required implementations of Clipboard. |
| 45 void WriteObjects(ClipboardType type, const ObjectMap& objects) override {} |
| 46 void WriteHTML(const char* markup_data, |
| 47 size_t markup_len, |
| 48 const char* url_data, |
| 49 size_t url_len) override {} |
| 50 void WriteRTF(const char* rtf_data, size_t data_len) override {} |
| 51 void WriteBookmark(const char* title_data, |
| 52 size_t title_len, |
| 53 const char* url_data, |
| 54 size_t url_len) override {} |
| 55 void WriteWebSmartPaste() override {} |
| 56 void WriteBitmap(const SkBitmap& bitmap) override {} |
| 57 void WriteData(const FormatType& format, |
| 58 const char* data_data, |
| 59 size_t data_len) override {} |
| 60 |
| 61 private: |
| 62 base::string16 contents_; |
| 63 base::Time last_modified_time_; |
| 64 }; |
| 65 |
| 66 void MockClipboard::ReadText(ClipboardType type, base::string16* result) const { |
| 67 (*result) = contents_; |
| 68 } |
| 69 |
| 70 base::Time MockClipboard::GetClipboardLastModifiedTime() const { |
| 71 return last_modified_time_; |
| 72 } |
| 73 |
| 74 void MockClipboard::WriteText(const char* text_data, size_t text_len) { |
| 75 base::UTF8ToUTF16(text_data, text_len, &contents_); |
| 76 } |
| 77 |
| 78 void MockClipboard::SetClipboardLastModifiedTime(const base::Time& time) { |
| 79 last_modified_time_ = time; |
| 80 } |
| 81 |
| 82 /* |
| 83 class ClipboardRecentContentGenericTest : public ::testing::Test { |
| 84 protected: |
| 85 ClipboardRecentContentGenericTest() { |
| 86 ui::TestClipboard::CreateForCurrentThread(); |
| 87 } |
| 88 |
| 89 ~ClipboardRecentContentGenericTest() { |
| 90 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 91 } |
| 92 |
| 93 void SetClipboardContent(const base::string16& content, |
| 94 const base::TimeDelta& time) { |
| 95 Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| 96 clipboard_content_.reset(new ClipboardRecentContentIOSWithFakeUptime( |
| 97 application_scheme, [NSUserDefaults standardUserDefaults])); |
| 98 clipboard_content_->SetUptime(time_delta); |
| 99 } |
| 100 |
| 101 void SetStoredPasteboardChangeDate(NSDate* changeDate) { |
| 102 clipboard_content_->last_pasteboard_change_date_.reset([changeDate copy]); |
| 103 clipboard_content_->SaveToUserDefaults(); |
| 104 } |
| 105 |
| 106 void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { |
| 107 clipboard_content_->last_pasteboard_change_count_ = newChangeCount; |
| 108 clipboard_content_->SaveToUserDefaults(); |
| 109 } |
| 110 |
| 111 protected: |
| 112 std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_; |
| 113 }; |
| 114 */ |
| 115 |
| 116 TEST_F(ClipboardRecentContentGenericTest, RecognizesURLs) { |
| 117 /* |
| 118 www |
| 119 query string |
| 120 www.example.com |
| 121 http://www.example.com/ |
| 122 // Trailing slash shouldn't matter. |
| 123 http://www.example.com |
| 124 https://another-example.com/ |
| 125 ftp://example.com/ |
| 126 about:version |
| 127 data:,Hello%2C%20World! |
| 128 http://malformed url |
| 129 http://another.com/malformed url |
| 130 http://xn--c1yn36f |
| 131 http://點看 |
| 132 */ |
| 133 // *** |
| 134 } |
| 135 |
| 136 TEST_F(ClipboardRecentContentGenericTest, OlderURLsNotSuggested) { |
| 137 // *** |
| 138 } |
| 139 |
| 140 TEST_F(ClipboardRecentContentGenericTest, GetClipboardContentAge) { |
| 141 // *** |
| 142 } |
| 143 |
| 144 TEST_F(ClipboardRecentContentGenericTest, SuppressClipboardContent) { |
| 145 // Make sure the URL is suggested. |
| 146 |
| 147 // After suppressing it, it shouldn't be suggested. |
| 148 |
| 149 // If the content changes, the new content should be suggested again. |
| 150 |
| 151 // *** |
| 152 } |
OLD | NEW |