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
import XCTest
final class ScrollPerformanceTests: XCTestCase {
func testFeedDoesNotBuildEveryRowBeforeScrolling() {
assertLazyFeed(fixture: "-ui-testing-image-scroll", firstPostID: "image-scroll-0", rowCount: 24)
}
func testRichFeedDoesNotBuildEveryRowBeforeScrolling() {
assertLazyFeed(
fixture: "-ui-testing-rich-scroll",
firstPostID: "at://mae.example/app.bsky.feed.post/scroll-0-main", rowCount: 48
)
}
private func assertLazyFeed(fixture: String, firstPostID: String, rowCount: Int) {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", fixture, "-profile-view-updates"
]
app.launch()
XCTAssertTrue(app.buttons["postText-\(firstPostID)"].waitForExistence(timeout: 10))
app.buttons["Read view update counts"].tap()
let snapshot = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
let createdRows = snapshot.split(separator: ";").filter { $0.hasPrefix("FeedPostRow-") }
let attachment = XCTAttachment(string: snapshot)
attachment.name = "Feed rows created before scrolling"
attachment.lifetime = .keepAlways
add(attachment)
print("Feed rows created before scrolling: \(createdRows.count). \(snapshot)")
XCTAssertGreaterThan(createdRows.count, 0)
XCTAssertLessThan(
createdRows.count, rowCount,
"The feed must leave offscreen rows unbuilt until they approach the viewport."
)
}
func testImageFeedScrolling() {
measureScrolling(fixture: "-ui-testing-image-scroll", firstPostID: "image-scroll-0", waitsForImage: true)
}
func testRichFeedScrolling() {
measureScrolling(
fixture: "-ui-testing-rich-scroll",
firstPostID: "at://mae.example/app.bsky.feed.post/scroll-0-main"
)
}
private func measureScrolling(fixture: String, firstPostID: String, waitsForImage: Bool = false) {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", fixture]
let options = XCTMeasureOptions()
options.iterationCount = 5
options.invocationOptions = [.manuallyStart, .manuallyStop]
measure(
metrics: [
XCTOSSignpostMetric.scrollingAndDecelerationMetric,
XCTCPUMetric(application: app),
XCTMemoryMetric(application: app)
], options: options
) {
app.launch()
let firstPost = app.buttons["postText-\(firstPostID)"]
XCTAssertTrue(firstPost.waitForExistence(timeout: 10))
if waitsForImage {
let firstRow = app.cells.containing(.button, identifier: "postText-\(firstPostID)").firstMatch
XCTAssertTrue(firstRow.buttons["Attached image"].firstMatch.waitForExistence(timeout: 5))
}
let list = app.collectionViews.firstMatch
startMeasuring()
for _ in 0..<6 { list.swipeUp(velocity: .fast) }
stopMeasuring()
XCTAssertFalse(firstPost.isHittable)
app.terminate()
}
}
}