OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 7 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
8 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" | 8 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
11 | 11 |
12 class TestMouseObserver : public PanelMouseWatcherObserver { | 12 class TestMouseObserver : public PanelMouseWatcherObserver { |
13 public: | 13 public: |
14 TestMouseObserver() : mouse_movements_(0) {} | 14 TestMouseObserver() : mouse_movements_(0) {} |
15 // Overridden from PanelMouseWatcherObserver: | 15 // Overridden from PanelMouseWatcherObserver: |
16 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE { | 16 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE { |
17 ++mouse_movements_; | 17 ++mouse_movements_; |
18 } | 18 } |
19 int mouse_movements_; | 19 int mouse_movements_; |
20 }; | 20 }; |
21 | 21 |
22 class PanelMouseWatcherTest : public testing::Test { | 22 class PanelMouseWatcherTest : public testing::Test { |
23 }; | 23 }; |
24 | 24 |
25 TEST_F(PanelMouseWatcherTest, StartStopWatching) { | 25 TEST_F(PanelMouseWatcherTest, StartStopWatching) { |
26 MessageLoop loop(MessageLoop::TYPE_UI); | 26 base::MessageLoop loop(base::MessageLoop::TYPE_UI); |
27 | 27 |
28 scoped_ptr<PanelMouseWatcher> watcher(PanelMouseWatcher::Create()); | 28 scoped_ptr<PanelMouseWatcher> watcher(PanelMouseWatcher::Create()); |
29 EXPECT_FALSE(watcher->IsActive()); | 29 EXPECT_FALSE(watcher->IsActive()); |
30 | 30 |
31 scoped_ptr<TestMouseObserver> user1(new TestMouseObserver()); | 31 scoped_ptr<TestMouseObserver> user1(new TestMouseObserver()); |
32 scoped_ptr<TestMouseObserver> user2(new TestMouseObserver()); | 32 scoped_ptr<TestMouseObserver> user2(new TestMouseObserver()); |
33 | 33 |
34 // No observers. | 34 // No observers. |
35 watcher->NotifyMouseMovement(gfx::Point(42, 101)); | 35 watcher->NotifyMouseMovement(gfx::Point(42, 101)); |
36 EXPECT_EQ(0, user1->mouse_movements_); | 36 EXPECT_EQ(0, user1->mouse_movements_); |
(...skipping 19 matching lines...) Expand all Loading... |
56 // Back to one observer. | 56 // Back to one observer. |
57 watcher->RemoveObserver(user1.get()); | 57 watcher->RemoveObserver(user1.get()); |
58 EXPECT_TRUE(watcher->IsActive()); | 58 EXPECT_TRUE(watcher->IsActive()); |
59 int saved_count = user1->mouse_movements_; | 59 int saved_count = user1->mouse_movements_; |
60 watcher->NotifyMouseMovement(gfx::Point(1, 2)); | 60 watcher->NotifyMouseMovement(gfx::Point(1, 2)); |
61 EXPECT_EQ(saved_count, user1->mouse_movements_); | 61 EXPECT_EQ(saved_count, user1->mouse_movements_); |
62 EXPECT_GE(user2->mouse_movements_, 2); | 62 EXPECT_GE(user2->mouse_movements_, 2); |
63 watcher->RemoveObserver(user2.get()); | 63 watcher->RemoveObserver(user2.get()); |
64 EXPECT_FALSE(watcher->IsActive()); | 64 EXPECT_FALSE(watcher->IsActive()); |
65 } | 65 } |
OLD | NEW |