This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "ash/wm/workspace/magnetism_matcher.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash {
TEST(MagnetismMatcherTest, TrivialLeft) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 50, 60);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
EXPECT_FALSE(matcher.AreEdgesObscured());
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - distance - 10,
initial_bounds.y() - distance - 10, 2, 3), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - 2, initial_bounds.y(), 1, 1),
&edge));
EXPECT_EQ(MAGNETISM_EDGE_LEFT, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_LEADING, edge.secondary_edge);
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - 2,
initial_bounds.y() + distance + 1 , 1, 1),
&edge));
EXPECT_EQ(MAGNETISM_EDGE_LEFT, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
}
TEST(MagnetismMatcherTest, TrivialBottom) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 50, 60);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
EXPECT_FALSE(matcher.AreEdgesObscured());
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - distance - 10,
initial_bounds.y() - distance - 10, 2, 3), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - 2,
initial_bounds.bottom() + 4, 10, 1), &edge));
EXPECT_EQ(MAGNETISM_EDGE_BOTTOM, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_LEADING, edge.secondary_edge);
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() + distance + 1,
initial_bounds.bottom() + 4, 10, 1), &edge));
EXPECT_EQ(MAGNETISM_EDGE_BOTTOM, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.right() - 10 - 1,
initial_bounds.bottom() + 4, 10, 1), &edge));
EXPECT_EQ(MAGNETISM_EDGE_BOTTOM, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_TRAILING, edge.secondary_edge);
}
TEST(MagnetismMatcherTest, ObscureLeading) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 150, 160);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.right() - distance * 2,
initial_bounds.y() - distance - 2,
distance * 3,
(distance + 2) * 2), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.right() + 1,
initial_bounds.y(),
distance,
5), &edge));
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.right() + 1,
initial_bounds.y() + distance + 1,
distance,
15), &edge));
EXPECT_EQ(MAGNETISM_EDGE_RIGHT, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
}
TEST(MagnetismMatcherTest, DontObscureOtherSide) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 150, 160);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - distance + 1,
initial_bounds.y() + 2,
distance * 2 + 2,
initial_bounds.height() + distance * 4), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.right() - 1,
initial_bounds.y() + distance + 1,
distance,
5), &edge));
EXPECT_EQ(MAGNETISM_EDGE_RIGHT, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
}
TEST(MagnetismMatcherTest, ObscureCenter) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 150, 160);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(100, initial_bounds.bottom() - distance - 2,
20,
(distance + 2) * 2), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(110, initial_bounds.bottom() + 1,
10, 5), &edge));
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(90,
initial_bounds.bottom() + 1,
10, 5), &edge));
EXPECT_EQ(MAGNETISM_EDGE_BOTTOM, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
}
TEST(MagnetismMatcherTest, ObscureTrailing) {
const int distance = MagnetismMatcher::kMagneticDistance;
const gfx::Rect initial_bounds(20, 10, 150, 160);
MagnetismMatcher matcher(initial_bounds, kAllMagnetismEdges);
MatchedEdge edge;
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - distance - 2,
150,
(distance + 2) * 2,
50), &edge));
EXPECT_FALSE(matcher.AreEdgesObscured());
EXPECT_FALSE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - 4,
160, 3, 20), &edge));
EXPECT_TRUE(matcher.ShouldAttach(
gfx::Rect(initial_bounds.x() - 4,
140, 3, 20), &edge));
EXPECT_EQ(MAGNETISM_EDGE_LEFT, edge.primary_edge);
EXPECT_EQ(SECONDARY_MAGNETISM_EDGE_NONE, edge.secondary_edge);
}
}