diff --git a/Blockzilla.xcodeproj/project.pbxproj b/Blockzilla.xcodeproj/project.pbxproj index e1df0c6f8a..0482a1e720 100644 --- a/Blockzilla.xcodeproj/project.pbxproj +++ b/Blockzilla.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 34056D10515852F370C83A01 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAB8E622E994545108473554 /* QuartzCore.framework */; }; 4285B8E0671F40DA543A2E58 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 29B90C056305836CB297FF79 /* AssetsLibrary.framework */; }; 4F582F7B1F44A10F006C744B /* OpenInFocusTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F582F7A1F44A10F006C744B /* OpenInFocusTest.swift */; }; + 4FE4E6F61FBB5E2C001BB779 /* TPSidebarBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE4E6F51FBB5E2C001BB779 /* TPSidebarBadge.swift */; }; 58BD00527359D003DADE601E /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC16C41C8D4A74C79A493D42 /* CoreVideo.framework */; }; 5AFDBB0CF3A9FBA175D2B693 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 427B752EF11959F9C38B12D6 /* AVFoundation.framework */; }; 6616A36F1BD17EFA00C7E493 /* style.css in Resources */ = {isa = PBXBuildFile; fileRef = 6616A36E1BD17EFA00C7E493 /* style.css */; }; @@ -199,6 +200,7 @@ 29B90C056305836CB297FF79 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 427B752EF11959F9C38B12D6 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 4F582F7A1F44A10F006C744B /* OpenInFocusTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenInFocusTest.swift; sourceTree = ""; }; + 4FE4E6F51FBB5E2C001BB779 /* TPSidebarBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TPSidebarBadge.swift; sourceTree = ""; }; 6616A36E1BD17EFA00C7E493 /* style.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = style.css; sourceTree = ""; }; 742C99D31F3A3AD200717D69 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 7449B1361F290F7B001A199D /* af */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -701,6 +703,7 @@ 0BA39A871DD2B8E4005F970A /* Info.plist */, 0BA7B7BF1E9D6C1B0058EA5B /* XCUITests-Bridging-Header.h */, 4F582F7A1F44A10F006C744B /* OpenInFocusTest.swift */, + 4FE4E6F51FBB5E2C001BB779 /* TPSidebarBadge.swift */, ); path = XCUITest; sourceTree = ""; @@ -1289,6 +1292,7 @@ 0B70C1631DE6128900CEF7E0 /* WebsiteMemoryTest.swift in Sources */, 4F582F7B1F44A10F006C744B /* OpenInFocusTest.swift in Sources */, 0BC928CE1E366A6E004AC581 /* AsianLocaleTest.swift in Sources */, + 4FE4E6F61FBB5E2C001BB779 /* TPSidebarBadge.swift in Sources */, 0BA39A861DD2B8E4005F970A /* WebsiteAccessTest.swift in Sources */, 0B0D6BC41F3CDDBB00497D08 /* CollapsedURLTest.swift in Sources */, ); diff --git a/Blockzilla/Lib/TrackingProtection/TrackingProtectionSummaryViewController.swift b/Blockzilla/Lib/TrackingProtection/TrackingProtectionSummaryViewController.swift index f96deed739..781bbea31a 100644 --- a/Blockzilla/Lib/TrackingProtection/TrackingProtectionSummaryViewController.swift +++ b/Blockzilla/Lib/TrackingProtection/TrackingProtectionSummaryViewController.swift @@ -145,6 +145,7 @@ class TrackingProtectionBreakdownItem: UIView { counterLabel.font = UIFont.systemFont(ofSize: 17, weight: .regular) counterLabel.textColor = UIConstants.colors.trackingProtectionPrimary + counterLabel.accessibilityIdentifier = "TrackingProtectionBreakdownItem.counterLabel" addSubview(counterLabel) indicatorView.snp.makeConstraints { make in @@ -314,6 +315,7 @@ class TrackingProtectionToggleView: UIView { addSubview(label) toggle.onTintColor = UIConstants.colors.toggleOn + toggle.accessibilityIdentifier = "TrackingProtectionToggleView.toggleTrackingProtection" addSubview(toggle) borderView.backgroundColor = UIConstants.colors.settingsSeparator @@ -381,6 +383,7 @@ class TrackingProtectionView: UIView { backgroundColor = UIConstants.colors.background closeButton.setImage(#imageLiteral(resourceName: "icon_stop_menu"), for: .normal) + closeButton.accessibilityIdentifier = "TrackingProtectionView.closeButton" addSubview(closeButton) addSubview(scrollView) diff --git a/Blockzilla/URLBar.swift b/Blockzilla/URLBar.swift index 721d88954a..f11b62da64 100644 --- a/Blockzilla/URLBar.swift +++ b/Blockzilla/URLBar.swift @@ -749,6 +749,7 @@ class TrackingProtectionBadge: UIView { counterLabel.textAlignment = .center counterLabel.font = UIFont.boldSystemFont(ofSize: 8) counterLabel.text = "0" + counterLabel.accessibilityIdentifier = "TrackingProtectionBadge.counterLabel" trackingProtectionOff.alpha = 0 addSubview(trackingProtectionOff) diff --git a/XCUITest/TPSidebarBadge.swift b/XCUITest/TPSidebarBadge.swift new file mode 100644 index 0000000000..fcf8482720 --- /dev/null +++ b/XCUITest/TPSidebarBadge.swift @@ -0,0 +1,125 @@ +/* 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 XCTest + +class TrackingProtectionSidebar: BaseTestCase { + + override func setUp() { + super.setUp() + dismissFirstRunUI() + } + + override func tearDown() { + app.terminate() + super.tearDown() + } + + func testActiveProtectionSidebar() { + + // Visit https://www.mozilla.org + loadWebPage("mozilla") + + // Check the correct site is reached + waitForWebPageLoad() + + // Check for the presence of the shield + // Currently, Mozilla has one (1) analytical tracker + XCTAssertEqual(app.staticTexts["TrackingProtectionBadge.counterLabel"].label, "1") + + // Open the tracking protection sidebar + app.otherElements["URLBar.trackingProtectionIcon"].tap() + + // Wait for the sidebar to open + waitforExistence(element: app.staticTexts["Tracking Protection"]) + + // Check for the tracker count in the sidebar + var counters = app.staticTexts.matching(identifier: "TrackingProtectionBreakdownItem.counterLabel") + + // Check for the existence of one (1) analytical tracker on Mozilla + XCTAssertEqual(counters.element(boundBy: 0).label, "0") // Ad Trackers + XCTAssertEqual(counters.element(boundBy: 1).label, "1") // Analytical trackers + XCTAssertEqual(counters.element(boundBy: 2).label, "0") // Social trackers + XCTAssertEqual(counters.element(boundBy: 3).label, "0") // Content trackers + + // Close the sidebar + app.buttons["TrackingProtectionView.closeButton"].tap() + + // Erase the history + app.buttons["ERASE"].tap() + waitforExistence(element: app.staticTexts["Your browsing history has been erased."]) + + // Load another website known for zero (0) trackers + loadWebPage("http://localhost:6573/licenses.html\n") + waitForWebPageLoad() + + // Check for the presence of the shield + // Check for the presence of zero (0) trackers + XCTAssertEqual(app.staticTexts["TrackingProtectionBadge.counterLabel"].label, "0") + + // Open the tracking protection sidebar + app.otherElements["URLBar.trackingProtectionIcon"].tap() + + // Wait for the sidebar to open + waitforExistence(element: app.staticTexts["Tracking Protection"]) + + // Check for the tracker count in the sidebar + counters = app.staticTexts.matching(identifier: "TrackingProtectionBreakdownItem.counterLabel") + for i in 0..