| OLD | NEW |
| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 9 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ui::SelectFileDialog::FileTypeInfo file_type_info; | 63 ui::SelectFileDialog::FileTypeInfo file_type_info; |
| 64 bool acceptsAllTypes = false; | 64 bool acceptsAllTypes = false; |
| 65 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 65 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 66 base::FilePath::StringType(), NULL, &acceptsAllTypes); | 66 base::FilePath::StringType(), NULL, &acceptsAllTypes); |
| 67 EXPECT_TRUE(file_type_info.include_all_files); | 67 EXPECT_TRUE(file_type_info.include_all_files); |
| 68 EXPECT_TRUE(file_type_info.extensions.empty()); | 68 EXPECT_TRUE(file_type_info.extensions.empty()); |
| 69 | 69 |
| 70 // Test grouping of multiple types. | 70 // Test grouping of multiple types. |
| 71 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 71 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 72 std::vector<linked_ptr<AcceptOption> > options; | 72 std::vector<linked_ptr<AcceptOption> > options; |
| 73 options.push_back(linked_ptr<AcceptOption>( | 73 options.push_back(linked_ptr<AcceptOption>(BuildAcceptOption( |
| 74 BuildAcceptOption("", "application/x-chrome-extension", "jso"))); | 74 std::string(), "application/x-chrome-extension", "jso"))); |
| 75 acceptsAllTypes = false; | 75 acceptsAllTypes = false; |
| 76 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 76 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 77 base::FilePath::StringType(), &options, &acceptsAllTypes); | 77 base::FilePath::StringType(), &options, &acceptsAllTypes); |
| 78 EXPECT_FALSE(file_type_info.include_all_files); | 78 EXPECT_FALSE(file_type_info.include_all_files); |
| 79 ASSERT_EQ(file_type_info.extensions.size(), (size_t) 1); | 79 ASSERT_EQ(file_type_info.extensions.size(), (size_t) 1); |
| 80 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()) << | 80 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()) << |
| 81 "No override must be specified for boring accept types"; | 81 "No override must be specified for boring accept types"; |
| 82 // Note here (and below) that the expectedTypes are sorted, because we use a | 82 // Note here (and below) that the expectedTypes are sorted, because we use a |
| 83 // set internally to generate the output: thus, the output is sorted. | 83 // set internally to generate the output: thus, the output is sorted. |
| 84 std::vector<base::FilePath::StringType> expectedTypes; | 84 std::vector<base::FilePath::StringType> expectedTypes; |
| 85 expectedTypes.push_back(ToStringType("crx")); | 85 expectedTypes.push_back(ToStringType("crx")); |
| 86 expectedTypes.push_back(ToStringType("jso")); | 86 expectedTypes.push_back(ToStringType("jso")); |
| 87 CheckExtensions(expectedTypes, file_type_info.extensions[0]); | 87 CheckExtensions(expectedTypes, file_type_info.extensions[0]); |
| 88 | 88 |
| 89 // Test that not satisfying the extension will force all types. | 89 // Test that not satisfying the extension will force all types. |
| 90 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 90 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 91 options.clear(); | 91 options.clear(); |
| 92 options.push_back(linked_ptr<AcceptOption>( | 92 options.push_back(linked_ptr<AcceptOption>( |
| 93 BuildAcceptOption("", "", "unrelated"))); | 93 BuildAcceptOption(std::string(), std::string(), "unrelated"))); |
| 94 acceptsAllTypes = false; | 94 acceptsAllTypes = false; |
| 95 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 95 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 96 ToStringType(".jso"), &options, &acceptsAllTypes); | 96 ToStringType(".jso"), &options, &acceptsAllTypes); |
| 97 EXPECT_TRUE(file_type_info.include_all_files); | 97 EXPECT_TRUE(file_type_info.include_all_files); |
| 98 | 98 |
| 99 // Test multiple list entries, all containing their own types. | 99 // Test multiple list entries, all containing their own types. |
| 100 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 100 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 101 options.clear(); | 101 options.clear(); |
| 102 options.push_back(linked_ptr<AcceptOption>( | 102 options.push_back(linked_ptr<AcceptOption>( |
| 103 BuildAcceptOption("", "", "jso,js"))); | 103 BuildAcceptOption(std::string(), std::string(), "jso,js"))); |
| 104 options.push_back(linked_ptr<AcceptOption>( | 104 options.push_back(linked_ptr<AcceptOption>( |
| 105 BuildAcceptOption("", "", "cpp,cc"))); | 105 BuildAcceptOption(std::string(), std::string(), "cpp,cc"))); |
| 106 acceptsAllTypes = false; | 106 acceptsAllTypes = false; |
| 107 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 107 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 108 base::FilePath::StringType(), &options, &acceptsAllTypes); | 108 base::FilePath::StringType(), &options, &acceptsAllTypes); |
| 109 ASSERT_EQ(file_type_info.extensions.size(), options.size()); | 109 ASSERT_EQ(file_type_info.extensions.size(), options.size()); |
| 110 | 110 |
| 111 expectedTypes.clear(); | 111 expectedTypes.clear(); |
| 112 expectedTypes.push_back(ToStringType("js")); | 112 expectedTypes.push_back(ToStringType("js")); |
| 113 expectedTypes.push_back(ToStringType("jso")); | 113 expectedTypes.push_back(ToStringType("jso")); |
| 114 CheckExtensions(expectedTypes, file_type_info.extensions[0]); | 114 CheckExtensions(expectedTypes, file_type_info.extensions[0]); |
| 115 | 115 |
| 116 expectedTypes.clear(); | 116 expectedTypes.clear(); |
| 117 expectedTypes.push_back(ToStringType("cc")); | 117 expectedTypes.push_back(ToStringType("cc")); |
| 118 expectedTypes.push_back(ToStringType("cpp")); | 118 expectedTypes.push_back(ToStringType("cpp")); |
| 119 CheckExtensions(expectedTypes, file_type_info.extensions[1]); | 119 CheckExtensions(expectedTypes, file_type_info.extensions[1]); |
| 120 | 120 |
| 121 // Test accept type that causes description override. | 121 // Test accept type that causes description override. |
| 122 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 122 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 123 options.clear(); | 123 options.clear(); |
| 124 options.push_back(linked_ptr<AcceptOption>( | 124 options.push_back(linked_ptr<AcceptOption>( |
| 125 BuildAcceptOption("", "image/*", "html"))); | 125 BuildAcceptOption(std::string(), "image/*", "html"))); |
| 126 acceptsAllTypes = false; | 126 acceptsAllTypes = false; |
| 127 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 127 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 128 base::FilePath::StringType(), &options, &acceptsAllTypes); | 128 base::FilePath::StringType(), &options, &acceptsAllTypes); |
| 129 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); | 129 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); |
| 130 EXPECT_FALSE(file_type_info.extension_description_overrides[0].empty()) << | 130 EXPECT_FALSE(file_type_info.extension_description_overrides[0].empty()) << |
| 131 "Accept type \"image/*\" must generate description override"; | 131 "Accept type \"image/*\" must generate description override"; |
| 132 | 132 |
| 133 // Test multiple accept types that cause description override causes us to | 133 // Test multiple accept types that cause description override causes us to |
| 134 // still present the default. | 134 // still present the default. |
| 135 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 135 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 136 options.clear(); | 136 options.clear(); |
| 137 options.push_back(linked_ptr<AcceptOption>( | 137 options.push_back(linked_ptr<AcceptOption>(BuildAcceptOption( |
| 138 BuildAcceptOption("", "image/*,audio/*,video/*", ""))); | 138 std::string(), "image/*,audio/*,video/*", std::string()))); |
| 139 acceptsAllTypes = false; | 139 acceptsAllTypes = false; |
| 140 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 140 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 141 base::FilePath::StringType(), &options, &acceptsAllTypes); | 141 base::FilePath::StringType(), &options, &acceptsAllTypes); |
| 142 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); | 142 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); |
| 143 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()); | 143 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()); |
| 144 | 144 |
| 145 // Test explicit description override. | 145 // Test explicit description override. |
| 146 file_type_info = ui::SelectFileDialog::FileTypeInfo(); | 146 file_type_info = ui::SelectFileDialog::FileTypeInfo(); |
| 147 options.clear(); | 147 options.clear(); |
| 148 options.push_back(linked_ptr<AcceptOption>( | 148 options.push_back(linked_ptr<AcceptOption>( |
| 149 BuildAcceptOption("File Types 101", "image/jpeg", ""))); | 149 BuildAcceptOption("File Types 101", "image/jpeg", std::string()))); |
| 150 acceptsAllTypes = false; | 150 acceptsAllTypes = false; |
| 151 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, | 151 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, |
| 152 base::FilePath::StringType(), &options, &acceptsAllTypes); | 152 base::FilePath::StringType(), &options, &acceptsAllTypes); |
| 153 EXPECT_EQ(file_type_info.extension_description_overrides[0], | 153 EXPECT_EQ(file_type_info.extension_description_overrides[0], |
| 154 UTF8ToUTF16("File Types 101")); | 154 UTF8ToUTF16("File Types 101")); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(FileSystemApiUnitTest, FileSystemChooseEntryFunctionSuggestionTest) { | 157 TEST_F(FileSystemApiUnitTest, FileSystemChooseEntryFunctionSuggestionTest) { |
| 158 std::string opt_name; | 158 std::string opt_name; |
| 159 base::FilePath suggested_name; | 159 base::FilePath suggested_name; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 178 // TODO(thorogood): Fix this test on Windows. | 178 // TODO(thorogood): Fix this test on Windows. |
| 179 // Filter out absolute paths with no basename. | 179 // Filter out absolute paths with no basename. |
| 180 opt_name = std::string("/"); | 180 opt_name = std::string("/"); |
| 181 FileSystemChooseEntryFunction::BuildSuggestion(&opt_name, &suggested_name, | 181 FileSystemChooseEntryFunction::BuildSuggestion(&opt_name, &suggested_name, |
| 182 &suggested_extension); | 182 &suggested_extension); |
| 183 EXPECT_FALSE(suggested_name.IsAbsolute()); | 183 EXPECT_FALSE(suggested_name.IsAbsolute()); |
| 184 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty()); | 184 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty()); |
| 185 EXPECT_TRUE(suggested_extension.empty()); | 185 EXPECT_TRUE(suggested_extension.empty()); |
| 186 #endif | 186 #endif |
| 187 } | 187 } |
| OLD | NEW |