| Index: components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc
|
| diff --git a/components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc b/components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..53bfb793e63eb018efabecd87e7f8e3ee5a9cf89
|
| --- /dev/null
|
| +++ b/components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc
|
| @@ -0,0 +1,152 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/open_from_clipboard/clipboard_recent_content_generic.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "ui/base/clipboard/clipboard.h"
|
| +
|
| +class MockClipboard : public base::Clipboard {
|
| + public:
|
| + void ReadText(ClipboardType type, base::string16* result) const override;
|
| + base::Time GetClipboardLastModifiedTime() const override;
|
| +
|
| + // Empty required implementations of Clipboard.
|
| + void OnPreShutdown() override {}
|
| + uint64_t GetSequenceNumber(ClipboardType type) const override {}
|
| + bool IsFormatAvailable(const FormatType& format,
|
| + ClipboardType type) const override {}
|
| + void Clear(ClipboardType type) override {}
|
| + void ReadAvailableTypes(ClipboardType type,
|
| + std::vector<base::string16>* types,
|
| + bool* contains_filenames) const override {}
|
| + void ReadAsciiText(ClipboardType type, std::string* result) const override {}
|
| + void ReadHTML(ClipboardType type,
|
| + base::string16* markup,
|
| + std::string* src_url,
|
| + uint32_t* fragment_start,
|
| + uint32_t* fragment_end) const override {}
|
| + void ReadRTF(ClipboardType type, std::string* result) const override {}
|
| + SkBitmap ReadImage(ClipboardType type) const override {}
|
| + void ReadCustomData(ClipboardType clipboard_type,
|
| + const base::string16& type,
|
| + base::string16* result) const override {}
|
| + void ReadBookmark(base::string16* title, std::string* url) const override {}
|
| + void ReadData(const FormatType& format, std::string* result) const override {}
|
| +
|
| + protected:
|
| + void WriteText(const char* text_data, size_t text_len) override;
|
| + void SetClipboardLastModifiedTime(const base::Time& time);
|
| +
|
| + // Empty required implementations of Clipboard.
|
| + void WriteObjects(ClipboardType type, const ObjectMap& objects) override {}
|
| + void WriteHTML(const char* markup_data,
|
| + size_t markup_len,
|
| + const char* url_data,
|
| + size_t url_len) override {}
|
| + void WriteRTF(const char* rtf_data, size_t data_len) override {}
|
| + void WriteBookmark(const char* title_data,
|
| + size_t title_len,
|
| + const char* url_data,
|
| + size_t url_len) override {}
|
| + void WriteWebSmartPaste() override {}
|
| + void WriteBitmap(const SkBitmap& bitmap) override {}
|
| + void WriteData(const FormatType& format,
|
| + const char* data_data,
|
| + size_t data_len) override {}
|
| +
|
| + private:
|
| + base::string16 contents_;
|
| + base::Time last_modified_time_;
|
| +};
|
| +
|
| +void MockClipboard::ReadText(ClipboardType type, base::string16* result) const {
|
| + (*result) = contents_;
|
| +}
|
| +
|
| +base::Time MockClipboard::GetClipboardLastModifiedTime() const {
|
| + return last_modified_time_;
|
| +}
|
| +
|
| +void MockClipboard::WriteText(const char* text_data, size_t text_len) {
|
| + base::UTF8ToUTF16(text_data, text_len, &contents_);
|
| +}
|
| +
|
| +void MockClipboard::SetClipboardLastModifiedTime(const base::Time& time) {
|
| + last_modified_time_ = time;
|
| +}
|
| +
|
| +/*
|
| +class ClipboardRecentContentGenericTest : public ::testing::Test {
|
| + protected:
|
| + ClipboardRecentContentGenericTest() {
|
| + ui::TestClipboard::CreateForCurrentThread();
|
| + }
|
| +
|
| + ~ClipboardRecentContentGenericTest() {
|
| + ui::Clipboard::DestroyClipboardForCurrentThread();
|
| + }
|
| +
|
| + void SetClipboardContent(const base::string16& content,
|
| + const base::TimeDelta& time) {
|
| + Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
| + clipboard_content_.reset(new ClipboardRecentContentIOSWithFakeUptime(
|
| + application_scheme, [NSUserDefaults standardUserDefaults]));
|
| + clipboard_content_->SetUptime(time_delta);
|
| + }
|
| +
|
| + void SetStoredPasteboardChangeDate(NSDate* changeDate) {
|
| + clipboard_content_->last_pasteboard_change_date_.reset([changeDate copy]);
|
| + clipboard_content_->SaveToUserDefaults();
|
| + }
|
| +
|
| + void SetStoredPasteboardChangeCount(NSInteger newChangeCount) {
|
| + clipboard_content_->last_pasteboard_change_count_ = newChangeCount;
|
| + clipboard_content_->SaveToUserDefaults();
|
| + }
|
| +
|
| + protected:
|
| + std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_;
|
| +};
|
| +*/
|
| +
|
| +TEST_F(ClipboardRecentContentGenericTest, RecognizesURLs) {
|
| + /*
|
| + www
|
| + query string
|
| + www.example.com
|
| + http://www.example.com/
|
| + // Trailing slash shouldn't matter.
|
| + http://www.example.com
|
| + https://another-example.com/
|
| + ftp://example.com/
|
| + about:version
|
| + data:,Hello%2C%20World!
|
| + http://malformed url
|
| + http://another.com/malformed url
|
| + http://xn--c1yn36f
|
| + http://點看
|
| + */
|
| + // ***
|
| +}
|
| +
|
| +TEST_F(ClipboardRecentContentGenericTest, OlderURLsNotSuggested) {
|
| + // ***
|
| +}
|
| +
|
| +TEST_F(ClipboardRecentContentGenericTest, GetClipboardContentAge) {
|
| + // ***
|
| +}
|
| +
|
| +TEST_F(ClipboardRecentContentGenericTest, SuppressClipboardContent) {
|
| + // Make sure the URL is suggested.
|
| +
|
| + // After suppressing it, it shouldn't be suggested.
|
| +
|
| + // If the content changes, the new content should be suggested again.
|
| +
|
| + // ***
|
| +}
|
|
|