summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/shell_dialogs_win_unittest.cc
blob: b267e16fc0a57c58c99344abb544c9a0637503a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/shell_dialogs.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(AppendExtensionIfNeeded, EndingInPeriod_ExtensionAppended) {
  const std::wstring filename = L"sample.txt.";
  const std::wstring filter_selected = L"*.txt";
  const std::wstring suggested_ext = L"txt";

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"sample.txt.txt", actual_filename);
}

TEST(AppendExtensionIfNeeded, UnknownMimeType_ExtensionAppended) {
  const std::wstring filename = L"sample.unknown-mime-type";
  const std::wstring filter_selected = L"*.txt";
  const std::wstring suggested_ext = L"txt";

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"sample.unknown-mime-type.txt", actual_filename);
}

TEST(AppendExtensionIfNeeded, RecognizableMimeType_NoExtensionAppended) {
  const std::wstring filename = L"sample.html";
  const std::wstring filter_selected = L"*.txt";
  const std::wstring suggested_ext = L"txt";

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"sample.html", actual_filename);
}

TEST(AppendExtensionIfNeeded, OnlyPeriods_ExtensionAppended) {
  const std::wstring filename = L"...";
  const std::wstring filter_selected = L"*.txt";
  const std::wstring suggested_ext = L"txt";

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"...txt", actual_filename);
}

TEST(AppendExtensionIfNeeded, EqualToExtension_ExtensionAppended) {
  const std::wstring filename = L"txt";
  const std::wstring filter_selected = L"*.txt";
  const std::wstring suggested_ext = L"txt";

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"txt.txt", actual_filename);
}

TEST(AppendExtensionIfNeeded, AllFilesFilter_NoExtensionAppended) {
  const std::wstring filename = L"sample.unknown-mime-type";
  const std::wstring filter_selected = L"*.*";
  const std::wstring suggested_ext;

  const std::wstring actual_filename = AppendExtensionIfNeeded(filename,
      filter_selected, suggested_ext);

  ASSERT_EQ(L"sample.unknown-mime-type", actual_filename);
}