This source file includes following definitions.
- SetUp
- SetWorkArea
- PlaceTaskbar
- PlaceCursor
- DoFindAnchorPoint
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/app_list/win/app_list_win.h"
#include "chrome/browser/ui/app_list/app_list_positioner.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace {
const int kScreenWidth = 800;
const int kScreenHeight = 600;
const int kWindowWidth = 100;
const int kWindowHeight = 200;
const int kTaskbarSize = 30;
const int kMinDistanceFromEdge = 3;
const int kSnapDistance = 50;
const int kCursorOnTaskbar = kTaskbarSize / 2;
const int kCursorNearTaskbar = kTaskbarSize + kSnapDistance;
const int kCursorAwayFromTaskbar = kCursorNearTaskbar + 1;
const int kWindowNearEdge = kWindowWidth / 4;
const int kWindowAwayFromEdge = 158;
const int kWin8SplitPoint = 200;
}
class AppListWinUnitTest : public testing::Test {
public:
virtual void SetUp() OVERRIDE {
display_.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
display_.set_work_area(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
cursor_ = gfx::Point();
taskbar_rect_ = gfx::Rect();
}
void SetWorkArea(int x, int y, int width, int height) {
display_.set_work_area(gfx::Rect(x, y, width, height));
}
void PlaceTaskbar(AppListPositioner::ScreenEdge edge) {
const gfx::Rect& work_area = display_.work_area();
switch (edge) {
case AppListPositioner::SCREEN_EDGE_UNKNOWN:
taskbar_rect_ = gfx::Rect();
break;
case AppListPositioner::SCREEN_EDGE_LEFT:
taskbar_rect_ = gfx::Rect(
work_area.x(), work_area.y(), kTaskbarSize, work_area.height());
break;
case AppListPositioner::SCREEN_EDGE_RIGHT:
taskbar_rect_ =
gfx::Rect(work_area.x() + work_area.width() - kTaskbarSize,
work_area.y(),
kTaskbarSize,
work_area.height());
break;
case AppListPositioner::SCREEN_EDGE_TOP:
taskbar_rect_ = gfx::Rect(
work_area.x(), work_area.y(), work_area.width(), kTaskbarSize);
break;
case AppListPositioner::SCREEN_EDGE_BOTTOM:
taskbar_rect_ =
gfx::Rect(work_area.x(),
work_area.y() + work_area.height() - kTaskbarSize,
work_area.width(),
kTaskbarSize);
break;
}
}
void PlaceCursor(int x, int y) {
cursor_ = gfx::Point(x, y);
}
gfx::Point DoFindAnchorPoint() const {
return AppListWin::FindAnchorPoint(gfx::Size(kWindowWidth, kWindowHeight),
display_,
cursor_,
taskbar_rect_);
}
private:
gfx::Display display_;
gfx::Point cursor_;
gfx::Rect taskbar_rect_;
};
TEST_F(AppListWinUnitTest, FindAnchorPointNoTaskbar) {
PlaceCursor(0, 0);
EXPECT_EQ(
gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kWindowHeight / 2 - kMinDistanceFromEdge),
DoFindAnchorPoint());
}
TEST_F(AppListWinUnitTest, FindAnchorPointMouseOffTaskbar) {
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorAwayFromTaskbar);
EXPECT_EQ(gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kWindowAwayFromEdge, kCursorAwayFromTaskbar);
EXPECT_EQ(gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kTaskbarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kCursorAwayFromTaskbar, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kTaskbarSize + kWindowWidth / 2 + kMinDistanceFromEdge,
kWindowHeight / 2 + kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kScreenWidth - kCursorAwayFromTaskbar, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kScreenWidth - kTaskbarSize - kWindowWidth / 2 -
kMinDistanceFromEdge,
kWindowHeight / 2 + kMinDistanceFromEdge),
DoFindAnchorPoint());
}
TEST_F(AppListWinUnitTest, FindAnchorPointMouseOnTaskbar) {
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorOnTaskbar);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorNearTaskbar);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kWindowAwayFromEdge, kCursorNearTaskbar);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kTaskbarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kCursorNearTaskbar, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kTaskbarSize + kWindowWidth / 2 + kMinDistanceFromEdge,
kWindowAwayFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kScreenWidth - kCursorNearTaskbar, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kScreenWidth - kTaskbarSize - kWindowWidth / 2 -
kMinDistanceFromEdge,
kWindowAwayFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowNearEdge, kScreenHeight - kCursorOnTaskbar);
EXPECT_EQ(gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kScreenWidth - kWindowNearEdge, kScreenHeight - kCursorOnTaskbar);
EXPECT_EQ(gfx::Point(kScreenWidth - kWindowWidth / 2 - kMinDistanceFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
}
TEST_F(AppListWinUnitTest, FindAnchorPointWin8SplitScreen) {
SetWorkArea(
kWin8SplitPoint, 0, kScreenWidth - kWin8SplitPoint, kScreenHeight);
EXPECT_EQ(
gfx::Point(kWin8SplitPoint + kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kWindowHeight / 2 - kMinDistanceFromEdge),
DoFindAnchorPoint());
PlaceTaskbar(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorOnTaskbar);
EXPECT_EQ(
gfx::Point(kWin8SplitPoint + kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kTaskbarSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoFindAnchorPoint());
}