Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 1636183003: Fix crash in the HWNDMessageHandler::HandleMouseInputForCaption function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index 41bbe8198d7b40b9136deaf3ae068bb795c3be87..57235012eee16f786ca0c6d8b49c0f1c7aca4366 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -3213,7 +3213,8 @@ TEST_F(WidgetTest, CharMessagesAsKeyboardMessagesDoesNotCrash) {
class SubclassWindowHelper {
public:
explicit SubclassWindowHelper(HWND window)
- : window_(window) {
+ : window_(window),
+ message_to_destroy_on_(0) {
EXPECT_EQ(instance_, nullptr);
instance_ = this;
EXPECT_TRUE(Subclass());
@@ -3233,6 +3234,10 @@ class SubclassWindowHelper {
messages_.clear();
}
+ void set_message_to_destroy_on(unsigned int message) {
+ message_to_destroy_on_ = message;
+ }
+
private:
bool Subclass() {
old_proc_ = reinterpret_cast<WNDPROC>(
@@ -3258,14 +3263,20 @@ class SubclassWindowHelper {
// Keep track of messags received for this window.
instance_->messages_.insert(message);
- return ::CallWindowProc(instance_->old_proc_, window, message, w_param,
- l_param);
+ LRESULT ret = ::CallWindowProc(instance_->old_proc_, window, message,
+ w_param, l_param);
+ if (message == instance_->message_to_destroy_on_) {
+ instance_->Unsubclass();
+ ::DestroyWindow(window);
+ }
+ return ret;
}
WNDPROC old_proc_;
HWND window_;
static SubclassWindowHelper* instance_;
std::set<unsigned int> messages_;
+ unsigned int message_to_destroy_on_;
DISALLOW_COPY_AND_ASSIGN(SubclassWindowHelper);
};
@@ -3347,6 +3358,38 @@ TEST_F(WidgetTest, SysCommandMoveOnNCLButtonDownOnCaptionAndMoveTest) {
widget.CloseNow();
}
+
+// This test validates that destroying the window in the context of the
+// WM_SYSCOMMAND message with SC_MOVE does not crash.
+TEST_F(WidgetTest, DestroyInSysCommandNCLButtonDownOnCaption) {
+ Widget widget;
+ Widget::InitParams params =
+ CreateParams(Widget::InitParams::TYPE_WINDOW);
+ params.native_widget = new PlatformDesktopNativeWidget(&widget);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget.Init(params);
+ widget.SetBounds(gfx::Rect(0, 0, 200, 200));
+ widget.Show();
+ ::SetCursorPos(500, 500);
+
+ HWND window = widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget();
+
+ SubclassWindowHelper subclass_helper(window);
+
+ // Destroying the window in the context of the WM_SYSCOMMAND message
+ // should not crash.
+ subclass_helper.set_message_to_destroy_on(WM_SYSCOMMAND);
+
+ ::PostMessage(window, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(100, 100));
+ ::PostMessage(window, WM_NCMOUSEMOVE, HTCAPTION, MAKELPARAM(110, 110));
+ RunPendingMessages();
+
+ EXPECT_TRUE(subclass_helper.received_message(WM_NCLBUTTONDOWN));
+ EXPECT_TRUE(subclass_helper.received_message(WM_SYSCOMMAND));
+
+ widget.CloseNow();
+}
+
#endif
// Test that SetAlwaysOnTop and IsAlwaysOnTop are consistent.
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698