Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
garvankeeley committed Aug 12, 2020
1 parent 17c71ed commit c006fc3
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ClientTests/TabEventHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import Foundation
@testable import Client
import WebKit

import GCDWebServers
import XCTest
import Shared

class TabEventHandlerTests: XCTestCase {

Expand All @@ -22,6 +23,36 @@ class TabEventHandlerTests: XCTestCase {
TabEvent.post(.didLoseFocus, for: tab)
XCTAssertFalse(handler.isFocused!)
}


func testBlankPopupURL() {
let webServer = GCDWebServer()
webServer.addHandler(forMethod: "GET", path: "/blankpopup", request: GCDWebServerRequest.self) { (request) -> GCDWebServerResponse in
let page = """
<html>
<body onload="window.open('')">open about:blank popup</body>
</html>
"""
return GCDWebServerDataResponse(html: page)!
}

if webServer.start(withPort: 0, bonjourName: nil) == false {
XCTFail("Can't start the GCDWebServer")
}
let webServerBase = "http://localhost:\(webServer.port)"

BrowserViewController.foregroundBVC().profile.prefs.setBool(false, forKey: PrefsKeys.KeyBlockPopups)
BrowserViewController.foregroundBVC().tabManager.addTab(URLRequest(url: URL(string: "\(webServerBase)/blankpopup")!))
let expectation = self.expectation(description: "Waiting on favicon fetching")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
BrowserViewController.foregroundBVC().tabManager.tabs.forEach { tab in
if tab.url?.absoluteString == "about:blank" {
expectation.fulfill()
}
}
}
waitForExpectations(timeout: 20, handler: nil)
}
}


Expand Down

0 comments on commit c006fc3

Please sign in to comment.