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

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: fixed args, need_suggestion bool 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..6961f32a24de274d7219905cb2f1c847921fd631
--- /dev/null
+++ b/chrome/browser/extensions/api/file_system/file_system_api_unittest.cc
@@ -0,0 +1,64 @@
+// 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.
+ scoped_ptr<SelectFileDialog::FileTypeInfo> file_type_info(
+ new SelectFileDialog::FileTypeInfo());
+ bool acceptsAllTypes = false;
+ FileSystemChooseFileFunction::BuildFileTypeInfo(file_type_info.get(),
+ 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.reset(new SelectFileDialog::FileTypeInfo());
+ std::vector<std::string> accepts;
+ accepts.push_back(".jso,application/x-chrome-extension");
+ acceptsAllTypes = false;
+ FileSystemChooseFileFunction::BuildFileTypeInfo(file_type_info.get(),
+ &accepts, &acceptsAllTypes);
+ EXPECT_FALSE(file_type_info->include_all_files);
+ EXPECT_EQ(file_type_info->extensions.size(), (size_t) 1);
+}
+
+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