forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopSitesTests.swift
119 lines (93 loc) · 4.39 KB
/
TopSitesTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* 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 WebKit
class TopSitesTests: KIFTestCase {
private var webRoot: String!
override func setUp() {
webRoot = SimplePageServer.start()
}
func createNewTab(){
tester().tapViewWithAccessibilityLabel("Show Tabs")
tester().tapViewWithAccessibilityLabel("Add Tab")
tester().waitForViewWithAccessibilityLabel("Search or enter address")
}
func openURLForPageNumber(pageNo: Int) {
let url = "\(webRoot)/numberedPage.html?page=\(pageNo)"
tester().tapViewWithAccessibilityIdentifier("url")
tester().clearTextFromAndThenEnterTextIntoCurrentFirstResponder("\(url)\n")
tester().waitForWebViewElementWithAccessibilityLabel("Page \(pageNo)")
}
func rotateToLandscape() {
// Rotate to landscape.
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
func rotateToPortrait() {
// Rotate to landscape.
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
// A bit internal :/
func extractTextSizeFromThumbnail(thumbnail: UIView) -> CGFloat? {
guard let contentView = thumbnail.subviews.first, let wrapper = contentView.subviews.first,
let textWrapper = wrapper.subviews.last, let label = textWrapper.subviews.first as? UILabel else { return nil }
return label.font.pointSize
}
func testRotatingOnTopSites() {
// go to top sites. rotate to landscape, rotate back again. ensure it doesn't crash
createNewTab()
rotateToLandscape()
rotateToPortrait()
// go to top sites. rotate to landscape, switch to another tab, switch back to top sites, ensure it doesn't crash
rotateToLandscape()
tester().tapViewWithAccessibilityLabel("History")
tester().tapViewWithAccessibilityLabel("Top sites")
rotateToPortrait()
// go to web page. rotate to landscape. click URL Bar, rotate to portrait. ensure it doesn't crash.
openURLForPageNumber(1)
rotateToLandscape()
tester().tapViewWithAccessibilityIdentifier("url")
tester().waitForViewWithAccessibilityLabel("Top sites")
rotateToPortrait()
tester().tapViewWithAccessibilityLabel("Cancel")
}
func testChangingDyamicFontOnTopSites() {
DynamicFontUtils.restoreDynamicFontSize(tester())
createNewTab()
let thumbnail = tester().waitForViewWithAccessibilityLabel("The Mozilla Project")
let size = extractTextSizeFromThumbnail(thumbnail)
DynamicFontUtils.bumpDynamicFontSize(tester())
let bigSize = extractTextSizeFromThumbnail(thumbnail)
DynamicFontUtils.lowerDynamicFontSize(tester())
let smallSize = extractTextSizeFromThumbnail(thumbnail)
XCTAssertGreaterThan(bigSize!, size!)
XCTAssertGreaterThanOrEqual(size!, smallSize!)
openURLForPageNumber(1) // Needed for the teardown
}
func testRemovingSite() {
// Load a page
tester().tapViewWithAccessibilityIdentifier("url")
let url1 = "\(webRoot)/numberedPage.html?page=1"
tester().clearTextFromAndThenEnterTextIntoCurrentFirstResponder("\(url1)\n")
tester().waitForWebViewElementWithAccessibilityLabel("Page 1")
// Open top sites
tester().tapViewWithAccessibilityIdentifier("url")
tester().tapViewWithAccessibilityLabel("Top sites")
// Verify the row exists and that the Remove Page button is hidden
let row = tester().waitForViewWithAccessibilityLabel("127.0.0.1")
tester().waitForAbsenceOfViewWithAccessibilityLabel("Remove page")
// Long press the row and click the remove button
row.longPressAtPoint(CGPointZero, duration: 1)
tester().tapViewWithAccessibilityLabel("Remove page")
// Close editing mode
tester().tapViewWithAccessibilityLabel("Done")
// Close top sites
tester().tapViewWithAccessibilityLabel("Cancel")
}
override func tearDown() {
DynamicFontUtils.restoreDynamicFontSize(tester())
BrowserUtils.resetToAboutHome(tester())
}
}