This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Windows] Don't crash if GetPointerType is unsupported #35442
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50f217f
[Windows] Don't crash if GetPointerType is unavailable
loic-sharma 259a1e0
License all the things
loic-sharma bab8493
Fix style
loic-sharma 4fafb67
Disallow copy and assign
loic-sharma 374bfdb
Address feedback
loic-sharma fb43e52
Address feedback
loic-sharma 24b6f6a
Address feedback
loic-sharma 8af42f6
Address feedback
loic-sharma cd94fcf
Add test comments
loic-sharma f94a856
Tag crash
loic-sharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_DIRECT_MANIPULATION_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_DIRECT_MANIPULATION_H_ | ||
|
|
||
| #include "flutter/shell/platform/windows/direct_manipulation.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| /// Mock for the |DirectManipulationOwner| base class. | ||
| class MockDirectManipulationOwner : public DirectManipulationOwner { | ||
| public: | ||
| explicit MockDirectManipulationOwner(Window* window) | ||
| : DirectManipulationOwner(window){}; | ||
| virtual ~MockDirectManipulationOwner() = default; | ||
|
|
||
| MOCK_METHOD1(SetContact, void(UINT contact_id)); | ||
|
|
||
| private: | ||
| FML_DISALLOW_COPY_AND_ASSIGN(MockDirectManipulationOwner); | ||
| }; | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_DIRECT_MANIPULATION_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_WINDOWS_PROC_TABLE_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_WINDOWS_PROC_TABLE_H_ | ||
|
|
||
| #include "flutter/shell/platform/windows/windows_proc_table.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| /// Mock for the |WindowsProcTable| base class. | ||
| class MockWindowsProcTable : public WindowsProcTable { | ||
| public: | ||
| MockWindowsProcTable() = default; | ||
| virtual ~MockWindowsProcTable() = default; | ||
|
|
||
| MOCK_METHOD2(GetPointerType, | ||
| BOOL(UINT32 pointer_id, POINTER_INPUT_TYPE* pointer_type)); | ||
|
|
||
| private: | ||
| FML_DISALLOW_COPY_AND_ASSIGN(MockWindowsProcTable); | ||
| }; | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_WINDOWS_PROC_TABLE_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,15 @@ | |
|
|
||
| #include <array> | ||
|
|
||
| #include "flutter/shell/platform/windows/testing/mock_direct_manipulation.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_text_input_manager.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_window.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h" | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using testing::_; | ||
| using testing::Eq; | ||
| using testing::InSequence; | ||
| using testing::Invoke; | ||
| using testing::Return; | ||
|
|
@@ -39,9 +43,11 @@ TEST(MockWindow, VerticalScroll) { | |
| } | ||
|
|
||
| TEST(MockWindow, OnImeCompositionCompose) { | ||
| MockTextInputManager* text_input_manager = new MockTextInputManager(); | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto* text_input_manager = new MockTextInputManager(); | ||
| std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager); | ||
| MockWindow window(std::move(text_input_manager_ptr)); | ||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager_ptr)); | ||
| EXPECT_CALL(*text_input_manager, GetComposingString()) | ||
| .WillRepeatedly( | ||
| Return(std::optional<std::u16string>(std::u16string(u"nihao")))); | ||
|
|
@@ -63,9 +69,11 @@ TEST(MockWindow, OnImeCompositionCompose) { | |
| } | ||
|
|
||
| TEST(MockWindow, OnImeCompositionResult) { | ||
| MockTextInputManager* text_input_manager = new MockTextInputManager(); | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto* text_input_manager = new MockTextInputManager(); | ||
| std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't remember why this is using new and not make_unique() but definitely feel free to clean it up.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I'll do it in a follow-up pull request. I need to merge this one back into the beta release branch, which is already has hairy merge conflicts 😅 |
||
| MockWindow window(std::move(text_input_manager_ptr)); | ||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager_ptr)); | ||
| EXPECT_CALL(*text_input_manager, GetComposingString()) | ||
| .WillRepeatedly( | ||
| Return(std::optional<std::u16string>(std::u16string(u"nihao")))); | ||
|
|
@@ -87,9 +95,11 @@ TEST(MockWindow, OnImeCompositionResult) { | |
| } | ||
|
|
||
| TEST(MockWindow, OnImeCompositionResultAndCompose) { | ||
| MockTextInputManager* text_input_manager = new MockTextInputManager(); | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto* text_input_manager = new MockTextInputManager(); | ||
| std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager); | ||
| MockWindow window(std::move(text_input_manager_ptr)); | ||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager_ptr)); | ||
|
|
||
| // This situation is that Google Japanese Input finished composing "今日" in | ||
| // "今日は" but is still composing "は". | ||
|
|
@@ -123,9 +133,11 @@ TEST(MockWindow, OnImeCompositionResultAndCompose) { | |
| } | ||
|
|
||
| TEST(MockWindow, OnImeCompositionClearChange) { | ||
| MockTextInputManager* text_input_manager = new MockTextInputManager(); | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto* text_input_manager = new MockTextInputManager(); | ||
| std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager); | ||
| MockWindow window(std::move(text_input_manager_ptr)); | ||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager_ptr)); | ||
| EXPECT_CALL(window, OnComposeChange(std::u16string(u""), 0)).Times(1); | ||
| EXPECT_CALL(window, OnComposeCommit()).Times(1); | ||
| ON_CALL(window, OnImeComposition) | ||
|
|
@@ -272,5 +284,81 @@ TEST(MockWindow, Paint) { | |
| window.InjectWindowMessage(WM_PAINT, 0, 0); | ||
| } | ||
|
|
||
| // Verify direct manipulation isn't notified of pointer hit tests. | ||
| TEST(MockWindow, PointerHitTest) { | ||
loic-sharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| UINT32 pointer_id = 123; | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto text_input_manager = std::make_unique<MockTextInputManager>(); | ||
|
|
||
| EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _)) | ||
| .Times(1) | ||
| .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE* type) { | ||
| *type = PT_POINTER; | ||
| return TRUE; | ||
| }); | ||
|
|
||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager)); | ||
|
|
||
| auto direct_manipulation = | ||
| std::make_unique<MockDirectManipulationOwner>(&window); | ||
|
|
||
| EXPECT_CALL(*direct_manipulation, SetContact).Times(0); | ||
|
|
||
| window.SetDirectManipulationOwner(std::move(direct_manipulation)); | ||
| window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0); | ||
| } | ||
|
|
||
| // Verify direct manipulation is notified of touchpad hit tests. | ||
| TEST(MockWindow, TouchPadHitTest) { | ||
| UINT32 pointer_id = 123; | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto text_input_manager = std::make_unique<MockTextInputManager>(); | ||
|
|
||
| EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _)) | ||
| .Times(1) | ||
| .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE* type) { | ||
| *type = PT_TOUCHPAD; | ||
| return TRUE; | ||
| }); | ||
|
|
||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager)); | ||
|
|
||
| auto direct_manipulation = | ||
| std::make_unique<MockDirectManipulationOwner>(&window); | ||
|
|
||
| EXPECT_CALL(*direct_manipulation, SetContact(Eq(pointer_id))).Times(1); | ||
|
|
||
| window.SetDirectManipulationOwner(std::move(direct_manipulation)); | ||
| window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0); | ||
| } | ||
|
|
||
| // Verify direct manipulation isn't notified of unknown hit tests. | ||
| // This can happen if determining the pointer type fails, for example, | ||
| // if GetPointerType is unsupported by the current Windows version. | ||
| // See: https://github.com/flutter/flutter/issues/109412 | ||
| TEST(MockWindow, UnknownPointerTypeSkipsDirectManipulation) { | ||
| UINT32 pointer_id = 123; | ||
| auto windows_proc_table = std::make_unique<MockWindowsProcTable>(); | ||
| auto text_input_manager = std::make_unique<MockTextInputManager>(); | ||
|
|
||
| EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _)) | ||
| .Times(1) | ||
| .WillOnce( | ||
| [](UINT32 pointer_id, POINTER_INPUT_TYPE* type) { return FALSE; }); | ||
loic-sharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| MockWindow window(std::move(windows_proc_table), | ||
| std::move(text_input_manager)); | ||
|
|
||
| auto direct_manipulation = | ||
| std::make_unique<MockDirectManipulationOwner>(&window); | ||
|
|
||
| EXPECT_CALL(*direct_manipulation, SetContact).Times(0); | ||
|
|
||
| window.SetDirectManipulationOwner(std::move(direct_manipulation)); | ||
| window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.