Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/common/win_util_unittest.cc

Issue 113169: Move win_util.h from common to app. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/win_util.cc ('k') | chrome/plugin/plugin_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/common/win_util.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 TEST(WinUtilTest, EnsureRectIsVisibleInRect) {
9 gfx::Rect parent_rect(0, 0, 500, 400);
10
11 {
12 // Child rect x < 0
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);
16 }
17
18 {
19 // Child rect y < 0
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);
23 }
24
25 {
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);
30 }
31
32 {
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);
37 }
38
39 {
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);
44 }
45
46 {
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);
51 }
52 }
53
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
78 // All Files filter.
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"},
84 };
85
86 TEST(WinUtilTest, AppendingExtensions) {
87 for (unsigned int i = 0; i < arraysize(filename_cases); ++i) {
88 const filename_case& value = filename_cases[i];
89 std::wstring result =
90 win_util::AppendExtensionIfNeeded(value.filename, value.filter_selected,
91 value.suggested_ext);
92 EXPECT_EQ(value.result, result);
93 }
94 }
OLDNEW
« no previous file with comments | « chrome/common/win_util.cc ('k') | chrome/plugin/plugin_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698