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
|
// 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 "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(OmniboxResultViewTest, CheckComputeMatchWidths) {
int contents_max_width, description_max_width;
const int separator_width = 10;
// Both contents and description fit fine.
OmniboxResultView::ComputeMatchMaxWidths(
100, separator_width, 50, 200, true, &contents_max_width,
&description_max_width);
EXPECT_EQ(-1, contents_max_width);
EXPECT_EQ(-1, description_max_width);
// Contents should be given as much space as it wants up to 300 pixels.
OmniboxResultView::ComputeMatchMaxWidths(
100, separator_width, 50, 100, true, &contents_max_width,
&description_max_width);
EXPECT_EQ(-1, 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.
OmniboxResultView::ComputeMatchMaxWidths(
300, separator_width, 75, 384, true, &contents_max_width,
&description_max_width);
EXPECT_EQ(-1, contents_max_width);
EXPECT_EQ(0, description_max_width);
// Both contents and description will be limited.
OmniboxResultView::ComputeMatchMaxWidths(
310, separator_width, 150, 400, true, &contents_max_width,
&description_max_width);
EXPECT_EQ(300, contents_max_width);
EXPECT_EQ(400 - 300 - separator_width, description_max_width);
// Contents takes all available space.
OmniboxResultView::ComputeMatchMaxWidths(
400, separator_width, 0, 200, true, &contents_max_width,
&description_max_width);
EXPECT_EQ(-1, contents_max_width);
EXPECT_EQ(0, description_max_width);
// Half and half.
OmniboxResultView::ComputeMatchMaxWidths(
395, separator_width, 395, 700, true, &contents_max_width,
&description_max_width);
EXPECT_EQ((700 - separator_width) / 2, contents_max_width);
EXPECT_EQ((700 - separator_width) / 2, description_max_width);
// When we disallow shrinking the contents, it should get as much space as
// it wants.
OmniboxResultView::ComputeMatchMaxWidths(
395, separator_width, 395, 700, false, &contents_max_width,
&description_max_width);
EXPECT_EQ(-1, contents_max_width);
EXPECT_EQ(295, description_max_width);
// (available_width - separator_width) is odd, so contents gets the extra
// pixel.
OmniboxResultView::ComputeMatchMaxWidths(
395, separator_width, 395, 699, true, &contents_max_width,
&description_max_width);
EXPECT_EQ((700 - separator_width) / 2, contents_max_width);
EXPECT_EQ((700 - separator_width) / 2 - 1, description_max_width);
// Not enough space to draw anything.
OmniboxResultView::ComputeMatchMaxWidths(
1, 1, 1, 0, true, &contents_max_width, &description_max_width);
EXPECT_EQ(0, contents_max_width);
EXPECT_EQ(0, description_max_width);
}
|