Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Tracking Protection Sidebar XCUITest (#720)
Browse files Browse the repository at this point in the history
* Tracking Protection Sidebar XCUITest

Added preliminary tracking protection sidebar XCUITest (and new accessibility identifiers)

* Initial review changes

Added waits for certain elements before actions
  • Loading branch information
AaronMT authored Nov 21, 2017
1 parent e84c036 commit f50621c
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Blockzilla.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
4FE4E6F51FBB5E2C001BB779 /* TPSidebarBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TPSidebarBadge.swift; sourceTree = "<group>"; };
6616A36E1BD17EFA00C7E493 /* style.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = style.css; sourceTree = "<group>"; };
742C99D31F3A3AD200717D69 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7449B1361F290F7B001A199D /* af */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -701,6 +703,7 @@
0BA39A871DD2B8E4005F970A /* Info.plist */,
0BA7B7BF1E9D6C1B0058EA5B /* XCUITests-Bridging-Header.h */,
4F582F7A1F44A10F006C744B /* OpenInFocusTest.swift */,
4FE4E6F51FBB5E2C001BB779 /* TPSidebarBadge.swift */,
);
path = XCUITest;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions Blockzilla/URLBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
125 changes: 125 additions & 0 deletions XCUITest/TPSidebarBadge.swift
Original file line number Diff line number Diff line change
@@ -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..<counters.staticTexts.count {
XCTAssertEqual(counters.element(boundBy: i).label, "0")
}

// Close the sidebar
app.buttons["TrackingProtectionView.closeButton"].tap()

// Erase the history
waitforExistence(element: app.buttons["ERASE"])
app.buttons["ERASE"].tap()
waitforExistence(element: app.staticTexts["Your browsing history has been erased."])
}

func testInactiveProtectionSidebar() {

// Visit https://www.mozilla.org
loadWebPage("mozilla")

// Check the correct site is reached
waitForWebPageLoad()

// Open the tracking protection sidebar
app.otherElements["URLBar.trackingProtectionIcon"].tap()

// Wait for the sidebar to open
waitforExistence(element: app.staticTexts["Tracking Protection"])

// Disable tracking protection
waitforExistence(element: app.switches["TrackingProtectionToggleView.toggleTrackingProtection"])
app.switches["TrackingProtectionToggleView.toggleTrackingProtection"].tap()

// Reopen 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
let counters = app.staticTexts.matching(identifier: "TrackingProtectionBreakdownItem.counterLabel")

for i in 0..<counters.staticTexts.count {
XCTAssertEqual(counters.element(boundBy: i).label, "--")
}

// Close the sidebar
app.buttons["TrackingProtectionView.closeButton"].tap()
waitforNoExistence(element: app.staticTexts["TrackingProtectionToggleView.toggleTrackingProtection"])

// Check that no counter exists (tracking protection: disabled)
XCTAssertEqual(app.staticTexts["TrackingProtectionBadge.counterLabel"].exists, false)

// Erase the history
waitforExistence(element: app.buttons["ERASE"])
app.buttons["ERASE"].tap()
waitforExistence(element: app.staticTexts["Your browsing history has been erased."])
}
}

0 comments on commit f50621c

Please sign in to comment.