Chromium Code Reviews| 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 | |
| 41 TEST_F(ClipboardUtilMacTest, PasteboardItemWithTitle) { | |
| 42 NSString* urlString = @"https://www.google.com/"; | |
| 43 NSString* title = @"Burrowing Yams"; | |
| 44 | |
| 45 base::scoped_nsobject<NSPasteboardItem> item( | |
| 46 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, title)); | |
| 47 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; | |
| 48 [pasteboard writeObjects:@[ item ]]; | |
| 49 | |
| 50 NSArray* urls = nil; | |
| 51 NSArray* titles = nil; | |
| 52 [pasteboard getURLs:&urls andTitles:&titles convertingFilenames:NO]; | |
| 53 | |
| 54 ASSERT_EQ(1u, [urls count]); | |
| 55 EXPECT_NSEQ(urlString, [urls objectAtIndex:0]); | |
| 56 ASSERT_EQ(1u, [titles count]); | |
| 57 EXPECT_NSEQ(title, [titles objectAtIndex:0]); | |
| 58 } | |
| 59 | |
| 60 TEST_F(ClipboardUtilMacTest, PasteboardItemWithFilePath) { | |
| 61 NSURL* url = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; | |
| 62 ASSERT_TRUE(url); | |
| 63 NSString* urlString = [url absoluteString]; | |
| 64 | |
| 65 base::scoped_nsobject<NSPasteboardItem> item( | |
| 66 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); | |
| 67 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName]; | |
| 68 [pasteboard writeObjects:@[ item ]]; | |
| 69 | |
| 70 NSArray* urls = nil; | |
| 71 NSArray* titles = nil; | |
| 72 [pasteboard getURLs:&urls andTitles:&titles convertingFilenames:NO]; | |
| 73 | |
| 74 ASSERT_EQ(1u, [urls count]); | |
| 75 EXPECT_NSEQ(urlString, [urls objectAtIndex:0]); | |
| 76 ASSERT_EQ(1u, [titles count]); | |
| 77 EXPECT_NSEQ(urlString, [titles objectAtIndex:0]); | |
| 78 } | |
| 79 | |
| 80 } // namespace | |
|
Avi (use Gerrit)
2016/03/19 01:15:20
Can we have tests that don't use the Mozilla code?
erikchen
2016/03/21 18:26:38
Good suggestion. I've added to each test to check
| |
| OLD | NEW |