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
|
// Copyright (c) 2012 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 "ui/views/view_model_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/view.h"
#include "ui/views/view_model.h"
namespace views {
// Makes sure SetViewBoundsToIdealBounds updates the view appropriately.
TEST(ViewModelUtils, SetViewBoundsToIdealBounds) {
View v1;
ViewModel model;
model.Add(&v1, 0);
gfx::Rect v1_bounds(1, 2, 3, 4);
model.set_ideal_bounds(0, v1_bounds);
ViewModelUtils::SetViewBoundsToIdealBounds(model);
EXPECT_EQ(v1_bounds, v1.bounds());
}
// Assertions for DetermineMoveIndex.
TEST(ViewModelUtils, DetermineMoveIndex) {
View v1, v2, v3;
ViewModel model;
model.Add(&v1, 0);
model.Add(&v2, 1);
model.Add(&v3, 2);
model.set_ideal_bounds(0, gfx::Rect(0, 0, 10, 10));
model.set_ideal_bounds(1, gfx::Rect(10, 0, 1000, 10));
model.set_ideal_bounds(2, gfx::Rect(1010, 0, 2, 10));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::HORIZONTAL, -10, 0));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::HORIZONTAL, 4, 0));
EXPECT_EQ(1, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::HORIZONTAL, 506, 0));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::HORIZONTAL, 1010, 0));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::HORIZONTAL, 2000, 0));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::HORIZONTAL, -10, 0));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::HORIZONTAL, 4, 0));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::HORIZONTAL, 12, 0));
// Try the same when vertical.
model.set_ideal_bounds(0, gfx::Rect(0, 0, 10, 10));
model.set_ideal_bounds(1, gfx::Rect(0, 10, 10, 1000));
model.set_ideal_bounds(2, gfx::Rect(0, 1010, 10, 2));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::VERTICAL, 0, -10));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::VERTICAL, 0, 4));
EXPECT_EQ(1, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::VERTICAL, 0, 506));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::VERTICAL, 0, 1010));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v1, ViewModelUtils::VERTICAL, 0, 2000));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::VERTICAL, 0, -10));
EXPECT_EQ(0, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::VERTICAL, 0, 4));
EXPECT_EQ(2, ViewModelUtils::DetermineMoveIndex(
model, &v2, ViewModelUtils::VERTICAL, 0, 12));
}
} // namespace views
|