-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTabManagerStoreTests.swift
101 lines (83 loc) · 3.48 KB
/
TabManagerStoreTests.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
/* 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/. */
@testable import Client
import Shared
import Storage
import UIKit
import WebKit
import XCTest
class TabManagerStoreTests: XCTestCase {
let profile = TabManagerMockProfile()
var manager: TabManager!
let configuration = WKWebViewConfiguration()
override func setUp() {
super.setUp()
manager = TabManager(profile: profile, imageStore: nil)
configuration.processPool = WKProcessPool()
if UIDevice.current.userInterfaceIdiom == .pad {
// BVC.viewWillAppear() calls restoreTabs() which interferes with these tests. (On iPhone, ClientTests never dismiss the intro screen, on iPad the intro is a popover on the BVC).
// Wait for this to happen (UIView.window only gets assigned after viewWillAppear()), then begin testing.
let bvc = (UIApplication.shared.delegate as! AppDelegate).browserViewController
let predicate = XCTNSPredicateExpectation(predicate: NSPredicate(format: "view.window != nil"), object: bvc)
wait(for: [predicate], timeout: 20)
}
manager.testClearArchive()
}
override func tearDown() {
super.tearDown()
}
// Without session data, a Tab can't become a SavedTab and get archived
func addTabWithSessionData(isPrivate: Bool = false) {
let tab = Tab(bvc: BrowserViewController.foregroundBVC(), configuration: configuration, isPrivate: isPrivate)
tab.url = URL(string: "http://yahoo.com")!
manager.configureTab(tab, request: URLRequest(url: tab.url!), flushToDisk: false, zombie: false)
tab.sessionData = SessionData(currentPage: 0, urls: [tab.url!], lastUsedTime: Date.now())
}
func testNoData() {
XCTAssertEqual(manager.testTabCountOnDisk(), 0, "Expected 0 tabs on disk")
XCTAssertEqual(manager.testCountRestoredTabs(), 0)
}
func testPrivateTabsAreArchived() {
for _ in 0..<2 {
addTabWithSessionData(isPrivate: true)
}
let e = expectation(description: "saved")
manager.storeChanges().uponQueue(.main) {_ in
XCTAssertEqual(self.manager.testTabCountOnDisk(), 2)
e.fulfill()
}
waitForExpectations(timeout: 2, handler: nil)
}
func testAddedTabsAreStored() {
// Add 2 tabs
for _ in 0..<2 {
addTabWithSessionData()
}
var e = expectation(description: "saved")
manager.storeChanges().uponQueue(.main) { _ in
XCTAssertEqual(self.manager.testTabCountOnDisk(), 2)
e.fulfill()
}
waitForExpectations(timeout: 2, handler: nil)
// Add 2 more
for _ in 0..<2 {
addTabWithSessionData()
}
e = expectation(description: "saved")
manager.storeChanges().uponQueue(.main) { _ in
XCTAssertEqual(self.manager.testTabCountOnDisk(), 4)
e.fulfill()
}
waitForExpectations(timeout: 2, handler: nil)
// Remove all tabs, and add just 1 tab
manager.removeAll()
addTabWithSessionData()
e = expectation(description: "saved")
manager.storeChanges().uponQueue(.main) {_ in
XCTAssertEqual(self.manager.testTabCountOnDisk(), 1)
e.fulfill()
}
waitForExpectations(timeout: 2, handler: nil)
}
}