This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Couldn't load subscription status.
- Fork 6k
hasStrings on Windows #27749
Merged
fluttergithubbot
merged 20 commits into
flutter:master
from
justinmc:has-strings-windows
Aug 25, 2021
Merged
hasStrings on Windows #27749
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
70a0f5e
Working hasStrings on windows
justinmc c9d633a
Analyzer
justinmc 39990f3
Blind attempt at tests since I'm unable to run them right now
justinmc c3060cd
Analyzer fix
justinmc 83af633
Fix windows newlines
justinmc b7c562e
Analyzer fix
justinmc 64c5751
Add unittests file to build, it must have been missed accidentally
justinmc 85528fd
Tests compiling but not passsing
justinmc a640fcc
Analyzer fixes
justinmc aa4dc9e
Merge branch 'master' into has-strings-windows
justinmc 61e2fa5
Old tests pass thanks to work in fix-platform-handler-unittests branch
justinmc 5a35ed2
First new test passes too
justinmc 6cef1f2
All tests pass
justinmc 1c6744a
Attempt at formatting
justinmc e4587a8
Analyzer fixes
justinmc 4c5afb3
Fix my poor string conversions
justinmc b81e8f3
Rename HasStrings to GetHasStrings
justinmc 3a161be
Merge branch 'master' into has-strings-windows
justinmc 620e7aa
Use original MethodCall format with correct type
justinmc b06f2c8
Remove accidental printf!
justinmc 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 |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
|
|
||
| #include <memory> | ||
|
|
||
| #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" | ||
| #include "flutter/shell/platform/common/json_method_codec.h" | ||
| #include "flutter/shell/platform/windows/testing/test_binary_messenger.h" | ||
| #include "gmock/gmock.h" | ||
|
|
@@ -22,9 +21,11 @@ using ::testing::_; | |
| static constexpr char kChannelName[] = "flutter/platform"; | ||
|
|
||
| static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; | ||
| static constexpr char kHasStringsClipboardMethod[] = "Clipboard.hasStrings"; | ||
| static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; | ||
|
|
||
| static constexpr char kTextPlainFormat[] = "text/plain"; | ||
| static constexpr char kFakeContentType[] = "text/madeupcontenttype"; | ||
|
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. This fake content type must begin with "text" even though it's supposed to fail. If it doesn't, then rapidjson can't parse the json at all. |
||
|
|
||
| // Test implementation of PlatformHandler to allow testing the PlatformHandler | ||
| // logic. | ||
|
|
@@ -38,7 +39,9 @@ class TestPlatformHandler : public PlatformHandler { | |
| // |PlatformHandler| | ||
| MOCK_METHOD2(GetPlainText, | ||
| void(std::unique_ptr<MethodResult<rapidjson::Document>>, | ||
| const char*)); | ||
| std::string_view key)); | ||
| MOCK_METHOD1(GetHasStrings, | ||
| void(std::unique_ptr<MethodResult<rapidjson::Document>>)); | ||
| MOCK_METHOD2(SetPlainText, | ||
| void(const std::string&, | ||
| std::unique_ptr<MethodResult<rapidjson::Document>>)); | ||
|
|
@@ -61,9 +64,9 @@ TEST(PlatformHandler, GettingTextCallsThrough) { | |
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType); | ||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kStringType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->PushBack(kTextPlainFormat, allocator); | ||
| args->SetString(kTextPlainFormat); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kGetClipboardDataMethod, | ||
| std::move(args))); | ||
|
|
@@ -85,9 +88,9 @@ TEST(PlatformHandler, RejectsGettingUnknownTypes) { | |
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType); | ||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kStringType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->PushBack("madeup/contenttype", allocator); | ||
| args->SetString(kFakeContentType); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kGetClipboardDataMethod, | ||
| std::move(args))); | ||
|
|
@@ -103,6 +106,53 @@ TEST(PlatformHandler, RejectsGettingUnknownTypes) { | |
| })); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, GetHasStringsCallsThrough) { | ||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kStringType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->SetString(kTextPlainFormat); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kHasStringsClipboardMethod, | ||
| std::move(args))); | ||
|
|
||
| // Set up a handler to call a response on |result| so that it doesn't log | ||
| // on destruction about leaking. | ||
| ON_CALL(platform_handler, GetHasStrings) | ||
| .WillByDefault( | ||
| [](std::unique_ptr<MethodResult<rapidjson::Document>> result) { | ||
| result->NotImplemented(); | ||
| }); | ||
|
|
||
| EXPECT_CALL(platform_handler, GetHasStrings(_)); | ||
| EXPECT_TRUE(messenger.SimulateEngineMessage( | ||
| kChannelName, encoded->data(), encoded->size(), | ||
| [](const uint8_t* reply, size_t reply_size) {})); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, RejectsGetHasStringsOnUnknownTypes) { | ||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kStringType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->SetString(kFakeContentType); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kHasStringsClipboardMethod, | ||
| std::move(args))); | ||
|
|
||
| MockMethodResult result; | ||
| // Requsting an unknow content type is an error. | ||
| EXPECT_CALL(result, ErrorInternal(_, _, _)); | ||
| EXPECT_TRUE(messenger.SimulateEngineMessage( | ||
| kChannelName, encoded->data(), encoded->size(), | ||
| [&](const uint8_t* reply, size_t reply_size) { | ||
| JsonMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope( | ||
| reply, reply_size, &result); | ||
| })); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, SettingTextCallsThrough) { | ||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing a compiler error for some reason, removing it seemed to work 🤷