From 8c44b2535c9298fbb87f74d990fa513c86224eae Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Fri, 10 May 2024 16:33:17 +0100 Subject: [PATCH 1/4] ensure bookmarks can be shown in top hits --- Sources/Suggestions/SuggestionProcessing.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/Suggestions/SuggestionProcessing.swift b/Sources/Suggestions/SuggestionProcessing.swift index 27dfcab63..b80dbf20f 100644 --- a/Sources/Suggestions/SuggestionProcessing.swift +++ b/Sources/Suggestions/SuggestionProcessing.swift @@ -157,11 +157,18 @@ final class SuggestionProcessing { if case .bookmark = $0, $0.url?.naked == nakedUrl { return true } return false }), case let Suggestion.bookmark(title: title, url: url, isFavorite: isFavorite, allowedInTopHits: _) = newSuggestion { + #if os(macOS) // Copy allowedInTopHits from original suggestion return Suggestion.bookmark(title: title, url: url, isFavorite: isFavorite, allowedInTopHits: historySuggestion.allowedInTopHits) + #else + return Suggestion.bookmark(title: title, + url: url, + isFavorite: isFavorite, + allowedInTopHits: true) + #endif } else { return nil } @@ -178,10 +185,17 @@ final class SuggestionProcessing { if case .historyEntry = $0, $0.url?.naked == nakedUrl { return true } return false }), historySuggestion.allowedInTopHits { + #if os(macOS) return Suggestion.bookmark(title: title, url: url, isFavorite: isFavorite, allowedInTopHits: historySuggestion.allowedInTopHits) + #else + return Suggestion.bookmark(title: title, + url: url, + isFavorite: isFavorite, + allowedInTopHits: true) + #endif } else { return nil } From 4a3912972322bdc5db3dd59c107f0ea9e0e4bd6e Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Sat, 18 May 2024 00:04:55 +0100 Subject: [PATCH 2/4] call clean with todays date instead trying to use entries which might not have loaded yet --- Sources/History/HistoryCoordinator.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/History/HistoryCoordinator.swift b/Sources/History/HistoryCoordinator.swift index d9fb7f8c6..54d2df181 100644 --- a/Sources/History/HistoryCoordinator.swift +++ b/Sources/History/HistoryCoordinator.swift @@ -161,13 +161,10 @@ final public class HistoryCoordinator: HistoryCoordinating { } public func burnAll(completion: @escaping () -> Void) { - guard let historyDictionary = historyDictionary else { return } - - let entries = Array(historyDictionary.values) - - removeEntries(entries, completionHandler: { _ in + clean(until: Date()) { + self.historyDictionary = [:] completion() - }) + } } public func burnDomains(_ baseDomains: Set, tld: TLD, completion: @escaping () -> Void) { From c5faa4f9a62391124e00cb7f9ee687bc97dc5da6 Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Mon, 20 May 2024 12:11:44 +0100 Subject: [PATCH 3/4] see if unit test line number reported changes --- Tests/HistoryTests/HistoryCoordinatorTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/HistoryTests/HistoryCoordinatorTests.swift b/Tests/HistoryTests/HistoryCoordinatorTests.swift index 6358347b8..d85ddd639 100644 --- a/Tests/HistoryTests/HistoryCoordinatorTests.swift +++ b/Tests/HistoryTests/HistoryCoordinatorTests.swift @@ -134,6 +134,7 @@ class HistoryCoordinatorTests: XCTestCase { XCTAssert(historyCoordinator.history!.count == 4) historyCoordinator.burnAll { + // Test a theory XCTAssert(historyStoringMock.removeEntriesArray.count == 4) } } From 5a6a30add196c5718f5a5daae9aa835560f1c028 Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Mon, 20 May 2024 12:24:19 +0100 Subject: [PATCH 4/4] wait for burn all to finish before asserting --- Tests/HistoryTests/HistoryCoordinatorTests.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/HistoryTests/HistoryCoordinatorTests.swift b/Tests/HistoryTests/HistoryCoordinatorTests.swift index d85ddd639..968f203e9 100644 --- a/Tests/HistoryTests/HistoryCoordinatorTests.swift +++ b/Tests/HistoryTests/HistoryCoordinatorTests.swift @@ -116,6 +116,7 @@ class HistoryCoordinatorTests: XCTestCase { } func testWhenHistoryIsBurning_ThenHistoryIsCleanedIncludingFireproofDomains() { + let burnAllFinished = expectation(description: "Burn All Finished") let (historyStoringMock, historyCoordinator) = HistoryCoordinator.aHistoryCoordinator let url1 = URL(string: "https://duckduckgo.com")! @@ -134,9 +135,16 @@ class HistoryCoordinatorTests: XCTestCase { XCTAssert(historyCoordinator.history!.count == 4) historyCoordinator.burnAll { - // Test a theory - XCTAssert(historyStoringMock.removeEntriesArray.count == 4) + // We now clean the database directly so we don't burn by entry + XCTAssert(historyStoringMock.removeEntriesArray.count == 0) + + // And we reset the entries dictionary + XCTAssert(historyCoordinator.history!.count == 0) + + burnAllFinished.fulfill() } + + waitForExpectations(timeout: 2.0) } func testWhenBurningVisits_removesHistoryWhenVisitsCountHitsZero() {