This source file includes following definitions.
- available_bounds_
- GetAvailableScreenBounds
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ui/gfx/insets.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
namespace views {
typedef ViewsTestBase BubbleFrameViewTest;
namespace {
const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT;
const SkColor kColor = SK_ColorRED;
const int kMargin = 6;
class TestBubbleFrameView : public BubbleFrameView {
public:
TestBubbleFrameView()
: BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)),
available_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
SetBubbleBorder(scoped_ptr<views::BubbleBorder>(
new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor)));
}
virtual ~TestBubbleFrameView() {}
virtual gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) OVERRIDE {
return available_bounds_;
}
private:
gfx::Rect available_bounds_;
DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
};
}
TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
TestBubbleFrameView frame;
EXPECT_EQ(kArrow, frame.bubble_border()->arrow());
EXPECT_EQ(kColor, frame.bubble_border()->background_color());
int margin_x = frame.content_margins().left();
int margin_y = frame.content_margins().top();
gfx::Insets insets = frame.bubble_border()->GetInsets();
EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x());
EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y());
}
TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) {
TestBubbleFrameView frame;
gfx::Rect window_bounds;
gfx::Insets insets = frame.bubble_border()->GetInsets();
int xposition = 95 - insets.width();
frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow());
EXPECT_GT(window_bounds.x(), xposition);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_RIGHT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow());
EXPECT_GT(window_bounds.x(), xposition);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_RIGHT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow());
EXPECT_GT(window_bounds.x(), xposition);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow());
EXPECT_GT(window_bounds.x(), xposition);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
EXPECT_GT(window_bounds.y(), 100 + 50 - 10);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
EXPECT_LT(window_bounds.y(), 900 - 500 - 15);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
EXPECT_LT(window_bounds.y(), 900 - 500 - 15);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_RIGHT);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
EXPECT_LT(window_bounds.y(), 900 - 500 - 15);
}
TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsMirroringFails) {
TestBubbleFrameView frame;
frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
gfx::Rect window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(400, 100, 50, 50),
gfx::Size(500, 700),
true);
EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow());
}
TEST_F(BubbleFrameViewTest, TestMirroringForCenteredArrow) {
TestBubbleFrameView frame;
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_CENTER);
gfx::Rect window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 700),
true);
EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow());
frame.bubble_border()->set_arrow(BubbleBorder::TOP_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(300, 800, 50, 50),
gfx::Size(500, 200),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, frame.bubble_border()->arrow());
frame.bubble_border()->set_arrow(BubbleBorder::LEFT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(800, 300, 50, 50),
gfx::Size(200, 500),
true);
EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow());
frame.bubble_border()->set_arrow(BubbleBorder::RIGHT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 300, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow());
}
TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsDontTryMirror) {
TestBubbleFrameView frame;
frame.bubble_border()->set_arrow(BubbleBorder::TOP_RIGHT);
gfx::Rect window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 900, 50, 50),
gfx::Size(500, 500),
false);
EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow());
EXPECT_LT(window_bounds.x(), 100 + 50 - 500);
EXPECT_GT(window_bounds.y(), 900 + 50 - 10);
}
TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsCenterArrows) {
TestBubbleFrameView frame;
gfx::Rect window_bounds;
frame.bubble_border()->set_arrow(BubbleBorder::TOP_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(500, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.x() + window_bounds.width() / 2, 525);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(500, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.x() + window_bounds.width() / 2, 525);
frame.bubble_border()->set_arrow(BubbleBorder::LEFT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 400, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.y() + window_bounds.height() / 2, 425);
frame.bubble_border()->set_arrow(BubbleBorder::RIGHT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 400, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.y() + window_bounds.height() / 2, 425);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.x(), 0);
EXPECT_EQ(window_bounds.x() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.x(), 0);
EXPECT_EQ(window_bounds.x() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125);
frame.bubble_border()->set_arrow(BubbleBorder::TOP_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.right(), 1000);
EXPECT_EQ(window_bounds.x() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
frame.bubble_border()->set_arrow(BubbleBorder::BOTTOM_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.right(), 1000);
EXPECT_EQ(window_bounds.x() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
frame.bubble_border()->set_arrow(BubbleBorder::LEFT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.y(), 0);
EXPECT_EQ(window_bounds.y() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125);
frame.bubble_border()->set_arrow(BubbleBorder::RIGHT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 100, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.y(), 0);
EXPECT_EQ(window_bounds.y() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125);
frame.bubble_border()->set_arrow(BubbleBorder::LEFT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(100, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.bottom(), 1000);
EXPECT_EQ(window_bounds.y() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
frame.bubble_border()->set_arrow(BubbleBorder::RIGHT_CENTER);
window_bounds = frame.GetUpdatedWindowBounds(
gfx::Rect(900, 900, 50, 50),
gfx::Size(500, 500),
true);
EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow());
EXPECT_EQ(window_bounds.bottom(), 1000);
EXPECT_EQ(window_bounds.y() +
frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
}
}