Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm

Issue 2230983002: Stop using UIPasteboardChangedNotification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 setValue:[NSString stringWithUTF8String:data] 37 setValue:[NSString stringWithUTF8String:data]
38 forPasteboardType:@"public.plain-text"]; 38 forPasteboardType:@"public.plain-text"];
39 } 39 }
40 const char kUnrecognizedURL[] = "ftp://foo/"; 40 const char kUnrecognizedURL[] = "ftp://foo/";
41 const char kRecognizedURL[] = "http://bar/"; 41 const char kRecognizedURL[] = "http://bar/";
42 const char kAppSpecificURL[] = "test://qux/"; 42 const char kAppSpecificURL[] = "test://qux/";
43 const char kAppSpecificScheme[] = "test"; 43 const char kAppSpecificScheme[] = "test";
44 NSTimeInterval kSevenHours = 60 * 60 * 7; 44 NSTimeInterval kSevenHours = 60 * 60 * 7;
45 } // namespace 45 } // namespace
46 46
47 class ClipboardRecentContentIOSWithFakeUptime
48 : public ClipboardRecentContentIOS {
49 public:
50 ClipboardRecentContentIOSWithFakeUptime(const std::string& application_scheme,
51 NSUserDefaults* group_user_defaults)
52 : ClipboardRecentContentIOS(application_scheme, group_user_defaults) {}
53 // Sets the uptime.
54 void SetUptime(base::TimeDelta uptime) { uptime_ = uptime; }
55
56 protected:
57 base::TimeDelta Uptime() const override { return uptime_; }
58
59 private:
60 base::TimeDelta uptime_;
61 };
62
47 class ClipboardRecentContentIOSTest : public ::testing::Test { 63 class ClipboardRecentContentIOSTest : public ::testing::Test {
48 protected: 64 protected:
49 ClipboardRecentContentIOSTest() { 65 ClipboardRecentContentIOSTest() {
50 // By default, set that the device booted 10 days ago. 66 // By default, set that the device booted 10 days ago.
51 ResetClipboardRecentContent(kAppSpecificScheme, 67 ResetClipboardRecentContent(kAppSpecificScheme,
52 base::TimeDelta::FromDays(10)); 68 base::TimeDelta::FromDays(10));
53 } 69 }
54 70
55 void SimulateDeviceRestart() { 71 void SimulateDeviceRestart() {
56 ResetClipboardRecentContent(kAppSpecificScheme, 72 ResetClipboardRecentContent(kAppSpecificScheme,
57 base::TimeDelta::FromSeconds(0)); 73 base::TimeDelta::FromSeconds(0));
58 } 74 }
59 75
60 void ResetClipboardRecentContent(const std::string& application_scheme, 76 void ResetClipboardRecentContent(const std::string& application_scheme,
61 base::TimeDelta time_delta) { 77 base::TimeDelta time_delta) {
62 clipboard_content_.reset( 78 clipboard_content_.reset(new ClipboardRecentContentIOSWithFakeUptime(
63 new ClipboardRecentContentIOS(application_scheme, time_delta)); 79 application_scheme, [NSUserDefaults standardUserDefaults]));
80 clipboard_content_->SetUptime(time_delta);
64 } 81 }
65 82
66 void SetStoredPasteboardChangeDate(NSDate* changeDate) { 83 void SetStoredPasteboardChangeDate(NSDate* changeDate) {
67 clipboard_content_->last_pasteboard_change_date_.reset([changeDate copy]); 84 clipboard_content_->last_pasteboard_change_date_.reset([changeDate copy]);
68 clipboard_content_->SaveToUserDefaults(); 85 clipboard_content_->SaveToUserDefaults();
69 } 86 }
70 87
71 void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { 88 void SetStoredPasteboardChangeCount(NSInteger newChangeCount) {
72 clipboard_content_->last_pasteboard_change_count_ = newChangeCount; 89 clipboard_content_->last_pasteboard_change_count_ = newChangeCount;
73 clipboard_content_->SaveToUserDefaults(); 90 clipboard_content_->SaveToUserDefaults();
74 } 91 }
75 92
76 protected: 93 protected:
77 std::unique_ptr<ClipboardRecentContentIOS> clipboard_content_; 94 std::unique_ptr<ClipboardRecentContentIOSWithFakeUptime> clipboard_content_;
78 }; 95 };
79 96
80 TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { 97 TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) {
81 GURL gurl; 98 GURL gurl;
82 99
83 // Test unrecognized URL. 100 // Test unrecognized URL.
84 SetPasteboardContent(kUnrecognizedURL); 101 SetPasteboardContent(kUnrecognizedURL);
85 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); 102 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
86 103
87 // Test recognized URL. 104 // Test recognized URL.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 SetPasteboardImage(TestUIImage()); 189 SetPasteboardImage(TestUIImage());
173 190
174 // Pasteboard should appear empty. 191 // Pasteboard should appear empty.
175 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); 192 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
176 193
177 // Tests that if URL is added again, pasteboard provides it normally. 194 // Tests that if URL is added again, pasteboard provides it normally.
178 SetPasteboardContent(kRecognizedURL); 195 SetPasteboardContent(kRecognizedURL);
179 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); 196 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
180 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); 197 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
181 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698