diff --git a/DuckDuckGo/Tab/Model/Tab.swift b/DuckDuckGo/Tab/Model/Tab.swift index 09fc3be7a4..a477674a7b 100644 --- a/DuckDuckGo/Tab/Model/Tab.swift +++ b/DuckDuckGo/Tab/Model/Tab.swift @@ -700,10 +700,7 @@ protocol NewWindowPolicyDecisionMaker { return } - let title = webView.title?.trimmingWhitespace() - if title != self.title { - self.title = title - } + self.title = webView.title?.trimmingWhitespace() if let wkBackForwardListItem = webView.backForwardList.currentItem, content.urlForWebView == wkBackForwardListItem.url, diff --git a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift index 7ed73a4504..d90fa2aa37 100644 --- a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift +++ b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift @@ -136,14 +136,12 @@ final class TabViewModel { } } .switchToLatest() - .sink { [weak self] event in + .sink { [weak self] _ in guard let self else { return } updateAddressBarStrings() - if case .didCommit = event { - updateCanBeBookmarked() - updateFavicon() - } + updateFavicon() + updateCanBeBookmarked() } .store(in: &cancellables) } @@ -180,9 +178,8 @@ final class TabViewModel { .filter { [weak self] _ in self?.tab.isLazyLoadingInProgress == false } - .receive(on: DispatchQueue.main) - .sink { [weak self] _ in - self?.updateFavicon() + .sink { [weak self] favicon in + self?.updateFavicon(favicon) } .store(in: &cancellables) } @@ -315,7 +312,7 @@ final class TabViewModel { } } - private func updateFavicon() { + private func updateFavicon(_ tabFavicon: NSImage?? = .none /* provided from .sink or taken from tab.favicon (optional) if .none */) { guard !isShowingErrorPage else { favicon = .alertCircleColor16 return @@ -341,10 +338,10 @@ final class TabViewModel { case .url, .onboarding, .none, .subscription: break } - if let favicon = tab.favicon { + if let favicon: NSImage? = tabFavicon { self.favicon = favicon } else { - favicon = nil + self.favicon = tab.favicon } } diff --git a/UnitTests/Onboarding/OnboardingTests.swift b/UnitTests/Onboarding/OnboardingTests.swift index 729d97636e..f0366d6498 100644 --- a/UnitTests/Onboarding/OnboardingTests.swift +++ b/UnitTests/Onboarding/OnboardingTests.swift @@ -37,6 +37,7 @@ class OnboardingTests: XCTestCase { XCTAssertEqual(model.state, .startFlow) } + @MainActor func testStateChanges() { let model = OnboardingViewModel(delegate: delegate) assertStateChange(model, .startFlow, .welcome, model.onSplashFinished) @@ -94,10 +95,11 @@ class OnboardingTests: XCTestCase { XCTAssertEqual(model.state, .startFlow) } + @MainActor private func assertStateChange(_ model: OnboardingViewModel, _ expectedCurrentState: OnboardingViewModel.OnboardingPhase, _ expectedFinalState: OnboardingViewModel.OnboardingPhase, - _ mutator: () -> Void, + _ mutator: @MainActor () -> Void, file: StaticString = #file, line: UInt = #line) { diff --git a/UnitTests/Preferences/DownloadsPreferencesTests.swift b/UnitTests/Preferences/DownloadsPreferencesTests.swift index afefd8fb8f..fbcb7a9b13 100644 --- a/UnitTests/Preferences/DownloadsPreferencesTests.swift +++ b/UnitTests/Preferences/DownloadsPreferencesTests.swift @@ -183,6 +183,7 @@ class DownloadsPreferencesTests: XCTestCase { waitForExpectations(timeout: 0) XCTAssertFalse(preferences.shouldOpenPopupOnCompletion) XCTAssertEqual(persistor2.values().difference(from: valuesWithFalse), []) + withExtendedLifetime(c) {} } private func createTemporaryTestDirectory(named name: String = DownloadsPreferencesTests.defaultTestDirectoryName) -> URL { diff --git a/UnitTests/Tab/Services/FaviconManagerMock.swift b/UnitTests/Tab/Services/FaviconManagerMock.swift index 70356792c6..ed0efbd473 100644 --- a/UnitTests/Tab/Services/FaviconManagerMock.swift +++ b/UnitTests/Tab/Services/FaviconManagerMock.swift @@ -29,7 +29,7 @@ final class FaviconManagerMock: FaviconManagement { @Published var areFaviconsLoaded = true var faviconsLoadedPublisher: Published.Publisher { $areFaviconsLoaded } - func handleFaviconLinks(_ faviconLinks: [FaviconUserScript.FaviconLink], documentUrl: URL, completion: @escaping (Favicon?) -> Void) { + func handleFaviconLinks(_ faviconLinks: [FaviconUserScript.FaviconLink], documentUrl: URL, completion: @escaping @MainActor (Favicon?) -> Void) { completion(nil) } @@ -49,12 +49,12 @@ final class FaviconManagerMock: FaviconManagement { return nil } - func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set, completion: @escaping () -> Void) { + func burnExcept(fireproofDomains: DuckDuckGo_Privacy_Browser.FireproofDomains, bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, savedLogins: Set, completion: @escaping @MainActor () -> Void) { completion() } // swiftlint:disable:next function_parameter_count - func burnDomains(_ domains: Set, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping () -> Void) { + func burnDomains(_ domains: Set, exceptBookmarks bookmarkManager: DuckDuckGo_Privacy_Browser.BookmarkManager, exceptSavedLogins: Set, exceptExistingHistory history: History, tld: Common.TLD, completion: @escaping @MainActor () -> Void) { completion() } }