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

Unified Diff: chrome/browser/extensions/api/file_system/file_system_api_unittest.cc

Issue 10692105: Updates file type selector for fileSystem API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: use find() instead of iter, remove own description generation code, cleanup tests Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/file_system/file_system_api_unittest.cc
diff --git a/chrome/browser/extensions/api/file_system/file_system_api_unittest.cc b/chrome/browser/extensions/api/file_system/file_system_api_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cabd2e2d6afa67cd384bbd36233818e7a11a5c78
--- /dev/null
+++ b/chrome/browser/extensions/api/file_system/file_system_api_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "chrome/browser/extensions/api/file_system/file_system_api.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using extensions::FileSystemChooseFileFunction;
+
+class FileSystemApiUnitTest : public testing::Test {
+};
+
+TEST_F(FileSystemApiUnitTest,
+ FileSystemChooseFileFunctionFileTypeInfoTest) {
+ // AcceptsAllTypes is ignored when no other extensions are available.
+ SelectFileDialog::FileTypeInfo file_type_info;
+ bool acceptsAllTypes = false;
+ FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info,
+ FilePath::StringType(), NULL, &acceptsAllTypes);
+ EXPECT_TRUE(file_type_info.include_all_files);
+ EXPECT_TRUE(file_type_info.extensions.empty());
+
+ // Test grouping of multiple types.
+ file_type_info = SelectFileDialog::FileTypeInfo();
+ std::vector<std::string> accepts;
+ accepts.push_back(".jso,application/x-chrome-extension");
+ acceptsAllTypes = false;
+ FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info,
+ FilePath::StringType(), &accepts, &acceptsAllTypes);
+ EXPECT_FALSE(file_type_info.include_all_files);
+ 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.
+
+ // 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.
+ file_type_info = SelectFileDialog::FileTypeInfo();
+ accepts.clear();
+ accepts.push_back(".unrelated");
+ acceptsAllTypes = false;
+ FileSystemChooseFileFunction::BuildFileTypeInfo(&file_type_info,
+ FilePath::StringType(".jso"), &accepts, &acceptsAllTypes);
+ EXPECT_TRUE(file_type_info.include_all_files);
+}
+
+TEST_F(FileSystemApiUnitTest, FileSystemChooseFileFunctionSuggestionTest) {
+ std::string opt_name;
+ FilePath suggested_name;
+ FilePath::StringType suggested_extension;
+
+ opt_name = std::string("normal_path.txt");
+ FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
+ &suggested_extension);
+ EXPECT_FALSE(suggested_name.IsAbsolute());
+ EXPECT_EQ(suggested_name.MaybeAsASCII(), "normal_path.txt");
+ EXPECT_EQ(suggested_extension, "txt");
+
+ // We should provide just the basename, i.e., "path".
+ opt_name = std::string("/a/bad/path");
+ FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
+ &suggested_extension);
+ EXPECT_FALSE(suggested_name.IsAbsolute());
+ EXPECT_EQ(suggested_name.MaybeAsASCII(), "path");
+ EXPECT_TRUE(suggested_extension.empty());
+
+ // Filter out absolute paths with no basename.
+ opt_name = std::string("/");
+ FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
+ &suggested_extension);
+ EXPECT_FALSE(suggested_name.IsAbsolute());
+ EXPECT_TRUE(suggested_name.MaybeAsASCII().empty());
+ EXPECT_TRUE(suggested_extension.empty());
+}

Powered by Google App Engine
This is Rietveld 408576698