This source file includes following definitions.
- OnMouseMove
- TEST_F
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/point.h"
class TestMouseObserver : public PanelMouseWatcherObserver {
public:
TestMouseObserver() : mouse_movements_(0) {}
virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE {
++mouse_movements_;
}
int mouse_movements_;
};
class PanelMouseWatcherTest : public testing::Test {
};
TEST_F(PanelMouseWatcherTest, StartStopWatching) {
base::MessageLoopForUI loop;
scoped_ptr<PanelMouseWatcher> watcher(PanelMouseWatcher::Create());
EXPECT_FALSE(watcher->IsActive());
scoped_ptr<TestMouseObserver> user1(new TestMouseObserver());
scoped_ptr<TestMouseObserver> user2(new TestMouseObserver());
watcher->NotifyMouseMovement(gfx::Point(42, 101));
EXPECT_EQ(0, user1->mouse_movements_);
EXPECT_EQ(0, user2->mouse_movements_);
watcher->AddObserver(user1.get());
EXPECT_TRUE(watcher->IsActive());
watcher->NotifyMouseMovement(gfx::Point(42, 101));
EXPECT_GE(user1->mouse_movements_, 1);
EXPECT_EQ(0, user2->mouse_movements_);
watcher->RemoveObserver(user1.get());
EXPECT_FALSE(watcher->IsActive());
watcher->AddObserver(user1.get());
EXPECT_TRUE(watcher->IsActive());
watcher->AddObserver(user2.get());
watcher->NotifyMouseMovement(gfx::Point(101, 42));
EXPECT_GE(user1->mouse_movements_, 2);
EXPECT_GE(user2->mouse_movements_, 1);
watcher->RemoveObserver(user1.get());
EXPECT_TRUE(watcher->IsActive());
int saved_count = user1->mouse_movements_;
watcher->NotifyMouseMovement(gfx::Point(1, 2));
EXPECT_EQ(saved_count, user1->mouse_movements_);
EXPECT_GE(user2->mouse_movements_, 2);
watcher->RemoveObserver(user2.get());
EXPECT_FALSE(watcher->IsActive());
}