| Index: components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| diff --git a/components/browser_watcher/window_hang_monitor_win_unittest.cc b/components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| index 0a2f414901c69d00f6c3109fa4be71604271b5c2..2396e08bfa0caadb71a816c96c3c8701f1b8487c 100644
|
| --- a/components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| +++ b/components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| @@ -57,9 +57,9 @@ class HangMonitorThread {
|
| DestroyWatcher();
|
| }
|
|
|
| - // Starts the background thread and the monitor to observe the window named
|
| - // |window_name| in |process|. Blocks until the monitor has been initialized.
|
| - bool Start(base::Process process, const base::string16& window_name) {
|
| + // Starts the background thread and the monitor to observe Chrome message
|
| + // window for |process|. Blocks until the monitor has been initialized.
|
| + bool Start(base::Process process) {
|
| if (!thread_.StartWithOptions(
|
| base::Thread::Options(base::MessageLoop::TYPE_UI, 0))) {
|
| return false;
|
| @@ -67,10 +67,10 @@ class HangMonitorThread {
|
|
|
| base::WaitableEvent complete(false, false);
|
| if (!thread_.task_runner()->PostTask(
|
| - FROM_HERE, base::Bind(&HangMonitorThread::StartupOnThread,
|
| - base::Unretained(this), window_name,
|
| - base::Passed(process.Pass()),
|
| - base::Unretained(&complete)))) {
|
| + FROM_HERE,
|
| + base::Bind(&HangMonitorThread::StartupOnThread,
|
| + base::Unretained(this), base::Passed(std::move(process)),
|
| + base::Unretained(&complete)))) {
|
| return false;
|
| }
|
|
|
| @@ -110,16 +110,14 @@ class HangMonitorThread {
|
| event_received_.Signal();
|
| }
|
|
|
| - // Initializes the WindowHangMonitor to observe the window named |window_name|
|
| - // in |process|. Signals |complete| when done.
|
| - void StartupOnThread(const base::string16& window_name,
|
| - base::Process process,
|
| - base::WaitableEvent* complete) {
|
| + // Initializes the WindowHangMonitor to observe the Chrome message window for
|
| + // |process|. Signals |complete| when done.
|
| + void StartupOnThread(base::Process process, base::WaitableEvent* complete) {
|
| hang_monitor_.reset(new WindowHangMonitor(
|
| base::TimeDelta::FromMilliseconds(100),
|
| base::TimeDelta::FromMilliseconds(100),
|
| base::Bind(&HangMonitorThread::EventCallback, base::Unretained(this))));
|
| - hang_monitor_->Initialize(process.Pass(), window_name);
|
| + hang_monitor_->Initialize(std::move(process));
|
| complete->Signal();
|
| }
|
|
|
| @@ -147,9 +145,6 @@ class WindowHangMonitorTest : public testing::Test {
|
| window_thread_("WindowHangMonitorTest window_thread") {}
|
|
|
| void SetUp() override {
|
| - // Pick a window name unique to this process.
|
| - window_name_ = base::StringPrintf(L"WindowHanMonitorTest-%d",
|
| - base::GetCurrentProcId());
|
| ASSERT_TRUE(window_thread_.StartWithOptions(
|
| base::Thread::Options(base::MessageLoop::TYPE_UI, 0)));
|
| }
|
| @@ -165,8 +160,7 @@ class WindowHangMonitorTest : public testing::Test {
|
| ASSERT_TRUE(window_thread_.task_runner()->PostTask(
|
| FROM_HERE,
|
| base::Bind(&WindowHangMonitorTest::CreateMessageWindowInWorkerThread,
|
| - base::Unretained(this), window_name_, &succeeded,
|
| - &created)));
|
| + base::Unretained(this), &succeeded, &created)));
|
| created.Wait();
|
| ASSERT_TRUE(succeeded);
|
| }
|
| @@ -200,8 +194,6 @@ class WindowHangMonitorTest : public testing::Test {
|
| return message_window_.get();
|
| }
|
|
|
| - const base::string16& window_name() const { return window_name_; }
|
| -
|
| base::Thread* window_thread() { return &window_thread_; }
|
|
|
| private:
|
| @@ -219,14 +211,13 @@ class WindowHangMonitorTest : public testing::Test {
|
| return false; // Pass through to DefWindowProc.
|
| }
|
|
|
| - void CreateMessageWindowInWorkerThread(const base::string16& name,
|
| - bool* success,
|
| + void CreateMessageWindowInWorkerThread(bool* success,
|
| base::WaitableEvent* created) {
|
| message_window_.reset(new base::win::MessageWindow);
|
| *success = message_window_->CreateNamed(
|
| base::Bind(&WindowHangMonitorTest::MessageCallback,
|
| base::Unretained(this)),
|
| - name);
|
| + L"BogusMessageWindowName");
|
| created->Signal();
|
| }
|
|
|
| @@ -238,7 +229,6 @@ class WindowHangMonitorTest : public testing::Test {
|
|
|
| HangMonitorThread monitor_thread_;
|
| scoped_ptr<base::win::MessageWindow> message_window_;
|
| - base::string16 window_name_;
|
| base::Lock ping_lock_;
|
| base::WaitableEvent ping_event_;
|
| size_t pings_;
|
| @@ -262,7 +252,7 @@ TEST_F(WindowHangMonitorTest, NoWindow) {
|
| base::Bind(base::IgnoreResult(&base::Process::Terminate),
|
| base::Unretained(&process), 1, true));
|
|
|
| - monitor_thread().Start(process.Duplicate(), window_name());
|
| + monitor_thread().Start(process.Duplicate());
|
|
|
| ASSERT_FALSE(monitor_thread().TimedWaitForEvent(
|
| base::TimeDelta::FromMilliseconds(150)));
|
| @@ -279,7 +269,7 @@ TEST_F(WindowHangMonitorTest, NoWindow) {
|
| TEST_F(WindowHangMonitorTest, WindowBeforeWatcher) {
|
| CreateMessageWindow();
|
|
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| WaitForPing();
|
|
|
| @@ -290,7 +280,7 @@ TEST_F(WindowHangMonitorTest, WindowBeforeWatcher) {
|
| TEST_F(WindowHangMonitorTest, WindowBeforeDestroy) {
|
| CreateMessageWindow();
|
|
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| WaitForPing();
|
|
|
| @@ -303,7 +293,7 @@ TEST_F(WindowHangMonitorTest, WindowBeforeDestroy) {
|
| }
|
|
|
| TEST_F(WindowHangMonitorTest, NoWindowBeforeDestroy) {
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| ASSERT_FALSE(monitor_thread().TimedWaitForEvent(
|
| base::TimeDelta::FromMilliseconds(150)));
|
| @@ -313,7 +303,7 @@ TEST_F(WindowHangMonitorTest, NoWindowBeforeDestroy) {
|
| }
|
|
|
| TEST_F(WindowHangMonitorTest, WatcherBeforeWindow) {
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| ASSERT_FALSE(monitor_thread().TimedWaitForEvent(
|
| base::TimeDelta::FromMilliseconds(150)));
|
| @@ -329,7 +319,7 @@ TEST_F(WindowHangMonitorTest, WatcherBeforeWindow) {
|
| TEST_F(WindowHangMonitorTest, DetectsWindowDisappearance) {
|
| CreateMessageWindow();
|
|
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| WaitForPing();
|
|
|
| @@ -342,27 +332,10 @@ TEST_F(WindowHangMonitorTest, DetectsWindowDisappearance) {
|
| base::TimeDelta::FromMilliseconds(150)));
|
| }
|
|
|
| -TEST_F(WindowHangMonitorTest, DetectsWindowNameChange) {
|
| - // This test changes the title of the message window as a proxy for what
|
| - // happens if the window handle is reused for a different purpose. The latter
|
| - // is impossible to test in a deterministic fashion.
|
| - CreateMessageWindow();
|
| -
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| -
|
| - ASSERT_FALSE(monitor_thread().TimedWaitForEvent(
|
| - base::TimeDelta::FromMilliseconds(150)));
|
| -
|
| - ASSERT_TRUE(::SetWindowText(message_window()->hwnd(), L"Gonsky"));
|
| -
|
| - ASSERT_EQ(WindowHangMonitor::WINDOW_VANISHED,
|
| - monitor_thread().WaitForEvent());
|
| -}
|
| -
|
| TEST_F(WindowHangMonitorTest, DetectsWindowHang) {
|
| CreateMessageWindow();
|
|
|
| - monitor_thread().Start(base::Process::Current(), window_name());
|
| + monitor_thread().Start(base::Process::Current());
|
|
|
| ASSERT_FALSE(monitor_thread().TimedWaitForEvent(
|
| base::TimeDelta::FromMilliseconds(150)));
|
|
|