Commit 961644ad authored by tapted's avatar tapted Committed by Commit bot

Use PostTask, not performSelector in NativeWidgetMac::Close()

In rare circumstances (more often with ASAN), a call to

[window performSelector:@selector(close) withObject:nil afterDelay:0];

doesn't get run when ViewsTestBase::TearDown() does
  base::RunLoop run_loop;
  run_loop.RunUntilIdle();

ViewsTestBase then destroys other stuff. And, when the posted selector
eventually gets executed, bad stuff happens.

To fix, post a "regular" task, invoking -[NSWindow close]. Use a block
to retain the window receiving the close.

BUG=624648

Review-Url: https://codereview.chromium.org/2115453002
Cr-Commit-Position: refs/heads/master@{#403400}
parent bd59b111
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#include <utility> #include <utility>
#import "base/mac/bind_objc_block.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h" #import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#import "ui/base/cocoa/window_size_constants.h" #import "ui/base/cocoa/window_size_constants.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
...@@ -367,7 +369,13 @@ void NativeWidgetMac::Close() { ...@@ -367,7 +369,13 @@ void NativeWidgetMac::Close() {
// like -performClose:, first remove the window from AppKit's display // like -performClose:, first remove the window from AppKit's display
// list to avoid crashes like http://crbug.com/156101. // list to avoid crashes like http://crbug.com/156101.
[window orderOut:nil]; [window orderOut:nil];
[window performSelector:@selector(close) withObject:nil afterDelay:0];
// Many tests assume that base::RunLoop().RunUntilIdle() is always sufficient
// to execute a close. However, in rare cases, -performSelector:..afterDelay:0
// does not do this. So post a regular task.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindBlock(^{
[window close];
}));
} }
void NativeWidgetMac::CloseNow() { void NativeWidgetMac::CloseNow() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment