Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MTE-3430 - Add Tracking protection test id 2307063 #21944

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"TrackingProtectionTests\/testLockIconMenu()",
"TrackingProtectionTests\/testLockIconSecureConnection()",
"TrackingProtectionTests\/testProtectionLevelMoreInfoMenu()",
"TrackingProtectionTests\/testStrictTrackingProtection()",
"URLValidationTests",
"UrlBarTests",
"WhatsNewTest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,72 @@
import XCTest
import Common

// swiftlint:disable line_length
let standardBlockedElementsString = "Firefox blocks cross-site trackers, social trackers, cryptominers, and fingerprinters."
let strictBlockedElementsString = "Firefox blocks cross-site trackers, social trackers, cryptominers, fingerprinters, and tracking content."
// swiftlint:enable line_length

// Urls
let websiteWithBlockedElements = "twitter.com"
let differentWebsite = path(forTestPage: "test-example.html")
let trackingProtectionTestUrl = "https://senglehardt.com/test/trackingprotection/test_pages/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How stable is this website? We have had tests that depends on external sites that fail occasionally because the site was slow or implements a CAPTCHA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @clarmso . So far the page is pretty stable but once we use it in a CI environment maybe we can have some issues. The page is a very simple page, with just some links and the test is only opening the webpage, is not using any content. The manual test case use this url, this is why I used the same url. The point is that to check the tracking protection we have to check an element in the padlock in the urlbar, so technically we can use any page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webpage is a mozilla webpage so it should safe to use


// Selectors
let buttonSettings = "Settings"
let buttonDone = "Done"
let reloadButton = "TabLocationView.reloadButton"
let reloadWithWithoutProtectionButton = "shieldSlashLarge"
let secureTrackingProtectionOnLabel = "Secure connection"
let secureTrackingProtectionOffLabel = "Secure connection. Enhanced Tracking Protection is off."

class TrackingProtectionTests: BaseTestCase {
private func disableEnableTrackingProtectionForSite() {
navigator.performAction(Action.TrackingProtectionperSiteToggle)
}

private func checkTrackingProtectionDisabledForSite() {
mozWaitForElementToNotExist(app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection])
}

private func checkTrackingProtectionEnabledForSite() {
navigator.goto(TrackingProtectionContextMenuDetails)
mozWaitForElementToExist(app.cells.staticTexts["Enhanced Tracking Protection is ON for this site."])
}

private func reloadWithWithoutTrackingProtection(label: String) {
mozWaitForElementToExist(app.buttons.element(matching: .button, identifier: reloadButton), timeout: 10)
app.buttons.element(matching: .button, identifier: reloadButton).press(forDuration: 3)
if label == "Without Tracking Protection" {
XCTAssertEqual(
"Reload Without Tracking Protection",
app.otherElements.element(matching: .any, identifier: reloadWithWithoutProtectionButton).label
)
} else {
XCTAssertEqual(
"Reload With Tracking Protection",
app.otherElements.element(
matching: .any,
identifier: reloadWithWithoutProtectionButton
).label
)
}
app.otherElements.element(matching: .any, identifier: reloadWithWithoutProtectionButton).tap()
mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection], timeout: 5)
}

private func enableStrictMode() {
navigator.performAction(Action.EnableStrictMode)
app.buttons[buttonSettings].tap()
app.buttons[buttonDone].tap()
}

func checkTrackingProtectionOn() -> Bool {
var trackingProtection = true
if iPad() {
sleep(1)
}
if app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label
== secureTrackingProtectionOffLabel {
trackingProtection = false
}
return trackingProtection
}

// https://mozilla.testrail.io/index.php?/cases/view/2307059
// Smoketest
func testStandardProtectionLevel() {
Expand Down Expand Up @@ -60,27 +117,6 @@ class TrackingProtectionTests: BaseTestCase {
navigator.performAction(Action.SwitchETP)
}

private func disableEnableTrackingProtectionForSite() {
navigator.performAction(Action.TrackingProtectionperSiteToggle)
}

private func checkTrackingProtectionDisabledForSite() {
mozWaitForElementToNotExist(app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection])
}

private func checkTrackingProtectionEnabledForSite() {
navigator.goto(TrackingProtectionContextMenuDetails)
mozWaitForElementToExist(app.cells.staticTexts["Enhanced Tracking Protection is ON for this site."])
}

private func enableStrictMode() {
navigator.performAction(Action.EnableStrictMode)

// Dismiss the alert and go back to the site
app.alerts.buttons.firstMatch.tap()
app.buttons["Done"].tap()
}

// https://mozilla.testrail.io/index.php?/cases/view/2319381
func testLockIconMenu() {
navigator.openURL(differentWebsite)
Expand Down Expand Up @@ -172,7 +208,10 @@ class TrackingProtectionTests: BaseTestCase {
app.links.staticTexts["expired"].tap()
waitUntilPageLoad()
// The page is correctly displayed with the lock icon disabled
mozWaitForElementToExist(app.staticTexts["This Connection is Untrusted"], timeout: TIMEOUT_LONG)
mozWaitForElementToExist(
app.staticTexts["This Connection is Untrusted"],
timeout: TIMEOUT_LONG
)
mozWaitForElementToExist(app.staticTexts.elementContainingText("Firefox has not connected to this website."))
XCTAssertEqual(app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label, "Connection not secure")
}
Expand All @@ -193,4 +232,47 @@ class TrackingProtectionTests: BaseTestCase {
navigator.performAction(Action.CloseTPContextMenu)
mozWaitForElementToNotExist(app.staticTexts["Secure connection"])
}

// https://mozilla.testrail.io/index.php?/cases/view/2307063
func testStrictTrackingProtection() {
navigator.goto(TrackingProtectionSettings)
// Enable Strict Protection Level
enableStrictMode()
navigator.nowAt(BrowserTab)
navigator.openURL(trackingProtectionTestUrl)

if checkTrackingProtectionOn() {
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOnLabel
)
navigator.nowAt(BrowserTab)
reloadWithWithoutTrackingProtection(label: "Without Tracking Protection")
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOffLabel
)
reloadWithWithoutTrackingProtection(label: "With Tracking Protection")
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOnLabel
)
} else {
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOffLabel
)
navigator.nowAt(BrowserTab)
reloadWithWithoutTrackingProtection(label: "With Tracking Protection")
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOnLabel
)
reloadWithWithoutTrackingProtection(label: "Without Tracking Protection")
XCTAssertEqual(
app.buttons[AccessibilityIdentifiers.Toolbar.trackingProtection].label,
secureTrackingProtectionOffLabel
)
}
}
}
Loading