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

Side by Side Diff: chrome/browser/file_select_helper_unittest.cc

Issue 2450543002: Directory upload: remember the last directory chosen, not its parent (Closed)
Patch Set: Tweak test file paths Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/file_select_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/path_service.h" 14 #include "base/path_service.h"
13 #include "base/process/launch.h" 15 #include "base/process/launch.h"
14 #include "build/build_config.h" 16 #include "build/build_config.h"
15 #include "chrome/browser/file_select_helper.h" 17 #include "chrome/browser/file_select_helper.h"
16 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
18 22
23 using content::FileChooserParams;
24
19 class FileSelectHelperTest : public testing::Test { 25 class FileSelectHelperTest : public testing::Test {
20 public: 26 public:
21 FileSelectHelperTest() {} 27 FileSelectHelperTest() {}
22 28
23 protected: 29 protected:
24 void SetUp() override { 30 void SetUp() override {
25 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); 31 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
26 data_dir_ = data_dir_.AppendASCII("file_select_helper"); 32 data_dir_ = data_dir_.AppendASCII("file_select_helper");
27 ASSERT_TRUE(base::PathExists(data_dir_)); 33 ASSERT_TRUE(base::PathExists(data_dir_));
28 } 34 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0}; 112 base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0};
107 #endif 113 #endif
108 base::FilePath bad_filename(kBadName); 114 base::FilePath bad_filename(kBadName);
109 ASSERT_FALSE(bad_filename.empty()); 115 ASSERT_FALSE(bad_filename.empty());
110 // The only thing we are testing is that if the source filename was non-empty, 116 // The only thing we are testing is that if the source filename was non-empty,
111 // the resulting filename is also not empty. Invalid encoded filenames can 117 // the resulting filename is also not empty. Invalid encoded filenames can
112 // cause conversions to fail. Such failures shouldn't cause the resulting 118 // cause conversions to fail. Such failures shouldn't cause the resulting
113 // filename to disappear. 119 // filename to disappear.
114 EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty()); 120 EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty());
115 } 121 }
122
123 TEST_F(FileSelectHelperTest, LastSelectedDirectory) {
124 content::TestBrowserThreadBundle browser_thread_bundle;
125 TestingProfile profile;
126 scoped_refptr<FileSelectHelper> file_select_helper =
127 new FileSelectHelper(&profile);
128
129 const int index = 0;
130 void* params = nullptr;
131
132 const base::FilePath dir_path_1 = data_dir_.AppendASCII("dir1");
133 const base::FilePath dir_path_2 = data_dir_.AppendASCII("dir2");
134 const base::FilePath file_path_1 = dir_path_1.AppendASCII("file1.txt");
135 const base::FilePath file_path_2 = dir_path_1.AppendASCII("file2.txt");
136 const base::FilePath file_path_3 = dir_path_2.AppendASCII("file3.txt");
137 std::vector<base::FilePath> files; // Both in dir1.
138 files.push_back(file_path_1);
139 files.push_back(file_path_2);
140 std::vector<base::FilePath> dirs;
141 dirs.push_back(dir_path_1);
142 dirs.push_back(dir_path_2);
143
144 // Modes where the parent of the selection is remembered.
145 const std::vector<FileChooserParams::Mode> modes = {
146 FileChooserParams::Open,
147 FileChooserParams::OpenMultiple,
148 FileChooserParams::Save,
149 };
150
151 for (const auto& mode : modes) {
152 file_select_helper->dialog_mode_ = mode;
153
154 file_select_helper->AddRef(); // Normally called by RunFileChooser().
155 file_select_helper->FileSelected(file_path_1, index, params);
156 EXPECT_EQ(dir_path_1, profile.last_selected_directory());
157
158 file_select_helper->AddRef(); // Normally called by RunFileChooser().
159 file_select_helper->FileSelected(file_path_2, index, params);
160 EXPECT_EQ(dir_path_1, profile.last_selected_directory());
161
162 file_select_helper->AddRef(); // Normally called by RunFileChooser().
163 file_select_helper->FileSelected(file_path_3, index, params);
164 EXPECT_EQ(dir_path_2, profile.last_selected_directory());
165
166 file_select_helper->AddRef(); // Normally called by RunFileChooser().
167 file_select_helper->MultiFilesSelected(files, params);
168 EXPECT_EQ(dir_path_1, profile.last_selected_directory());
169 }
170
171 // Type where the selected folder itself is remembered.
172 file_select_helper->dialog_mode_ = FileChooserParams::UploadFolder;
173
174 file_select_helper->AddRef(); // Normally called by RunFileChooser().
175 file_select_helper->FileSelected(dir_path_1, index, params);
176 EXPECT_EQ(dir_path_1, profile.last_selected_directory());
177
178 file_select_helper->AddRef(); // Normally called by RunFileChooser().
179 file_select_helper->FileSelected(dir_path_2, index, params);
180 EXPECT_EQ(dir_path_2, profile.last_selected_directory());
181
182 file_select_helper->AddRef(); // Normally called by RunFileChooser().
183 file_select_helper->MultiFilesSelected(dirs, params);
184 EXPECT_EQ(dir_path_1, profile.last_selected_directory());
185 }
OLDNEW
« no previous file with comments | « chrome/browser/file_select_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698