Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,48 @@ class BrowserViewControllerWebViewDelegateTests: XCTestCase {
}
}

// @MainActor
// func testWebViewDecidePolicyForNavigationAction_allowMarketPlaceScheme_whenUserAction() {
// let subject = createSubject()
// let url = URL(string: "marketplace-kit://install?exampleApp.com")!
// let tab = createTab()
// tabManager.tabs = [tab]
// let navigationAction = MockNavigationAction(url: url, type: .linkActivated)
//
// subject.webView(tab.webView!,
// decidePolicyFor: navigationAction) { policy in
// XCTAssertEqual(policy, .allow)
// }
// }

@MainActor
func testWebViewDecidePolicyForNavigationAction_cancelMarketPlaceScheme_whenNotMainFrame() {
let subject = createSubject()
let url = URL(string: "marketplace-kit://install?exampleApp.com")!
let tab = createTab()
tabManager.tabs = [tab]
let navigationAction = MockNavigationAction(url: url, type: .linkActivated)

subject.webView(tab.webView!,
decidePolicyFor: navigationAction) { policy in
XCTAssertEqual(policy, .cancel)
}
}

@MainActor
func testWebViewDecidePolicyForNavigationAction_cancelMarketPlaceScheme_whenReloadAction() {
let subject = createSubject()
let url = URL(string: "marketplace-kit://install?exampleApp.com")!
let tab = createTab()
tabManager.tabs = [tab]
let navigationAction = MockNavigationAction(url: url, type: .reload)

subject.webView(tab.webView!,
decidePolicyFor: navigationAction) { policy in
XCTAssertEqual(policy, .cancel)
}
}

// MARK: - Authentication

@MainActor
Expand Down Expand Up @@ -368,9 +410,20 @@ class BrowserViewControllerWebViewDelegateTests: XCTestCase {
}
}

final class MockFrameInfo: WKFrameInfo {
private let main: Bool

init(isMainFrame: Bool) {
self.main = isMainFrame
super.init()
}
override var isMainFrame: Bool { main }
}

class MockNavigationAction: WKNavigationAction {
private var type: WKNavigationType?
private var urlRequest: URLRequest
private var frame: WKFrameInfo?

override var navigationType: WKNavigationType {
return type ?? .other
Expand All @@ -380,9 +433,14 @@ class MockNavigationAction: WKNavigationAction {
return urlRequest
}

init(url: URL, type: WKNavigationType? = nil) {
override var targetFrame: WKFrameInfo? {
return frame
}

init(url: URL, type: WKNavigationType? = nil, isMainFrame: Bool = true) {
self.type = type
self.urlRequest = URLRequest(url: url)
self.frame = MockFrameInfo(isMainFrame: isMainFrame)
}
}

Expand Down
Loading