Repository navigation
Fix hidden browser slot inspector focus crash #1211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2434,7 +2434,9 @@ final class BrowserSessionHistoryRestoreTests: XCTestCase { | |
|
|
||
| @MainActor | ||
| final class BrowserDeveloperToolsVisibilityPersistenceTests: XCTestCase { | ||
| private final class WKInspectorProbeView: NSView {} | ||
| private final class WKInspectorProbeView: NSView { | ||
| override var acceptsFirstResponder: Bool { true } | ||
| } | ||
|
|
||
| private final class FakeInspector: NSObject { | ||
| private(set) var attachCount = 0 | ||
|
|
@@ -11515,6 +11517,46 @@ final class BrowserWindowPortalLifecycleTests: XCTestCase { | |
| ) | ||
| } | ||
|
|
||
| func testHidingBrowserSlotYieldsOwnedInspectorFirstResponder() { | ||
| let window = NSWindow( | ||
| contentRect: NSRect(x: 0, y: 0, width: 520, height: 320), | ||
| styleMask: [.titled, .closable], | ||
| backing: .buffered, | ||
| defer: false | ||
| ) | ||
| defer { window.orderOut(nil) } | ||
| realizeWindowLayout(window) | ||
|
|
||
| guard let contentView = window.contentView else { | ||
| XCTFail("Expected content view") | ||
| return | ||
| } | ||
|
|
||
| let slot = WindowBrowserSlotView(frame: NSRect(x: 40, y: 24, width: 260, height: 180)) | ||
| contentView.addSubview(slot) | ||
|
|
||
| let inspectorContainer = NSView(frame: slot.bounds) | ||
| inspectorContainer.autoresizingMask = [.width, .height] | ||
| let inspectorView = WKInspectorProbeView(frame: inspectorContainer.bounds) | ||
| inspectorView.autoresizingMask = [.width, .height] | ||
| inspectorContainer.addSubview(inspectorView) | ||
| slot.addSubview(inspectorContainer) | ||
| contentView.layoutSubtreeIfNeeded() | ||
|
|
||
| XCTAssertTrue( | ||
| window.makeFirstResponder(inspectorView), | ||
| "Precondition failed: inspector probe should become first responder" | ||
| ) | ||
| XCTAssertTrue(window.firstResponder === inspectorView) | ||
|
|
||
| slot.isHidden = true | ||
|
|
||
| XCTAssertNil( | ||
| window.firstResponder, | ||
| "Hiding a browser slot should yield any owned inspector responder before it goes off-screen" | ||
| ) | ||
| } | ||
|
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. Missing test coverage for The PR adds two guard sites — the
Comment on lines
+11520
to
+11558
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 regression never reaches the hide path. The Suggested fixprivate final class WKInspectorProbeView: NSView {
override var acceptsFirstResponder: Bool { true }
}🤖 Prompt for AI Agents |
||
|
|
||
| func testHiddenPortalSyncDoesNotStealLocallyHostedDevToolsWebViewDuringResize() { | ||
| let window = NSWindow( | ||
| contentRect: NSRect(x: 0, y: 0, width: 520, height: 320), | ||
|
|
||
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.
This precondition assumes
window.makeFirstResponder(inspectorView)can succeed, but theWKInspectorProbeViewused inBrowserWindowPortalLifecycleTestsstill inheritsNSViewwithout overridingacceptsFirstResponder, which defaults tofalsein AppKit. In that case this assertion fails and the regression does not actually cover the slot-hiding focus-yield path the fix relies on.Useful? React with 👍 / 👎.