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 28 matching lines...) Expand all Loading... |
39 [[UIPasteboard generalPasteboard] | 39 [[UIPasteboard generalPasteboard] |
40 setValue:[NSString stringWithUTF8String:data] | 40 setValue:[NSString stringWithUTF8String:data] |
41 forPasteboardType:@"public.plain-text"]; | 41 forPasteboardType:@"public.plain-text"]; |
42 } | 42 } |
43 const char kUnrecognizedURL[] = "bad://foo/"; | 43 const char kUnrecognizedURL[] = "bad://foo/"; |
44 const char kRecognizedURL[] = "good://bar/"; | 44 const char kRecognizedURL[] = "good://bar/"; |
45 const char kRecognizedURL2[] = "good://bar/2"; | 45 const char kRecognizedURL2[] = "good://bar/2"; |
46 const char kAppSpecificURL[] = "test://qux/"; | 46 const char kAppSpecificURL[] = "test://qux/"; |
47 const char kAppSpecificScheme[] = "test"; | 47 const char kAppSpecificScheme[] = "test"; |
48 const char kRecognizedScheme[] = "good"; | 48 const char kRecognizedScheme[] = "good"; |
49 NSTimeInterval kSevenHours = 60 * 60 * 7; | 49 NSTimeInterval kLongerThanMaxAge = 60 * 60 * 7; |
| 50 NSTimeInterval kMaxAge = 60 * 60 * 1; |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 @interface ClipboardRecentContentImplIOSWithFakeUptime | 53 @interface ClipboardRecentContentImplIOSWithFakeUptime |
53 : ClipboardRecentContentImplIOS | 54 : ClipboardRecentContentImplIOS |
54 @property(nonatomic) NSTimeInterval fakeUptime; | 55 @property(nonatomic) NSTimeInterval fakeUptime; |
55 | 56 |
56 - (instancetype)initWithDelegate:(id<ClipboardRecentContentDelegate>)delegate | 57 - (instancetype)initWithMaxAge:(NSTimeInterval)maxAge |
57 authorizedSchemes:(NSArray*)authorizedSchemes | 58 authorizedSchemes:(NSArray*)authorizedSchemes |
58 userDefaults:(NSUserDefaults*)groupUserDefaults | 59 userDefaults:(NSUserDefaults*)groupUserDefaults |
59 uptime:(NSTimeInterval)uptime; | 60 uptime:(NSTimeInterval)uptime; |
60 | 61 |
61 @end | 62 @end |
62 | 63 |
63 @implementation ClipboardRecentContentImplIOSWithFakeUptime | 64 @implementation ClipboardRecentContentImplIOSWithFakeUptime |
64 | 65 |
65 @synthesize fakeUptime = _fakeUptime; | 66 @synthesize fakeUptime = _fakeUptime; |
66 | 67 |
67 - (instancetype)initWithDelegate:(id<ClipboardRecentContentDelegate>)delegate | 68 - (instancetype)initWithMaxAge:(NSTimeInterval)maxAge |
68 authorizedSchemes:(NSSet*)authorizedSchemes | 69 authorizedSchemes:(NSSet*)authorizedSchemes |
69 userDefaults:(NSUserDefaults*)groupUserDefaults | 70 userDefaults:(NSUserDefaults*)groupUserDefaults |
70 uptime:(NSTimeInterval)uptime { | 71 uptime:(NSTimeInterval)uptime { |
71 self = [super initWithAuthorizedSchemes:authorizedSchemes | 72 self = [super initWithMaxAge:maxAge |
72 userDefaults:groupUserDefaults | 73 authorizedSchemes:authorizedSchemes |
73 delegate:delegate]; | 74 userDefaults:groupUserDefaults |
| 75 delegate:nil]; |
74 if (self) { | 76 if (self) { |
75 _fakeUptime = uptime; | 77 _fakeUptime = uptime; |
76 } | 78 } |
77 return self; | 79 return self; |
78 } | 80 } |
79 | 81 |
80 - (NSTimeInterval)uptime { | 82 - (NSTimeInterval)uptime { |
81 return self.fakeUptime; | 83 return self.fakeUptime; |
82 } | 84 } |
83 | 85 |
(...skipping 17 matching lines...) Expand all Loading... |
101 | 103 |
102 void SimulateDeviceRestart() { | 104 void SimulateDeviceRestart() { |
103 ResetClipboardRecentContent(kAppSpecificScheme, | 105 ResetClipboardRecentContent(kAppSpecificScheme, |
104 base::TimeDelta::FromSeconds(0)); | 106 base::TimeDelta::FromSeconds(0)); |
105 } | 107 } |
106 | 108 |
107 void ResetClipboardRecentContent(const std::string& application_scheme, | 109 void ResetClipboardRecentContent(const std::string& application_scheme, |
108 base::TimeDelta time_delta) { | 110 base::TimeDelta time_delta) { |
109 clipboard_content_implementation_ = | 111 clipboard_content_implementation_ = |
110 [[ClipboardRecentContentImplIOSWithFakeUptime alloc] | 112 [[ClipboardRecentContentImplIOSWithFakeUptime alloc] |
111 initWithDelegate:nil | 113 initWithMaxAge:kMaxAge |
112 authorizedSchemes:@[ | 114 authorizedSchemes:@[ |
113 base::SysUTF8ToNSString(kRecognizedScheme), | 115 base::SysUTF8ToNSString(kRecognizedScheme), |
114 base::SysUTF8ToNSString(application_scheme) | 116 base::SysUTF8ToNSString(application_scheme) |
115 ] | 117 ] |
116 userDefaults:[NSUserDefaults standardUserDefaults] | 118 userDefaults:[NSUserDefaults standardUserDefaults] |
117 uptime:time_delta.InSecondsF()]; | 119 uptime:time_delta.InSecondsF()]; |
118 | 120 |
119 clipboard_content_ = | 121 clipboard_content_ = |
120 base::MakeUnique<ClipboardRecentContentIOSWithFakeUptime>( | 122 base::MakeUnique<ClipboardRecentContentIOSWithFakeUptime>( |
121 clipboard_content_implementation_); | 123 clipboard_content_implementation_); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) { | 162 TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) { |
161 GURL gurl; | 163 GURL gurl; |
162 SetPasteboardContent(kRecognizedURL); | 164 SetPasteboardContent(kRecognizedURL); |
163 | 165 |
164 // Test that recent pasteboard data is provided. | 166 // Test that recent pasteboard data is provided. |
165 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 167 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
166 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); | 168 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
167 | 169 |
168 // Test that old pasteboard data is not provided. | 170 // Test that old pasteboard data is not provided. |
169 SetStoredPasteboardChangeDate( | 171 SetStoredPasteboardChangeDate( |
170 [NSDate dateWithTimeIntervalSinceNow:-kSevenHours]); | 172 [NSDate dateWithTimeIntervalSinceNow:-kLongerThanMaxAge]); |
171 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 173 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
172 | 174 |
173 // Tests that if chrome is relaunched, old pasteboard data is still | 175 // Tests that if chrome is relaunched, old pasteboard data is still |
174 // not provided. | 176 // not provided. |
175 ResetClipboardRecentContent(kAppSpecificScheme, | 177 ResetClipboardRecentContent(kAppSpecificScheme, |
176 base::TimeDelta::FromDays(10)); | 178 base::TimeDelta::FromDays(10)); |
177 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 179 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
178 | 180 |
179 SimulateDeviceRestart(); | 181 SimulateDeviceRestart(); |
180 // Tests that if the device is restarted, old pasteboard data is still | 182 // Tests that if the device is restarted, old pasteboard data is still |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 SetPasteboardImage(TestUIImage()); | 230 SetPasteboardImage(TestUIImage()); |
229 | 231 |
230 // Pasteboard should appear empty. | 232 // Pasteboard should appear empty. |
231 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 233 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
232 | 234 |
233 // Tests that if URL is added again, pasteboard provides it normally. | 235 // Tests that if URL is added again, pasteboard provides it normally. |
234 SetPasteboardContent(kRecognizedURL); | 236 SetPasteboardContent(kRecognizedURL); |
235 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 237 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
236 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); | 238 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
237 } | 239 } |
OLD | NEW |