This source file includes following definitions.
- SetUp
- SetWorkArea
- PlaceShelf
- PlaceCursor
- DoFindAnchorPoint
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/app_list/linux/app_list_linux.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 kMenuBarSize = 22;
const int kShelfSize = 30;
const int kCursorOnShelf = kShelfSize / 2;
const int kCursorNearShelfX = kShelfSize + kWindowWidth;
const int kCursorAwayFromShelfX = kCursorNearShelfX + 1;
const int kCursorNearShelfY = kShelfSize + kWindowHeight;
const int kCursorAwayFromShelfY = kCursorNearShelfY + 1;
const int kWindowNearEdge = kWindowWidth / 4;
const int kWindowAwayFromEdge = 158;
}
class AppListLinuxUnitTest : public testing::Test {
public:
virtual void SetUp() OVERRIDE {
display_.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
display_.set_work_area(
gfx::Rect(0, kMenuBarSize, kScreenWidth, kScreenHeight - kMenuBarSize));
cursor_ = gfx::Point();
shelf_edge_ = AppListPositioner::SCREEN_EDGE_UNKNOWN;
}
void SetWorkArea(int x, int y, int width, int height) {
display_.set_work_area(gfx::Rect(x, y, width, height));
}
void PlaceShelf(AppListPositioner::ScreenEdge edge) {
shelf_edge_ = edge;
switch (edge) {
case AppListPositioner::SCREEN_EDGE_LEFT:
display_.set_work_area(gfx::Rect(kShelfSize,
kMenuBarSize,
kScreenWidth - kShelfSize,
kScreenHeight - kMenuBarSize));
break;
case AppListPositioner::SCREEN_EDGE_RIGHT:
display_.set_work_area(gfx::Rect(0,
kMenuBarSize,
kScreenWidth - kShelfSize,
kScreenHeight - kMenuBarSize));
break;
case AppListPositioner::SCREEN_EDGE_TOP:
display_.set_work_area(
gfx::Rect(0,
kMenuBarSize + kShelfSize,
kScreenWidth,
kScreenHeight - kMenuBarSize - kShelfSize));
break;
case AppListPositioner::SCREEN_EDGE_BOTTOM:
display_.set_work_area(
gfx::Rect(0,
kMenuBarSize,
kScreenWidth,
kScreenHeight - kMenuBarSize - kShelfSize));
break;
case AppListPositioner::SCREEN_EDGE_UNKNOWN:
NOTREACHED();
break;
}
}
void PlaceCursor(int x, int y) {
cursor_ = gfx::Point(x, y);
}
gfx::Point DoFindAnchorPoint() const {
return AppListLinux::FindAnchorPoint(gfx::Size(kWindowWidth, kWindowHeight),
display_,
cursor_,
shelf_edge_);
}
private:
gfx::Display display_;
gfx::Point cursor_;
AppListPositioner::ScreenEdge shelf_edge_;
};
TEST_F(AppListLinuxUnitTest, FindAnchorPointNoShelf) {
PlaceCursor(0, 0);
EXPECT_EQ(gfx::Point(kWindowWidth / 2, kMenuBarSize + kWindowHeight / 2),
DoFindAnchorPoint());
}
TEST_F(AppListLinuxUnitTest, FindAnchorPointMouseOffShelf) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorAwayFromShelfY);
EXPECT_EQ(gfx::Point(kWindowWidth / 2,
kScreenHeight - kShelfSize - kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kWindowAwayFromEdge, kMenuBarSize + kCursorAwayFromShelfY);
EXPECT_EQ(gfx::Point(kWindowWidth / 2,
kMenuBarSize + kShelfSize + kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kCursorAwayFromShelfX, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kShelfSize + kWindowWidth / 2,
kMenuBarSize + kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kScreenWidth - kCursorAwayFromShelfX, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kScreenWidth - kShelfSize - kWindowWidth / 2,
kMenuBarSize + kWindowHeight / 2),
DoFindAnchorPoint());
}
TEST_F(AppListLinuxUnitTest, FindAnchorPointMouseOnShelf) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorOnShelf);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kScreenHeight - kCursorNearShelfY);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kWindowAwayFromEdge, kMenuBarSize + kCursorNearShelfY);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kMenuBarSize + kShelfSize + kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kCursorNearShelfX, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kShelfSize + kWindowWidth / 2, kWindowAwayFromEdge),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kScreenWidth - kCursorNearShelfX, kWindowAwayFromEdge);
EXPECT_EQ(gfx::Point(kScreenWidth - kShelfSize - kWindowWidth / 2,
kWindowAwayFromEdge),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowNearEdge, kScreenHeight - kCursorOnShelf);
EXPECT_EQ(gfx::Point(kWindowWidth / 2,
kScreenHeight - kShelfSize - kWindowHeight / 2),
DoFindAnchorPoint());
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kScreenWidth - kWindowNearEdge, kScreenHeight - kCursorOnShelf);
EXPECT_EQ(gfx::Point(kScreenWidth - kWindowWidth / 2,
kScreenHeight - kShelfSize - kWindowHeight / 2),
DoFindAnchorPoint());
}