| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #import "ui/base/clipboard/clipboard_util_mac.h" | 5 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/gtest_mac.h" | 10 #include "testing/gtest_mac.h" |
| 11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 12 #include "third_party/mozilla/NSPasteboard+Utils.h" | 12 #include "third_party/mozilla/NSPasteboard+Utils.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class ClipboardUtilMacTest : public PlatformTest { | 16 class ClipboardUtilMacTest : public PlatformTest { |
| 17 public: | 17 public: |
| 18 ClipboardUtilMacTest() { } | 18 ClipboardUtilMacTest() { } |
| 19 |
| 20 NSDictionary* DictionaryFromPasteboard(NSPasteboard* pboard) { |
| 21 NSArray* types = [pboard types]; |
| 22 NSMutableDictionary* data = [NSMutableDictionary dictionary]; |
| 23 for (NSString* type in types) { |
| 24 [data setObject:[pboard dataForType:type] forKey:type]; |
| 25 } |
| 26 return data; |
| 27 } |
| 19 }; | 28 }; |
| 20 | 29 |
| 21 TEST_F(ClipboardUtilMacTest, PasteboardItemFromUrl) { | 30 TEST_F(ClipboardUtilMacTest, PasteboardItemFromUrl) { |
| 22 NSString* urlString = | 31 NSString* urlString = |
| 23 @"https://www.google.com/" | 32 @"https://www.google.com/" |
| 24 @"search?q=test&oq=test&aqs=chrome..69i57l2j69i60l4.278j0j7&" | 33 @"search?q=test&oq=test&aqs=chrome..69i57l2j69i60l4.278j0j7&" |
| 25 @"sourceid=chrome&ie=UTF-8"; | 34 @"sourceid=chrome&ie=UTF-8"; |
| 26 | 35 |
| 27 base::scoped_nsobject<NSPasteboardItem> item( | 36 base::scoped_nsobject<NSPasteboardItem> item( |
| 28 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); | 37 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 98 |
| 90 TEST_F(ClipboardUtilMacTest, CheckForLeak) { | 99 TEST_F(ClipboardUtilMacTest, CheckForLeak) { |
| 91 for (int i = 0; i < 10000; ++i) { | 100 for (int i = 0; i < 10000; ++i) { |
| 92 @autoreleasepool { | 101 @autoreleasepool { |
| 93 scoped_refptr<ui::UniquePasteboard> pboard = new ui::UniquePasteboard; | 102 scoped_refptr<ui::UniquePasteboard> pboard = new ui::UniquePasteboard; |
| 94 EXPECT_TRUE(pboard->get()); | 103 EXPECT_TRUE(pboard->get()); |
| 95 } | 104 } |
| 96 } | 105 } |
| 97 } | 106 } |
| 98 | 107 |
| 108 TEST_F(ClipboardUtilMacTest, CompareToWriteToPasteboard) { |
| 109 NSString* urlString = @"https://www.cnn.com/"; |
| 110 |
| 111 base::scoped_nsobject<NSPasteboardItem> item( |
| 112 ui::ClipboardUtil::PasteboardItemFromUrl(urlString, nil)); |
| 113 scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard; |
| 114 [pasteboard->get() writeObjects:@[ item ]]; |
| 115 |
| 116 scoped_refptr<ui::UniquePasteboard> pboard = new ui::UniquePasteboard; |
| 117 [pboard->get() setDataForURL:urlString title:urlString]; |
| 118 |
| 119 NSDictionary* data1 = DictionaryFromPasteboard(pasteboard->get()); |
| 120 NSDictionary* data2 = DictionaryFromPasteboard(pboard->get()); |
| 121 EXPECT_NSEQ(data1, data2); |
| 122 } |
| 123 |
| 99 } // namespace | 124 } // namespace |
| OLD | NEW |