Revision control

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
@testable import Client
import WebKit
import XCTest
class TabEventHandlerTests: XCTestCase {
func testEventDelivery() {
let tab = Tab(bvc: BrowserViewController.foregroundBVC(), configuration: WKWebViewConfiguration())
let handler = DummyHandler()
XCTAssertNil(handler.isFocused)
TabEvent.post(.didGainFocus, for: tab)
XCTAssertTrue(handler.isFocused!)
TabEvent.post(.didLoseFocus, for: tab)
XCTAssertFalse(handler.isFocused!)
}
}
class DummyHandler: TabEventHandler {
// This is not how this should be written in production — the handler shouldn't be keeping track
// of individual tab state.
var isFocused: Bool? = nil
init() {
register(self, forTabEvents: .didGainFocus, .didLoseFocus)
}
func tabDidGainFocus(_ tab: Tab) {
isFocused = true
}
func tabDidLoseFocus(_ tab: Tab) {
isFocused = false
}
}