1 // Copyright (c) 2006-2008 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.
5 #include "app/win_util.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 TEST(WinUtilTest
, EnsureRectIsVisibleInRect
) {
9 gfx::Rect
parent_rect(0, 0, 500, 400);
13 gfx::Rect
child_rect(-50, 20, 100, 100);
14 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
15 EXPECT_EQ(gfx::Rect(10, 20, 100, 100), child_rect
);
20 gfx::Rect
child_rect(20, -50, 100, 100);
21 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
22 EXPECT_EQ(gfx::Rect(20, 10, 100, 100), child_rect
);
26 // Child rect right > parent_rect.right
27 gfx::Rect
child_rect(450, 20, 100, 100);
28 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
29 EXPECT_EQ(gfx::Rect(390, 20, 100, 100), child_rect
);
33 // Child rect bottom > parent_rect.bottom
34 gfx::Rect
child_rect(20, 350, 100, 100);
35 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
36 EXPECT_EQ(gfx::Rect(20, 290, 100, 100), child_rect
);
40 // Child rect width > parent_rect.width
41 gfx::Rect
child_rect(20, 20, 700, 100);
42 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
43 EXPECT_EQ(gfx::Rect(20, 20, 480, 100), child_rect
);
47 // Child rect height > parent_rect.height
48 gfx::Rect
child_rect(20, 20, 100, 700);
49 win_util::EnsureRectIsVisibleInRect(parent_rect
, &child_rect
, 10);
50 EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect
);
54 static const struct filename_case
{
55 const wchar_t* filename
;
56 const wchar_t* filter_selected
;
57 const wchar_t* suggested_ext
;
58 const wchar_t* result
;
59 } filename_cases
[] = {
60 // Test a specific filter (*.jpg).
61 {L
"f", L
"*.jpg", L
"jpg", L
"f.jpg"},
62 {L
"f.", L
"*.jpg", L
"jpg", L
"f..jpg"},
63 {L
"f..", L
"*.jpg", L
"jpg", L
"f...jpg"},
64 {L
"f.jpeg", L
"*.jpg", L
"jpg", L
"f.jpeg"},
65 // Further guarantees.
66 {L
"f.jpg.jpg", L
"*.jpg", L
"jpg", L
"f.jpg.jpg"},
67 {L
"f.exe.jpg", L
"*.jpg", L
"jpg", L
"f.exe.jpg"},
68 {L
"f.jpg.exe", L
"*.jpg", L
"jpg", L
"f.jpg.exe.jpg"},
69 {L
"f.exe..", L
"*.jpg", L
"jpg", L
"f.exe...jpg"},
70 {L
"f.jpg..", L
"*.jpg", L
"jpg", L
"f.jpg...jpg"},
71 // Test the All Files filter (*.jpg).
72 {L
"f", L
"*.*", L
"jpg", L
"f"},
73 {L
"f.", L
"*.*", L
"jpg", L
"f"},
74 {L
"f..", L
"*.*", L
"jpg", L
"f"},
75 {L
"f.jpg", L
"*.*", L
"jpg", L
"f.jpg"},
76 {L
"f.jpeg", L
"*.*", L
"jpg", L
"f.jpeg"}, // Same MIME type (diff. ext).
77 // Test the empty filter, which should behave identically to the
79 {L
"f", L
"", L
"jpg", L
"f"},
80 {L
"f.", L
"", L
"jpg", L
"f"},
81 {L
"f..", L
"", L
"jpg", L
"f"},
82 {L
"f.jpg", L
"", L
"jpg", L
"f.jpg"},
83 {L
"f.jpeg", L
"", L
"jpg", L
"f.jpeg"},