OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "base/file_path.h" | |
6 #include "base/file_util.h" | |
7 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 using extensions::FileSystemChooseFileFunction; | |
11 | |
12 class FileSystemApiUnitTest : public testing::Test { | |
13 }; | |
14 | |
15 TEST_F(FileSystemApiUnitTest, | |
16 FileSystemChooseFileFunctionFileTypeInfoTest) { | |
17 // AcceptsAllTypes is ignored when no other extensions are available. | |
18 SelectFileDialog::FileTypeInfo file_type_info; | |
19 bool acceptsAllTypes = false; | |
20 FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info, | |
21 FilePath::StringType(), NULL, &acceptsAllTypes); | |
22 EXPECT_TRUE(file_type_info.include_all_files); | |
23 EXPECT_TRUE(file_type_info.extensions.empty()); | |
24 | |
25 // Test grouping of multiple types. | |
26 file_type_info = SelectFileDialog::FileTypeInfo(); | |
27 std::vector<std::string> accepts; | |
28 accepts.push_back(".jso,application/x-chrome-extension"); | |
29 acceptsAllTypes = false; | |
30 FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info, | |
31 FilePath::StringType(), &accepts, &acceptsAllTypes); | |
32 EXPECT_FALSE(file_type_info.include_all_files); | |
33 EXPECT_EQ(file_type_info.extensions.size(), (size_t) 1); | |
benwells
2012/07/30 01:07:16
Should test that the extensions are as expected.
thorogood
2012/07/30 06:39:16
Done.
| |
34 | |
35 // Test that not satisfying the extension will force all types. | |
benwells
2012/07/30 01:07:16
Add more tests:
* test with multiple accept types
thorogood
2012/07/30 06:39:16
Done.
| |
36 file_type_info = SelectFileDialog::FileTypeInfo(); | |
37 accepts.clear(); | |
38 accepts.push_back(".unrelated"); | |
39 acceptsAllTypes = false; | |
40 FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info, | |
41 FilePath::StringType(".jso"), &accepts, &acceptsAllTypes); | |
42 EXPECT_TRUE(file_type_info.include_all_files); | |
43 } | |
44 | |
45 TEST_F(FileSystemApiUnitTest, FileSystemChooseFileFunctionSuggestionTest) { | |
46 std::string opt_name; | |
47 FilePath suggested_name; | |
48 FilePath::StringType suggested_extension; | |
49 | |
50 opt_name = std::string("normal_path.txt"); | |
51 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name, | |
52 &suggested_extension); | |
53 EXPECT_FALSE(suggested_name.IsAbsolute()); | |
54 EXPECT_EQ(suggested_name.MaybeAsASCII(), "normal_path.txt"); | |
55 EXPECT_EQ(suggested_extension, "txt"); | |
56 | |
57 // We should provide just the basename, i.e., "path". | |
58 opt_name = std::string("/a/bad/path"); | |
59 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name, | |
60 &suggested_extension); | |
61 EXPECT_FALSE(suggested_name.IsAbsolute()); | |
62 EXPECT_EQ(suggested_name.MaybeAsASCII(), "path"); | |
63 EXPECT_TRUE(suggested_extension.empty()); | |
64 | |
65 // Filter out absolute paths with no basename. | |
66 opt_name = std::string("/"); | |
67 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name, | |
68 &suggested_extension); | |
69 EXPECT_FALSE(suggested_name.IsAbsolute()); | |
70 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty()); | |
71 EXPECT_TRUE(suggested_extension.empty()); | |
72 } | |
OLD | NEW |