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

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: Comments from avi. 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
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/path_service.h"
10 #include "base/process/launch.h"
5 #include "chrome/browser/file_select_helper.h" 11 #include "chrome/browser/file_select_helper.h"
12 #include "chrome/common/chrome_paths.h"
6 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
7 14
8 TEST(FileSelectHelperTest, IsAcceptTypeValid) { 15 class FileSelectHelperTest : public testing::Test {
16 public:
17 FileSelectHelperTest() {}
18
19 protected:
20 virtual void SetUp() OVERRIDE {
Lei Zhang 2014/10/09 18:41:55 nit: we're switching to "override"
erikchen 2014/10/09 23:33:36 Done.
21 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
22 data_dir_ = data_dir_.AppendASCII("file_select_helper");
23 ASSERT_TRUE(base::PathExists(data_dir_));
Lei Zhang 2014/10/09 18:41:55 Who creates this?
erikchen 2014/10/09 23:33:36 it's already there. it's a test directory that got
Lei Zhang 2014/10/10 01:32:28 Ah, that's what I get for ignoring the rest of the
24 }
25
26 // The path to input data used in tests.
27 base::FilePath data_dir_;
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(FileSelectHelperTest);
31 };
32
33 TEST_F(FileSelectHelperTest, IsAcceptTypeValid) {
9 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b")); 34 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b"));
10 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def")); 35 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def"));
11 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*")); 36 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*"));
12 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a")); 37 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a"));
13 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc")); 38 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc"));
14 39
15 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid(".")); 40 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("."));
16 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/")); 41 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/"));
17 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*")); 42 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*"));
18 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def ")); 43 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def "));
19 } 44 }
45
46 #if defined(OS_MACOSX) && !defined(OS_IOS)
47 TEST_F(FileSelectHelperTest, ZipPackage) {
erikchen 2014/10/08 20:14:44 I changed the unit test to zip and unzip the packa
48 // Zip the package.
49 const char* app_name = "CalculatorFake.app";
Lei Zhang 2014/10/09 18:41:55 const char app_name[], otherwise you can potential
erikchen 2014/10/09 23:33:36 Done.
50 base::FilePath src = data_dir_.Append(app_name);
51 base::FilePath dest = FileSelectHelper::ZipPackage(src);
52 EXPECT_FALSE(dest.empty());
Lei Zhang 2014/10/09 18:41:55 Assert here, otherwise you'd pass an empty path to
erikchen 2014/10/09 23:33:36 Done. Asserted the line after this as well, since
53 EXPECT_TRUE(base::PathExists(dest));
54
55 base::ScopedTempDir temp_dir;
56 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
Lei Zhang 2014/10/09 18:41:55 You should assert true. Otherwise what happens if
erikchen 2014/10/09 23:33:36 Done.
57
58 // Unzip the package into a temporary directory.
59 CommandLine cl(base::FilePath("/usr/bin/unzip"));
60 cl.AppendArg(dest.value().c_str());
61 cl.AppendArg("-d");
62 cl.AppendArg(temp_dir.path().value().c_str());
63 std::string output;
64 EXPECT_TRUE(base::GetAppOutput(cl, &output));
65
66 // Verify that several key files haven't changed.
67 const char* files_to_verify[] = {"Contents/Info.plist",
68 "Contents/MacOS/Calculator",
69 "Contents/_CodeSignature/CodeResources"};
70 unsigned long file_count =
Lei Zhang 2014/10/09 18:41:55 use arraysize() ?
erikchen 2014/10/09 23:33:36 Done.
71 sizeof(files_to_verify) / sizeof(files_to_verify[0]);
72 for (unsigned long i = 0; i < file_count; i++) {
Lei Zhang 2014/10/09 18:41:54 and size_t ?
erikchen 2014/10/09 23:33:36 Done.
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

Powered by Google App Engine
This is Rietveld 408576698