File: omnibox_popup_model_unittest.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (141 lines) | stat: -rw-r--r-- 5,948 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2014 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 "components/omnibox/browser/omnibox_popup_model.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(OmniboxPopupModelTest, ComputeMatchMaxWidths) {
    int contents_max_width, description_max_width;
    const int separator_width = 10;
    const int kMinimumContentsWidth = 300;
    int contents_width, description_width, available_width;

    // Both contents and description fit fine.
    contents_width = 100;
    description_width = 50;
    available_width = 200;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ(description_width, description_max_width);

    // Contents should be given as much space as it wants up to 300 pixels.
    contents_width = 100;
    description_width = 50;
    available_width = 100;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ(0, description_max_width);

    // Description should be hidden if it's at least 75 pixels wide but doesn't
    // get 75 pixels of space.
    contents_width = 300;
    description_width = 100;
    available_width = 384;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ(0, description_max_width);

    // If contents and description are on separate lines, each can take the full
    // available width.
    contents_width = 300;
    description_width = 100;
    available_width = 384;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        true, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ(description_width, description_max_width);

    // Both contents and description will be limited.
    contents_width = 310;
    description_width = 150;
    available_width = 400;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(kMinimumContentsWidth, contents_max_width);
    EXPECT_EQ(available_width - kMinimumContentsWidth - separator_width,
              description_max_width);

    // Contents takes all available space.
    contents_width = 400;
    description_width = 0;
    available_width = 200;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(available_width, contents_max_width);
    EXPECT_EQ(0, description_max_width);

    // Large contents will be truncated but small description won't if two line
    // suggestion.
    contents_width = 400;
    description_width = 100;
    available_width = 200;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        true, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(available_width, contents_max_width);
    EXPECT_EQ(description_width, description_max_width);

    // Large description will be truncated but small contents won't if two line
    // suggestion.
    contents_width = 100;
    description_width = 400;
    available_width = 200;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        true, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ(available_width, description_max_width);

    // Half and half.
    contents_width = 395;
    description_width = 395;
    available_width = 700;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(345, contents_max_width);
    EXPECT_EQ(345, description_max_width);

    // When we disallow shrinking the contents, it should get as much space as
    // it wants.
    contents_width = 395;
    description_width = 395;
    available_width = 700;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, false, &contents_max_width, &description_max_width);
    EXPECT_EQ(contents_width, contents_max_width);
    EXPECT_EQ((available_width - contents_width - separator_width),
              description_max_width);

    // (available_width - separator_width) is odd, so contents gets the extra
    // pixel.
    contents_width = 395;
    description_width = 395;
    available_width = 699;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(345, contents_max_width);
    EXPECT_EQ(344, description_max_width);

    // Not enough space to draw anything.
    contents_width = 1;
    description_width = 1;
    available_width = 0;
    OmniboxPopupModel::ComputeMatchMaxWidths(
        contents_width, separator_width, description_width, available_width,
        false, true, &contents_max_width, &description_max_width);
    EXPECT_EQ(0, contents_max_width);
    EXPECT_EQ(0, description_max_width);
}