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);
}
|