-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10359ba
commit 6ddab78
Showing
3 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
// | ||
// PinnedTabsTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import XCTest | ||
|
||
class PinnedTabsTests: XCTestCase { | ||
private var app: XCUIApplication! | ||
|
||
override func setUpWithError() throws { | ||
continueAfterFailure = false | ||
app = XCUIApplication() | ||
app.launchEnvironment["UITEST_MODE"] = "1" | ||
app.launch() | ||
|
||
app.typeKey("n", modifierFlags: .command) | ||
} | ||
|
||
override class func setUp() { | ||
UITests.firstRun() | ||
} | ||
|
||
func testPinnedTabsFunctionality() { | ||
openThreeSitesOnSameWindow() | ||
openNewWindowAndLoadSite() | ||
moveBackToPreviousWindows() | ||
|
||
/// It is important that we wait some seconds to execute the navigate tabs commands | ||
/// the reason is that switching windows take its time and the other windows is not show | ||
/// immediately. | ||
sleep(2) | ||
pinsPageOne() | ||
sleep(1) | ||
pinsPageTwo() | ||
sleep (1) | ||
assertsPageTwoIsPinned() | ||
sleep(1) | ||
assertsPageOneIsPinned() | ||
sleep(1) | ||
dragsPageTwoPinnedTabToTheFirstPosition() | ||
sleep(1) | ||
assertsCommandWFunctionality() | ||
assertWindowTwoHasTheTwoPinnedTabFromWindowsOne() | ||
sleep(2) | ||
app.terminate() | ||
assertPinnedTabsRestoredState() | ||
} | ||
|
||
// MARK: - Utilities | ||
|
||
private func openThreeSitesOnSameWindow() { | ||
openSite(pageTitle: "Page #1") | ||
app.openNewTab() | ||
openSite(pageTitle: "Page #2") | ||
app.openNewTab() | ||
openSite(pageTitle: "Page #3") | ||
} | ||
|
||
private func openNewWindowAndLoadSite() { | ||
app.typeKey("n", modifierFlags: .command) | ||
openSite(pageTitle: "Page #4") | ||
} | ||
|
||
private func moveBackToPreviousWindows() { | ||
let menuItem = app.menuItems["Page #3"].firstMatch | ||
XCTAssertTrue( | ||
menuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Reset bookmarks menu item didn't become available in a reasonable timeframe." | ||
) | ||
menuItem.hover() | ||
app.typeKey(XCUIKeyboardKey.return, modifierFlags: []) | ||
} | ||
|
||
private func openSite(pageTitle: String) { | ||
let url = UITests.simpleServedPage(titled: pageTitle) | ||
let addressBarTextField = app.windows.firstMatch.textFields["AddressBarViewController.addressBarTextField"] | ||
XCTAssertTrue( | ||
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"The address bar text field didn't become available in a reasonable timeframe." | ||
) | ||
addressBarTextField.typeURL(url) | ||
XCTAssertTrue( | ||
app.windows.firstMatch.webViews[pageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Visited site didn't load with the expected title in a reasonable timeframe." | ||
) | ||
} | ||
|
||
private func pinsPageOne() { | ||
app.typeKey("[", modifierFlags: [.command, .shift]) | ||
app.typeKey("[", modifierFlags: [.command, .shift]) | ||
app.menuItems["Pin Tab"].tap() | ||
} | ||
|
||
private func pinsPageTwo() { | ||
app.typeKey("]", modifierFlags: [.command, .shift]) | ||
app.menuItems["Pin Tab"].tap() | ||
} | ||
|
||
private func assertsPageTwoIsPinned() { | ||
XCTAssertTrue(app.menuItems["Unpin Tab"].firstMatch.exists) | ||
XCTAssertFalse(app.menuItems["Pin Tab"].firstMatch.exists) | ||
} | ||
|
||
private func assertsPageOneIsPinned() { | ||
app.typeKey("[", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(app.menuItems["Unpin Tab"].firstMatch.exists) | ||
XCTAssertFalse(app.menuItems["Pin Tab"].firstMatch.exists) | ||
} | ||
|
||
private func dragsPageTwoPinnedTabToTheFirstPosition() { | ||
app.typeKey("]", modifierFlags: [.command, .shift]) | ||
let toolbar = app.toolbars.firstMatch | ||
let toolbarCoordinate = toolbar.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)) | ||
let startPoint = toolbarCoordinate.withOffset(CGVector(dx: 120, dy: 15)) | ||
let endPoint = toolbarCoordinate.withOffset(CGVector(dx: 0, dy: 0)) | ||
startPoint.press(forDuration: 0, thenDragTo: endPoint) | ||
|
||
sleep(1) | ||
|
||
/// Asserts the re-order worked by moving to the next tab and checking is Page #1 | ||
app.typeKey("]", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(app.staticTexts["Sample text for Page #1"].exists) | ||
} | ||
|
||
private func assertsCommandWFunctionality() { | ||
app.typeKey("w", modifierFlags: .command) | ||
XCTAssertTrue(app.staticTexts["Sample text for Page #3"].exists) | ||
} | ||
|
||
private func assertWindowTwoHasTheTwoPinnedTabFromWindowsOne() { | ||
let items = app.menuItems.matching(identifier: "Page #4") | ||
let pageFourMenuItem = items.element(boundBy: 1) | ||
XCTAssertTrue( | ||
pageFourMenuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Reset bookmarks menu item didn't become available in a reasonable timeframe." | ||
) | ||
pageFourMenuItem.hover() | ||
app.typeKey(XCUIKeyboardKey.return, modifierFlags: []) | ||
|
||
sleep(2) | ||
|
||
/// Goes to Page #2 to check the state | ||
app.typeKey("[", modifierFlags: [.command, .shift]) | ||
app.typeKey("[", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(app.staticTexts["Sample text for Page #2"].exists) | ||
/// Goes to Page #1 to check the state | ||
app.typeKey("]", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(app.staticTexts["Sample text for Page #1"].exists) | ||
} | ||
|
||
private func assertPinnedTabsRestoredState() { | ||
let newApp = XCUIApplication() | ||
newApp.launch() | ||
|
||
sleep(2) | ||
|
||
/// Goes to Page #2 to check the state | ||
newApp.typeKey("[", modifierFlags: [.command, .shift]) | ||
newApp.typeKey("[", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(newApp.staticTexts["Sample text for Page #2"].waitForExistence(timeout: UITests.Timeouts.elementExistence)) | ||
/// Goes to Page #1 to check the state | ||
newApp.typeKey("]", modifierFlags: [.command, .shift]) | ||
XCTAssertTrue(newApp.staticTexts["Sample text for Page #1"].waitForExistence(timeout: UITests.Timeouts.elementExistence)) | ||
} | ||
} |