| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "components/open_from_clipboard/clipboard_recent_content_generic.h" | 5 #include "components/open_from_clipboard/clipboard_recent_content_generic.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 {"http://點看/path", true}, | 58 {"http://點看/path", true}, |
| 59 {" http://點看/path ", true}, | 59 {" http://點看/path ", true}, |
| 60 {" http://點看/path extra word", false}, | 60 {" http://點看/path extra word", false}, |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 ClipboardRecentContentGeneric recent_content; | 63 ClipboardRecentContentGeneric recent_content; |
| 64 base::Time now = base::Time::Now(); | 64 base::Time now = base::Time::Now(); |
| 65 for (size_t i = 0; i < arraysize(test_data); ++i) { | 65 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 66 test_clipboard_->WriteText(test_data[i].clipboard.data(), | 66 test_clipboard_->WriteText(test_data[i].clipboard.data(), |
| 67 test_data[i].clipboard.length()); | 67 test_data[i].clipboard.length()); |
| 68 test_clipboard_->SetClipboardLastModifiedTime( | 68 test_clipboard_->SetLastModifiedTime(now - |
| 69 now - base::TimeDelta::FromSeconds(10)); | 69 base::TimeDelta::FromSeconds(10)); |
| 70 GURL url; | 70 GURL url; |
| 71 EXPECT_EQ(test_data[i].expected_get_recent_url_value, | 71 EXPECT_EQ(test_data[i].expected_get_recent_url_value, |
| 72 recent_content.GetRecentURLFromClipboard(&url)) | 72 recent_content.GetRecentURLFromClipboard(&url)) |
| 73 << "for input " << test_data[i].clipboard; | 73 << "for input " << test_data[i].clipboard; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(ClipboardRecentContentGenericTest, OlderURLsNotSuggested) { | 77 TEST_F(ClipboardRecentContentGenericTest, OlderURLsNotSuggested) { |
| 78 ClipboardRecentContentGeneric recent_content; | 78 ClipboardRecentContentGeneric recent_content; |
| 79 base::Time now = base::Time::Now(); | 79 base::Time now = base::Time::Now(); |
| 80 std::string text = "http://example.com/"; | 80 std::string text = "http://example.com/"; |
| 81 test_clipboard_->WriteText(text.data(), text.length()); | 81 test_clipboard_->WriteText(text.data(), text.length()); |
| 82 test_clipboard_->SetClipboardLastModifiedTime( | 82 test_clipboard_->SetLastModifiedTime(now - base::TimeDelta::FromSeconds(10)); |
| 83 now - base::TimeDelta::FromSeconds(10)); | |
| 84 GURL url; | 83 GURL url; |
| 85 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); | 84 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); |
| 86 // If the last modified time is days ago, the URL shouldn't be suggested. | 85 // If the last modified time is days ago, the URL shouldn't be suggested. |
| 87 test_clipboard_->SetClipboardLastModifiedTime(now - | 86 test_clipboard_->SetLastModifiedTime(now - base::TimeDelta::FromDays(2)); |
| 88 base::TimeDelta::FromDays(2)); | |
| 89 EXPECT_FALSE(recent_content.GetRecentURLFromClipboard(&url)); | 87 EXPECT_FALSE(recent_content.GetRecentURLFromClipboard(&url)); |
| 90 } | 88 } |
| 91 | 89 |
| 92 TEST_F(ClipboardRecentContentGenericTest, GetClipboardContentAge) { | 90 TEST_F(ClipboardRecentContentGenericTest, GetClipboardContentAge) { |
| 93 ClipboardRecentContentGeneric recent_content; | 91 ClipboardRecentContentGeneric recent_content; |
| 94 base::Time now = base::Time::Now(); | 92 base::Time now = base::Time::Now(); |
| 95 std::string text = " whether URL or not should not matter here."; | 93 std::string text = " whether URL or not should not matter here."; |
| 96 test_clipboard_->WriteText(text.data(), text.length()); | 94 test_clipboard_->WriteText(text.data(), text.length()); |
| 97 test_clipboard_->SetClipboardLastModifiedTime( | 95 test_clipboard_->SetLastModifiedTime(now - base::TimeDelta::FromSeconds(32)); |
| 98 now - base::TimeDelta::FromSeconds(32)); | |
| 99 base::TimeDelta age = recent_content.GetClipboardContentAge(); | 96 base::TimeDelta age = recent_content.GetClipboardContentAge(); |
| 100 // It's possible the GetClipboardContentAge() took some time, so allow a | 97 // It's possible the GetClipboardContentAge() took some time, so allow a |
| 101 // little slop (5 seconds) in this comparison; don't check for equality. | 98 // little slop (5 seconds) in this comparison; don't check for equality. |
| 102 EXPECT_LT(age - base::TimeDelta::FromSeconds(32), | 99 EXPECT_LT(age - base::TimeDelta::FromSeconds(32), |
| 103 base::TimeDelta::FromSeconds(5)); | 100 base::TimeDelta::FromSeconds(5)); |
| 104 } | 101 } |
| 105 | 102 |
| 106 TEST_F(ClipboardRecentContentGenericTest, SuppressClipboardContent) { | 103 TEST_F(ClipboardRecentContentGenericTest, SuppressClipboardContent) { |
| 107 // Make sure the URL is suggested. | 104 // Make sure the URL is suggested. |
| 108 ClipboardRecentContentGeneric recent_content; | 105 ClipboardRecentContentGeneric recent_content; |
| 109 base::Time now = base::Time::Now(); | 106 base::Time now = base::Time::Now(); |
| 110 std::string text = "http://example.com/"; | 107 std::string text = "http://example.com/"; |
| 111 test_clipboard_->WriteText(text.data(), text.length()); | 108 test_clipboard_->WriteText(text.data(), text.length()); |
| 112 test_clipboard_->SetClipboardLastModifiedTime( | 109 test_clipboard_->SetLastModifiedTime(now - base::TimeDelta::FromSeconds(10)); |
| 113 now - base::TimeDelta::FromSeconds(10)); | |
| 114 GURL url; | 110 GURL url; |
| 115 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); | 111 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); |
| 116 | 112 |
| 117 // After suppressing it, it shouldn't be suggested. | 113 // After suppressing it, it shouldn't be suggested. |
| 118 recent_content.SuppressClipboardContent(); | 114 recent_content.SuppressClipboardContent(); |
| 119 EXPECT_FALSE(recent_content.GetRecentURLFromClipboard(&url)); | 115 EXPECT_FALSE(recent_content.GetRecentURLFromClipboard(&url)); |
| 120 | 116 |
| 121 // If the clipboard changes, even if to the same thing again, the content | 117 // If the clipboard changes, even if to the same thing again, the content |
| 122 // should be suggested again. | 118 // should be suggested again. |
| 123 test_clipboard_->WriteText(text.data(), text.length()); | 119 test_clipboard_->WriteText(text.data(), text.length()); |
| 124 test_clipboard_->SetClipboardLastModifiedTime(now); | 120 test_clipboard_->SetLastModifiedTime(now); |
| 125 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); | 121 EXPECT_TRUE(recent_content.GetRecentURLFromClipboard(&url)); |
| 126 } | 122 } |
| OLD | NEW |