Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / file_select_helper_unittest.cc
blobc7c128e3b4ac392060d07aba87ae0454acb3a88d
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
3 // found in the LICENSE file.
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"
12 #include "chrome/browser/file_select_helper.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 class FileSelectHelperTest : public testing::Test {
17 public:
18 FileSelectHelperTest() {}
20 protected:
21 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_));
27 // The path to input data used in tests.
28 base::FilePath data_dir_;
30 private:
31 DISALLOW_COPY_AND_ASSIGN(FileSelectHelperTest);
34 TEST_F(FileSelectHelperTest, IsAcceptTypeValid) {
35 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("a/b"));
36 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/def"));
37 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid("abc/*"));
38 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".a"));
39 EXPECT_TRUE(FileSelectHelper::IsAcceptTypeValid(".abc"));
41 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("."));
42 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("/"));
43 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("ABC/*"));
44 EXPECT_FALSE(FileSelectHelper::IsAcceptTypeValid("abc/def "));
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));
56 base::ScopedTempDir temp_dir;
57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
59 // Unzip the package into a temporary directory.
60 base::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));
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));
80 #endif // defined(OS_MACOSX) && !defined(OS_IOS)