-
Notifications
You must be signed in to change notification settings - Fork 6k
hasStrings on Windows #27749
hasStrings on Windows #27749
Changes from 16 commits
70a0f5e
c9d633a
39990f3
c3060cd
83af633
b7c562e
64c5751
85528fd
a640fcc
aa4dc9e
61e2fa5
5a35ed2
6cef1f2
1c6744a
e4587a8
4c5afb3
b81e8f3
3a161be
620e7aa
b06f2c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
|
Contributor
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. This was causing a compiler error for some reason, removing it seemed to work 🤷 |
||
| #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"; | ||
|
Contributor
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. 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(HasStrings, | ||
| void(std::unique_ptr<MethodResult<rapidjson::Document>>)); | ||
| MOCK_METHOD2(SetPlainText, | ||
| void(const std::string&, | ||
| std::unique_ptr<MethodResult<rapidjson::Document>>)); | ||
|
|
@@ -61,12 +64,10 @@ TEST(PlatformHandler, GettingTextCallsThrough) { | |
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->PushBack(kTextPlainFormat, allocator); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kGetClipboardDataMethod, | ||
| std::move(args))); | ||
| std::ostringstream jsonStringStream; | ||
| jsonStringStream << "{\"method\":\"" << kGetClipboardDataMethod | ||
| << "\",\"args\":\"" << kTextPlainFormat << "\"}"; | ||
| std::string jsonString = jsonStringStream.str(); | ||
|
|
||
| // Set up a handler to call a response on |result| so that it doesn't log | ||
| // on destruction about leaking. | ||
|
|
@@ -77,27 +78,68 @@ TEST(PlatformHandler, GettingTextCallsThrough) { | |
|
|
||
| EXPECT_CALL(platform_handler, GetPlainText(_, ::testing::StrEq("text"))); | ||
| EXPECT_TRUE(messenger.SimulateEngineMessage( | ||
| kChannelName, encoded->data(), encoded->size(), | ||
| [](const uint8_t* reply, size_t reply_size) {})); | ||
| kChannelName, reinterpret_cast<const unsigned char*>(jsonString.c_str()), | ||
| jsonString.size(), [](const uint8_t* reply, size_t reply_size) {})); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, RejectsGettingUnknownTypes) { | ||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType); | ||
| auto& allocator = args->GetAllocator(); | ||
| args->PushBack("madeup/contenttype", allocator); | ||
| auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall( | ||
| MethodCall<rapidjson::Document>(kGetClipboardDataMethod, | ||
| std::move(args))); | ||
| std::ostringstream jsonStringStream; | ||
| jsonStringStream << "{\"method\":\"" << kGetClipboardDataMethod | ||
| << "\",\"args\":\"" << kFakeContentType << "\"}"; | ||
| std::string jsonString = jsonStringStream.str(); | ||
|
|
||
| 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) { | ||
| kChannelName, reinterpret_cast<const unsigned char*>(jsonString.c_str()), | ||
| jsonString.size(), [&](const uint8_t* reply, size_t reply_size) { | ||
| JsonMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope( | ||
| reply, reply_size, &result); | ||
| })); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, HasStringsCallsThrough) { | ||
|
Contributor
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. I was NOT able to run these tests locally! Are we ok if the checks just pass here on Github? Which unittests.exe file in
Contributor
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. It should be
In theory, but since it's missing from the build the GitHub checks aren't telling us anything.
Contributor
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. Ah, I felt like something was up. Thanks, I'll add it! |
||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| std::ostringstream jsonStringStream; | ||
| jsonStringStream << "{\"method\":\"" << kHasStringsClipboardMethod | ||
| << "\",\"args\":\"" << kTextPlainFormat << "\"}"; | ||
| std::string jsonString = jsonStringStream.str(); | ||
|
|
||
| // Set up a handler to call a response on |result| so that it doesn't log | ||
| // on destruction about leaking. | ||
| ON_CALL(platform_handler, HasStrings) | ||
| .WillByDefault( | ||
| [](std::unique_ptr<MethodResult<rapidjson::Document>> result) { | ||
| result->NotImplemented(); | ||
| }); | ||
|
|
||
| EXPECT_CALL(platform_handler, HasStrings(_)); | ||
| EXPECT_TRUE(messenger.SimulateEngineMessage( | ||
| kChannelName, reinterpret_cast<const unsigned char*>(jsonString.c_str()), | ||
| jsonString.size(), [](const uint8_t* reply, size_t reply_size) {})); | ||
| } | ||
|
|
||
| TEST(PlatformHandler, RejectsHasStringsOnUnknownTypes) { | ||
| TestBinaryMessenger messenger; | ||
| TestPlatformHandler platform_handler(&messenger); | ||
|
|
||
| std::ostringstream jsonStringStream; | ||
| jsonStringStream << "{\"method\":\"" << kHasStringsClipboardMethod | ||
| << "\",\"args\":\"" << kFakeContentType << "\"}"; | ||
| std::string jsonString = jsonStringStream.str(); | ||
|
|
||
| MockMethodResult result; | ||
| // Requsting an unknow content type is an error. | ||
| EXPECT_CALL(result, ErrorInternal(_, _, _)); | ||
| EXPECT_TRUE(messenger.SimulateEngineMessage( | ||
| kChannelName, reinterpret_cast<const unsigned char*>(jsonString.c_str()), | ||
| jsonString.size(), [&](const uint8_t* reply, size_t reply_size) { | ||
| JsonMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope( | ||
| reply, reply_size, &result); | ||
| })); | ||
|
|
||
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.
Sorry if I'm revisiting an established design. But this name looks pretty confusing. Why is it
HasStringinstead ofHasString? And can we rename it to a "verb", such asGetHasStringto represent the fact that it is a query from the framework?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.
Plural
HasStringscame from native iOS hasStrings, which is where all of this started. I'll change the Windows methods toGetHasStringswhile keeping the method channel name the same "Clipboard.hasStrings".