mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 09:18:42 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
84
mobile/ios/ClientTests/PanelDataObserversTests.swift
Normal file
84
mobile/ios/ClientTests/PanelDataObserversTests.swift
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* 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 Shared
|
||||
import XCTest
|
||||
@testable import Client
|
||||
|
||||
private class MockDataObserverDelegate: DataObserverDelegate {
|
||||
var didInvalidateCount = 0
|
||||
var willInvalidateCount = 0
|
||||
var highlightsRefreshCount = 0
|
||||
var topSitesRefreshCount = 0
|
||||
|
||||
func didInvalidateDataSources(refresh forced: Bool, highlightsRefreshed: Bool, topSitesRefreshed: Bool) {
|
||||
didInvalidateCount += 1
|
||||
if highlightsRefreshed {
|
||||
highlightsRefreshCount += 1
|
||||
}
|
||||
|
||||
if topSitesRefreshed {
|
||||
topSitesRefreshCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
func willInvalidateDataSources(forceHighlights highlights: Bool, forceTopSites topSites: Bool) {
|
||||
willInvalidateCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
class PanelDataObserversTests: XCTestCase {
|
||||
func testActivityStreamDelegates() {
|
||||
let profile = MockProfile()
|
||||
let observer = ActivityStreamDataObserver(profile: profile)
|
||||
let delegate = MockDataObserverDelegate()
|
||||
observer.delegate = delegate
|
||||
|
||||
NotificationCenter.default.post(name: NotificationFirefoxAccountChanged,
|
||||
object: nil)
|
||||
NotificationCenter.default.post(name: NotificationProfileDidFinishSyncing,
|
||||
object: nil)
|
||||
NotificationCenter.default.post(name: NotificationPrivateDataClearedHistory,
|
||||
object: nil)
|
||||
|
||||
waitForCondition(timeout: 5) { delegate.didInvalidateCount == 3 && delegate.willInvalidateCount == 3 }
|
||||
}
|
||||
|
||||
func testHighlightsCacheInvalidation20Min() {
|
||||
let profile = MockProfile()
|
||||
let observer = ActivityStreamDataObserver(profile: profile)
|
||||
let delegate = MockDataObserverDelegate()
|
||||
observer.delegate = delegate
|
||||
|
||||
// Set to 20min since refresh
|
||||
profile.prefs.setLong(Date.now() - (OneMinuteInMilliseconds * 20), forKey: PrefsKeys.ASLastInvalidation)
|
||||
observer.refreshIfNeeded(forceHighlights: false, forceTopSites: false)
|
||||
waitForCondition(timeout: 5) { delegate.highlightsRefreshCount == 1 }
|
||||
}
|
||||
|
||||
func testHighlightEmptyCache() {
|
||||
let profile = MockProfile()
|
||||
let observer = ActivityStreamDataObserver(profile: profile)
|
||||
let delegate = MockDataObserverDelegate()
|
||||
observer.delegate = delegate
|
||||
|
||||
// Set to no validation key
|
||||
profile.prefs.removeObjectForKey(PrefsKeys.ASLastInvalidation)
|
||||
observer.refreshIfNeeded(forceHighlights: false, forceTopSites: false)
|
||||
waitForCondition(timeout: 5) { delegate.highlightsRefreshCount == 1 }
|
||||
}
|
||||
|
||||
func testHighlightActiveCache() {
|
||||
let profile = MockProfile()
|
||||
let observer = ActivityStreamDataObserver(profile: profile)
|
||||
let delegate = MockDataObserverDelegate()
|
||||
observer.delegate = delegate
|
||||
|
||||
// Set to 10min since refresh
|
||||
profile.prefs.setLong(Date.now() - (OneMinuteInMilliseconds * 10), forKey: PrefsKeys.ASLastInvalidation)
|
||||
observer.refreshIfNeeded(forceHighlights: false, forceTopSites: false)
|
||||
waitForCondition(timeout: 5) { delegate.didInvalidateCount == 1 && delegate.highlightsRefreshCount == 0 }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue