diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 6ccbd8dd19..cdbd6c01d3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -28,14 +28,49 @@ @end @implementation FlutterPlatformPluginTest -- (void)testSearchWebInvoked { +- (void)testSearchWebInvokedWithEscapedTerm { + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); + FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease]; std::unique_ptr> _weakFactory = std::make_unique>(engine); [engine runWithEntrypoint:nil]; XCTestExpectation* invokeExpectation = - [self expectationWithDescription:@"Web search launched with search term"]; + [self expectationWithDescription:@"Web search launched with escaped search term"]; + + FlutterPlatformPlugin* plugin = + [[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease]; + FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); + + FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"SearchWeb.invoke" + arguments:@"Testing Word!"]; + + FlutterResult result = ^(id result) { + OCMVerify([mockPlugin searchWeb:@"Testing Word!"]); + OCMVerify([mockApplication openURL:[NSURL URLWithString:@"x-web-search://?Testing%20Word!"] + options:@{} + completionHandler:nil]); + [invokeExpectation fulfill]; + }; + + [mockPlugin handleMethodCall:methodCall result:result]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + [mockApplication stopMocking]; +} + +- (void)testSearchWebInvokedWithNonEscapedTerm { + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); + + FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease]; + std::unique_ptr> _weakFactory = + std::make_unique>(engine); + [engine runWithEntrypoint:nil]; + + XCTestExpectation* invokeExpectation = + [self expectationWithDescription:@"Web search launched with non escaped search term"]; FlutterPlatformPlugin* plugin = [[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease]; @@ -46,11 +81,15 @@ FlutterResult result = ^(id result) { OCMVerify([mockPlugin searchWeb:@"Test"]); + OCMVerify([mockApplication openURL:[NSURL URLWithString:@"x-web-search://?Test"] + options:@{} + completionHandler:nil]); [invokeExpectation fulfill]; }; [mockPlugin handleMethodCall:methodCall result:result]; [self waitForExpectationsWithTimeout:1 handler:nil]; + [mockApplication stopMocking]; } - (void)testLookUpCallInitiated {