| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/gtest_mac.h" |
| 10 #include "testing/platform_test.h" |
| 11 #include "third_party/mozilla/NSPasteboard+Utils.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 class ClipboardUtilMacTest : public PlatformTest { |
| 16 public: |
| 17 ClipboardUtilMacTest() { } |
| 18 }; |
| 19 |
| 20 TEST_F(ClipboardUtilMacTest, PasteboardItemFromUrl) { |
| 21 NSString* urlString = |
| 22 @"https://www.google.com/" |
| 23 @"search?q=test&oq=test&aqs=chrome..69i57l2j69i60l4.278j0j7&" |
| 24 @"sourceid=chrome&ie=UTF-8"; |
| 25 |
| 26 base::scoped_nsobject<NSPasteboardItem> item( |
| 27 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); |
| 28 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; |
| 29 [pasteboard writeObjects:@[ item ]]; |
| 30 |
| 31 NSArray* urls = nil; |
| 32 NSArray* titles = nil; |
| 33 [pasteboard getURLs:&urls andTitles:&titles convertingFilenames:NO]; |
| 34 |
| 35 ASSERT_EQ(1u, [urls count]); |
| 36 EXPECT_NSEQ(urlString, [urls objectAtIndex:0]); |
| 37 ASSERT_EQ(1u, [titles count]); |
| 38 EXPECT_NSEQ(urlString, [titles objectAtIndex:0]); |
| 39 |
| 40 NSURL* url = [NSURL URLFromPasteboard:pasteboard]; |
| 41 EXPECT_NSEQ([url absoluteString], urlString); |
| 42 } |
| 43 |
| 44 TEST_F(ClipboardUtilMacTest, PasteboardItemWithTitle) { |
| 45 NSString* urlString = @"https://www.google.com/"; |
| 46 NSString* title = @"Burrowing Yams"; |
| 47 |
| 48 base::scoped_nsobject<NSPasteboardItem> item( |
| 49 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, title)); |
| 50 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; |
| 51 [pasteboard writeObjects:@[ item ]]; |
| 52 |
| 53 NSArray* urls = nil; |
| 54 NSArray* titles = nil; |
| 55 [pasteboard getURLs:&urls andTitles:&titles convertingFilenames:NO]; |
| 56 |
| 57 ASSERT_EQ(1u, [urls count]); |
| 58 EXPECT_NSEQ(urlString, [urls objectAtIndex:0]); |
| 59 ASSERT_EQ(1u, [titles count]); |
| 60 EXPECT_NSEQ(title, [titles objectAtIndex:0]); |
| 61 |
| 62 NSURL* url = [NSURL URLFromPasteboard:pasteboard]; |
| 63 EXPECT_NSEQ([url absoluteString], urlString); |
| 64 } |
| 65 |
| 66 TEST_F(ClipboardUtilMacTest, PasteboardItemWithFilePath) { |
| 67 NSURL* url = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; |
| 68 ASSERT_TRUE(url); |
| 69 NSString* urlString = [url absoluteString]; |
| 70 |
| 71 base::scoped_nsobject<NSPasteboardItem> item( |
| 72 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); |
| 73 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; |
| 74 [pasteboard writeObjects:@[ item ]]; |
| 75 |
| 76 NSArray* urls = nil; |
| 77 NSArray* titles = nil; |
| 78 [pasteboard getURLs:&urls andTitles:&titles convertingFilenames:NO]; |
| 79 |
| 80 ASSERT_EQ(1u, [urls count]); |
| 81 EXPECT_NSEQ(urlString, [urls objectAtIndex:0]); |
| 82 ASSERT_EQ(1u, [titles count]); |
| 83 EXPECT_NSEQ(urlString, [titles objectAtIndex:0]); |
| 84 |
| 85 NSURL* urlFromPasteboard = [NSURL URLFromPasteboard:pasteboard]; |
| 86 EXPECT_NSEQ(urlFromPasteboard, url); |
| 87 } |
| 88 |
| 89 } // namespace |
| OLD | NEW |