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

Side by Side Diff: ui/base/clipboard/clipboard_util_mac_unittest.mm

Issue 2094553003: [Merge to 2743] [Mac] Fix regression with copying URLs from the Omnibox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 5 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
« no previous file with comments | « ui/base/clipboard/clipboard_util_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_util_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698