| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <gflags/gflags.h> | 5 #include <gflags/gflags.h> |
| 6 #include <gtest/gtest.h> | 6 #include <gtest/gtest.h> |
| 7 | 7 |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "window_manager/callback.h" | 10 #include "window_manager/callback.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 MockXConnection xconn; | 35 MockXConnection xconn; |
| 36 xconn.SetPointerPosition(Point(0, 0)); | 36 xconn.SetPointerPosition(Point(0, 0)); |
| 37 | 37 |
| 38 // Watch for the pointer moving into a 20x30 rectangle at (50, 100). | 38 // Watch for the pointer moving into a 20x30 rectangle at (50, 100). |
| 39 TestCallbackCounter counter; | 39 TestCallbackCounter counter; |
| 40 scoped_ptr<PointerPositionWatcher> watcher( | 40 scoped_ptr<PointerPositionWatcher> watcher( |
| 41 new PointerPositionWatcher( | 41 new PointerPositionWatcher( |
| 42 &event_loop, | 42 &event_loop, |
| 43 &xconn, | 43 &xconn, |
| 44 NewPermanentCallback(&counter, &TestCallbackCounter::Increment), | 44 NewPermanentCallback(&counter, &TestCallbackCounter::Increment), |
| 45 true, // watch_for_entering_target | 45 true, // watch_for_entering_target |
| 46 50, 100, // x, y | 46 Rect(50, 100, 20, 30))); |
| 47 20, 30)); // width, height | |
| 48 EXPECT_GE(watcher->timeout_id(), 0); | 47 EXPECT_GE(watcher->timeout_id(), 0); |
| 49 | 48 |
| 50 // Check that the callback doesn't get run and the timer stays active as | 49 // Check that the callback doesn't get run and the timer stays active as |
| 51 // long as the pointer is outside of the rectangle. | 50 // long as the pointer is outside of the rectangle. |
| 52 watcher->TriggerTimeout(); | 51 watcher->TriggerTimeout(); |
| 53 EXPECT_EQ(0, counter.num_calls()); | 52 EXPECT_EQ(0, counter.num_calls()); |
| 54 EXPECT_GE(watcher->timeout_id(), 0); | 53 EXPECT_GE(watcher->timeout_id(), 0); |
| 55 | 54 |
| 56 xconn.SetPointerPosition(Point(49, 105)); | 55 xconn.SetPointerPosition(Point(49, 105)); |
| 57 watcher->TriggerTimeout(); | 56 watcher->TriggerTimeout(); |
| 58 EXPECT_EQ(0, counter.num_calls()); | 57 EXPECT_EQ(0, counter.num_calls()); |
| 59 EXPECT_GE(watcher->timeout_id(), 0); | 58 EXPECT_GE(watcher->timeout_id(), 0); |
| 60 | 59 |
| 61 // As soon as the pointer moves into the rectangle, the callback should | 60 // As soon as the pointer moves into the rectangle, the callback should |
| 62 // be run and the timer should be destroyed. | 61 // be run and the timer should be destroyed. |
| 63 xconn.SetPointerPosition(Point(50, 105)); | 62 xconn.SetPointerPosition(Point(50, 105)); |
| 64 watcher->TriggerTimeout(); | 63 watcher->TriggerTimeout(); |
| 65 EXPECT_EQ(1, counter.num_calls()); | 64 EXPECT_EQ(1, counter.num_calls()); |
| 66 EXPECT_EQ(-1, watcher->timeout_id()); | 65 EXPECT_EQ(-1, watcher->timeout_id()); |
| 67 | 66 |
| 68 // Now create a new watcher that waits for the pointer to move *outside* | 67 // Now create a new watcher that waits for the pointer to move *outside* |
| 69 // of the same region. | 68 // of the same region. |
| 70 watcher.reset( | 69 watcher.reset( |
| 71 new PointerPositionWatcher( | 70 new PointerPositionWatcher( |
| 72 &event_loop, | 71 &event_loop, |
| 73 &xconn, | 72 &xconn, |
| 74 NewPermanentCallback(&counter, &TestCallbackCounter::Increment), | 73 NewPermanentCallback(&counter, &TestCallbackCounter::Increment), |
| 75 false, // watch_for_entering_target=false | 74 false, // watch_for_entering_target=false |
| 76 50, 100, // x, y | 75 Rect(50, 100, 20, 30))); |
| 77 20, 30)); // width, height | |
| 78 EXPECT_GE(watcher->timeout_id(), 0); | 76 EXPECT_GE(watcher->timeout_id(), 0); |
| 79 counter.Reset(); | 77 counter.Reset(); |
| 80 | 78 |
| 81 watcher->TriggerTimeout(); | 79 watcher->TriggerTimeout(); |
| 82 EXPECT_EQ(0, counter.num_calls()); | 80 EXPECT_EQ(0, counter.num_calls()); |
| 83 EXPECT_GE(watcher->timeout_id(), 0); | 81 EXPECT_GE(watcher->timeout_id(), 0); |
| 84 | 82 |
| 85 xconn.SetPointerPosition(Point(69, 129)); | 83 xconn.SetPointerPosition(Point(69, 129)); |
| 86 watcher->TriggerTimeout(); | 84 watcher->TriggerTimeout(); |
| 87 EXPECT_EQ(0, counter.num_calls()); | 85 EXPECT_EQ(0, counter.num_calls()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 WatcherContainer container; | 101 WatcherContainer container; |
| 104 container.set_watcher( | 102 container.set_watcher( |
| 105 new PointerPositionWatcher( | 103 new PointerPositionWatcher( |
| 106 &event_loop, | 104 &event_loop, |
| 107 &xconn, | 105 &xconn, |
| 108 NewPermanentCallback( | 106 NewPermanentCallback( |
| 109 &container, | 107 &container, |
| 110 &WatcherContainer::set_watcher, | 108 &WatcherContainer::set_watcher, |
| 111 static_cast<PointerPositionWatcher*>(NULL)), | 109 static_cast<PointerPositionWatcher*>(NULL)), |
| 112 true, // watch_for_entering_target | 110 true, // watch_for_entering_target |
| 113 0, 0, // x, y | 111 Rect(0, 0, 10, 10))); |
| 114 10, 10)); // width, height | |
| 115 | 112 |
| 116 container.watcher->TriggerTimeout(); | 113 container.watcher->TriggerTimeout(); |
| 117 EXPECT_TRUE(container.watcher.get() == NULL); | 114 EXPECT_TRUE(container.watcher.get() == NULL); |
| 118 } | 115 } |
| 119 | 116 |
| 120 } // namespace window_manager | 117 } // namespace window_manager |
| 121 | 118 |
| 122 int main(int argc, char** argv) { | 119 int main(int argc, char** argv) { |
| 123 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); | 120 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); |
| 124 } | 121 } |
| OLD | NEW |