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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api_unittest.cc

Issue 265703011: cleanup: pass string as const reference from c/b/extension/api (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
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/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/strings/string_split.h" 6 #include "base/strings/string_split.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 8 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/shell_dialogs/select_file_dialog.h" 10 #include "ui/shell_dialogs/select_file_dialog.h"
11 11
12 using extensions::FileSystemChooseEntryFunction; 12 using extensions::FileSystemChooseEntryFunction;
13 using extensions::api::file_system::AcceptOption; 13 using extensions::api::file_system::AcceptOption;
14 14
15 namespace { 15 namespace {
16 16
17 void CheckExtensions(const std::vector<base::FilePath::StringType>& expected, 17 void CheckExtensions(const std::vector<base::FilePath::StringType>& expected,
18 std::vector<base::FilePath::StringType>& actual) { 18 std::vector<base::FilePath::StringType>& actual) {
19 EXPECT_EQ(expected.size(), actual.size()); 19 EXPECT_EQ(expected.size(), actual.size());
20 if (expected.size() != actual.size()) 20 if (expected.size() != actual.size())
21 return; 21 return;
22 22
23 for (size_t i = 0; i < expected.size(); ++i) { 23 for (size_t i = 0; i < expected.size(); ++i) {
24 EXPECT_EQ(expected[i], actual[i]); 24 EXPECT_EQ(expected[i], actual[i]);
25 } 25 }
26 } 26 }
27 27
28 AcceptOption* BuildAcceptOption(std::string description, 28 AcceptOption* BuildAcceptOption(const std::string& description,
29 std::string mime_types, 29 std::string mime_types,
Devlin 2014/05/02 15:34:15 why not also make the other two params const &?
limasdf 2014/05/02 16:26:46 Done. I dont know why-_- I didn't
30 std::string extensions) { 30 std::string extensions) {
31 AcceptOption* option = new AcceptOption(); 31 AcceptOption* option = new AcceptOption();
32 32
33 if (!description.empty()) 33 if (!description.empty())
34 option->description.reset(new std::string(description)); 34 option->description.reset(new std::string(description));
35 35
36 if (!mime_types.empty()) { 36 if (!mime_types.empty()) {
37 option->mime_types.reset(new std::vector<std::string>()); 37 option->mime_types.reset(new std::vector<std::string>());
38 base::SplitString(mime_types, ',', option->mime_types.get()); 38 base::SplitString(mime_types, ',', option->mime_types.get());
39 } 39 }
40 40
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 BuildAcceptOption(std::string(), std::string(), "unrelated"))); 92 BuildAcceptOption(std::string(), std::string(), "unrelated")));
93 acceptsAllTypes = false; 93 acceptsAllTypes = false;
94 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 94 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
95 ToStringType(".jso"), &options, &acceptsAllTypes); 95 ToStringType(".jso"), &options, &acceptsAllTypes);
96 EXPECT_TRUE(file_type_info.include_all_files); 96 EXPECT_TRUE(file_type_info.include_all_files);
97 97
98 // Test multiple list entries, all containing their own types. 98 // Test multiple list entries, all containing their own types.
99 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 99 file_type_info = ui::SelectFileDialog::FileTypeInfo();
100 options.clear(); 100 options.clear();
101 options.push_back(linked_ptr<AcceptOption>( 101 options.push_back(linked_ptr<AcceptOption>(
102 BuildAcceptOption(std::string(), std::string(), "jso,js"))); 102 BuildAcceptOption(std::string(), std::string(), "jso,js")));
Devlin 2014/05/02 15:34:15 Yet another "while you're here" request. :) Can y
limasdf 2014/05/02 16:26:46 Done.
103 options.push_back(linked_ptr<AcceptOption>( 103 options.push_back(linked_ptr<AcceptOption>(
104 BuildAcceptOption(std::string(), std::string(), "cpp,cc"))); 104 BuildAcceptOption(std::string(), std::string(), "cpp,cc")));
105 acceptsAllTypes = false; 105 acceptsAllTypes = false;
106 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 106 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
107 base::FilePath::StringType(), &options, &acceptsAllTypes); 107 base::FilePath::StringType(), &options, &acceptsAllTypes);
108 ASSERT_EQ(file_type_info.extensions.size(), options.size()); 108 ASSERT_EQ(file_type_info.extensions.size(), options.size());
109 109
110 expectedTypes.clear(); 110 expectedTypes.clear();
111 expectedTypes.push_back(ToStringType("js")); 111 expectedTypes.push_back(ToStringType("js"));
112 expectedTypes.push_back(ToStringType("jso")); 112 expectedTypes.push_back(ToStringType("jso"));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // TODO(thorogood): Fix this test on Windows. 177 // TODO(thorogood): Fix this test on Windows.
178 // Filter out absolute paths with no basename. 178 // Filter out absolute paths with no basename.
179 opt_name = std::string("/"); 179 opt_name = std::string("/");
180 FileSystemChooseEntryFunction::BuildSuggestion(&opt_name, &suggested_name, 180 FileSystemChooseEntryFunction::BuildSuggestion(&opt_name, &suggested_name,
181 &suggested_extension); 181 &suggested_extension);
182 EXPECT_FALSE(suggested_name.IsAbsolute()); 182 EXPECT_FALSE(suggested_name.IsAbsolute());
183 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty()); 183 EXPECT_TRUE(suggested_name.MaybeAsASCII().empty());
184 EXPECT_TRUE(suggested_extension.empty()); 184 EXPECT_TRUE(suggested_extension.empty());
185 #endif 185 #endif
186 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698