Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / omnibox_popup_model_unittest.cc
blobf7c3b4b37e9de741d5bbe1a0cf901bbc47f5e33a
1 // Copyright 2014 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 "chrome/browser/ui/omnibox/omnibox_popup_model.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 TEST(OmniboxPopupModelTest, ComputeMatchMaxWidths) {
9 int contents_max_width, description_max_width;
10 const int separator_width = 10;
11 const int kMinimumContentsWidth = 300;
12 int contents_width, description_width, available_width;
14 // Both contents and description fit fine.
15 contents_width = 100;
16 description_width = 50;
17 available_width = 200;
18 OmniboxPopupModel::ComputeMatchMaxWidths(
19 contents_width, separator_width, description_width, available_width,
20 true, &contents_max_width, &description_max_width);
21 EXPECT_EQ(contents_width, contents_max_width);
22 EXPECT_EQ(description_width, description_max_width);
24 // Contents should be given as much space as it wants up to 300 pixels.
25 contents_width = 100;
26 description_width = 50;
27 available_width = 100;
28 OmniboxPopupModel::ComputeMatchMaxWidths(
29 contents_width, separator_width, description_width, available_width,
30 true, &contents_max_width, &description_max_width);
31 EXPECT_EQ(contents_width, contents_max_width);
32 EXPECT_EQ(0, description_max_width);
34 // Description should be hidden if it's at least 75 pixels wide but doesn't
35 // get 75 pixels of space.
36 contents_width = 300;
37 description_width = 100;
38 available_width = 384;
39 OmniboxPopupModel::ComputeMatchMaxWidths(
40 contents_width, separator_width, description_width, available_width,
41 true, &contents_max_width, &description_max_width);
42 EXPECT_EQ(contents_width, contents_max_width);
43 EXPECT_EQ(0, description_max_width);
45 // Both contents and description will be limited.
46 contents_width = 310;
47 description_width = 150;
48 available_width = 400;
49 OmniboxPopupModel::ComputeMatchMaxWidths(
50 contents_width, separator_width, description_width, available_width,
51 true, &contents_max_width, &description_max_width);
52 OmniboxPopupModel::ComputeMatchMaxWidths(
53 310, separator_width, 150, 400, true, &contents_max_width,
54 &description_max_width);
55 EXPECT_EQ(kMinimumContentsWidth, contents_max_width);
56 EXPECT_EQ(available_width - kMinimumContentsWidth - separator_width,
57 description_max_width);
59 // Contents takes all available space.
60 contents_width = 400;
61 description_width = 0;
62 available_width = 200;
63 OmniboxPopupModel::ComputeMatchMaxWidths(
64 contents_width, separator_width, description_width, available_width,
65 true, &contents_max_width, &description_max_width);
66 EXPECT_EQ(contents_width, contents_max_width);
67 EXPECT_EQ(0, description_max_width);
69 // Half and half.
70 contents_width = 395;
71 description_width = 395;
72 available_width = 700;
73 OmniboxPopupModel::ComputeMatchMaxWidths(
74 contents_width, separator_width, description_width, available_width,
75 true, &contents_max_width, &description_max_width);
76 EXPECT_EQ(345, contents_max_width);
77 EXPECT_EQ(345, description_max_width);
79 // When we disallow shrinking the contents, it should get as much space as
80 // it wants.
81 contents_width = 395;
82 description_width = 395;
83 available_width = 700;
84 OmniboxPopupModel::ComputeMatchMaxWidths(
85 contents_width, separator_width, description_width, available_width,
86 false, &contents_max_width, &description_max_width);
87 EXPECT_EQ(contents_width, contents_max_width);
88 EXPECT_EQ((available_width - contents_width - separator_width),
89 description_max_width);
91 // (available_width - separator_width) is odd, so contents gets the extra
92 // pixel.
93 contents_width = 395;
94 description_width = 395;
95 available_width = 699;
96 OmniboxPopupModel::ComputeMatchMaxWidths(
97 contents_width, separator_width, description_width, available_width,
98 true, &contents_max_width, &description_max_width);
99 EXPECT_EQ(345, contents_max_width);
100 EXPECT_EQ(344, description_max_width);
102 // Not enough space to draw anything.
103 contents_width = 1;
104 description_width = 1;
105 available_width = 0;
106 OmniboxPopupModel::ComputeMatchMaxWidths(
107 contents_width, separator_width, description_width, available_width,
108 true, &contents_max_width, &description_max_width);
109 EXPECT_EQ(0, contents_max_width);
110 EXPECT_EQ(0, description_max_width);