From 0e1085c017eb7acb6641717c63f5945a8c0de026 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Thu, 9 Jan 2025 14:48:54 +0000 Subject: [PATCH] Uplift of #26870 (squashed) to release --- ios/brave-ios/App/Brave_iPad.xctestplan | 30 ---------- .../App/Client.xcodeproj/project.pbxproj | 2 - .../xcschemes/Debug (AppStore).xcscheme | 3 - .../xcschemes/Debug (No Core).xcscheme | 3 - .../xcshareddata/xcschemes/Debug.xcscheme | 3 - .../App/iOS/Delegates/AppDelegate.swift | 2 +- .../Brave/Frontend/Browser/BraveWebView.swift | 2 +- .../Browser/Search/BraveSearchManager.swift | 4 +- .../Sources/Brave/Frontend/Browser/Tab.swift | 4 +- .../Sources/Playlist/AVKitExtensions.swift | 2 +- .../Playlist/PlaylistDownloadManager.swift | 10 +--- .../Playlist/PlaylistMediaStreamer.swift | 5 +- .../Sources/UserAgent/UserAgent.swift | 15 ++--- .../Tests/UserAgentTests/UserAgentTests.swift | 55 +++---------------- ios/brave-ios/fastlane/Fastfile | 10 ---- 15 files changed, 27 insertions(+), 123 deletions(-) delete mode 100644 ios/brave-ios/App/Brave_iPad.xctestplan diff --git a/ios/brave-ios/App/Brave_iPad.xctestplan b/ios/brave-ios/App/Brave_iPad.xctestplan deleted file mode 100644 index b01419249ce5..000000000000 --- a/ios/brave-ios/App/Brave_iPad.xctestplan +++ /dev/null @@ -1,30 +0,0 @@ -{ - "configurations" : [ - { - "id" : "B360D002-AA9A-450B-99E4-F48566469CC5", - "name" : "Configuration 1", - "options" : { - - } - } - ], - "defaultOptions" : { - "maximumTestRepetitions" : 2, - "testRepetitionMode" : "retryOnFailure" - }, - "testTargets" : [ - { - "selectedTests" : [ - "UserAgentTests\/testDesktopUserAgent()", - "UserAgentTests\/testFirstUAPart()", - "UserAgentTests\/testIpadMobileUserAgent()" - ], - "target" : { - "containerPath" : "container:..", - "identifier" : "UserAgentTests", - "name" : "UserAgentTests" - } - } - ], - "version" : 1 -} diff --git a/ios/brave-ios/App/Client.xcodeproj/project.pbxproj b/ios/brave-ios/App/Client.xcodeproj/project.pbxproj index 1372d01c500b..52aaf22064f4 100644 --- a/ios/brave-ios/App/Client.xcodeproj/project.pbxproj +++ b/ios/brave-ios/App/Client.xcodeproj/project.pbxproj @@ -183,7 +183,6 @@ 0A5E04F823FEADA800E5A3E9 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 0A5E04FA23FEB53700E5A3E9 /* LaunchScreen.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = LaunchScreen.xcassets; sourceTree = ""; }; 0A60A1882358AF9E00953CA8 /* Brave.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = Brave.xctestplan; path = Client.xcodeproj/Brave.xctestplan; sourceTree = ""; }; - 0A66550D23E9EA540047EF2A /* Brave_iPad.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Brave_iPad.xctestplan; sourceTree = ""; }; 0A6AC4E824484FBC003D1ED7 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 2703FC14284FDB6300970FD2 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = Shortcuts/ru.lproj/BrowserIntents.strings; sourceTree = ""; }; 270ECFC628381E270089B8B7 /* brave-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "brave-ios"; path = ..; sourceTree = ""; }; @@ -790,7 +789,6 @@ 270ECFC628381E270089B8B7 /* brave-ios */, 27D67621282DAD3700BCE16E /* BrowserIntents.intentdefinition */, 0A60A1882358AF9E00953CA8 /* Brave.xctestplan */, - 0A66550D23E9EA540047EF2A /* Brave_iPad.xctestplan */, 0A24F836233EB5B4004D2F3A /* Configuration */, 270ECFC9283824F00089B8B7 /* iOS */, 2FE7D51E2B509DA50039FBA4 /* ActionExtension */, diff --git a/ios/brave-ios/App/Client.xcodeproj/xcshareddata/xcschemes/Debug (AppStore).xcscheme b/ios/brave-ios/App/Client.xcodeproj/xcshareddata/xcschemes/Debug (AppStore).xcscheme index c9cf2965100a..75f93e9148ea 100644 --- a/ios/brave-ios/App/Client.xcodeproj/xcshareddata/xcschemes/Debug (AppStore).xcscheme +++ b/ios/brave-ios/App/Client.xcodeproj/xcshareddata/xcschemes/Debug (AppStore).xcscheme @@ -72,9 +72,6 @@ reference = "container:Client.xcodeproj/Brave.xctestplan" default = "YES"> - - - - - - String { + return shouldUseDesktopMode(idiom: idiom) ? UserAgent.desktop : UserAgent.mobile } - public static var shouldUseDesktopMode: Bool { - if UIDevice.current.userInterfaceIdiom == .pad { - return Preferences.UserAgent.alwaysRequestDesktopSite.value - } - return false + public static func shouldUseDesktopMode( + idiom: UIUserInterfaceIdiom = UIDevice.current.userInterfaceIdiom + ) -> Bool { + return idiom == .pad ? Preferences.UserAgent.alwaysRequestDesktopSite.value : false } } diff --git a/ios/brave-ios/Tests/UserAgentTests/UserAgentTests.swift b/ios/brave-ios/Tests/UserAgentTests/UserAgentTests.swift index f1422efbcc7b..796580b4ff5b 100644 --- a/ios/brave-ios/Tests/UserAgentTests/UserAgentTests.swift +++ b/ios/brave-ios/Tests/UserAgentTests/UserAgentTests.swift @@ -109,63 +109,26 @@ class UserAgentTests: XCTestCase { waitForExpectations(timeout: 60, handler: nil) } - // MARK: iPad only tests - must run on iPad - - func testDesktopUserAgent() { - // Must run on iPad iOS 13+ - if UIDevice.current.userInterfaceIdiom != .pad - || ProcessInfo().operatingSystemVersion.majorVersion < 13 - { - return - } + func testDesktopUserAgentOnPad() { + Preferences.UserAgent.alwaysRequestDesktopSite.value = true XCTAssertTrue(desktopUARegex(UserAgent.desktop), "User agent computes correctly.") - let expectation = self.expectation(description: "Found Firefox user agent") - let webView = BraveWebView(frame: .zero, isPrivate: false) + let userAgent = UserAgent.userAgentForIdiom(.pad) - webView.evaluateSafeJavaScript( - functionName: "navigator.userAgent", - contentWorld: .page, - asFunction: false - ) { result, error in - let userAgent = result as! String - if self.mobileUARegex(userAgent) || !self.desktopUARegex(userAgent) { - XCTFail("User agent did not match expected pattern! \(userAgent)") - } - expectation.fulfill() + if self.mobileUARegex(userAgent) || !self.desktopUARegex(userAgent) { + XCTFail("User agent did not match expected pattern! \(userAgent)") } - - waitForExpectations(timeout: 60, handler: nil) } - func testIpadMobileUserAgent() { - // Must run on iPad iOS 13+ - if UIDevice.current.userInterfaceIdiom != .pad - || ProcessInfo().operatingSystemVersion.majorVersion < 13 - { - return - } - + func testMobileUserAgentOnPad() { Preferences.UserAgent.alwaysRequestDesktopSite.value = false XCTAssertTrue(mobileUARegex(UserAgent.mobile), "User agent computes correctly.") + let userAgent = UserAgent.userAgentForIdiom(.pad) - let expectation = self.expectation(description: "Found Firefox user agent") - let webView = BraveWebView(frame: .zero, isPrivate: false) - - webView.evaluateSafeJavaScript( - functionName: "navigator.userAgent", - contentWorld: .page, - asFunction: false - ) { result, error in - let userAgent = result as! String - if !self.mobileUARegex(userAgent) || self.desktopUARegex(userAgent) { - XCTFail("User agent did not match expected pattern! \(userAgent)") - } - expectation.fulfill() + if !self.mobileUARegex(userAgent) || self.desktopUARegex(userAgent) { + XCTFail("User agent did not match expected pattern! \(userAgent)") } - - waitForExpectations(timeout: 60, handler: nil) } } diff --git a/ios/brave-ios/fastlane/Fastfile b/ios/brave-ios/fastlane/Fastfile index 58b694b83243..2cb4c2cdec7f 100644 --- a/ios/brave-ios/fastlane/Fastfile +++ b/ios/brave-ios/fastlane/Fastfile @@ -20,18 +20,8 @@ platform :ios do defaultScanParams = scan_params() run_tests(defaultScanParams.merge!({ test_without_building: true, - devices: ["iPhone 16 (18.0)"], - ensure_devices_found: true, skip_testing: skipped_tests() })) - - run_tests(defaultScanParams.merge!({ - test_without_building: true, - devices: ["iPad (10th generation) (18.0)"], - ensure_devices_found: true, - output_files: "junit-ipad.xml", - testplan: "Brave_iPad" - })) end desc "Creates a Brave Beta build for TestFlight."