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

Side by Side Diff: chrome/browser/file_select_helper_unittest.cc

Issue 634833003: mac: Zip packages when they are selected by the file opener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use AppendRelativePath(). Created 6 years, 2 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 | « chrome/browser/file_select_helper_mac.mm ('k') | chrome/chrome_browser.gypi » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/command_line.h"
6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h"
10 #include "base/path_service.h"
11 #include "base/process/launch.h"
5 #include "chrome/browser/file_select_helper.h" 12 #include "chrome/browser/file_select_helper.h"
13 #include "chrome/common/chrome_paths.h"
6 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
7 15
8 TEST(FileSelectHelperTest, IsAcceptTypeValid) { 16 class FileSelectHelperTest : public testing::Test {
17 public:
18 FileSelectHelperTest() {}
19
20 protected:
21 virtual void SetUp() override {
22 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
23 data_dir_ = data_dir_.AppendASCII("file_select_helper");
24 ASSERT_TRUE(base::PathExists(data_dir_));
25 }
26
27 // The path to input data used in tests.
28 base::FilePath data_dir_;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(FileSelectHelperTest);
32 };
33
34 TEST_F(FileSelectHelperTest, IsAcceptTypeValid) {
9 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b")); 35 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b"));
10 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def")); 36 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def"));
11 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*")); 37 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*"));
12 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a")); 38 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a"));
13 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc")); 39 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc"));
14 40
15 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid(".")); 41 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("."));
16 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/")); 42 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/"));
17 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*")); 43 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*"));
18 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def ")); 44 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def "));
19 } 45 }
46
47 #if defined(OS_MACOSX) && !defined(OS_IOS)
48 TEST_F(FileSelectHelperTest, ZipPackage) {
49 // Zip the package.
50 const char app_name[] = "CalculatorFake.app";
51 base::FilePath src = data_dir_.Append(app_name);
52 base::FilePath dest = FileSelectHelper::ZipPackage(src);
53 ASSERT_FALSE(dest.empty());
54 ASSERT_TRUE(base::PathExists(dest));
55
56 base::ScopedTempDir temp_dir;
57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
58
59 // Unzip the package into a temporary directory.
60 CommandLine cl(base::FilePath("/usr/bin/unzip"));
61 cl.AppendArg(dest.value().c_str());
62 cl.AppendArg("-d");
63 cl.AppendArg(temp_dir.path().value().c_str());
64 std::string output;
65 EXPECT_TRUE(base::GetAppOutput(cl, &output));
66
67 // Verify that several key files haven't changed.
68 const char* files_to_verify[] = {"Contents/Info.plist",
69 "Contents/MacOS/Calculator",
70 "Contents/_CodeSignature/CodeResources"};
71 size_t file_count = arraysize(files_to_verify);
72 for (size_t i = 0; i < file_count; i++) {
73 const char* relative_path = files_to_verify[i];
74 base::FilePath orig_file = src.Append(relative_path);
75 base::FilePath final_file =
76 temp_dir.path().Append(app_name).Append(relative_path);
77 EXPECT_TRUE(base::ContentsEqual(orig_file, final_file));
78 }
79 }
80 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
OLDNEW
« no previous file with comments | « chrome/browser/file_select_helper_mac.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698