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 virtual ~DownloadUtilMacTest() {
26 [pasteboard_ releaseGlobally];
29 NSPasteboard* pasteboard() { return pasteboard_; }
32 NSPasteboard* pasteboard_;
35 // Ensure adding files to the pasteboard methods works as expected.
36 TEST_F(DownloadUtilMacTest, AddFileToPasteboardTest) {
37 // Get a download test file for addition to the pasteboard.
38 base::FilePath testPath;
39 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
40 base::FilePath testFile(FILE_PATH_LITERAL("download-test1.lib"));
41 testPath = testPath.Append(testFile);
43 // Add a test file to the pasteboard via the download_util method.
44 download_util::AddFileToPasteboard(pasteboard(), testPath);
46 // Test to see that the object type for dragging files is available.
47 NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
48 NSString* available = [pasteboard() availableTypeFromArray:types];
49 EXPECT_TRUE(available != nil);
51 // Ensure the path is what we expect.
52 NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType];
53 ASSERT_TRUE(files != nil);
54 NSString* expectedPath = [files objectAtIndex:0];
55 NSString* realPath = base::SysUTF8ToNSString(testPath.value());
56 EXPECT_NSEQ(expectedPath, realPath);