From f80bf7b7c1a4ded5aba26ff64314ed890b860ee5 Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Fri, 22 Nov 2024 19:24:13 +0000 Subject: [PATCH] update unit tests --- Core/WebCacheManager.swift | 1 - DuckDuckGo.xcodeproj/project.pbxproj | 8 + DuckDuckGoTests/CookieStorageTests.swift | 219 ++++-------------- DuckDuckGoTests/DataStoreIdManagerTests.swift | 31 +-- .../FireButtonReferenceTests.swift | 59 +---- DuckDuckGoTests/MockFireproofing.swift | 37 +++ DuckDuckGoTests/MockTabDelegate.swift | 4 +- DuckDuckGoTests/MockWebsiteDataManager.swift | 35 +++ .../OnboardingDaxFavouritesTests.swift | 6 +- .../OnboardingNavigationDelegateTests.swift | 5 +- .../PrivacyProDataReporterTests.swift | 4 +- DuckDuckGoTests/WebCacheManagerTests.swift | 16 +- 12 files changed, 156 insertions(+), 269 deletions(-) create mode 100644 DuckDuckGoTests/MockFireproofing.swift create mode 100644 DuckDuckGoTests/MockWebsiteDataManager.swift diff --git a/Core/WebCacheManager.swift b/Core/WebCacheManager.swift index 7e66ef0ed8..7390983add 100644 --- a/Core/WebCacheManager.swift +++ b/Core/WebCacheManager.swift @@ -41,7 +41,6 @@ extension HTTPCookie { } -@MainActor public protocol WebsiteDataManaging { func removeCookies(forDomains domains: [String], fromDataStore: WKWebsiteDataStore) async diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 052e9699ed..836714553a 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -565,6 +565,8 @@ 85C2971A248162CA0063A335 /* DaxOnboardingPadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C29719248162CA0063A335 /* DaxOnboardingPadViewController.swift */; }; 85C503F92CEF78C10075DF6F /* DataStoreIdManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C503F82CEF78C00075DF6F /* DataStoreIdManager.swift */; }; 85C503FB2CF0ADCE0075DF6F /* WebCacheManager+ObservationsDataClearing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C503FA2CF0ADBD0075DF6F /* WebCacheManager+ObservationsDataClearing.swift */; }; + 85C503FD2CF0E7B10075DF6F /* MockFireproofing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C503FC2CF0E7B10075DF6F /* MockFireproofing.swift */; }; + 85C503FF2CF0F4DC0075DF6F /* MockWebsiteDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C503FE2CF0F4D60075DF6F /* MockWebsiteDataManager.swift */; }; 85C8E61D2B0E47380029A6BD /* BookmarksDatabaseSetup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85C8E61C2B0E47380029A6BD /* BookmarksDatabaseSetup.swift */; }; 85C91CA224671F4C00A11132 /* AppDeepLinkSchemes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17D723B1E8BB374003E8B0E /* AppDeepLinkSchemes.swift */; }; 85D2187024BF24DB004373D2 /* FaviconRequestModifierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85D2186F24BF24DB004373D2 /* FaviconRequestModifierTests.swift */; }; @@ -1880,6 +1882,8 @@ 85C29719248162CA0063A335 /* DaxOnboardingPadViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaxOnboardingPadViewController.swift; sourceTree = ""; }; 85C503F82CEF78C00075DF6F /* DataStoreIdManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStoreIdManager.swift; sourceTree = ""; }; 85C503FA2CF0ADBD0075DF6F /* WebCacheManager+ObservationsDataClearing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WebCacheManager+ObservationsDataClearing.swift"; sourceTree = ""; }; + 85C503FC2CF0E7B10075DF6F /* MockFireproofing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockFireproofing.swift; sourceTree = ""; }; + 85C503FE2CF0F4D60075DF6F /* MockWebsiteDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWebsiteDataManager.swift; sourceTree = ""; }; 85C8E61C2B0E47380029A6BD /* BookmarksDatabaseSetup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksDatabaseSetup.swift; sourceTree = ""; }; 85CA53A324B9F2BD00A6288C /* Favicons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Favicons.swift; sourceTree = ""; }; 85CA53A924BB376800A6288C /* NotFoundCachingDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NotFoundCachingDownloader.swift; path = ../Core/NotFoundCachingDownloader.swift; sourceTree = ""; }; @@ -6080,6 +6084,7 @@ F17669A91E412A17003D3222 /* Mocks */ = { isa = PBXGroup; children = ( + 85C503FE2CF0F4D60075DF6F /* MockWebsiteDataManager.swift */, 8598D2E52CEBAA1B00C45685 /* MockFaviconStore.swift */, 9F4CC51A2C48C0C7006A96EB /* MockTabDelegate.swift */, C14882E927F20DD000D59F0C /* MockBookmarksCoreDataStorage.swift */, @@ -6099,6 +6104,7 @@ 9F69331C2C5A191400CD6A5D /* MockTutorialSettings.swift */, 852409302C78030D00CB28FC /* MockUsageSegmentation.swift */, 4B27FBB72C93F53B007E21A7 /* MockPersistentPixel.swift */, + 85C503FC2CF0E7B10075DF6F /* MockFireproofing.swift */, ); name = Mocks; sourceTree = ""; @@ -8146,6 +8152,7 @@ 316790E52C9352190090B0A2 /* MarketplaceAdPostbackManagerTests.swift in Sources */, F194FAFB1F14E622009B4DF8 /* UIFontExtensionTests.swift in Sources */, BBFF18B12C76448100C48D7D /* QuerySubmittedTests.swift in Sources */, + 85C503FF2CF0F4DC0075DF6F /* MockWebsiteDataManager.swift in Sources */, 854A8D812C7F4452001D62E5 /* AtbTests.swift in Sources */, 9F23B8092C2BE9B700950875 /* MockURLOpener.swift in Sources */, 9F8007262C5261AF003EDAF4 /* MockPrivacyDataReporter.swift in Sources */, @@ -8173,6 +8180,7 @@ C185ED672BD43DA100BAE9DC /* ImportPasswordsStatusHandlerTests.swift in Sources */, 6FF9AD452CE766F700C5A406 /* NewTabPageControllerPixelTests.swift in Sources */, F198D7981E3A45D90088DA8A /* WKWebViewConfigurationExtensionTests.swift in Sources */, + 85C503FD2CF0E7B10075DF6F /* MockFireproofing.swift in Sources */, 6F3529FF2CDCEDFF00A59170 /* OmniBarLoadingStateBearerTests.swift in Sources */, 564DE45E2C45218500D23241 /* OnboardingNavigationDelegateTests.swift in Sources */, C14E2F7729DE14EA002AC515 /* AutofillInterfaceUsernameTruncatorTests.swift in Sources */, diff --git a/DuckDuckGoTests/CookieStorageTests.swift b/DuckDuckGoTests/CookieStorageTests.swift index 7094a4daeb..5443c591bf 100644 --- a/DuckDuckGoTests/CookieStorageTests.swift +++ b/DuckDuckGoTests/CookieStorageTests.swift @@ -22,186 +22,59 @@ import XCTest import WebKit public class CookieStorageTests: XCTestCase { - - var storage: MigratableCookieStorage! - - // This is updated by the `make` function which preserves any cookies added as part of this test - let fireproofing = UserDefaultsFireproofing.shared - static let userDefaultsSuiteName = "test" - - public override func setUp() { - super.setUp() - let defaults = UserDefaults(suiteName: Self.userDefaultsSuiteName)! - defaults.removePersistentDomain(forName: Self.userDefaultsSuiteName) - storage = MigratableCookieStorage(userDefaults: defaults) - storage.isConsumed = true - fireproofing.clearAll() + func testLoadCookiesFromDefaultsAndRemovalWhenMigrationCompletes() { + let defaults = UserDefaults(suiteName: "test")! + defaults.removeSuite(named: "test") + + addCookies([ + make("example.com", name: "test1", value: "value1"), + make("example.com", name: "test2", value: "value2"), + make("facebook.com", name: "test3", value: "value3"), + ], defaults) + + let storage = MigratableCookieStorage(userDefaults: defaults) + XCTAssertEqual(storage.cookies.count, 3) + + XCTAssertTrue(storage.cookies.contains(where: { + $0.domain == "example.com" && + $0.name == "test1" && + $0.value == "value1" + })) + + XCTAssertTrue(storage.cookies.contains(where: { + $0.domain == "example.com" && + $0.name == "test2" && + $0.value == "value2" + })) + + XCTAssertTrue(storage.cookies.contains(where: { + $0.domain == "facebook.com" && + $0.name == "test3" && + $0.value == "value3" + })) + + // Now remove them all + storage.migrationComplete() + + XCTAssertTrue(storage.cookies.isEmpty) } - - func testWhenDomainRemovesAllCookesThenTheyAreClearedFromPersisted() { - fireproofing.addToAllowed(domain: "example.com") - - XCTAssertEqual(storage.updateCookies([ - make("example.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing), .empty) - XCTAssertEqual(1, storage.cookies.count) - - storage.isConsumed = true - storage.updateCookies([], preservingFireproofedDomains: fireproofing) + func addCookies(_ cookies: [HTTPCookie], _ defaults: UserDefaults) { - XCTAssertEqual(0, storage.cookies.count) + var cookieData = [[String: Any?]]() + cookies.forEach { cookie in + var mappedCookie = [String: Any?]() + cookie.properties?.forEach { + mappedCookie[$0.key.rawValue] = $0.value + } + cookieData.append(mappedCookie) + } + defaults.setValue(cookieData, forKey: MigratableCookieStorage.Keys.allowedCookies) } - func testWhenUpdatedThenDuckDuckGoCookiesAreNotRemoved() { - storage.updateCookies([ - make("duckduckgo.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(1, storage.cookies.count) - - storage.isConsumed = true - storage.updateCookies([ - make("duckduckgo.com", name: "x", value: "1"), - make("test.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(2, storage.cookies.count) - - storage.isConsumed = true - storage.updateCookies([ - make("usedev1.duckduckgo.com", name: "x", value: "1"), - make("duckduckgo.com", name: "x", value: "1"), - make("test.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(3, storage.cookies.count) - - } - - func testWhenUpdatedThenCookiesWithFutureExpirationAreNotRemoved() { - storage.updateCookies([ - make("test.com", name: "x", value: "1", expires: .distantFuture), - make("example.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(2, storage.cookies.count) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "test.com" })) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "example.com" })) - - } - - func testWhenUpdatingThenExistingExpiredCookiesAreRemoved() { - storage.cookies = [ - make("test.com", name: "x", value: "1", expires: Date(timeIntervalSinceNow: -100)), - ] - XCTAssertEqual(1, storage.cookies.count) - - storage.isConsumed = true - storage.updateCookies([ - make("example.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(1, storage.cookies.count) - XCTAssertFalse(storage.cookies.contains(where: { $0.domain == "test.com" })) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "example.com" })) - - } - - func testWhenExpiredCookieIsAddedThenItIsNotPersisted() { - - storage.updateCookies([ - make("example.com", name: "x", value: "1", expires: Date(timeIntervalSinceNow: -100)), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(0, storage.cookies.count) - - } - - func testWhenUpdatedThenNoLongerFireproofedDomainsAreCleared() { - storage.updateCookies([ - make("test.com", name: "x", value: "1"), - make("example.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - fireproofing.remove(domain: "test.com") - - storage.isConsumed = true - storage.updateCookies([ - make("example.com", name: "x", value: "1"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(1, storage.cookies.count) - XCTAssertFalse(storage.cookies.contains(where: { $0.domain == "test.com" })) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "example.com" })) - } - - func testWhenStorageInitialiedThenItIsEmptyAndIsReadyToBeUpdated() { - XCTAssertEqual(0, storage.cookies.count) - XCTAssertTrue(storage.isConsumed) - } - - func testWhenStorageIsUpdatedThenConsumedIsResetToFalse() { - storage.isConsumed = true - XCTAssertTrue(storage.isConsumed) - storage.updateCookies([ - make("test.com", name: "x", value: "1") - ], preservingFireproofedDomains: fireproofing) - XCTAssertFalse(storage.isConsumed) - } - - func testWhenStorageIsReinstanciatedThenUsesStoredData() { - storage.updateCookies([ - make("test.com", name: "x", value: "1") - ], preservingFireproofedDomains: fireproofing) - storage.isConsumed = true - - let otherStorage = MigratableCookieStorage(userDefaults: UserDefaults(suiteName: Self.userDefaultsSuiteName)!) - XCTAssertEqual(1, otherStorage.cookies.count) - XCTAssertTrue(otherStorage.isConsumed) - } - - func testWhenStorageIsUpdatedThenUpdatingAddsNewCookies() { - storage.updateCookies([ - make("test.com", name: "x", value: "1") - ], preservingFireproofedDomains: fireproofing) - XCTAssertEqual(1, storage.cookies.count) - } - - func testWhenStorageHasMatchingDOmainThenUpdatingReplacesCookies() { - storage.updateCookies([ - make("test.com", name: "x", value: "1") - ], preservingFireproofedDomains: fireproofing) - - storage.isConsumed = true - storage.updateCookies([ - make("test.com", name: "x", value: "2"), - make("test.com", name: "y", value: "3"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(2, storage.cookies.count) - XCTAssertFalse(storage.cookies.contains(where: { $0.domain == "test.com" && $0.name == "x" && $0.value == "1" })) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "test.com" && $0.name == "x" && $0.value == "2" })) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "test.com" && $0.name == "y" && $0.value == "3" })) - } - - func testWhenStorageUpdatedAndNotConsumedThenNothingHappens() { - storage.updateCookies([ - make("test.com", name: "x", value: "1") - ], preservingFireproofedDomains: fireproofing) - - storage.updateCookies([ - make("example.com", name: "y", value: "3"), - ], preservingFireproofedDomains: fireproofing) - - XCTAssertEqual(1, storage.cookies.count) - XCTAssertTrue(storage.cookies.contains(where: { $0.domain == "test.com" && $0.name == "x" && $0.value == "1" })) - } - func make(_ domain: String, name: String, value: String, expires: Date? = nil) -> HTTPCookie { - fireproofing.addToAllowed(domain: domain) return HTTPCookie(properties: [ .domain: domain, .name: name, @@ -210,5 +83,5 @@ public class CookieStorageTests: XCTestCase { .expires: expires as Any ])! } - + } diff --git a/DuckDuckGoTests/DataStoreIdManagerTests.swift b/DuckDuckGoTests/DataStoreIdManagerTests.swift index f4d1e3d2df..d507fb41da 100644 --- a/DuckDuckGoTests/DataStoreIdManagerTests.swift +++ b/DuckDuckGoTests/DataStoreIdManagerTests.swift @@ -26,45 +26,26 @@ import TestUtils class DataStoreIdManagerTests: XCTestCase { - func testWhenFreshlyInstalledThenIdIsAllocated() { + func testWhenFreshlyInstalledThenNoIdIsAllocated() { let manager = DataStoreIdManager(store: MockKeyValueStore()) - XCTAssertNil(manager.currentId) - manager.invalidateCurrentIdAndAllocateNew() - XCTAssertNotNil(manager.currentId) } - func testWhenIdIsInvalidatedThenNewIsCreated() { - + func testWhenIdIsInvalidatedThenNoNewIdIsCreated() { let manager = DataStoreIdManager(store: MockKeyValueStore()) - XCTAssertNil(manager.currentId) - manager.invalidateCurrentIdAndAllocateNew() - - let firstID = manager.currentId - XCTAssertNotNil(firstID) - - manager.invalidateCurrentIdAndAllocateNew() - let secondID = manager.currentId - - XCTAssertNotEqual(firstID, secondID) - - manager.invalidateCurrentIdAndAllocateNew() - let thirdID = manager.currentId - - XCTAssertNotEqual(firstID, thirdID) - XCTAssertNotEqual(secondID, thirdID) + manager.invalidateCurrentId() + XCTAssertNil(manager.currentId) } func testWhenIdAlreadyExistsThenItIsRedFromTheStore() { - let storedUUID = UUID().uuidString let store = MockKeyValueStore() store.set(storedUUID, forKey: DataStoreIdManager.Constants.currentWebContainerId.rawValue) - let manager = DataStoreIdManager(store: store) - XCTAssertEqual(manager.currentId?.uuidString, storedUUID) + manager.invalidateCurrentId() + XCTAssertNil(manager.currentId) } } diff --git a/DuckDuckGoTests/FireButtonReferenceTests.swift b/DuckDuckGoTests/FireButtonReferenceTests.swift index c786184548..93e7801d04 100644 --- a/DuckDuckGoTests/FireButtonReferenceTests.swift +++ b/DuckDuckGoTests/FireButtonReferenceTests.swift @@ -48,7 +48,7 @@ final class FireButtonReferenceTests: XCTestCase { @MainActor func testClearDataUsingLegacyContainer() async throws { // Using WKWebsiteDataStore(forIdentifier:) doesn't persist cookies in a testable way, so use the legacy container here. - let fireproofing = UserDefaultsFireproofing.shared + let fireproofing = UserDefaultsFireproofing.xshared fireproofing.clearAll() for site in testData.fireButtonFireproofing.fireproofedSites { @@ -60,8 +60,6 @@ final class FireButtonReferenceTests: XCTestCase { let referenceTests = testData.fireButtonFireproofing.tests.filter { $0.exceptPlatforms.contains("ios-browser") == false } - - let cookieStorage = MigratableCookieStorage() for test in referenceTests { let cookie = try XCTUnwrap(cookie(for: test)) @@ -69,15 +67,13 @@ final class FireButtonReferenceTests: XCTestCase { let warmup = DataStoreWarmup() await warmup.ensureReady(applicationState: .unknown) - let cookieStore = WKWebsiteDataStore.default().httpCookieStore + let dataStore = WKWebsiteDataStore.default() + let cookieStore = dataStore.httpCookieStore await cookieStore.setCookie(cookie) - - // Pretend the webview was loaded and the cookies were previously consumed - cookieStorage.isConsumed = true - - await WebCacheManager.shared.clear(cookieStorage: cookieStorage, fireproofing: fireproofing, dataStoreIdManager: DataStoreIdManager(store: MockKeyValueStore())) - let testCookie = cookieStorage.cookies.filter { $0.name == test.cookieName }.first + await WebCacheManager(cookieStorage: MigratableCookieStorage(), fireproofing: fireproofing, dataStoreIdManager: DataStoreIdManager(store: MockKeyValueStore())).clear(dataStore: dataStore) + + let testCookie = await cookieStore.allCookies().filter { $0.name == test.cookieName }.first if test.expectCookieRemoved { XCTAssertNil(testCookie, "Cookie should not exist for test: \(test.name)") @@ -86,52 +82,11 @@ final class FireButtonReferenceTests: XCTestCase { } // Reset cache - cookieStorage.cookies = [] + // cookieStorage.cookies = [] } } - - func testCookieStorage() throws { - let fireproofing = UserDefaultsFireproofing.shared - fireproofing.clearAll() - - for site in testData.fireButtonFireproofing.fireproofedSites { - let sanitizedSite = sanitizedSite(site) - print("Adding %s to fireproofed sites", sanitizedSite) - fireproofing.addToAllowed(domain: sanitizedSite) - } - - let referenceTests = testData.fireButtonFireproofing.tests.filter { - $0.exceptPlatforms.contains("ios-browser") == false - } - - let cookieStorage = MigratableCookieStorage() - cookieStorage.isConsumed = true - for test in referenceTests { - let cookie = try XCTUnwrap(cookie(for: test)) - - // Pretend the webview was loaded and the cookies were previously consumed - cookieStorage.isConsumed = true - - // This simulates loading the cookies from the current web view data stores and updating the storage - cookieStorage.updateCookies([ - cookie - ], preservingFireproofedDomains: fireproofing) - let testCookie = cookieStorage.cookies.filter { $0.name == test.cookieName }.first - - if test.expectCookieRemoved { - XCTAssertNil(testCookie, "Cookie should not exist for test: \(test.name)") - } else { - XCTAssertNotNil(testCookie, "Cookie should exist for test: \(test.name)") - } - - // Reset cache - cookieStorage.cookies = [] - cookieStorage.isConsumed = true - } - } - private func cookie(for test: Test) -> HTTPCookie? { HTTPCookie(properties: [.name: test.cookieName, .path: "", diff --git a/DuckDuckGoTests/MockFireproofing.swift b/DuckDuckGoTests/MockFireproofing.swift new file mode 100644 index 0000000000..15e4bd3e24 --- /dev/null +++ b/DuckDuckGoTests/MockFireproofing.swift @@ -0,0 +1,37 @@ +// +// MockFireproofing.swift +// DuckDuckGo +// +// 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 Foundation +import XCTest +@testable import Core + +// MARK: Mocks + +class MockFireproofing: UserDefaultsFireproofing { + override var allowedDomains: [String] { + return domains + } + + let domains: [String] + init(domains: [String] = []) { + self.domains = domains + } + +} + diff --git a/DuckDuckGoTests/MockTabDelegate.swift b/DuckDuckGoTests/MockTabDelegate.swift index fefb80faa7..6b50f42973 100644 --- a/DuckDuckGoTests/MockTabDelegate.swift +++ b/DuckDuckGoTests/MockTabDelegate.swift @@ -138,7 +138,9 @@ extension TabViewController { urlCredentialCreator: MockCredentialCreator(), featureFlagger: featureFlagger, subscriptionCookieManager: SubscriptionCookieManagerMock(), - textZoomCoordinator: MockTextZoomCoordinator() + textZoomCoordinator: MockTextZoomCoordinator(), + websiteDataManager: MockWebsiteDataManager(), + fireproofing: MockFireproofing() ) tab.attachWebView(configuration: .nonPersistent(), andLoadRequest: nil, consumeCookies: false, customWebView: customWebView) return tab diff --git a/DuckDuckGoTests/MockWebsiteDataManager.swift b/DuckDuckGoTests/MockWebsiteDataManager.swift new file mode 100644 index 0000000000..441b28cb76 --- /dev/null +++ b/DuckDuckGoTests/MockWebsiteDataManager.swift @@ -0,0 +1,35 @@ +// +// MockWebsiteDataManager.swift +// DuckDuckGo +// +// 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 WebKit + +@testable import Core + +class MockWebsiteDataManager: WebsiteDataManaging { + + func removeCookies(forDomains domains: [String], fromDataStore: WKWebsiteDataStore) async { + } + + func consumeCookies(intoHTTPCookieStore httpCookieStore: WKHTTPCookieStore) async { + } + + func clear(dataStore: WKWebsiteDataStore) async { + } + +} diff --git a/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift b/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift index 3aa6866fb5..b266186908 100644 --- a/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift +++ b/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift @@ -34,6 +34,8 @@ final class OnboardingDaxFavouritesTests: XCTestCase { private var tutorialSettingsMock: MockTutorialSettings! private var contextualOnboardingLogicMock: ContextualOnboardingLogicMock! + let mockWebsiteDataManager = MockWebsiteDataManager() + override func setUpWithError() throws { try super.setUpWithError() let db = CoreDataDatabase.bookmarksMock @@ -82,8 +84,10 @@ final class OnboardingDaxFavouritesTests: XCTestCase { subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled, voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true), featureFlagger: MockFeatureFlagger(), + fireproofing: MockFireproofing(), subscriptionCookieManager: SubscriptionCookieManagerMock(), - textZoomCoordinator: MockTextZoomCoordinator() + textZoomCoordinator: MockTextZoomCoordinator(), + websiteDataManager: mockWebsiteDataManager ) let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIViewController() diff --git a/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift b/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift index 52e2da5b9a..7c1f47bc6b 100644 --- a/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift +++ b/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift @@ -80,8 +80,11 @@ final class OnboardingNavigationDelegateTests: XCTestCase { subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled, voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true), featureFlagger: MockFeatureFlagger(), + fireproofing: MockFireproofing(), subscriptionCookieManager: SubscriptionCookieManagerMock(), - textZoomCoordinator: MockTextZoomCoordinator()) + textZoomCoordinator: MockTextZoomCoordinator(), + websiteDataManager: MockWebsiteDataManager() + ) let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIViewController() window.makeKeyAndVisible() diff --git a/DuckDuckGoTests/Subscription/PrivacyProDataReporterTests.swift b/DuckDuckGoTests/Subscription/PrivacyProDataReporterTests.swift index 65597fd1a0..b54c2f20fa 100644 --- a/DuckDuckGoTests/Subscription/PrivacyProDataReporterTests.swift +++ b/DuckDuckGoTests/Subscription/PrivacyProDataReporterTests.swift @@ -73,6 +73,7 @@ final class PrivacyProDataReporterTests: XCTestCase { autofillCheck: { true }, secureVaultMaker: { nil }, tabsModel: TabsModel(tabs: [], desktop: false), + fireproofing: MockFireproofing(), dateGenerator: mockCalendar.now ) anotherReporter = PrivacyProDataReporter( @@ -85,7 +86,8 @@ final class PrivacyProDataReporterTests: XCTestCase { featureFlagger: MockFeatureFlagger(), autofillCheck: { true }, secureVaultMaker: { nil }, - tabsModel: TabsModel(tabs: [Tab(), Tab(), Tab(), Tab()], desktop: false) + tabsModel: TabsModel(tabs: [Tab(), Tab(), Tab(), Tab()], desktop: false), + fireproofing: MockFireproofing() ) } diff --git a/DuckDuckGoTests/WebCacheManagerTests.swift b/DuckDuckGoTests/WebCacheManagerTests.swift index 0628268239..b2b9d253a6 100644 --- a/DuckDuckGoTests/WebCacheManagerTests.swift +++ b/DuckDuckGoTests/WebCacheManagerTests.swift @@ -22,6 +22,7 @@ import XCTest import WebKit import TestUtils +/* class WebCacheManagerTests: XCTestCase { override func setUp() { @@ -195,18 +196,5 @@ class WebCacheManagerTests: XCTestCase { let pool = WebCacheManager.shared.getValidDatabasePool() XCTAssertNotNil(pool, "DatabasePool should not be nil") } - - // MARK: Mocks - - class MockFireproofing: UserDefaultsFireproofing { - override var allowedDomains: [String] { - return domains - } - - let domains: [String] - init(domains: [String]) { - self.domains = domains - } - } - } +*/