OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_ios.h" | 5 #include "components/open_from_clipboard/clipboard_recent_content_ios.h" |
6 | 6 |
7 #import <CoreGraphics/CoreGraphics.h> | 7 #import <CoreGraphics/CoreGraphics.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 base::TimeDelta::FromSeconds(0)); | 74 base::TimeDelta::FromSeconds(0)); |
75 } | 75 } |
76 | 76 |
77 void ResetClipboardRecentContent(const std::string& application_scheme, | 77 void ResetClipboardRecentContent(const std::string& application_scheme, |
78 base::TimeDelta time_delta) { | 78 base::TimeDelta time_delta) { |
79 clipboard_content_.reset(new ClipboardRecentContentIOSWithFakeUptime( | 79 clipboard_content_.reset(new ClipboardRecentContentIOSWithFakeUptime( |
80 application_scheme, [NSUserDefaults standardUserDefaults])); | 80 application_scheme, [NSUserDefaults standardUserDefaults])); |
81 clipboard_content_->SetUptime(time_delta); | 81 clipboard_content_->SetUptime(time_delta); |
82 } | 82 } |
83 | 83 |
84 void SetStoredPasteboardChangeDate(NSDate* changeDate) { | 84 void SetStoredPasteboardChangeDate(NSDate* changeDate) { |
jif
2017/03/29 14:17:56
original author messed up 🙄
s/changeData/change_da
lody
2017/03/30 13:36:34
Done.
| |
85 clipboard_content_->last_pasteboard_change_date_.reset([changeDate copy]); | 85 clipboard_content_->SetLastPasteboardChangeDate(changeDate); |
86 clipboard_content_->SaveToUserDefaults(); | 86 clipboard_content_->SaveToUserDefaults(); |
87 } | 87 } |
88 | 88 |
89 void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { | |
90 clipboard_content_->last_pasteboard_change_count_ = newChangeCount; | |
91 clipboard_content_->SaveToUserDefaults(); | |
92 } | |
93 | |
94 protected: | 89 protected: |
95 std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_; | 90 std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_; |
96 }; | 91 }; |
97 | 92 |
98 TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { | 93 TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { |
99 GURL gurl; | 94 GURL gurl; |
100 | 95 |
101 // Test unrecognized URL. | 96 // Test unrecognized URL. |
102 SetPasteboardContent(kUnrecognizedURL); | 97 SetPasteboardContent(kUnrecognizedURL); |
103 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 98 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // Check that the pasteboard content is suppressed. | 152 // Check that the pasteboard content is suppressed. |
158 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 153 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
159 | 154 |
160 // Create a new clipboard content to test persistence. | 155 // Create a new clipboard content to test persistence. |
161 ResetClipboardRecentContent(kAppSpecificScheme, | 156 ResetClipboardRecentContent(kAppSpecificScheme, |
162 base::TimeDelta::FromDays(10)); | 157 base::TimeDelta::FromDays(10)); |
163 | 158 |
164 // Check that the pasteboard content is still suppressed. | 159 // Check that the pasteboard content is still suppressed. |
165 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 160 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
166 | 161 |
167 // Check that the even if the device is restarted, pasteboard content is | 162 // Check that the even if the device is restarted, pasteboard content is |
jif
2017/03/31 13:14:47
thanks!
| |
168 // still suppressed. | 163 // still suppressed. |
169 SimulateDeviceRestart(); | 164 SimulateDeviceRestart(); |
170 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 165 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
171 | 166 |
172 // Check that if the pasteboard changes, the new content is not | 167 // Check that if the pasteboard changes, the new content is not |
173 // supressed anymore. | 168 // supressed anymore. |
174 SetPasteboardContent(kRecognizedURL2); | 169 SetPasteboardContent(kRecognizedURL2); |
175 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 170 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
176 } | 171 } |
177 | 172 |
(...skipping 12 matching lines...) Expand all Loading... | |
190 SetPasteboardImage(TestUIImage()); | 185 SetPasteboardImage(TestUIImage()); |
191 | 186 |
192 // Pasteboard should appear empty. | 187 // Pasteboard should appear empty. |
193 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 188 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
194 | 189 |
195 // Tests that if URL is added again, pasteboard provides it normally. | 190 // Tests that if URL is added again, pasteboard provides it normally. |
196 SetPasteboardContent(kRecognizedURL); | 191 SetPasteboardContent(kRecognizedURL); |
197 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 192 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
198 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); | 193 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
199 } | 194 } |
OLD | NEW |