summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 00:01:43 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 00:01:43 +0000
commit26934aecea06513fc5e826578646c33fc37d1839 (patch)
tree06d477512da86835c383d14e013354013fca323c /ui
parentd74b1b199c0708aa2df99b9a4a2e39e672c0de55 (diff)
downloadchromium_src-26934aecea06513fc5e826578646c33fc37d1839.zip
chromium_src-26934aecea06513fc5e826578646c33fc37d1839.tar.gz
chromium_src-26934aecea06513fc5e826578646c33fc37d1839.tar.bz2
Replace RootWindow::GetInstance() usage in a bunch of tests with a new root_window() accessor exposed on AuraTestBase.
Also fixes one place in window.cc to use GetRootWindow() rather than RootWindow::GetInstance(). http://crbug.com/112131 TEST=none Review URL: https://chromiumcodereview.appspot.com/9421009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/event_filter_unittest.cc8
-rw-r--r--ui/aura/gestures/gesture_recognizer_unittest.cc92
-rw-r--r--ui/aura/root_window_unittest.cc28
-rw-r--r--ui/aura/test/aura_test_base.cc8
-rw-r--r--ui/aura/test/aura_test_base.h4
-rw-r--r--ui/aura/window.cc4
-rw-r--r--ui/aura/window_unittest.cc95
7 files changed, 120 insertions, 119 deletions
diff --git a/ui/aura/event_filter_unittest.cc b/ui/aura/event_filter_unittest.cc
index d498a93..11e059a 100644
--- a/ui/aura/event_filter_unittest.cc
+++ b/ui/aura/event_filter_unittest.cc
@@ -86,7 +86,7 @@ Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) {
// +- w111 (EF)
// +- w1111 <-- target window
TEST_F(EventFilterTest, Basic) {
- scoped_ptr<Window> w1(CreateWindow(1, RootWindow::GetInstance(), NULL));
+ scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL));
scoped_ptr<Window> w11(CreateWindow(11, w1.get(), NULL));
scoped_ptr<Window> w111(CreateWindow(111, w11.get(), NULL));
TestEventFilterWindowDelegate* d1111 = new TestEventFilterWindowDelegate;
@@ -95,7 +95,7 @@ TEST_F(EventFilterTest, Basic) {
TestEventFilter* root_window_filter = new TestEventFilter;
TestEventFilter* w1_filter = new TestEventFilter;
TestEventFilter* w111_filter = new TestEventFilter;
- RootWindow::GetInstance()->SetEventFilter(root_window_filter);
+ root_window()->SetEventFilter(root_window_filter);
w1->SetEventFilter(w1_filter);
w111->SetEventFilter(w111_filter);
@@ -106,7 +106,7 @@ TEST_F(EventFilterTest, Basic) {
EventGenerator generator(w1111.get());
generator.PressLeftButton();
KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
- RootWindow::GetInstance()->DispatchKeyEvent(&key_event);
+ root_window()->DispatchKeyEvent(&key_event);
// TODO(sadrul): TouchEvent!
EXPECT_EQ(1, root_window_filter->key_event_count());
@@ -132,7 +132,7 @@ TEST_F(EventFilterTest, Basic) {
w1_filter->set_consumes_mouse_events(true);
generator.ReleaseLeftButton();
- RootWindow::GetInstance()->DispatchKeyEvent(&key_event);
+ root_window()->DispatchKeyEvent(&key_event);
// TODO(sadrul): TouchEvent!
EXPECT_EQ(1, root_window_filter->key_event_count());
diff --git a/ui/aura/gestures/gesture_recognizer_unittest.cc b/ui/aura/gestures/gesture_recognizer_unittest.cc
index 6857675..6806add 100644
--- a/ui/aura/gestures/gesture_recognizer_unittest.cc
+++ b/ui/aura/gestures/gesture_recognizer_unittest.cc
@@ -120,7 +120,10 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
public:
- QueueTouchEventDelegate() : window_(NULL) {}
+ explicit QueueTouchEventDelegate(RootWindow* root_window)
+ : window_(NULL),
+ root_window_(root_window) {
+ }
virtual ~QueueTouchEventDelegate() {}
virtual ui::TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE {
@@ -129,13 +132,14 @@ class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
}
void ReceivedAck() {
- RootWindow::GetInstance()->AdvanceQueuedTouchEvent(window_, false);
+ root_window_->AdvanceQueuedTouchEvent(window_, false);
}
void set_window(Window* w) { window_ = w; }
private:
Window* window_;
+ RootWindow* root_window_;
DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate);
};
@@ -199,7 +203,8 @@ class GestureEventSynthDelegate : public TestWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate);
};
-void SendScrollEvents(int x_start,
+void SendScrollEvents(RootWindow* root_window,
+ int x_start,
int y_start,
base::TimeDelta time_start,
int dx,
@@ -216,17 +221,20 @@ void SendScrollEvents(int x_start,
TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 0);
Event::TestApi test_move(&move);
test_move.set_time_stamp(time);
- RootWindow::GetInstance()->DispatchTouchEvent(&move);
+ root_window->DispatchTouchEvent(&move);
x += dx;
y += dy;
time = time + base::TimeDelta::FromMilliseconds(time_step);
}
}
-void SendScrollEvent(int x, int y, GestureEventConsumeDelegate* delegate) {
+void SendScrollEvent(RootWindow* root_window,
+ int x,
+ int y,
+ GestureEventConsumeDelegate* delegate) {
delegate->Reset();
TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&move);
+ root_window->DispatchTouchEvent(&move);
}
const int kBufferedPoints = 10;
@@ -247,7 +255,7 @@ TEST_F(GestureRecognizerTest, GestureEventTap) {
delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -262,7 +270,7 @@ TEST_F(GestureRecognizerTest, GestureEventTap) {
Event::TestApi test_release(&release);
test_release.set_time_stamp(press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
- RootWindow::GetInstance()->DispatchTouchEvent(&release);
+ root_window()->DispatchTouchEvent(&release);
EXPECT_TRUE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -283,7 +291,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -295,7 +303,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
// should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
// The first movement is diagonal, to ensure that we have a free scroll,
// and not a rail scroll.
- SendScrollEvent(130, 230, delegate.get());
+ SendScrollEvent(root_window(), 130, 230, delegate.get());
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -306,7 +314,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
EXPECT_EQ(29, delegate->scroll_y());
// Move some more to generate a few more scroll updates.
- SendScrollEvent(110, 211, delegate.get());
+ SendScrollEvent(root_window(), 110, 211, delegate.get());
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -316,7 +324,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
EXPECT_EQ(-20, delegate->scroll_x());
EXPECT_EQ(-19, delegate->scroll_y());
- SendScrollEvent(140, 215, delegate.get());
+ SendScrollEvent(root_window(), 140, 215, delegate.get());
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -332,7 +340,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
Event::TestApi test_release(&release);
test_release.set_time_stamp(press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
- RootWindow::GetInstance()->DispatchTouchEvent(&release);
+ root_window()->DispatchTouchEvent(&release);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -351,15 +359,15 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
delegate.get(), -1234, bounds, NULL));
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
// Move the touch-point horizontally enough that it is considered a
// horizontal scroll.
- SendScrollEvent(20, 1, delegate.get());
+ SendScrollEvent(root_window(), 20, 1, delegate.get());
EXPECT_EQ(0, delegate->scroll_y());
EXPECT_EQ(20, delegate->scroll_x());
- SendScrollEvent(25, 6, delegate.get());
+ SendScrollEvent(root_window(), 25, 6, delegate.get());
EXPECT_TRUE(delegate->scroll_update());
EXPECT_EQ(5, delegate->scroll_x());
// y shouldn't change, as we're on a horizontal rail.
@@ -367,11 +375,11 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
- SendScrollEvents(1, 1, press.time_stamp(),
+ SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
1, 100, 1, kBufferedPoints, delegate.get());
- SendScrollEvent(0, 0, delegate.get());
- SendScrollEvent(5, 5, delegate.get());
+ SendScrollEvent(root_window(), 0, 0, delegate.get());
+ SendScrollEvent(root_window(), 5, 5, delegate.get());
// The rail should be broken
EXPECT_TRUE(delegate->scroll_update());
@@ -389,15 +397,15 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
delegate.get(), -1234, bounds, NULL));
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
// Move the touch-point vertically enough that it is considered a
// vertical scroll.
- SendScrollEvent(1, 20, delegate.get());
+ SendScrollEvent(root_window(), 1, 20, delegate.get());
EXPECT_EQ(0, delegate->scroll_x());
EXPECT_EQ(20, delegate->scroll_y());
- SendScrollEvent(6, 25, delegate.get());
+ SendScrollEvent(root_window(), 6, 25, delegate.get());
EXPECT_TRUE(delegate->scroll_update());
EXPECT_EQ(5, delegate->scroll_y());
// x shouldn't change, as we're on a vertical rail.
@@ -405,11 +413,11 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
- SendScrollEvents(1, 1, press.time_stamp(),
+ SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
100, 1, 1, kBufferedPoints, delegate.get());
- SendScrollEvent(0, 0, delegate.get());
- SendScrollEvent(5, 5, delegate.get());
+ SendScrollEvent(root_window(), 0, 0, delegate.get());
+ SendScrollEvent(root_window(), 5, 5, delegate.get());
// The rail should be broken
EXPECT_TRUE(delegate->scroll_update());
@@ -429,7 +437,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -444,7 +452,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
Event::TestApi test_release(&release);
test_release.set_time_stamp(press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
- RootWindow::GetInstance()->DispatchTouchEvent(&release);
+ root_window()->DispatchTouchEvent(&release);
EXPECT_TRUE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -459,7 +467,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
Event::TestApi test_release1(&press1);
test_release1.set_time_stamp(release.time_stamp() +
base::TimeDelta::FromMilliseconds(1000));
- RootWindow::GetInstance()->DispatchTouchEvent(&press1);
+ root_window()->DispatchTouchEvent(&press1);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -473,7 +481,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
// and not a rail scroll.
delegate->Reset();
TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&move);
+ root_window()->DispatchTouchEvent(&move);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -486,7 +494,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
// Move some more to generate a few more scroll updates.
delegate->Reset();
TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&move1);
+ root_window()->DispatchTouchEvent(&move1);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -498,7 +506,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
delegate->Reset();
TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&move2);
+ root_window()->DispatchTouchEvent(&move2);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -511,7 +519,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
// Release the touch. This should end the scroll.
delegate->Reset();
TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&release1);
+ root_window()->DispatchTouchEvent(&release1);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -530,7 +538,7 @@ TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) {
delegate->Reset();
GestureEvent tap(ui::ET_GESTURE_TAP, 20, 20, 0, base::Time::Now(), 0, 0);
- RootWindow::GetInstance()->DispatchGestureEvent(&tap);
+ root_window()->DispatchGestureEvent(&tap);
EXPECT_TRUE(delegate->mouse_enter());
EXPECT_TRUE(delegate->mouse_press());
EXPECT_TRUE(delegate->mouse_release());
@@ -539,7 +547,7 @@ TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) {
TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
scoped_ptr<QueueTouchEventDelegate> queued_delegate(
- new QueueTouchEventDelegate());
+ new QueueTouchEventDelegate(root_window()));
const int kWindowWidth = 123;
const int kWindowHeight = 45;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
@@ -551,7 +559,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
// Touch down on the window. This should not generate any gesture event.
queued_delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
EXPECT_FALSE(queued_delegate->double_tap());
@@ -566,7 +574,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
Event::TestApi test_release(&release);
test_release.set_time_stamp(press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
- RootWindow::GetInstance()->DispatchTouchEvent(&release);
+ root_window()->DispatchTouchEvent(&release);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
EXPECT_FALSE(queued_delegate->double_tap());
@@ -582,7 +590,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL));
delegate->Reset();
TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press2);
+ root_window()->DispatchTouchEvent(&press2);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -591,7 +599,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
EXPECT_FALSE(delegate->scroll_end());
TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&release2);
+ root_window()->DispatchTouchEvent(&release2);
// Process the first queued event.
queued_delegate->Reset();
@@ -617,7 +625,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
// window. The second press should still go to the first window.
queued_delegate->Reset();
TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
- RootWindow::GetInstance()->DispatchTouchEvent(&press3);
+ root_window()->DispatchTouchEvent(&press3);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
EXPECT_FALSE(queued_delegate->double_tap());
@@ -628,7 +636,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
queued_delegate->Reset();
delegate->Reset();
TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 1);
- RootWindow::GetInstance()->DispatchTouchEvent(&press4);
+ root_window()->DispatchTouchEvent(&press4);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(delegate->double_tap());
@@ -674,7 +682,7 @@ TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, NULL));
- aura::RootWindow* root = RootWindow::GetInstance();
+ aura::RootWindow* root = root_window();
delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
@@ -774,7 +782,7 @@ TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, NULL));
- aura::RootWindow* root = RootWindow::GetInstance();
+ aura::RootWindow* root = root_window();
delegate->Reset();
TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index 0dbfe3e..da28542 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -77,7 +77,7 @@ TEST_F(RootWindowTest, DispatchMouseEvent) {
gfx::Point point(101, 201);
MouseEvent event1(
ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON);
- RootWindow::GetInstance()->DispatchMouseEvent(&event1);
+ root_window()->DispatchMouseEvent(&event1);
// Event was tested for non-client area for the target window.
EXPECT_EQ(1, delegate1->non_client_count());
@@ -96,8 +96,7 @@ TEST_F(RootWindowTest, DispatchMouseEvent) {
// Check that we correctly track the state of the mouse buttons in response to
// button press and release events.
TEST_F(RootWindowTest, MouseButtonState) {
- RootWindow* root_window = RootWindow::GetInstance();
- EXPECT_FALSE(root_window->IsMouseButtonDown());
+ EXPECT_FALSE(root_window()->IsMouseButtonDown());
gfx::Point location;
scoped_ptr<MouseEvent> event;
@@ -108,8 +107,8 @@ TEST_F(RootWindowTest, MouseButtonState) {
location,
location,
ui::EF_LEFT_MOUSE_BUTTON));
- root_window->DispatchMouseEvent(event.get());
- EXPECT_TRUE(root_window->IsMouseButtonDown());
+ root_window()->DispatchMouseEvent(event.get());
+ EXPECT_TRUE(root_window()->IsMouseButtonDown());
// Additionally press the right.
event.reset(new MouseEvent(
@@ -117,8 +116,8 @@ TEST_F(RootWindowTest, MouseButtonState) {
location,
location,
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
- root_window->DispatchMouseEvent(event.get());
- EXPECT_TRUE(root_window->IsMouseButtonDown());
+ root_window()->DispatchMouseEvent(event.get());
+ EXPECT_TRUE(root_window()->IsMouseButtonDown());
// Release the left button.
event.reset(new MouseEvent(
@@ -126,8 +125,8 @@ TEST_F(RootWindowTest, MouseButtonState) {
location,
location,
ui::EF_RIGHT_MOUSE_BUTTON));
- root_window->DispatchMouseEvent(event.get());
- EXPECT_TRUE(root_window->IsMouseButtonDown());
+ root_window()->DispatchMouseEvent(event.get());
+ EXPECT_TRUE(root_window()->IsMouseButtonDown());
// Release the right button. We should ignore the Shift-is-down flag.
event.reset(new MouseEvent(
@@ -135,8 +134,8 @@ TEST_F(RootWindowTest, MouseButtonState) {
location,
location,
ui::EF_SHIFT_DOWN));
- root_window->DispatchMouseEvent(event.get());
- EXPECT_FALSE(root_window->IsMouseButtonDown());
+ root_window()->DispatchMouseEvent(event.get());
+ EXPECT_FALSE(root_window()->IsMouseButtonDown());
// Press the middle button.
event.reset(new MouseEvent(
@@ -144,12 +143,11 @@ TEST_F(RootWindowTest, MouseButtonState) {
location,
location,
ui::EF_MIDDLE_MOUSE_BUTTON));
- root_window->DispatchMouseEvent(event.get());
- EXPECT_TRUE(root_window->IsMouseButtonDown());
+ root_window()->DispatchMouseEvent(event.get());
+ EXPECT_TRUE(root_window()->IsMouseButtonDown());
}
TEST_F(RootWindowTest, TranslatedEvent) {
- RootWindow* root_window = RootWindow::GetInstance();
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
gfx::Rect(50, 50, 100, 100), NULL));
@@ -160,7 +158,7 @@ TEST_F(RootWindowTest, TranslatedEvent) {
EXPECT_EQ("100,100", root.root_location().ToString());
MouseEvent translated_event(
- root, root_window, w1.get(),
+ root, root_window(), w1.get(),
ui::ET_MOUSE_ENTERED, root.flags());
EXPECT_EQ("50,50", translated_event.location().ToString());
EXPECT_EQ("100,100", translated_event.root_location().ToString());
diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc
index 57316c7..576fac6 100644
--- a/ui/aura/test/aura_test_base.cc
+++ b/ui/aura/test/aura_test_base.cc
@@ -10,14 +10,14 @@
namespace aura {
namespace test {
-AuraTestBase::AuraTestBase() {
- helper_.InitRootWindow(RootWindow::GetInstance());
+AuraTestBase::AuraTestBase() : root_window_(RootWindow::GetInstance()) {
+ helper_.InitRootWindow(root_window_);
}
AuraTestBase::~AuraTestBase() {
// Flush the message loop because we have pending release tasks
// and these tasks if un-executed would upset Valgrind.
- helper_.RunAllPendingInMessageLoop(RootWindow::GetInstance());
+ helper_.RunAllPendingInMessageLoop(root_window_);
// Ensure that we don't use the previously-allocated static RootWindow object
// later -- on Linux, it holds a reference to our message loop's X connection.
@@ -35,7 +35,7 @@ void AuraTestBase::TearDown() {
}
void AuraTestBase::RunAllPendingInMessageLoop() {
- helper_.RunAllPendingInMessageLoop(RootWindow::GetInstance());
+ helper_.RunAllPendingInMessageLoop(root_window_);
}
} // namespace test
diff --git a/ui/aura/test/aura_test_base.h b/ui/aura/test/aura_test_base.h
index a35f777..08b1f84 100644
--- a/ui/aura/test/aura_test_base.h
+++ b/ui/aura/test/aura_test_base.h
@@ -12,6 +12,7 @@
#include "ui/aura/test/aura_test_helper.h"
namespace aura {
+class RootWindow;
namespace test {
// A base class for aura unit tests.
@@ -28,8 +29,11 @@ class AuraTestBase : public testing::Test {
protected:
void RunAllPendingInMessageLoop();
+ RootWindow* root_window() { return root_window_; }
+
private:
AuraTestHelper helper_;
+ RootWindow* root_window_;
DISALLOW_COPY_AND_ASSIGN(AuraTestBase);
};
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index b95ddcb..868d329 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -173,9 +173,7 @@ bool Window::IsVisible() const {
gfx::Rect Window::GetScreenBounds() const {
gfx::Point origin = bounds().origin();
- Window::ConvertPointToWindow(parent_,
- aura::RootWindow::GetInstance(),
- &origin);
+ Window::ConvertPointToWindow(parent_, GetRootWindow(), &origin);
return gfx::Rect(origin, bounds().size());
}
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 29e3364..f5aa649 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -301,7 +301,7 @@ TEST_F(WindowTest, GetEventHandlerForPoint) {
scoped_ptr<Window> w13(
CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get()));
- Window* root = RootWindow::GetInstance();
+ Window* root = root_window();
w1->parent()->SetBounds(gfx::Rect(500, 500));
EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5)));
EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11)));
@@ -314,7 +314,7 @@ TEST_F(WindowTest, GetEventHandlerForPoint) {
}
TEST_F(WindowTest, GetTopWindowContainingPoint) {
- Window* root = RootWindow::GetInstance();
+ Window* root = root_window();
root->SetBounds(gfx::Rect(0, 0, 300, 300));
scoped_ptr<Window> w1(
@@ -353,15 +353,14 @@ TEST_F(WindowTest, GetToplevelWindow) {
const gfx::Rect kBounds(0, 0, 10, 10);
TestWindowDelegate delegate;
- Window* root = aura::RootWindow::GetInstance();
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, root));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> w11(
CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get()));
scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get()));
scoped_ptr<Window> w1111(
CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get()));
- EXPECT_TRUE(root->GetToplevelWindow() == NULL);
+ EXPECT_TRUE(root_window()->GetToplevelWindow() == NULL);
EXPECT_TRUE(w1->GetToplevelWindow() == NULL);
EXPECT_EQ(w11.get(), w11->GetToplevelWindow());
EXPECT_EQ(w11.get(), w111->GetToplevelWindow());
@@ -485,7 +484,6 @@ TEST_F(WindowTest, StackChildAbove) {
// Various capture assertions.
TEST_F(WindowTest, CaptureTests) {
- aura::RootWindow* root_window = aura::RootWindow::GetInstance();
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
@@ -507,7 +505,7 @@ TEST_F(WindowTest, CaptureTests) {
delegate.ResetCounts();
TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0);
- root_window->DispatchTouchEvent(&touchev);
+ root_window()->DispatchTouchEvent(&touchev);
EXPECT_EQ(1, delegate.touch_event_count());
delegate.ResetCounts();
@@ -520,16 +518,16 @@ TEST_F(WindowTest, CaptureTests) {
generator.PressLeftButton();
EXPECT_EQ(1, delegate.mouse_event_count());
- root_window->DispatchTouchEvent(&touchev);
+ root_window()->DispatchTouchEvent(&touchev);
EXPECT_EQ(0, delegate.touch_event_count());
// Removing the capture window from parent should reset the capture window
// in the root window.
window->SetCapture();
- EXPECT_EQ(window.get(), root_window->capture_window());
+ EXPECT_EQ(window.get(), root_window()->capture_window());
window->parent()->RemoveChild(window.get());
EXPECT_FALSE(window->HasCapture());
- EXPECT_EQ(NULL, root_window->capture_window());
+ EXPECT_EQ(NULL, root_window()->capture_window());
}
// Changes capture while capture is already ongoing.
@@ -568,7 +566,6 @@ TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
// Verifies capture is reset when a window is destroyed.
TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
- RootWindow* root_window = RootWindow::GetInstance();
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
@@ -582,8 +579,8 @@ TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
window.reset();
// Make sure the root window doesn't reference the window anymore.
- EXPECT_EQ(NULL, root_window->mouse_pressed_handler());
- EXPECT_EQ(NULL, root_window->capture_window());
+ EXPECT_EQ(NULL, root_window()->mouse_pressed_handler());
+ EXPECT_EQ(NULL, root_window()->capture_window());
}
TEST_F(WindowTest, GetScreenBounds) {
@@ -835,8 +832,7 @@ TEST_F(WindowTest, IgnoreEventsTest) {
// Tests transformation on the root window.
TEST_F(WindowTest, Transform) {
- RootWindow* root_window = RootWindow::GetInstance();
- gfx::Size size = root_window->GetHostSize();
+ gfx::Size size = root_window()->GetHostSize();
EXPECT_EQ(gfx::Rect(size),
gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()));
@@ -844,20 +840,20 @@ TEST_F(WindowTest, Transform) {
ui::Transform transform;
transform.SetRotate(90.0f);
transform.ConcatTranslate(size.height(), 0);
- root_window->SetTransform(transform);
+ root_window()->SetTransform(transform);
// The size should be the transformed size.
gfx::Size transformed_size(size.height(), size.width());
- EXPECT_EQ(transformed_size.ToString(), root_window->GetHostSize().ToString());
+ EXPECT_EQ(transformed_size.ToString(),
+ root_window()->GetHostSize().ToString());
EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
- root_window->bounds().ToString());
+ root_window()->bounds().ToString());
EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()).ToString());
}
TEST_F(WindowTest, TransformGesture) {
- RootWindow* root_window = RootWindow::GetInstance();
- gfx::Size size = root_window->GetHostSize();
+ gfx::Size size = root_window()->GetHostSize();
scoped_ptr<GestureTrackPositionDelegate> delegate(
new GestureTrackPositionDelegate);
@@ -868,11 +864,11 @@ TEST_F(WindowTest, TransformGesture) {
ui::Transform transform;
transform.SetRotate(90.0f);
transform.ConcatTranslate(size.height(), 0);
- root_window->SetTransform(transform);
+ root_window()->SetTransform(transform);
TouchEvent press(ui::ET_TOUCH_PRESSED,
gfx::Point(size.height() - 10, 10), 0);
- root_window->DispatchTouchEvent(&press);
+ root_window()->DispatchTouchEvent(&press);
EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString());
}
@@ -1238,24 +1234,20 @@ TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) {
scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL));
// This brings window1 (and its layer) to the front.
- RootWindow::GetInstance()->StackChildAbove(window1.get(), window2.get());
- EXPECT_EQ(RootWindow::GetInstance()->children().front(), window2.get());
- EXPECT_EQ(RootWindow::GetInstance()->children().back(), window1.get());
- EXPECT_EQ(RootWindow::GetInstance()->layer()->children().front(),
- window2->layer());
- EXPECT_EQ(RootWindow::GetInstance()->layer()->children().back(),
- window1->layer());
+ root_window()->StackChildAbove(window1.get(), window2.get());
+ EXPECT_EQ(root_window()->children().front(), window2.get());
+ EXPECT_EQ(root_window()->children().back(), window1.get());
+ EXPECT_EQ(root_window()->layer()->children().front(), window2->layer());
+ EXPECT_EQ(root_window()->layer()->children().back(), window1->layer());
// Since window1 does not have a delegate, window2 should not move in
// front of it, nor should its layer.
window1->layer()->set_delegate(NULL);
- RootWindow::GetInstance()->StackChildAbove(window2.get(), window1.get());
- EXPECT_EQ(RootWindow::GetInstance()->children().front(), window2.get());
- EXPECT_EQ(RootWindow::GetInstance()->children().back(), window1.get());
- EXPECT_EQ(RootWindow::GetInstance()->layer()->children().front(),
- window2->layer());
- EXPECT_EQ(RootWindow::GetInstance()->layer()->children().back(),
- window1->layer());
+ root_window()->StackChildAbove(window2.get(), window1.get());
+ EXPECT_EQ(root_window()->children().front(), window2.get());
+ EXPECT_EQ(root_window()->children().back(), window1.get());
+ EXPECT_EQ(root_window()->layer()->children().front(), window2->layer());
+ EXPECT_EQ(root_window()->layer()->children().back(), window1->layer());
}
TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) {
@@ -1274,7 +1266,7 @@ TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) {
// Move window1 to the front. All transients should move with it, and their
// order should be preserved.
- RootWindow* root = RootWindow::GetInstance();
+ RootWindow* root = root_window();
root->StackChildAtTop(window1.get());
ASSERT_EQ(6u, root->children().size());
@@ -1334,15 +1326,14 @@ TEST_F(WindowTest, VisibilityClientIsVisible) {
// Tests mouse events on window change.
TEST_F(WindowTest, MouseEventsOnWindowChange) {
- RootWindow* root_window = RootWindow::GetInstance();
- gfx::Size size = root_window->GetHostSize();
+ gfx::Size size = root_window()->GetHostSize();
EventGenerator generator;
generator.MoveMouseTo(50, 50);
MouseTrackingDelegate d1;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1,
- gfx::Rect(0, 0, 100, 100), root_window));
+ gfx::Rect(0, 0, 100, 100), root_window()));
RunAllPendingInMessageLoop();
// The format of result is "Enter/Mouse/Leave".
EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset());
@@ -1412,8 +1403,9 @@ TEST_F(WindowTest, MouseEventsOnWindowChange) {
class StackingMadrigalLayoutManager : public LayoutManager {
public:
- StackingMadrigalLayoutManager() {
- RootWindow::GetInstance()->SetLayoutManager(this);
+ explicit StackingMadrigalLayoutManager(RootWindow* root_window)
+ : root_window_(root_window) {
+ root_window_->SetLayoutManager(this);
}
virtual ~StackingMadrigalLayoutManager() {
}
@@ -1425,15 +1417,14 @@ class StackingMadrigalLayoutManager : public LayoutManager {
virtual void OnWillRemoveWindowFromLayout(Window* child) OVERRIDE {}
virtual void OnChildWindowVisibilityChanged(Window* child,
bool visible) OVERRIDE {
- Window::Windows::const_iterator it =
- RootWindow::GetInstance()->children().begin();
+ Window::Windows::const_iterator it = root_window_->children().begin();
Window* last_window = NULL;
- for (; it != RootWindow::GetInstance()->children().end(); ++it) {
+ for (; it != root_window_->children().end(); ++it) {
if (*it == child && last_window) {
if (!visible)
- RootWindow::GetInstance()->StackChildAbove(last_window, *it);
+ root_window_->StackChildAbove(last_window, *it);
else
- RootWindow::GetInstance()->StackChildAbove(*it, last_window);
+ root_window_->StackChildAbove(*it, last_window);
break;
}
last_window = *it;
@@ -1444,6 +1435,8 @@ class StackingMadrigalLayoutManager : public LayoutManager {
SetChildBoundsDirect(child, requested_bounds);
}
+ RootWindow* root_window_;
+
DISALLOW_COPY_AND_ASSIGN(StackingMadrigalLayoutManager);
};
@@ -1495,7 +1488,7 @@ class StackingMadrigalVisibilityClient : public client::VisibilityClient {
// child. A fix is made to Window::StackAbove to prevent this, and this test
// verifies this fix.
TEST_F(WindowTest, StackingMadrigal) {
- new StackingMadrigalLayoutManager;
+ new StackingMadrigalLayoutManager(root_window());
StackingMadrigalVisibilityClient visibility_client;
scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
@@ -1525,7 +1518,7 @@ TEST_F(WindowTest, StackingMadrigal) {
// resulting in window12's layer being below window1's layer (though the
// windows themselves would still be correctly stacked, so events would pass
// through.)
- RootWindow::GetInstance()->StackChildAbove(window1.get(), window12.get());
+ root_window()->StackChildAbove(window1.get(), window12.get());
// Both window12 and its layer should be stacked above window1.
EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get()));
@@ -1542,7 +1535,7 @@ TEST_F(WindowTest, StackOverClosingTransient) {
scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get()));
// Both windows and layers are stacked in creation order.
- RootWindow* root = RootWindow::GetInstance();
+ RootWindow* root = root_window();
ASSERT_EQ(4u, root->children().size());
EXPECT_EQ(root->children()[0], window1.get());
EXPECT_EQ(root->children()[1], transient1.get());
@@ -1555,7 +1548,7 @@ TEST_F(WindowTest, StackOverClosingTransient) {
EXPECT_EQ(root->layer()->children()[3], transient2->layer());
// This brings window1 and its transient to the front.
- //root_window->StackChildAbove(window1.get(), window2.get());
+ // root_window()->StackChildAbove(window1.get(), window2.get());
root->StackChildAtTop(window1.get());
EXPECT_EQ(root->children()[0], window2.get());