Skip to content

Commit

Permalink
Merge branch 'main' into bunn/dbp/change-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunn committed Apr 9, 2024
2 parents 9dcaebb + ebb09c3 commit 427926d
Show file tree
Hide file tree
Showing 26 changed files with 901 additions and 47 deletions.
4 changes: 4 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,7 @@
EE339228291BDEFD009F62C1 /* JSAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE339227291BDEFD009F62C1 /* JSAlertController.swift */; };
EE3424602BA0853900173B1B /* VPNUninstaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE34245D2BA0853900173B1B /* VPNUninstaller.swift */; };
EE3424612BA0853900173B1B /* VPNUninstaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE34245D2BA0853900173B1B /* VPNUninstaller.swift */; };
EE54F7B32BBFEA49006218DB /* BookmarksAndFavoritesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */; };
EE66418C2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */; };
EE66418D2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */; };
EE66666F2B56EDE4001D898D /* VPNLocationsHostingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE66666E2B56EDE4001D898D /* VPNLocationsHostingViewController.swift */; };
Expand Down Expand Up @@ -4772,6 +4773,7 @@
EE0429DF2BA31D2F009EB20F /* FindInPageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FindInPageTests.swift; sourceTree = "<group>"; };
EE339227291BDEFD009F62C1 /* JSAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSAlertController.swift; sourceTree = "<group>"; };
EE34245D2BA0853900173B1B /* VPNUninstaller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNUninstaller.swift; sourceTree = "<group>"; };
EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarksAndFavoritesTests.swift; sourceTree = "<group>"; };
EE66418B2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift"; sourceTree = "<group>"; };
EE66666E2B56EDE4001D898D /* VPNLocationsHostingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNLocationsHostingViewController.swift; sourceTree = "<group>"; };
EE7F74902BB5D76600CD9456 /* BookmarksBarTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarksBarTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6556,6 +6558,7 @@
children = (
EEBCE6802BA444FA00B9DF00 /* Common */,
EED735352BB46B6000F173D6 /* AutocompleteTests.swift */,
EE54F7B22BBFEA48006218DB /* BookmarksAndFavoritesTests.swift */,
EE7F74902BB5D76600CD9456 /* BookmarksBarTests.swift */,
EE02D41B2BB460A600DBE6B3 /* BrowsingHistoryTests.swift */,
EE0429DF2BA31D2F009EB20F /* FindInPageTests.swift */,
Expand Down Expand Up @@ -12279,6 +12282,7 @@
EE02D41A2BB4609900DBE6B3 /* UITests.swift in Sources */,
EE0429E02BA31D2F009EB20F /* FindInPageTests.swift in Sources */,
EE02D4212BB460FE00DBE6B3 /* StringExtension.swift in Sources */,
EE54F7B32BBFEA49006218DB /* BookmarksAndFavoritesTests.swift in Sources */,
EE02D4222BB4611A00DBE6B3 /* TestsURLExtension.swift in Sources */,
7B4CE8E726F02135009134B1 /* TabBarTests.swift in Sources */,
EEBCE6832BA463DD00B9DF00 /* NSImageExtensions.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Bookmarks/Services/ContextualMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ private extension ContextualMenu {
static func addBookmarkToFavoritesMenuItem(isFavorite: Bool, bookmark: Bookmark?) -> NSMenuItem {
let title = isFavorite ? UserText.removeFromFavorites : UserText.addToFavorites
return menuItem(title, #selector(BookmarkMenuItemSelectors.toggleBookmarkAsFavorite(_:)), bookmark)
.withAccessibilityIdentifier(isFavorite == false ? "ContextualMenu.addBookmarkToFavoritesMenuItem" :
"ContextualMenu.removeBookmarkFromFavoritesMenuItem")
}

static func addBookmarksToFavoritesMenuItem(bookmarks: [Bookmark], allFavorites: Bool) -> NSMenuItem {
let title = allFavorites ? UserText.removeFromFavorites : UserText.addToFavorites
let accessibilityValue = allFavorites ? "Favorited" : "Unfavorited"
return menuItem(title, #selector(BookmarkMenuItemSelectors.toggleBookmarkAsFavorite(_:)), bookmarks)
.withAccessibilityIdentifier("ContextualMenu.addBookmarksToFavoritesMenuItem").withAccessibilityValue(accessibilityValue)
}

static func editBookmarkMenuItem(bookmark: Bookmark?) -> NSMenuItem {
Expand All @@ -180,6 +184,7 @@ private extension ContextualMenu {

static func deleteBookmarkMenuItem(bookmark: Bookmark?) -> NSMenuItem {
menuItem(UserText.bookmarksBarContextMenuDelete, #selector(BookmarkMenuItemSelectors.deleteBookmark(_:)), bookmark)
.withAccessibilityIdentifier("ContextualMenu.deleteBookmark")
}

static func moveToEndMenuItem(entity: BaseBookmarkEntity?, parent: BookmarkFolder?) -> NSMenuItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ final class BookmarkManagementSidebarViewController: NSViewController {
tabSwitcherButton.menu = NSMenu {
for content in Tab.TabContent.displayableTabTypes {
NSMenuItem(title: content.title!, representedObject: content)
.withAccessibilityIdentifier("BookmarkManagementSidebarViewController.\(content.title!)")
}
}

Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkOutlineCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ final class BookmarkOutlineCellView: NSTableCellView {
faviconImageView.imageScaling = .scaleProportionallyDown
faviconImageView.wantsLayer = true
faviconImageView.layer?.cornerRadius = 2.0
faviconImageView.setAccessibilityIdentifier("BookmarkOutlineCellView.favIconImageView")

titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.isEditable = false
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkTableCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ final class BookmarkTableCellView: NSTableCellView {
menuButton.translatesAutoresizingMaskIntoConstraints = false
menuButton.isBordered = false
menuButton.isHidden = true
menuButton.setAccessibilityIdentifier("BookmarkTableCellView.menuButton")
}

private func setupLayout() {
Expand Down Expand Up @@ -209,11 +210,14 @@ final class BookmarkTableCellView: NSTableCellView {

faviconImageView.image = bookmark.favicon(.small) ?? .bookmarkDefaultFavicon

faviconImageView.setAccessibilityIdentifier("BookmarkTableCellView.favIconImageView")
if bookmark.isFavorite {
accessoryImageView.isHidden = false
}

accessoryImageView.image = bookmark.isFavorite ? .favoriteFilledBorder : nil
accessoryImageView.setAccessibilityIdentifier("BookmarkTableCellView.accessoryImageView")
accessoryImageView.setAccessibilityValue(bookmark.isFavorite ? "Favorited" : "Unfavorited")
titleLabel.stringValue = bookmark.title
primaryTitleLabelValue = bookmark.title
tertiaryTitleLabelValue = bookmark.url
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Common/Extensions/NSMenuItemExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ extension NSMenuItem {
return self
}

func withAccessibilityValue(_ accessibilityValue: String) -> NSMenuItem {
self.setAccessibilityValue(accessibilityValue)
return self
}

@discardableResult
func withImage(_ image: NSImage?) -> NSMenuItem {
self.image = image
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/History/Services/EncryptedHistoryStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ final class EncryptedHistoryStore: HistoryStoring {
fetchedObjects = try self.context.fetch(fetchRequest)
} catch {
Pixel.fire(.debug(event: .historySaveFailed, error: error))
Pixel.fire(.debug(event: .historySaveFailedDaily, error: error), limitTo: .dailyFirst)
promise(.failure(error))
return
}
Expand Down Expand Up @@ -203,13 +204,15 @@ final class EncryptedHistoryStore: HistoryStoring {
switch insertionResult {
case .failure(let error):
Pixel.fire(.debug(event: .historySaveFailed, error: error))
Pixel.fire(.debug(event: .historySaveFailedDaily, error: error), limitTo: .dailyFirst)
context.reset()
promise(.failure(error))
case .success(let visitMOs):
do {
try self.context.save()
} catch {
Pixel.fire(.debug(event: .historySaveFailed, error: error))
Pixel.fire(.debug(event: .historySaveFailedDaily, error: error), limitTo: .dailyFirst)
context.reset()
promise(.failure(HistoryStoreError.savingFailed))
return
Expand Down
16 changes: 8 additions & 8 deletions DuckDuckGo/HomePage/View/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ struct Favorite: View {
.link {
model.open(bookmark)
}.contextMenu(ContextMenu(menuItems: {
Button(UserText.openInNewTab, action: { model.openInNewTab(bookmark) })
Button(UserText.openInNewWindow, action: { model.openInNewWindow(bookmark) })
Button(UserText.openInNewTab, action: { model.openInNewTab(bookmark) }).accessibilityIdentifier("HomePage.Views.openInNewTab")
Button(UserText.openInNewWindow, action: { model.openInNewWindow(bookmark) }).accessibilityIdentifier("HomePage.Views.openInNewWindow")
Divider()
Button(UserText.edit, action: { model.edit(bookmark) })
Button(UserText.removeFavorite, action: { model.removeFavorite(bookmark) })
Button(UserText.deleteBookmark, action: { model.deleteBookmark(bookmark) })
Button(UserText.edit, action: { model.edit(bookmark) }).accessibilityIdentifier("HomePage.Views.editBookmark")
Button(UserText.removeFavorite, action: { model.removeFavorite(bookmark) }).accessibilityIdentifier("HomePage.Views.removeFavorite")
Button(UserText.deleteBookmark, action: { model.deleteBookmark(bookmark) }).accessibilityIdentifier("HomePage.Views.deleteBookmark")
}))

}
Expand All @@ -344,13 +344,13 @@ extension HomePage.Models.FavoriteModel {
var favoriteView: some View {
switch favoriteType {
case .bookmark(let bookmark):
HomePage.Views.Favorite(bookmark: bookmark)
HomePage.Views.Favorite(bookmark: bookmark)?.accessibilityIdentifier("HomePage.Models.FavoriteModel.\(bookmark.title)")

case .addButton:
HomePage.Views.FavoritesGridAddButton()
HomePage.Views.FavoritesGridAddButton().accessibilityIdentifier("HomePage.Models.FavoriteModel.addButton")

case .ghostButton:
HomePage.Views.FavoritesGridGhostButton()
HomePage.Views.FavoritesGridGhostButton().accessibilityIdentifier("HomePage.Models.FavoriteModel.ghostButton")
}
}
}
3 changes: 2 additions & 1 deletion DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import SubscriptionUI
var forwardMenuItem: NSMenuItem { historyMenu.forwardMenuItem }

// MARK: Bookmarks
let manageBookmarksMenuItem = NSMenuItem(title: UserText.mainMenuHistoryManageBookmarks, action: #selector(MainViewController.showManageBookmarks))
let manageBookmarksMenuItem = NSMenuItem(title: UserText.mainMenuHistoryManageBookmarks, action: #selector(MainViewController.showManageBookmarks)).withAccessibilityIdentifier("MainMenu.manageBookmarksMenuItem")
var bookmarksMenuToggleBookmarksBarMenuItem = NSMenuItem(title: "BookmarksBarMenuPlaceholder", action: #selector(MainViewController.toggleBookmarksBarFromMenu), keyEquivalent: "B")
let importBookmarksMenuItem = NSMenuItem(title: UserText.importBookmarks, action: #selector(AppDelegate.openImportBrowserDataWindow))
let bookmarksMenu = NSMenu(title: UserText.bookmarks)
Expand Down Expand Up @@ -306,6 +306,7 @@ import SubscriptionUI
.submenu(favoritesMenu.buildItems {
NSMenuItem(title: UserText.mainMenuHistoryFavoriteThisPage, action: #selector(MainViewController.favoriteThisPage))
.withImage(.favorite)
.withAccessibilityIdentifier("MainMenu.favoriteThisPage")
NSMenuItem.separator()
})
.withImage(.favorite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ final class AddressBarButtonsViewController: NSViewController {

private func updateBookmarkButtonVisibility() {
guard view.window?.isPopUpWindow == false else { return }
bookmarkButton.setAccessibilityIdentifier("Bookmarks Button")
bookmarkButton.setAccessibilityIdentifier("AddressBarButtonsViewController.bookmarkButton")
let hasEmptyAddressBar = textFieldValue?.isEmpty ?? true
var showBookmarkButton: Bool {
guard let tabViewModel, tabViewModel.canBeBookmarked else { return false }
Expand Down Expand Up @@ -727,15 +727,18 @@ final class AddressBarButtonsViewController: NSViewController {

private func updateBookmarkButtonImage(isUrlBookmarked: Bool = false) {
if let url = tabViewModel?.tab.content.url,
isUrlBookmarked || bookmarkManager.isUrlBookmarked(url: url) {
isUrlBookmarked || bookmarkManager.isUrlBookmarked(url: url)
{
bookmarkButton.image = .bookmarkFilled
bookmarkButton.mouseOverTintColor = NSColor.bookmarkFilledTint
bookmarkButton.toolTip = UserText.editBookmarkTooltip
bookmarkButton.setAccessibilityValue("Bookmarked")
} else {
bookmarkButton.mouseOverTintColor = nil
bookmarkButton.image = .bookmark
bookmarkButton.contentTintColor = nil
bookmarkButton.toolTip = UserText.addBookmarkTooltip
bookmarkButton.setAccessibilityValue("Unbookmarked")
}
}

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ final class MoreOptionsMenu: NSMenu {
.targetting(self)
.withImage(.bookmarks)
.withSubmenu(bookmarksSubMenu)

.withAccessibilityIdentifier("MoreOptionsMenu.openBookmarks")
addItem(withTitle: UserText.downloads, action: #selector(openDownloads), keyEquivalent: "j")
.targetting(self)
.withImage(.downloads)
Expand Down Expand Up @@ -641,6 +641,7 @@ final class BookmarksSubMenu: NSMenu {
let bookmarkPageItem = addItem(withTitle: UserText.bookmarkThisPage, action: #selector(MoreOptionsMenu.bookmarkPage(_:)), keyEquivalent: "d")
.withModifierMask([.command])
.targetting(target)
.withAccessibilityIdentifier("MoreOptionsMenu.bookmarkPage")

bookmarkPageItem.isEnabled = tabCollectionViewModel.selectedTabViewModel?.canBeBookmarked == true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionActiveUser,
frequency: .dailyOnly,
withAdditionalParameters: ["cohort": PixelKit.dateString(for: defaults.vpnFirstEnabled)],
withAdditionalParameters: [PixelKit.Parameters.vpnCohort: PixelKit.cohort(from: defaults.vpnFirstEnabled)],
includeAppVersionParameter: true)
case .reportConnectionAttempt(attempt: let attempt):
switch attempt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension Preferences {
if model.isContinueSetUpAvailable {
ToggleMenuItem(UserText.newTabSetUpSectionTitle, isOn: $model.isContinueSetUpVisible)
}
ToggleMenuItem(UserText.newTabFavoriteSectionTitle, isOn: $model.isFavoriteVisible)
ToggleMenuItem(UserText.newTabFavoriteSectionTitle, isOn: $model.isFavoriteVisible).accessibilityIdentifier("Preferences.AppearanceView.showFavoritesToggle")
ToggleMenuItem(UserText.newTabRecentActivitySectionTitle, isOn: $model.isRecentActivityVisible)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension WindowsManager {
}

private class func setUpWindow(from item: WindowRestorationItem) {
guard let window = openNewWindow(with: item.model, showWindow: true) else { return }
guard let window = openNewWindow(with: item.model, showWindow: !item.isMiniaturized, isMiniaturized: item.isMiniaturized) else { return }
window.setContentSize(item.frame.size)
window.setFrameOrigin(item.frame.origin)
}
Expand Down Expand Up @@ -135,11 +135,13 @@ final class WindowRestorationItem: NSObject, NSSecureCoding {
private enum NSSecureCodingKeys {
static let frame = "frame"
static let model = "model"
static let isMiniaturized = "isMiniaturized"

}

let model: TabCollectionViewModel
let frame: NSRect
let isMiniaturized: Bool

@MainActor
init?(windowController: MainWindowController) {
Expand All @@ -150,6 +152,7 @@ final class WindowRestorationItem: NSObject, NSSecureCoding {

self.frame = windowController.window!.frame
self.model = windowController.mainViewController.tabCollectionViewModel
self.isMiniaturized = windowController.window!.isMiniaturized
}

static var supportsSecureCoding: Bool { true }
Expand All @@ -161,10 +164,12 @@ final class WindowRestorationItem: NSObject, NSSecureCoding {
}
self.model = model
self.frame = coder.decodeRect(forKey: NSSecureCodingKeys.frame)
self.isMiniaturized = coder.decodeBool(forKey: NSSecureCodingKeys.isMiniaturized)
}

func encode(with coder: NSCoder) {
coder.encode(frame, forKey: NSSecureCodingKeys.frame)
coder.encode(model, forKey: NSSecureCodingKeys.model)
coder.encode(isMiniaturized, forKey: NSSecureCodingKeys.isMiniaturized)
}
}
3 changes: 3 additions & 0 deletions DuckDuckGo/Statistics/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ extension Pixel {
case historyCleanEntriesFailed
case historyCleanVisitsFailed
case historySaveFailed
case historySaveFailedDaily
case historyInsertVisitFailed
case historyRemoveVisitsFailed

Expand Down Expand Up @@ -816,6 +817,8 @@ extension Pixel.Event.Debug {
return "history_clean_visits_failed"
case .historySaveFailed:
return "history_save_failed"
case .historySaveFailedDaily:
return "history_save_failed_daily"
case .historyInsertVisitFailed:
return "history_insert_visit_failed"
case .historyRemoveVisitsFailed:
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Statistics/PixelParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ extension Pixel.Event.Debug {
.historyCleanEntriesFailed,
.historyCleanVisitsFailed,
.historySaveFailed,
.historySaveFailedDaily,
.historyInsertVisitFailed,
.historyRemoveVisitsFailed,
.emailAutofillKeychainError,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private extension ContextMenuManager {
}

func bookmarkPageMenuItem() -> NSMenuItem {
NSMenuItem(title: UserText.bookmarkPage, action: #selector(MainViewController.bookmarkThisPage), target: nil, keyEquivalent: "")
NSMenuItem(title: UserText.bookmarkPage, action: #selector(MainViewController.bookmarkThisPage), target: nil, keyEquivalent: "").withAccessibilityIdentifier("ContextMenuManager.bookmarkPageMenuItem")
}

func openLinkInNewWindowMenuItem(from item: NSMenuItem) -> NSMenuItem {
Expand Down
Loading

0 comments on commit 427926d

Please sign in to comment.