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
3 // found in the LICENSE file.
5 // Download utility test for Mac OS X.
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "base/strings/sys_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/ui/cocoa/download/download_util_mac.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #import "testing/gtest_mac.h"
15 #include "testing/platform_test.h"
19 class DownloadUtilMacTest : public CocoaTest {
21 DownloadUtilMacTest() {
22 pasteboard_ = [NSPasteboard pasteboardWithUniqueName];
25 ~DownloadUtilMacTest() override { [pasteboard_ releaseGlobally]; }
27 NSPasteboard* pasteboard() { return pasteboard_; }
30 NSPasteboard* pasteboard_;
33 // Ensure adding files to the pasteboard methods works as expected.
34 TEST_F(DownloadUtilMacTest, AddFileToPasteboardTest) {
35 // Get a download test file for addition to the pasteboard.
36 base::FilePath testPath;
37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
38 base::FilePath testFile(FILE_PATH_LITERAL("download-test1.lib"));
39 testPath = testPath.Append(testFile);
41 // Add a test file to the pasteboard via the download_util method.
42 download_util::AddFileToPasteboard(pasteboard(), testPath);
44 // Test to see that the object type for dragging files is available.
45 NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
46 NSString* available = [pasteboard() availableTypeFromArray:types];
47 EXPECT_TRUE(available != nil);
49 // Ensure the path is what we expect.
50 NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType];
51 ASSERT_TRUE(files != nil);
52 NSString* expectedPath = [files objectAtIndex:0];
53 NSString* realPath = base::SysUTF8ToNSString(testPath.value());
54 EXPECT_NSEQ(expectedPath, realPath);