This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter_wkwebview] Implementation of Objective-C WKWebView Host Apis #5341
Merged
Merged
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fa84355
implementation of host apis
bparrishMines 7c13474
move comment and fix test
bparrishMines e48695f
add test to verify error
bparrishMines 085e363
add other methods
bparrishMines 8755174
change method name and add documentation
bparrishMines fa5dbeb
an
bparrishMines 16d19e9
PR feedback
bparrishMines dd0bb72
naming conventions
bparrishMines c4f5abb
use nonatomic
bparrishMines 0ae3db5
use nonatomic
bparrishMines ddb8971
format
bparrishMines 5b1245c
implement host api methods
bparrishMines 88e10d0
more tests
bparrishMines 6d7fdfd
misspelling
bparrishMines 196c07b
assets test
bparrishMines 25ce261
rest of tests
bparrishMines 99f043e
Merge branch 'master' of github.com:flutter/plugins into host_api
bparrishMines 5280385
test converter
bparrishMines 11ac0a3
URL
bparrishMines d3fc5e9
Merge branch 'master' of github.com:flutter/plugins into host_api
bparrishMines eba9e4b
fix test
bparrishMines 4bdbb1d
improve objc naming
bparrishMines 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
106 changes: 106 additions & 0 deletions
106
...ebview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m
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,106 @@ | ||
| // 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. | ||
|
|
||
| @import Flutter; | ||
| @import XCTest; | ||
| @import webview_flutter_wkwebview; | ||
|
|
||
| #import <OCMock/OCMock.h> | ||
|
|
||
| @interface FWFWebViewHostApiTests : XCTestCase | ||
| @end | ||
|
|
||
| @implementation FWFWebViewHostApiTests | ||
| - (void)testLoadRequest { | ||
| FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); | ||
|
|
||
| FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; | ||
| [instanceManager addInstance:mockWebView withIdentifier:0]; | ||
|
|
||
| FWFWebViewHostApiImpl *hostApi = | ||
| [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; | ||
|
|
||
| FlutterError *error; | ||
| FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"https://www.flutter.dev" | ||
| httpMethod:@"get" | ||
| httpBody:nil | ||
| allHttpHeaderFields:@{@"a" : @"header"}]; | ||
| [hostApi webViewWithInstanceId:@0 loadRequest:requestData error:&error]; | ||
|
|
||
| NSURL *url = [NSURL URLWithString:@"https://www.flutter.dev"]; | ||
| NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | ||
| request.HTTPMethod = @"get"; | ||
| request.allHTTPHeaderFields = @{@"a" : @"header"}; | ||
| OCMVerify([mockWebView loadRequest:request]); | ||
| XCTAssertNil(error); | ||
| } | ||
|
|
||
| - (void)testLoadRequestWithInvalidUrl { | ||
| FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); | ||
| OCMReject([mockWebView loadRequest:OCMOCK_ANY]); | ||
|
|
||
| FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; | ||
| [instanceManager addInstance:mockWebView withIdentifier:0]; | ||
|
|
||
| FWFWebViewHostApiImpl *hostApi = | ||
| [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; | ||
|
|
||
| FlutterError *error; | ||
| FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"%invalidUrl%" | ||
| httpMethod:nil | ||
| httpBody:nil | ||
| allHttpHeaderFields:@{}]; | ||
| [hostApi webViewWithInstanceId:@0 loadRequest:requestData error:&error]; | ||
| XCTAssertNotNil(error); | ||
| XCTAssertEqualObjects(error.code, @"CreateNSURLRequestFailure"); | ||
| XCTAssertEqualObjects(error.message, @"Failed instantiating an NSURLRequest."); | ||
| XCTAssertEqualObjects(error.details, @"Url was: '%invalidUrl%'"); | ||
| } | ||
|
|
||
| - (void)testSetCustomUserAgent { | ||
| FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); | ||
|
|
||
| FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; | ||
| [instanceManager addInstance:mockWebView withIdentifier:0]; | ||
|
|
||
| FWFWebViewHostApiImpl *hostApi = | ||
| [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; | ||
|
|
||
| FlutterError *error; | ||
| [hostApi webViewWithInstanceId:@0 setCustomUserAgent:@"userA" error:&error]; | ||
| OCMVerify([mockWebView setCustomUserAgent:@"userA"]); | ||
| XCTAssertNil(error); | ||
| } | ||
|
|
||
| - (void)testUrlForWebViewWithInstanceId { | ||
| FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); | ||
| OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://www.flutter.dev/"]); | ||
|
|
||
| FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; | ||
| [instanceManager addInstance:mockWebView withIdentifier:0]; | ||
|
|
||
| FWFWebViewHostApiImpl *hostApi = | ||
| [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; | ||
|
|
||
| FlutterError *error; | ||
| XCTAssertEqualObjects([hostApi urlForWebViewWithInstanceId:@0 error:&error], | ||
| @"https://www.flutter.dev/"); | ||
| XCTAssertNil(error); | ||
| } | ||
|
|
||
| - (void)testCanGoBack { | ||
| FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); | ||
| OCMStub([mockWebView canGoBack]).andReturn(YES); | ||
|
|
||
| FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; | ||
| [instanceManager addInstance:mockWebView withIdentifier:0]; | ||
|
|
||
| FWFWebViewHostApiImpl *hostApi = | ||
| [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; | ||
|
|
||
| FlutterError *error; | ||
| XCTAssertEqualObjects([hostApi webViewWithInstanceIdCanGoBack:@0 error:&error], @YES); | ||
| XCTAssertNil(error); | ||
| } | ||
| @end | ||
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
19 changes: 19 additions & 0 deletions
19
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // 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. | ||
|
|
||
| #import "FWFGeneratedWebKitApis.h" | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| /** | ||
| * Converts an FWFNSUrlRequestData to an NSURLRequest. | ||
| * | ||
| * @param data The data object containing information to create an NSURLRequest. | ||
| * | ||
| * @return An NSURLRequest or nil if data could not be converted. | ||
| */ | ||
| extern NSURLRequest* _Nullable FWFNSURLRequestFromRequestData( | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FWFNSUrlRequestData* data); | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
25 changes: 25 additions & 0 deletions
25
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m
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,25 @@ | ||
| // 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. | ||
|
|
||
| #import "FWFDataConverters.h" | ||
|
|
||
| #import <Flutter/Flutter.h> | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| NSURLRequest *_Nullable FWFNSURLRequestFromRequestData(FWFNSUrlRequestData *data) { | ||
| NSURL *url = [NSURL URLWithString:data.url]; | ||
| if (!url) { | ||
| return nil; | ||
| } | ||
|
|
||
| NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | ||
| if (!request) { | ||
| return nil; | ||
| } | ||
|
|
||
| [request setHTTPMethod:data.httpMethod]; | ||
| [request setHTTPBody:data.httpBody.data]; | ||
| [request setAllHTTPHeaderFields:data.allHttpHeaderFields]; | ||
|
|
||
| return request; | ||
| } | ||
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.