This source file includes following definitions.
- ResetPositioner
- SetUp
- PlaceShelf
- PlaceCursor
- DoGetAnchorPointForScreenCorner
- DoGetAnchorPointForShelfCorner
- DoGetAnchorPointForShelfCenter
- DoGetAnchorPointForShelfCursor
- DoGetShelfEdge
- DoGetCursorDistanceFromShelf
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/app_list/app_list_positioner.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.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 kMinDistanceFromEdge = 3;
const int kCursorOnShelf = kShelfSize / 2;
const int kCursorIgnore = -300;
const int kWindowNearEdge = kWindowWidth / 4;
const int kWindowAwayFromEdge = 158;
}
class AppListPositionerUnitTest : public testing::Test {
public:
void ResetPositioner() {
gfx::Size view_size(kWindowWidth, kWindowHeight);
positioner_.reset(
new AppListPositioner(display_, view_size, kMinDistanceFromEdge));
}
virtual void SetUp() OVERRIDE {
display_.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
display_.set_work_area(
gfx::Rect(0, kMenuBarSize, kScreenWidth, kScreenHeight - kMenuBarSize));
ResetPositioner();
cursor_ = gfx::Point();
}
void PlaceShelf(AppListPositioner::ScreenEdge edge) {
ResetPositioner();
switch (edge) {
case AppListPositioner::SCREEN_EDGE_UNKNOWN:
break;
case AppListPositioner::SCREEN_EDGE_LEFT:
positioner_->WorkAreaInset(kShelfSize, 0, 0, 0);
break;
case AppListPositioner::SCREEN_EDGE_RIGHT:
positioner_->WorkAreaInset(0, 0, kShelfSize, 0);
break;
case AppListPositioner::SCREEN_EDGE_TOP:
positioner_->WorkAreaInset(0, kShelfSize, 0, 0);
break;
case AppListPositioner::SCREEN_EDGE_BOTTOM:
positioner_->WorkAreaInset(0, 0, 0, kShelfSize);
break;
}
}
void PlaceCursor(int x, int y) {
cursor_ = gfx::Point(x, y);
}
gfx::Point DoGetAnchorPointForScreenCorner(
AppListPositioner::ScreenCorner corner) const {
return positioner_->GetAnchorPointForScreenCorner(corner);
}
gfx::Point DoGetAnchorPointForShelfCorner(
AppListPositioner::ScreenEdge shelf_edge) const {
return positioner_->GetAnchorPointForShelfCorner(shelf_edge);
}
gfx::Point DoGetAnchorPointForShelfCenter(
AppListPositioner::ScreenEdge shelf_edge) const {
return positioner_->GetAnchorPointForShelfCenter(shelf_edge);
}
gfx::Point DoGetAnchorPointForShelfCursor(
AppListPositioner::ScreenEdge shelf_edge) const {
return positioner_->GetAnchorPointForShelfCursor(shelf_edge, cursor_);
}
AppListPositioner::ScreenEdge DoGetShelfEdge(
const gfx::Rect& shelf_rect) const {
return positioner_->GetShelfEdge(shelf_rect);
}
int DoGetCursorDistanceFromShelf(
AppListPositioner::ScreenEdge shelf_edge) const {
return positioner_->GetCursorDistanceFromShelf(shelf_edge, cursor_);
}
private:
gfx::Display display_;
scoped_ptr<AppListPositioner> positioner_;
gfx::Point cursor_;
};
TEST_F(AppListPositionerUnitTest, ScreenCorner) {
EXPECT_EQ(gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kMenuBarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoGetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_TOP_LEFT));
EXPECT_EQ(gfx::Point(kScreenWidth - kWindowWidth / 2 - kMinDistanceFromEdge,
kMenuBarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoGetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_TOP_RIGHT));
EXPECT_EQ(
gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kWindowHeight / 2 - kMinDistanceFromEdge),
DoGetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_BOTTOM_LEFT));
EXPECT_EQ(
gfx::Point(kScreenWidth - kWindowWidth / 2 - kMinDistanceFromEdge,
kScreenHeight - kWindowHeight / 2 - kMinDistanceFromEdge),
DoGetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_BOTTOM_RIGHT));
}
TEST_F(AppListPositionerUnitTest, ShelfCorner) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
EXPECT_EQ(
gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge,
kMenuBarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_LEFT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
EXPECT_EQ(
gfx::Point(
kScreenWidth - kShelfSize - kWindowWidth / 2 - kMinDistanceFromEdge,
kMenuBarSize + kWindowHeight / 2 + kMinDistanceFromEdge),
DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_RIGHT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
EXPECT_EQ(gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kMenuBarSize + kShelfSize + kWindowHeight / 2 +
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_TOP));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
EXPECT_EQ(
gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_BOTTOM));
}
TEST_F(AppListPositionerUnitTest, ShelfCenter) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
EXPECT_EQ(
gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge,
(kMenuBarSize + kScreenHeight) / 2),
DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_LEFT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
EXPECT_EQ(
gfx::Point(
kScreenWidth - kShelfSize - kWindowWidth / 2 - kMinDistanceFromEdge,
(kMenuBarSize + kScreenHeight) / 2),
DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_RIGHT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
EXPECT_EQ(gfx::Point(kScreenWidth / 2,
kMenuBarSize + kShelfSize + kWindowHeight / 2 +
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_TOP));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
EXPECT_EQ(
gfx::Point(kScreenWidth / 2,
kScreenHeight - kShelfSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_BOTTOM));
}
TEST_F(AppListPositionerUnitTest, ShelfCursor) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kCursorIgnore, kWindowAwayFromEdge);
EXPECT_EQ(
gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge,
kWindowAwayFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_LEFT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kCursorIgnore, kWindowAwayFromEdge);
EXPECT_EQ(
gfx::Point(
kScreenWidth - kShelfSize - kWindowWidth / 2 - kMinDistanceFromEdge,
kWindowAwayFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_RIGHT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kWindowAwayFromEdge, kCursorIgnore);
EXPECT_EQ(gfx::Point(kWindowAwayFromEdge,
kMenuBarSize + kShelfSize + kWindowHeight / 2 +
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_TOP));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowAwayFromEdge, kCursorIgnore);
EXPECT_EQ(
gfx::Point(kWindowAwayFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_BOTTOM));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kWindowNearEdge, kCursorIgnore);
EXPECT_EQ(
gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_BOTTOM));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kScreenWidth - kWindowNearEdge, kCursorIgnore);
EXPECT_EQ(
gfx::Point(kScreenWidth - kWindowWidth / 2 - kMinDistanceFromEdge,
kScreenHeight - kShelfSize - kWindowHeight / 2 -
kMinDistanceFromEdge),
DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_BOTTOM));
}
TEST_F(AppListPositionerUnitTest, GetShelfEdge) {
gfx::Rect shelf_rect;
shelf_rect =
gfx::Rect(0, kMenuBarSize, kShelfSize, kScreenHeight - kMenuBarSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_LEFT, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect(kScreenWidth - kShelfSize,
kMenuBarSize,
kShelfSize,
kScreenHeight - kMenuBarSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_RIGHT, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect(0, 0, kScreenWidth, kShelfSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_TOP, DoGetShelfEdge(shelf_rect));
shelf_rect =
gfx::Rect(0, kScreenHeight - kShelfSize, kScreenWidth, kShelfSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_BOTTOM, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect();
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_UNKNOWN, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect(-10, 0, kScreenWidth, kShelfSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_UNKNOWN, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect(10, 0, kScreenWidth - 20, kShelfSize);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_UNKNOWN, DoGetShelfEdge(shelf_rect));
shelf_rect = gfx::Rect(0, kShelfSize, kScreenWidth, 60);
EXPECT_EQ(AppListPositioner::SCREEN_EDGE_UNKNOWN, DoGetShelfEdge(shelf_rect));
}
TEST_F(AppListPositionerUnitTest, GetCursorDistanceFromShelf) {
PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT);
PlaceCursor(kWindowAwayFromEdge, kCursorIgnore);
EXPECT_EQ(kWindowAwayFromEdge - kShelfSize,
DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_LEFT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT);
PlaceCursor(kScreenWidth - kWindowAwayFromEdge, kCursorIgnore);
EXPECT_EQ(kWindowAwayFromEdge - kShelfSize,
DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_RIGHT));
PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP);
PlaceCursor(kCursorIgnore, kMenuBarSize + kWindowAwayFromEdge);
EXPECT_EQ(kWindowAwayFromEdge - kShelfSize,
DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_TOP));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kCursorIgnore, kScreenHeight - kWindowAwayFromEdge);
EXPECT_EQ(
kWindowAwayFromEdge - kShelfSize,
DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM));
PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM);
PlaceCursor(kCursorIgnore, kScreenHeight - kCursorOnShelf);
EXPECT_EQ(
0, DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM));
}