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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(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 scoped_ptr<SelectFileDialog::FileTypeInfo> file_type_info(
19 new SelectFileDialog::FileTypeInfo());
20 bool acceptsAllTypes = false;
21 FileSystemChooseFileFunction::BuildFileTypeInfo(file_type_info.get(),
22 NULL, &acceptsAllTypes);
23 EXPECT_TRUE(file_type_info->include_all_files);
24 EXPECT_TRUE(file_type_info->extensions.empty());
25
26 // Test grouping of multiple types.
27 file_type_info.reset(new SelectFileDialog::FileTypeInfo());
28 std::vector<std::string> accepts;
29 accepts.push_back(".jso,application/x-chrome-extension");
30 acceptsAllTypes = false;
31 FileSystemChooseFileFunction::BuildFileTypeInfo(file_type_info.get(),
32 &accepts, &acceptsAllTypes);
33 EXPECT_FALSE(file_type_info->include_all_files);
34 EXPECT_EQ(file_type_info->extensions.size(), (size_t) 1);
35 }
36
37 TEST_F(FileSystemApiUnitTest, FileSystemChooseFileFunctionSuggestionTest) {
38 std::string opt_name;
39 FilePath suggested_name;
40 FilePath::StringType suggested_extension;
41
42 opt_name = std::string("normal_path.txt");
43 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
44 &suggested_extension);
45 EXPECT_FALSE(suggested_name.IsAbsolute());
46 EXPECT_EQ(suggested_name.MaybeAsASCII(), "normal_path.txt");
47 EXPECT_EQ(suggested_extension, "txt");
48
49 // We should provide just the basename, i.e., "path".
50 opt_name = std::string("/a/bad/path");
51 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
52 &suggested_extension);
53 EXPECT_FALSE(suggested_name.IsAbsolute());
54 EXPECT_EQ(suggested_name.MaybeAsASCII(), "path");
55 EXPECT_TRUE(suggested_extension.empty());
56
57 // Filter out absolute paths with no basename.
58 opt_name = std::string("/");
59 FileSystemChooseFileFunction::BuildSuggestion(&opt_name, &suggested_name,
60 &suggested_extension);
61 EXPECT_FALSE(suggested_name.IsAbsolute());
62 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty());
63 EXPECT_TRUE(suggested_extension.empty());
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698