Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
2.0.0
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
/* 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
import WebKit
import Shared
import EarlGrey
import SwiftyJSON
/// This test should be disabled since session restore does not seem to work
class SessionRestoreTests: KIFTestCase {
fileprivate var webRoot: String!
override func setUp() {
webRoot = SimplePageServer.start()
BrowserUtils.dismissFirstRunUI()
super.setUp()
}
func testTabRestore() {
let url1 = "\(webRoot!)/numberedPage.html?page=1"
let url2 = "\(webRoot!)/numberedPage.html?page=2"
let url3 = "\(webRoot!)/numberedPage.html?page=3"
// Build a session restore URL from the current homepage URL.
var jsonDict = [String: Any]()
jsonDict["history"] = [url1, url2, url3]
jsonDict["currentPage"] = -1 as Any?
let json = JSON(jsonDict)
let escapedJSON = json.stringValue()?.addingPercentEncoding(withAllowedCharacters: .URLAllowed)
let webView = tester().waitForView(withAccessibilityLabel: "Web content") as! WKWebView
let restoreURL = URL(string: "/about/sessionrestore?history=\(escapedJSON!)", relativeTo: webView.url!)
// Enter the restore URL and verify the back/forward history.
// After triggering the restore, the session should look like this:
// about:home, page1, *page2*, page3
// where page2 is active.
EarlGrey.selectElement(with: grey_accessibilityID("url"))
.perform(grey_tap())
EarlGrey.selectElement(with: grey_accessibilityID("address"))
.perform(grey_replaceText(restoreURL!.absoluteString))
EarlGrey.selectElement(with: grey_accessibilityID("address"))
.perform(grey_typeText("\n"))
tester().waitForWebViewElementWithAccessibilityLabel("Page 2")
EarlGrey.selectElement(with: grey_accessibilityLabel("Back"))
.perform(grey_tap())
tester().waitForWebViewElementWithAccessibilityLabel("Page 1")
EarlGrey.selectElement(with: grey_accessibilityLabel("Back"))
.perform(grey_tap())
let wentBack = GREYCondition(name: "Check browser went back", block: {
var errorOrNil: NSError?
let matcher = grey_allOf([grey_accessibilityLabel("Top sites"),
grey_sufficientlyVisible()])
EarlGrey.selectElement(with: matcher).assert(grey_notNil(), error: &errorOrNil)
let success = errorOrNil == nil
return success
}).wait(withTimeout: 5)
GREYAssertTrue(wentBack, reason: "Didn't go back")
let canGoBack: Bool
do {
try tester().tryFindingTappableView(withAccessibilityLabel: "Back")
canGoBack = true
} catch _ {
canGoBack = false
}
XCTAssertFalse(canGoBack, "Reached the beginning of browser history")
EarlGrey.selectElement(with: grey_accessibilityLabel("Forward"))
.perform(grey_tap())
EarlGrey.selectElement(with: grey_accessibilityLabel("Forward"))
.perform(grey_tap())
EarlGrey.selectElement(with: grey_accessibilityLabel("Forward"))
.perform(grey_tap())
tester().waitForWebViewElementWithAccessibilityLabel("Page 3")
let canGoForward: Bool
do {
try tester().tryFindingTappableView(withAccessibilityLabel: "Forward")
canGoForward = true
} catch _ {
canGoForward = false
}
XCTAssertFalse(canGoForward, "Reached the end of browser history")
}
override func tearDown() {
BrowserUtils.resetToAboutHome()
BrowserUtils.clearPrivateData()
}
}