Chromium Code Reviews| Index: components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
| diff --git a/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm b/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
| index 670a92354c071e8c1d0ace28573b338e4a0cebb6..ebd9447711658cf375c554231154b451218f0099 100644 |
| --- a/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
| +++ b/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
| @@ -9,6 +9,8 @@ |
| #include <memory> |
| +#include "base/strings/sys_string_conversions.h" |
| +#import "components/open_from_clipboard/clipboard_recent_content_impl_ios.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/platform_test.h" |
| @@ -37,28 +39,55 @@ void SetPasteboardContent(const char* data) { |
| setValue:[NSString stringWithUTF8String:data] |
| forPasteboardType:@"public.plain-text"]; |
| } |
| -const char kUnrecognizedURL[] = "ftp://foo/"; |
| -const char kRecognizedURL[] = "http://bar/"; |
| -const char kRecognizedURL2[] = "http://bar/2"; |
| +const char kUnrecognizedURL[] = "bad://foo/"; |
| +const char kRecognizedURL[] = "good://bar/"; |
| +const char kRecognizedURL2[] = "good://bar/2"; |
| const char kAppSpecificURL[] = "test://qux/"; |
| const char kAppSpecificScheme[] = "test"; |
| +const char kRecognizedScheme[] = "good"; |
| NSTimeInterval kSevenHours = 60 * 60 * 7; |
| } // namespace |
| +@interface ClipboardRecentContentImplIOSWithFakeUptime |
| + : ClipboardRecentContentImplIOS |
| +@property(nonatomic) NSTimeInterval fakeUptime; |
| + |
| +- (instancetype)initWithDelegate:(id<ClipboardRecentContentDelegate>)delegate |
| + authorizedSchemes:(NSArray*)authorizedSchemes |
| + userDefaults:(NSUserDefaults*)groupUserDefaults |
| + uptime:(NSTimeInterval)uptime; |
| + |
| +@end |
| + |
| +@implementation ClipboardRecentContentImplIOSWithFakeUptime |
| + |
| +@synthesize fakeUptime = _fakeUptime; |
| + |
| +- (instancetype)initWithDelegate:(id<ClipboardRecentContentDelegate>)delegate |
| + authorizedSchemes:(NSSet*)authorizedSchemes |
| + userDefaults:(NSUserDefaults*)groupUserDefaults |
| + uptime:(NSTimeInterval)uptime { |
| + self = [super initWithAuthorizedSchemes:authorizedSchemes |
| + userDefaults:groupUserDefaults |
| + delegate:delegate]; |
| + if (self) { |
| + _fakeUptime = uptime; |
| + } |
| + return self; |
| +} |
| + |
| +- (NSTimeInterval)uptime { |
| + return self.fakeUptime; |
| +} |
| + |
| +@end |
| + |
| class ClipboardRecentContentIOSWithFakeUptime |
| : public ClipboardRecentContentIOS { |
| public: |
| - ClipboardRecentContentIOSWithFakeUptime(const std::string& application_scheme, |
| - NSUserDefaults* group_user_defaults) |
| - : ClipboardRecentContentIOS(application_scheme, group_user_defaults) {} |
| - // Sets the uptime. |
| - void SetUptime(base::TimeDelta uptime) { uptime_ = uptime; } |
| - |
| - protected: |
| - base::TimeDelta Uptime() const override { return uptime_; } |
| - |
| - private: |
| - base::TimeDelta uptime_; |
| + ClipboardRecentContentIOSWithFakeUptime( |
| + ClipboardRecentContentImplIOS* implementation) |
| + : ClipboardRecentContentIOS(implementation) {} |
| }; |
| class ClipboardRecentContentIOSTest : public ::testing::Test { |
| @@ -76,23 +105,28 @@ class ClipboardRecentContentIOSTest : public ::testing::Test { |
| void ResetClipboardRecentContent(const std::string& application_scheme, |
| base::TimeDelta time_delta) { |
| - 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(); |
| + clipboard_content_impl_ = |
| + [[ClipboardRecentContentImplIOSWithFakeUptime alloc] |
| + initWithDelegate:nil |
| + authorizedSchemes:@[ |
| + base::SysUTF8ToNSString(kRecognizedScheme), |
| + base::SysUTF8ToNSString(application_scheme) |
| + ] |
| + userDefaults:[NSUserDefaults standardUserDefaults] |
| + uptime:time_delta.InSecondsF()]; |
| + |
| + clipboard_content_.reset( |
|
sdefresne
2017/04/06 14:51:11
Use base::MakeUnique<> if possible here.
lody
2017/04/06 15:12:07
Done.
|
| + new ClipboardRecentContentIOSWithFakeUptime(clipboard_content_impl_)); |
| } |
| - void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { |
| - clipboard_content_->last_pasteboard_change_count_ = newChangeCount; |
| - clipboard_content_->SaveToUserDefaults(); |
| + void SetStoredPasteboardChangeDate(NSDate* change_date) { |
| + clipboard_content_impl_.lastPasteboardChangeDate = [change_date copy]; |
| + [clipboard_content_impl_ saveToUserDefaults]; |
| } |
| protected: |
| std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_; |
| + ClipboardRecentContentImplIOSWithFakeUptime* clipboard_content_impl_; |
|
sdefresne
2017/04/06 14:51:11
s/clipboard_content_impl_/clipboard_content_implem
lody
2017/04/06 15:12:08
Done.
|
| }; |
| TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { |
| @@ -164,7 +198,7 @@ TEST_F(ClipboardRecentContentIOSTest, SupressedPasteboard) { |
| // Check that the pasteboard content is still suppressed. |
| EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
| - // Check that the even if the device is restarted, pasteboard content is |
| + // Check that even if the device is restarted, pasteboard content is |
| // still suppressed. |
| SimulateDeviceRestart(); |
| EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |