From 469e88ce76e54026e3311753715988f1d7a22c37 Mon Sep 17 00:00:00 2001 From: dragosb01 <134391433+dragosb01@users.noreply.github.com> Date: Fri, 12 Jan 2024 11:28:38 +0200 Subject: [PATCH] Add MTE-2019 automated test for URL validation (#3983) --- .../Blockzilla.xcodeproj/project.pbxproj | 4 ++ .../FullFunctionalTests.xctestplan | 1 + .../XCUITest/URLValidationTest.swift | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 focus-ios/focus-ios-tests/XCUITest/URLValidationTest.swift diff --git a/focus-ios/Blockzilla.xcodeproj/project.pbxproj b/focus-ios/Blockzilla.xcodeproj/project.pbxproj index b39d68e8df..ffaa078038 100644 --- a/focus-ios/Blockzilla.xcodeproj/project.pbxproj +++ b/focus-ios/Blockzilla.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 8400575A27353B1800E48144 /* UIPasteBoardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8400575927353B1800E48144 /* UIPasteBoardExtensions.swift */; }; 846A23182668CC4500DB3C37 /* FullScreen.js in Resources */ = {isa = PBXBuildFile; fileRef = 846A23172668CC4500DB3C37 /* FullScreen.js */; }; A89766DA1F57DCA9008183C5 /* (null) in Resources */ = {isa = PBXBuildFile; }; + B101243E2B4EE8C20099F3CA /* URLValidationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B101243D2B4EE8C20099F3CA /* URLValidationTest.swift */; }; B3481A551FCF261900CA2EA6 /* AutocompleteCustomUrlViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3481A541FCF261900CA2EA6 /* AutocompleteCustomUrlViewController.swift */; }; B3AFC2BC1F7C0B9F001AEF38 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3AFC2BB1F7C0B9F001AEF38 /* WebViewController.swift */; }; B3CD41C91FD1027000AEBD58 /* InsetTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3CD41C81FD1027000AEBD58 /* InsetTextField.swift */; }; @@ -674,6 +675,7 @@ A8EA0CE6289A4F4100B99C37 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = et.lproj/Intro.strings; sourceTree = ""; }; A8EA0CE7289A4F4100B99C37 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = et.lproj/Localizable.strings; sourceTree = ""; }; AAB8E622E994545108473554 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + B101243D2B4EE8C20099F3CA /* URLValidationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLValidationTest.swift; sourceTree = ""; }; B3481A541FCF261900CA2EA6 /* AutocompleteCustomUrlViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocompleteCustomUrlViewController.swift; sourceTree = ""; }; B3AFC2BB1F7C0B9F001AEF38 /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; }; B3CD41C81FD1027000AEBD58 /* InsetTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetTextField.swift; sourceTree = ""; }; @@ -1299,6 +1301,7 @@ 58408BA4265FC524003C4E4F /* BasicBrowsing.swift */, D440BC17276B3535003FD9B1 /* ShortcutsTest.swift */, C82F45F228193628000D7D84 /* TestHelpers.swift */, + B101243D2B4EE8C20099F3CA /* URLValidationTest.swift */, ); path = XCUITest; sourceTree = ""; @@ -2481,6 +2484,7 @@ 0BBBED431DD3B78300F9C565 /* SettingAppearanceTest.swift in Sources */, 1D199EF220D813D300CDF976 /* DragAndDropTest.swift in Sources */, 0BBBED411DD3823C00F9C565 /* BaseTestCase.swift in Sources */, + B101243E2B4EE8C20099F3CA /* URLValidationTest.swift in Sources */, 1D47758820C1E66000C074AE /* CopyTest.swift in Sources */, 0B37F9A61E2FCAD4002DF74B /* SearchProviderTest.swift in Sources */, 58408BA5265FC524003C4E4F /* BasicBrowsing.swift in Sources */, diff --git a/focus-ios/focus-ios-tests/FullFunctionalTests.xctestplan b/focus-ios/focus-ios-tests/FullFunctionalTests.xctestplan index 8d55343d5e..bc1c5ca692 100644 --- a/focus-ios/focus-ios-tests/FullFunctionalTests.xctestplan +++ b/focus-ios/focus-ios-tests/FullFunctionalTests.xctestplan @@ -35,6 +35,7 @@ "ShortcutsTest", "TrackingProtectionMenu\/testActiveProtectionSidebar()", "TrackingProtectionMenu\/testProtectionSidebar()", + "URLValidationTest", "WebsiteAccessTests\/testVisitWebsite()" ], "target" : { diff --git a/focus-ios/focus-ios-tests/XCUITest/URLValidationTest.swift b/focus-ios/focus-ios-tests/XCUITest/URLValidationTest.swift new file mode 100644 index 0000000000..400fc56a69 --- /dev/null +++ b/focus-ios/focus-ios-tests/XCUITest/URLValidationTest.swift @@ -0,0 +1,43 @@ +// 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 XCTest + +class URLValidationTest: BaseTestCase { + override func setUp() { + super.setUp() + continueAfterFailure = true + } + + let urlTypes = ["mozilla.org", "mozilla.org/", "https://mozilla.org", "mozilla.org/en", "mozilla.org/en-", + "mozilla.org/en-US", "https://mozilla.org/", "https://mozilla.org/en", "https://mozilla.org/en-US"] + let urlHttpTypes=["http://example.com", "http://example.com/"] + + // https://testrail.stage.mozaws.net/index.php?/cases/view/2460275 + func testDifferentURLTypes() { + for i in urlTypes { + loadAndValidateURL(URL: i) + } + + for i in urlHttpTypes { + loadAndValidateHttpURLs(URL: i) + } + } + + private func loadAndValidateURL(URL: String) { + loadWebPage(URL) + waitForWebPageLoad() + XCTAssertTrue(app.otherElements.staticTexts["Mozilla"].exists, "The website was not loaded properly") + XCTAssertTrue(app.buttons["Menu"].exists) + XCTAssertEqual(app.textFields["URLBar.urlText"].value as? String, "www.mozilla.org") + } + + private func loadAndValidateHttpURLs(URL: String) { + loadWebPage(URL) + waitForWebPageLoad() + XCTAssertTrue(app.otherElements.staticTexts["Example Domain"].exists, "The website was not loaded properly") + XCTAssertEqual(app.textFields["URLBar.urlText"].value as? String, "example.com") + } +}