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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_util_mac_unittest.mm

Issue 1852433004: Fix NSPasteboard leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error. Created 4 years, 8 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 | « no previous file | chrome/browser/ui/cocoa/find_pasteboard_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Download utility test for Mac OS X. 5 // Download utility test for Mac OS X.
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h" 9 #include "base/path_service.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/ui/cocoa/download/download_util_mac.h" 12 #import "chrome/browser/ui/cocoa/download/download_util_mac.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #import "testing/gtest_mac.h" 15 #import "testing/gtest_mac.h"
15 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
17 #import "ui/base/clipboard/clipboard_util_mac.h"
16 18
17 namespace { 19 namespace {
18 20
19 class DownloadUtilMacTest : public CocoaTest { 21 class DownloadUtilMacTest : public CocoaTest {
20 public: 22 public:
21 DownloadUtilMacTest() { 23 DownloadUtilMacTest() { pasteboard_ = new ui::UniquePasteboard; }
22 pasteboard_ = [NSPasteboard pasteboardWithUniqueName];
23 }
24 24
25 ~DownloadUtilMacTest() override { [pasteboard_ releaseGlobally]; } 25 NSPasteboard* pasteboard() { return pasteboard_->get(); }
26
27 NSPasteboard* pasteboard() { return pasteboard_; }
28 26
29 private: 27 private:
30 NSPasteboard* pasteboard_; 28 scoped_refptr<ui::UniquePasteboard> pasteboard_;
31 }; 29 };
32 30
33 // Ensure adding files to the pasteboard methods works as expected. 31 // Ensure adding files to the pasteboard methods works as expected.
34 TEST_F(DownloadUtilMacTest, AddFileToPasteboardTest) { 32 TEST_F(DownloadUtilMacTest, AddFileToPasteboardTest) {
35 // Get a download test file for addition to the pasteboard. 33 // Get a download test file for addition to the pasteboard.
36 base::FilePath testPath; 34 base::FilePath testPath;
37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath)); 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
38 base::FilePath testFile(FILE_PATH_LITERAL("download-test1.lib")); 36 base::FilePath testFile(FILE_PATH_LITERAL("download-test1.lib"));
39 testPath = testPath.Append(testFile); 37 testPath = testPath.Append(testFile);
40 38
41 // Add a test file to the pasteboard via the download_util method. 39 // Add a test file to the pasteboard via the download_util method.
42 download_util::AddFileToPasteboard(pasteboard(), testPath); 40 download_util::AddFileToPasteboard(pasteboard(), testPath);
43 41
44 // Test to see that the object type for dragging files is available. 42 // Test to see that the object type for dragging files is available.
45 NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType]; 43 NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
46 NSString* available = [pasteboard() availableTypeFromArray:types]; 44 NSString* available = [pasteboard() availableTypeFromArray:types];
47 EXPECT_TRUE(available != nil); 45 EXPECT_TRUE(available != nil);
48 46
49 // Ensure the path is what we expect. 47 // Ensure the path is what we expect.
50 NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType]; 48 NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType];
51 ASSERT_TRUE(files != nil); 49 ASSERT_TRUE(files != nil);
52 NSString* expectedPath = [files objectAtIndex:0]; 50 NSString* expectedPath = [files objectAtIndex:0];
53 NSString* realPath = base::SysUTF8ToNSString(testPath.value()); 51 NSString* realPath = base::SysUTF8ToNSString(testPath.value());
54 EXPECT_NSEQ(expectedPath, realPath); 52 EXPECT_NSEQ(expectedPath, realPath);
55 } 53 }
56 54
57 } // namespace 55 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/find_pasteboard_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698