Skip to content

Commit

Permalink
Fix #6310: always use Safari UA for desktop (#6468)
Browse files Browse the repository at this point in the history
* Fix #6310: always use Safari UA for desktop

* Remove testDesktopUserAgent (for now) because of the hard-coded desktop UA
  • Loading branch information
garvankeeley authored Apr 27, 2020
1 parent a9e88d8 commit 5bd7a74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
18 changes: 10 additions & 8 deletions ClientTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class ClientTests: XCTestCase {
}
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.")
}

// 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.")
// }
}
14 changes: 3 additions & 11 deletions Shared/UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class UserAgent {
}

public static func desktopUserAgent() -> String {
return UserAgentBuilder.defaultDesktopUserAgent().userAgent()
return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15"
}

public static func mobileUserAgent() -> String {
Expand All @@ -62,11 +62,7 @@ open class UserAgent {
public static func getUserAgent(domain: String, platform: UserAgentPlatform) -> String {
switch platform {
case .Desktop:
if let customUA = CustomUserAgentConstant.desktopUserAgent[domain] {
return customUA
} else {
return desktopUserAgent()
}
return desktopUserAgent()
case .Mobile:
if let customUA = CustomUserAgentConstant.mobileUserAgent[domain] {
return customUA
Expand Down Expand Up @@ -98,11 +94,7 @@ public struct CustomUserAgentConstant {
public static let mobileUserAgent = [
"paypal.com": defaultMobileUA,
"yahoo.com": defaultMobileUA ]
public static let desktopUserAgent = [
"paypal.com": customDesktopUA,
"yahoo.com": customDesktopUA,
"youtube.com": customDesktopUA,
"whatsapp.com": customDesktopUA ]

}

public struct UserAgentBuilder {
Expand Down

0 comments on commit 5bd7a74

Please sign in to comment.