Skip to content

Commit

Permalink
Nb/6331 fix buddybuild tests (#6332)
Browse files Browse the repository at this point in the history
* Fix #6331 - Updated useregent tests

* Removed webview user agent test
  • Loading branch information
nbhasin2 authored Mar 31, 2020
1 parent 089219a commit c091617
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions ClientTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,19 @@ class ClientTests: XCTestCase {
XCTAssertTrue(loc != nil, "Sync UA is as expected. Was \(ua)")
}

// Simple test to make sure the WKWebView UA matches the expected FxiOS pattern.
func testUserAgent() {
func testMobileUserAgent() {
let compare: (String) -> Bool = { ua in
let range = ua.range(of: "^Mozilla/5\\.0 \\(.+\\) AppleWebKit/[0-9\\.]+ \\(KHTML, like Gecko\\)", options: .regularExpression)
return range != nil
}

XCTAssertTrue(compare(UserAgent.getUserAgent()), "User agent computes correctly.")
//XCTAssertTrue(compare(UserAgent.cachedUserAgent(checkiOSVersion: true)!), "User agent is cached correctly.")

let expectation = self.expectation(description: "Found Firefox user agent")

let webView = WKWebView()
webView.evaluateJavaScript("navigator.userAgent") { result, error in
let userAgent = result as! String
if compare(userAgent) {
expectation.fulfill()
} else {
XCTFail("User agent did not match expected pattern! \(userAgent)")
}
}

waitForExpectations(timeout: 5, handler: nil)
XCTAssertTrue(compare(UserAgent.mobileUserAgent()), "User agent computes correctly.")
}

func testDesktopUserAgent() {
let compare: (String) -> Bool = { ua in
let range = ua.range(of: "^Mozilla/5\\.0 \\(Macintosh; Intel Mac OS X [0-9\\.]+\\)", options: .regularExpression)
return range != nil
}

XCTAssertTrue(compare(UserAgent.desktopUserAgent()), "Desktop user agent computes correctly.")
}
}

0 comments on commit c091617

Please sign in to comment.