diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 23:12:25 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 23:12:25 +0000 |
commit | 4a0765a6e06b2e188c68999a52b3fea976e72c40 (patch) | |
tree | 4d5f07ef3228e084d415aee83047b2f243493d7e /app/win_util_unittest.cc | |
parent | 11592b698eb4de8e9874e746f796fe6cd8a56bf6 (diff) | |
download | chromium_src-4a0765a6e06b2e188c68999a52b3fea976e72c40.zip chromium_src-4a0765a6e06b2e188c68999a52b3fea976e72c40.tar.gz chromium_src-4a0765a6e06b2e188c68999a52b3fea976e72c40.tar.bz2 |
Move win_util.h from common to app.
http://crbug.com/11387
Review URL: http://codereview.chromium.org/113169
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15694 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/win_util_unittest.cc')
-rw-r--r-- | app/win_util_unittest.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/app/win_util_unittest.cc b/app/win_util_unittest.cc new file mode 100644 index 0000000..18fb0d0 --- /dev/null +++ b/app/win_util_unittest.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2006-2008 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 "app/win_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(WinUtilTest, EnsureRectIsVisibleInRect) { + gfx::Rect parent_rect(0, 0, 500, 400); + + { + // Child rect x < 0 + gfx::Rect child_rect(-50, 20, 100, 100); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(10, 20, 100, 100), child_rect); + } + + { + // Child rect y < 0 + gfx::Rect child_rect(20, -50, 100, 100); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(20, 10, 100, 100), child_rect); + } + + { + // Child rect right > parent_rect.right + gfx::Rect child_rect(450, 20, 100, 100); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(390, 20, 100, 100), child_rect); + } + + { + // Child rect bottom > parent_rect.bottom + gfx::Rect child_rect(20, 350, 100, 100); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(20, 290, 100, 100), child_rect); + } + + { + // Child rect width > parent_rect.width + gfx::Rect child_rect(20, 20, 700, 100); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(20, 20, 480, 100), child_rect); + } + + { + // Child rect height > parent_rect.height + gfx::Rect child_rect(20, 20, 100, 700); + win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10); + EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect); + } +} + +static const struct filename_case { + const wchar_t* filename; + const wchar_t* filter_selected; + const wchar_t* suggested_ext; + const wchar_t* result; +} filename_cases[] = { + // Test a specific filter (*.jpg). + {L"f", L"*.jpg", L"jpg", L"f.jpg"}, + {L"f.", L"*.jpg", L"jpg", L"f..jpg"}, + {L"f..", L"*.jpg", L"jpg", L"f...jpg"}, + {L"f.jpeg", L"*.jpg", L"jpg", L"f.jpeg"}, + // Further guarantees. + {L"f.jpg.jpg", L"*.jpg", L"jpg", L"f.jpg.jpg"}, + {L"f.exe.jpg", L"*.jpg", L"jpg", L"f.exe.jpg"}, + {L"f.jpg.exe", L"*.jpg", L"jpg", L"f.jpg.exe.jpg"}, + {L"f.exe..", L"*.jpg", L"jpg", L"f.exe...jpg"}, + {L"f.jpg..", L"*.jpg", L"jpg", L"f.jpg...jpg"}, + // Test the All Files filter (*.jpg). + {L"f", L"*.*", L"jpg", L"f"}, + {L"f.", L"*.*", L"jpg", L"f"}, + {L"f..", L"*.*", L"jpg", L"f"}, + {L"f.jpg", L"*.*", L"jpg", L"f.jpg"}, + {L"f.jpeg", L"*.*", L"jpg", L"f.jpeg"}, // Same MIME type (diff. ext). + // Test the empty filter, which should behave identically to the + // All Files filter. + {L"f", L"", L"jpg", L"f"}, + {L"f.", L"", L"jpg", L"f"}, + {L"f..", L"", L"jpg", L"f"}, + {L"f.jpg", L"", L"jpg", L"f.jpg"}, + {L"f.jpeg", L"", L"jpg", L"f.jpeg"}, +}; + +TEST(WinUtilTest, AppendingExtensions) { + for (unsigned int i = 0; i < arraysize(filename_cases); ++i) { + const filename_case& value = filename_cases[i]; + std::wstring result = + win_util::AppendExtensionIfNeeded(value.filename, value.filter_selected, + value.suggested_ext); + EXPECT_EQ(value.result, result); + } +} |