• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2010 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.
4
5// Download utility test for Mac OS X.
6
7#include "base/path_service.h"
8#include "base/sys_string_conversions.h"
9#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10#import "chrome/browser/ui/cocoa/download/download_util_mac.h"
11#include "chrome/common/chrome_paths.h"
12#include "testing/gtest/include/gtest/gtest.h"
13#import "testing/gtest_mac.h"
14#include "testing/platform_test.h"
15
16namespace {
17
18class DownloadUtilMacTest : public CocoaTest {
19 public:
20  DownloadUtilMacTest() {
21    pasteboard_ = [NSPasteboard pasteboardWithUniqueName];
22  }
23
24  virtual ~DownloadUtilMacTest() {
25    [pasteboard_ releaseGlobally];
26  }
27
28  NSPasteboard* const pasteboard() { return pasteboard_; }
29
30 private:
31  NSPasteboard* pasteboard_;
32};
33
34// Ensure adding files to the pasteboard methods works as expected.
35TEST_F(DownloadUtilMacTest, AddFileToPasteboardTest) {
36  // Get a download test file for addition to the pasteboard.
37  FilePath testPath;
38  ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
39  FilePath testFile(FILE_PATH_LITERAL("download-test1.lib"));
40  testPath = testPath.Append(testFile);
41
42  // Add a test file to the pasteboard via the download_util method.
43  download_util::AddFileToPasteboard(pasteboard(), testPath);
44
45  // Test to see that the object type for dragging files is available.
46  NSArray* types =  [NSArray arrayWithObject:NSFilenamesPboardType];
47  NSString* available = [pasteboard() availableTypeFromArray:types];
48  EXPECT_TRUE(available != nil);
49
50  // Ensure the path is what we expect.
51  NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType];
52  ASSERT_TRUE(files != nil);
53  NSString* expectedPath = [files objectAtIndex:0];
54  NSString* realPath = base::SysUTF8ToNSString(testPath.value());
55  EXPECT_NSEQ(expectedPath, realPath);
56}
57
58}  // namespace
59