OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "ui/base/win/open_file_name_win.h" | 5 #include "ui/base/win/open_file_name_win.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 ASSERT_TRUE(ofn.GetOPENFILENAME()->lpstrFile); | 114 ASSERT_TRUE(ofn.GetOPENFILENAME()->lpstrFile); |
115 EXPECT_EQ(base::FilePath(), base::FilePath(ofn.GetOPENFILENAME()->lpstrFile)); | 115 EXPECT_EQ(base::FilePath(), base::FilePath(ofn.GetOPENFILENAME()->lpstrFile)); |
116 | 116 |
117 // File is ignored in absence of a directory. | 117 // File is ignored in absence of a directory. |
118 ofn.SetInitialSelection(base::FilePath(), kFile); | 118 ofn.SetInitialSelection(base::FilePath(), kFile); |
119 ASSERT_FALSE(ofn.GetOPENFILENAME()->lpstrInitialDir); | 119 ASSERT_FALSE(ofn.GetOPENFILENAME()->lpstrInitialDir); |
120 ASSERT_TRUE(ofn.GetOPENFILENAME()->lpstrFile); | 120 ASSERT_TRUE(ofn.GetOPENFILENAME()->lpstrFile); |
121 EXPECT_EQ(base::FilePath(), base::FilePath(ofn.GetOPENFILENAME()->lpstrFile)); | 121 EXPECT_EQ(base::FilePath(), base::FilePath(ofn.GetOPENFILENAME()->lpstrFile)); |
122 } | 122 } |
123 | 123 |
124 TEST(OpenFileNameTest, GetSingleResult) { | 124 TEST(OpenFileNameTest, GetSingleResultFromSingleSelect) { |
| 125 ui::win::OpenFileName ofn(kHwnd, kFlags); |
| 126 base::FilePath result; |
| 127 |
| 128 SetResult(L"C:\\dir\\file", &ofn); |
| 129 result = ofn.GetSingleResult(); |
| 130 EXPECT_EQ(base::FilePath(L"C:\\dir\\file"), result); |
| 131 |
| 132 SetResult(L"", &ofn); |
| 133 result = ofn.GetSingleResult(); |
| 134 EXPECT_EQ(base::FilePath(), result); |
| 135 } |
| 136 |
| 137 TEST(OpenFileNameTest, GetSingleResultFromMultiSelect) { |
125 const base::string16 kNull(L"\0", 1); | 138 const base::string16 kNull(L"\0", 1); |
126 ui::win::OpenFileName ofn(kHwnd, kFlags); | 139 ui::win::OpenFileName ofn(kHwnd, kFlags | OFN_ALLOWMULTISELECT); |
127 base::FilePath result; | 140 base::FilePath result; |
128 | 141 |
129 SetResult(L"C:\\dir\\file" + kNull, &ofn); | 142 SetResult(L"C:\\dir\\file" + kNull, &ofn); |
130 result = ofn.GetSingleResult(); | 143 result = ofn.GetSingleResult(); |
131 EXPECT_EQ(base::FilePath(L"C:\\dir\\file"), result); | 144 EXPECT_EQ(base::FilePath(L"C:\\dir\\file"), result); |
132 | 145 |
133 SetResult(L"C:\\dir" + kNull + L"file" + kNull, &ofn); | 146 SetResult(L"C:\\dir" + kNull + L"file" + kNull, &ofn); |
134 result = ofn.GetSingleResult(); | 147 result = ofn.GetSingleResult(); |
135 EXPECT_EQ(base::FilePath(L"C:\\dir\\file"), result); | 148 EXPECT_EQ(base::FilePath(L"C:\\dir\\file"), result); |
136 | 149 |
137 SetResult(L"C:\\dir" + kNull + L"file" + kNull + L"otherfile" + kNull, &ofn); | 150 SetResult(L"C:\\dir" + kNull + L"file" + kNull + L"otherfile" + kNull, &ofn); |
138 result = ofn.GetSingleResult(); | 151 result = ofn.GetSingleResult(); |
139 EXPECT_EQ(base::FilePath(), result); | 152 EXPECT_EQ(base::FilePath(), result); |
140 | 153 |
141 SetResult(L"", &ofn); | 154 SetResult(L"", &ofn); |
142 result = ofn.GetSingleResult(); | 155 result = ofn.GetSingleResult(); |
143 EXPECT_EQ(base::FilePath(), result); | 156 EXPECT_EQ(base::FilePath(), result); |
144 } | 157 } |
145 | 158 |
146 TEST(OpenFileNameTest, GetResult) { | 159 TEST(OpenFileNameTest, GetResult) { |
147 const base::string16 kNull(L"\0", 1); | 160 const base::string16 kNull(L"\0", 1); |
148 | 161 |
149 ui::win::OpenFileName ofn(kHwnd, kFlags); | 162 ui::win::OpenFileName ofn(kHwnd, kFlags | OFN_ALLOWMULTISELECT); |
150 base::FilePath directory; | 163 base::FilePath directory; |
151 std::vector<base::FilePath> filenames; | 164 std::vector<base::FilePath> filenames; |
152 | 165 |
153 SetResult(L"C:\\dir\\file" + kNull, &ofn); | 166 SetResult(L"C:\\dir\\file" + kNull, &ofn); |
154 ofn.GetResult(&directory, &filenames); | 167 ofn.GetResult(&directory, &filenames); |
155 EXPECT_EQ(base::FilePath(L"C:\\dir"), directory); | 168 EXPECT_EQ(base::FilePath(L"C:\\dir"), directory); |
156 ASSERT_EQ(1u, filenames.size()); | 169 ASSERT_EQ(1u, filenames.size()); |
157 EXPECT_EQ(base::FilePath(L"file"), filenames[0]); | 170 EXPECT_EQ(base::FilePath(L"file"), filenames[0]); |
158 | 171 |
159 directory.clear(); | 172 directory.clear(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 ui::win::OpenFileName::SetResult(directory, filenames, ofn.GetOPENFILENAME()); | 240 ui::win::OpenFileName::SetResult(directory, filenames, ofn.GetOPENFILENAME()); |
228 CheckResult(L"C:\\dir" + kNull + L"file" + kNull + L"otherfile" + kNull, ofn); | 241 CheckResult(L"C:\\dir" + kNull + L"file" + kNull + L"otherfile" + kNull, ofn); |
229 | 242 |
230 base::char16 short_buffer[10] = L""; | 243 base::char16 short_buffer[10] = L""; |
231 | 244 |
232 ofn.GetOPENFILENAME()->lpstrFile = short_buffer; | 245 ofn.GetOPENFILENAME()->lpstrFile = short_buffer; |
233 ofn.GetOPENFILENAME()->nMaxFile = arraysize(short_buffer); | 246 ofn.GetOPENFILENAME()->nMaxFile = arraysize(short_buffer); |
234 ui::win::OpenFileName::SetResult(directory, filenames, ofn.GetOPENFILENAME()); | 247 ui::win::OpenFileName::SetResult(directory, filenames, ofn.GetOPENFILENAME()); |
235 CheckResult(L"", ofn); | 248 CheckResult(L"", ofn); |
236 } | 249 } |
OLD | NEW |