| 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 f884e09025cd1e04669a5140198ae462190d5a4f..6383eb86383c10896f7d7bedb260fa6769fa7154 100644
|
| --- a/components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| +++ b/components/browser_watcher/window_hang_monitor_win_unittest.cc
|
| @@ -55,9 +55,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;
|
| @@ -65,10 +65,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(process.Pass()),
|
| + base::Unretained(&complete)))) {
|
| return false;
|
| }
|
|
|
| @@ -108,16 +108,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(process.Pass());
|
| complete->Signal();
|
| }
|
|
|
| @@ -145,9 +143,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)));
|
| }
|
| @@ -163,8 +158,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);
|
| }
|
| @@ -198,8 +192,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:
|
| @@ -217,14 +209,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"MessageWindowName");
|
| created->Signal();
|
| }
|
|
|
| @@ -236,7 +227,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_;
|
| @@ -260,7 +250,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)));
|
| @@ -277,7 +267,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();
|
|
|
| @@ -288,7 +278,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();
|
|
|
| @@ -301,7 +291,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)));
|
| @@ -311,7 +301,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)));
|
| @@ -327,7 +317,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();
|
|
|
| @@ -340,27 +330,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)));
|
|
|