<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/scoped_ptr.h"
#include "base/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:
  // Overridden from PanelMouseWatcherObserver:
  virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE {
    ++mouse_movements_;
  }
  int mouse_movements_;
};

class PanelMouseWatcherTest : public testing::Test {
};

TEST_F(PanelMouseWatcherTest, StartStopWatching) {
  MessageLoop loop(MessageLoop::TYPE_UI);

  scoped_ptr<PanelMouseWatcher> watcher(PanelMouseWatcher::Create());
  EXPECT_FALSE(watcher->IsActive());

  scoped_ptr<TestMouseObserver> user1(new TestMouseObserver());
  scoped_ptr<TestMouseObserver> user2(new TestMouseObserver());

  // No observers.
  watcher->NotifyMouseMovement(gfx::Point(42, 101));
  EXPECT_EQ(0, user1->mouse_movements_);
  EXPECT_EQ(0, user2->mouse_movements_);

  // Only one mouse observer.
  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());

  // More than one mouse observer.
  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);

  // Back to one observer.
  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());
}
<commit_msg>Fix an uninitialized memory read in PanelMouseWatcherTest.StartStopWatching.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/scoped_ptr.h"
#include "base/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) {}
  // Overridden from PanelMouseWatcherObserver:
  virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE {
    ++mouse_movements_;
  }
  int mouse_movements_;
};

class PanelMouseWatcherTest : public testing::Test {
};

TEST_F(PanelMouseWatcherTest, StartStopWatching) {
  MessageLoop loop(MessageLoop::TYPE_UI);

  scoped_ptr<PanelMouseWatcher> watcher(PanelMouseWatcher::Create());
  EXPECT_FALSE(watcher->IsActive());

  scoped_ptr<TestMouseObserver> user1(new TestMouseObserver());
  scoped_ptr<TestMouseObserver> user2(new TestMouseObserver());

  // No observers.
  watcher->NotifyMouseMovement(gfx::Point(42, 101));
  EXPECT_EQ(0, user1->mouse_movements_);
  EXPECT_EQ(0, user2->mouse_movements_);

  // Only one mouse observer.
  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());

  // More than one mouse observer.
  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);

  // Back to one observer.
  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());
}

{'fraction_non_alphanumeric': 0.13748350197976242, 'fraction_numerical': 0.02001759788825341, 'mean_word_length': 6.093603744149766, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6885624', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1540, 'n_words': 264}