Skip to content

Commit a4898b6

Browse files
[webview_flutter_wkwebview] Fixes crash when running WKNavigationResponse tests on Xcode 26 (#10316)
Fixes flutter/flutter#173326 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 8a6538e commit a4898b6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/NavigationDelegateProxyAPITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class NavigationDelegateProxyAPITests: XCTestCase {
6262
let registrar = TestProxyApiRegistrar()
6363
let instance = NavigationDelegateImpl(api: api, registrar: registrar)
6464
let webView = WKWebView(frame: .zero)
65-
let navigationResponse = TestNavigationResponse()
65+
let navigationResponse = TestNavigationResponse.instance
6666

6767
var result: WKNavigationResponsePolicy?
6868
let callbackExpectation = expectation(description: "Wait for callback.")

packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/NavigationResponseProxyAPITests.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NavigationResponseProxyAPITests: XCTestCase {
1212
let registrar = TestProxyApiRegistrar()
1313
let api = registrar.apiDelegate.pigeonApiWKNavigationResponse(registrar)
1414

15-
let instance = WKNavigationResponse()
15+
let instance = TestNavigationResponse.instance
1616
let value = try? api.pigeonDelegate.response(pigeonApi: api, pigeonInstance: instance)
1717

1818
XCTAssertEqual(value, instance.response)
@@ -22,16 +22,24 @@ class NavigationResponseProxyAPITests: XCTestCase {
2222
let registrar = TestProxyApiRegistrar()
2323
let api = registrar.apiDelegate.pigeonApiWKNavigationResponse(registrar)
2424

25-
let instance = TestNavigationResponse()
25+
let instance = TestNavigationResponse.instance
2626
let value = try? api.pigeonDelegate.isForMainFrame(pigeonApi: api, pigeonInstance: instance)
2727

2828
XCTAssertEqual(value, instance.isForMainFrame)
2929
}
3030
}
3131

3232
class TestNavigationResponse: WKNavigationResponse {
33+
// Provides a static instance to prevent a crash when a WKNavigationResponse is deallocated
34+
// See https://github.com/flutter/flutter/issues/173326
35+
static let instance = TestNavigationResponse()
36+
3337
let testResponse = URLResponse()
3438

39+
private override init() {
40+
super.init()
41+
}
42+
3543
override var isForMainFrame: Bool {
3644
return true
3745
}

0 commit comments

Comments
 (0)