@@ -161,7 +161,120 @@ - (void)testLoadFileFailsWithInvalidPath {
161161 OCMReject ([mockWebView loadFileURL: [OCMArg any ] allowingReadAccessToURL: [OCMArg any ]]);
162162}
163163
164- - (void )testLoadFileSucceedsWithBaseUrl {
164+ - (void )testLoadFlutterAssetSucceeds {
165+ NSBundle *mockBundle = OCMPartialMock ([NSBundle mainBundle ]);
166+ NSString *filePath = [FlutterDartProject lookupKeyForAsset: @" assets/file.html" ];
167+ NSURL *url = [NSURL URLWithString: [@" file:///" stringByAppendingString: filePath]];
168+ [OCMStub ([mockBundle URLForResource: [filePath stringByDeletingPathExtension ]
169+ withExtension: @" html" ]) andReturn: (url)];
170+
171+ XCTestExpectation *resultExpectation =
172+ [self expectationWithDescription: @" Should return successful result over the method channel." ];
173+ FLTWebViewController *controller =
174+ [[FLTWebViewController alloc ] initWithFrame: CGRectMake (0 , 0 , 300 , 400 )
175+ viewIdentifier: 1
176+ arguments: nil
177+ binaryMessenger: self .mockBinaryMessenger];
178+ FLTWKWebView *mockWebView = OCMClassMock (FLTWKWebView.class );
179+ controller.webView = mockWebView;
180+ [controller onMethodCall: [FlutterMethodCall methodCallWithMethodName: @" loadFlutterAsset"
181+ arguments: @" assets/file.html" ]
182+ result: ^(id _Nullable result) {
183+ XCTAssertNil (result);
184+ [resultExpectation fulfill ];
185+ }];
186+
187+ [self waitForExpectations: @[ resultExpectation ] timeout: 1.0 ];
188+ OCMVerify ([mockWebView loadFileURL: url
189+ allowingReadAccessToURL: [url URLByDeletingLastPathComponent ]]);
190+ }
191+
192+ - (void )testLoadFlutterAssetFailsWithInvalidKey {
193+ NSArray *resultExpectations = @[
194+ [self expectationWithDescription: @" Should return failed result when argument is nil." ],
195+ [self expectationWithDescription:
196+ @" Should return failed result when argument is not of type NSString*." ],
197+ [self expectationWithDescription:
198+ @" Should return failed result when argument is an empty string." ],
199+ ];
200+
201+ FLTWebViewController *controller =
202+ [[FLTWebViewController alloc ] initWithFrame: CGRectMake (0 , 0 , 300 , 400 )
203+ viewIdentifier: 1
204+ arguments: nil
205+ binaryMessenger: self .mockBinaryMessenger];
206+ FLTWKWebView *mockWebView = OCMClassMock (FLTWKWebView.class );
207+ controller.webView = mockWebView;
208+ [controller onMethodCall: [FlutterMethodCall methodCallWithMethodName: @" loadFlutterAsset"
209+ arguments: nil ]
210+ result: ^(id _Nullable result) {
211+ FlutterError *expected =
212+ [FlutterError errorWithCode: @" loadFlutterAsset_invalidKey"
213+ message: @" Supplied asset key is not valid."
214+ details: @" Argument is nil." ];
215+ [FLTWebViewTests assertFlutterError: result withExpected: expected];
216+ [resultExpectations[0 ] fulfill ];
217+ }];
218+ [controller onMethodCall: [FlutterMethodCall methodCallWithMethodName: @" loadFlutterAsset"
219+ arguments: @(10 )]
220+ result: ^(id _Nullable result) {
221+ FlutterError *expected =
222+ [FlutterError errorWithCode: @" loadFlutterAsset_invalidKey"
223+ message: @" Supplied asset key is not valid."
224+ details: @" Argument is not of type NSString." ];
225+ [FLTWebViewTests assertFlutterError: result withExpected: expected];
226+ [resultExpectations[1 ] fulfill ];
227+ }];
228+ [controller onMethodCall: [FlutterMethodCall methodCallWithMethodName: @" loadFlutterAsset"
229+ arguments: @" " ]
230+ result: ^(id _Nullable result) {
231+ FlutterError *expected =
232+ [FlutterError errorWithCode: @" loadFlutterAsset_invalidKey"
233+ message: @" Supplied asset key is not valid."
234+ details: @" Argument contains an empty string." ];
235+ [FLTWebViewTests assertFlutterError: result withExpected: expected];
236+ [resultExpectations[2 ] fulfill ];
237+ }];
238+
239+ [self waitForExpectations: resultExpectations timeout: 1.0 ];
240+ OCMReject ([mockWebView loadFileURL: [OCMArg any ] allowingReadAccessToURL: [OCMArg any ]]);
241+ }
242+
243+ - (void )testLoadFlutterAssetFailsWithParsingError {
244+ NSBundle *mockBundle = OCMPartialMock ([NSBundle mainBundle ]);
245+ NSString *filePath = [FlutterDartProject lookupKeyForAsset: @" assets/file.html" ];
246+ [OCMStub ([mockBundle URLForResource: [filePath stringByDeletingPathExtension ]
247+ withExtension: @" html" ]) andReturn: (nil )];
248+
249+ XCTestExpectation *resultExpectation =
250+ [self expectationWithDescription: @" Should return failed result over the method channel." ];
251+ FLTWebViewController *controller =
252+ [[FLTWebViewController alloc ] initWithFrame: CGRectMake (0 , 0 , 300 , 400 )
253+ viewIdentifier: 1
254+ arguments: nil
255+ binaryMessenger: self .mockBinaryMessenger];
256+ FLTWKWebView *mockWebView = OCMClassMock (FLTWKWebView.class );
257+ controller.webView = mockWebView;
258+ [controller
259+ onMethodCall: [FlutterMethodCall methodCallWithMethodName: @" loadFlutterAsset"
260+ arguments: @" assets/file.html" ]
261+ result: ^(id _Nullable result) {
262+ FlutterError *expected = [FlutterError
263+ errorWithCode: @" loadFlutterAsset_invalidKey"
264+ message: @" Failed parsing file path for supplied key."
265+ details: [NSString
266+ stringWithFormat:
267+ @" Failed to convert path '%@ ' into NSURL for key '%@ '." ,
268+ filePath, @" assets/file.html" ]];
269+ [FLTWebViewTests assertFlutterError: result withExpected: expected];
270+ [resultExpectation fulfill ];
271+ }];
272+
273+ [self waitForExpectations: @[ resultExpectation ] timeout: 1.0 ];
274+ OCMReject ([mockWebView loadFileURL: [OCMArg any ] allowingReadAccessToURL: [OCMArg any ]]);
275+ }
276+
277+ - (void )testLoadHtmlStringSucceedsWithBaseUrl {
165278 NSURL *baseUrl = [NSURL URLWithString: @" https://flutter.dev" ];
166279 XCTestExpectation *resultExpectation =
167280 [self expectationWithDescription: @" Should return successful result over the method channel." ];
@@ -186,7 +299,7 @@ - (void)testLoadFileSucceedsWithBaseUrl {
186299 OCMVerify ([mockWebView loadHTMLString: @" some HTML string" baseURL: baseUrl]);
187300}
188301
189- - (void )testLoadFileSucceedsWithoutBaseUrl {
302+ - (void )testLoadHtmlStringSucceedsWithoutBaseUrl {
190303 XCTestExpectation *resultExpectation =
191304 [self expectationWithDescription: @" Should return successful result over the method channel." ];
192305 FLTWebViewController *controller =
0 commit comments