- add sources.
[platform/framework/web/crosswalk.git] / src / ui / shell_dialogs / select_file_dialog_win_unittest.cc
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 "testing/gtest/include/gtest/gtest.h"
6 #include "ui/shell_dialogs/select_file_dialog.h"
7 #include "ui/shell_dialogs/select_file_dialog_win.h"
8
9 TEST(ShellDialogsWin, AppendExtensionIfNeeded) {
10   struct AppendExtensionTestCase {
11     const wchar_t* filename;
12     const wchar_t* filter_selected;
13     const wchar_t* suggested_ext;
14     const wchar_t* expected_filename;
15   } test_cases[] = {
16     // Known extensions, with or without associated MIME types, should not get
17     // an extension appended.
18     { L"sample.html",    L"*.txt",     L"txt",     L"sample.html" },
19     { L"sample.reg",     L"*.txt",     L"txt",     L"sample.reg" },
20
21     // An unknown extension, or no extension, should get the default extension
22     // appended.
23     { L"sample.unknown", L"*.txt",     L"txt",     L"sample.unknown.txt" },
24     { L"sample",         L"*.txt",     L"txt",     L"sample.txt" },
25     // ...unless the unknown and default extensions match.
26     { L"sample.unknown", L"*.unknown", L"unknown", L"sample.unknown" },
27
28     // The extension alone should be treated like a filename with no extension.
29     { L"txt",            L"*.txt",     L"txt",     L"txt.txt" },
30
31     // Trailing dots should cause us to append an extension.
32     { L"sample.txt.",    L"*.txt",     L"txt",     L"sample.txt.txt" },
33     { L"...",            L"*.txt",     L"txt",     L"...txt" },
34
35     // If the filter is changed to "All files", we allow any filename.
36     { L"sample.unknown", L"*.*",       L"",        L"sample.unknown" },
37   };
38
39   for (size_t i = 0; i < arraysize(test_cases); ++i) {
40     EXPECT_EQ(std::wstring(test_cases[i].expected_filename),
41               ui::AppendExtensionIfNeeded(test_cases[i].filename,
42                                           test_cases[i].filter_selected,
43                                           test_cases[i].suggested_ext));
44   }
45 }
46