forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientTests.swift
46 lines (39 loc) · 1.79 KB
/
ClientTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* 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 UIKit
import XCTest
import Shared
import Storage
import WebKit
@testable import Client
class ClientTests: XCTestCase {
func testSyncUA() {
let ua = UserAgent.syncUserAgent
let device = DeviceInfo.deviceModel()
let systemVersion = UIDevice.current.systemVersion
if AppInfo.appVersion != "0.0.1" {
let expectedRegex = "^Firefox-iOS-Sync/[0-9\\.]+b[0-9]* \\(\(device); iPhone OS \(systemVersion)\\) \\([-_A-Za-z0-9= \\(\\)]+\\)$"
let loc = ua.range(of: expectedRegex, options: .regularExpression)
XCTAssertTrue(loc != nil, "Sync UA is as expected. Was \(ua)")
} else {
XCTAssertTrue(ua.range(of: "dev") != nil)
}
}
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.mobileUserAgent()), "User agent computes correctly.")
}
// Disabling for now due to https://github.com/mozilla-mobile/firefox-ios/pull/6468
// This hard-codes the desktop UA, not much to test as a result of that
// 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.")
// }
}