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 <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
8 | 9 |
9 #include <memory> | 10 #include <memory> |
10 | 11 |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
| 17 UIImage* TestUIImage() { |
| 18 CGRect frame = CGRectMake(0, 0, 1.0, 1.0); |
| 19 UIGraphicsBeginImageContext(frame.size); |
| 20 |
| 21 CGContextRef context = UIGraphicsGetCurrentContext(); |
| 22 CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); |
| 23 CGContextFillRect(context, frame); |
| 24 |
| 25 UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); |
| 26 UIGraphicsEndImageContext(); |
| 27 |
| 28 return image; |
| 29 } |
| 30 |
16 void SetPasteboardImage(UIImage* image) { | 31 void SetPasteboardImage(UIImage* image) { |
17 [[UIPasteboard generalPasteboard] setImage:image]; | 32 [[UIPasteboard generalPasteboard] setImage:image]; |
18 } | 33 } |
19 | 34 |
20 void SetPasteboardContent(const char* data) { | 35 void SetPasteboardContent(const char* data) { |
21 [[UIPasteboard generalPasteboard] | 36 [[UIPasteboard generalPasteboard] |
22 setValue:[NSString stringWithUTF8String:data] | 37 setValue:[NSString stringWithUTF8String:data] |
23 forPasteboardType:@"public.plain-text"]; | 38 forPasteboardType:@"public.plain-text"]; |
24 } | 39 } |
25 const char kUnrecognizedURL[] = "ftp://foo/"; | 40 const char kUnrecognizedURL[] = "ftp://foo/"; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 TEST_F(ClipboardRecentContentIOSTest, AddingNonStringRemovesCachedString) { | 162 TEST_F(ClipboardRecentContentIOSTest, AddingNonStringRemovesCachedString) { |
148 GURL gurl; | 163 GURL gurl; |
149 SetPasteboardContent(kRecognizedURL); | 164 SetPasteboardContent(kRecognizedURL); |
150 | 165 |
151 // Test that recent pasteboard data is provided. | 166 // Test that recent pasteboard data is provided. |
152 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 167 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
153 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); | 168 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
154 | 169 |
155 // Overwrite pasteboard with an image. | 170 // Overwrite pasteboard with an image. |
156 base::scoped_nsobject<UIImage> image([[UIImage alloc] init]); | 171 base::scoped_nsobject<UIImage> image([[UIImage alloc] init]); |
157 SetPasteboardImage(image); | 172 SetPasteboardImage(TestUIImage()); |
158 | 173 |
159 // Pasteboard should appear empty. | 174 // Pasteboard should appear empty. |
160 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 175 EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
161 | 176 |
162 // Tests that if URL is added again, pasteboard provides it normally. | 177 // Tests that if URL is added again, pasteboard provides it normally. |
163 SetPasteboardContent(kRecognizedURL); | 178 SetPasteboardContent(kRecognizedURL); |
164 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); | 179 EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
165 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); | 180 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
166 } | 181 } |
OLD | NEW |