This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd215d9
commit fb8f9bb
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2024 The Brave Authors. All rights reserved. | ||
// 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 https://mozilla.org/MPL/2.0/. | ||
|
||
import Foundation | ||
import Preferences | ||
|
||
enum DefaultBrowserHelper { | ||
/// Whether or not its likely that Brave is the users default browser based on a 14 day usage period | ||
static func isBraveLikelyDefaultBrowser() -> Bool { | ||
guard let date = Preferences.General.lastHTTPURLOpenedDate.value else { return false } | ||
return date >= Date.now.addingTimeInterval(-14.days) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 The Brave Authors. All rights reserved. | ||
// 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 https://mozilla.org/MPL/2.0/. | ||
|
||
import Foundation | ||
@testable import Brave | ||
import XCTest | ||
import Preferences | ||
|
||
class DefaultBrowserHelperTests: XCTestCase { | ||
override func setUp() async throws { | ||
Preferences.General.lastHTTPURLOpenedDate.reset() | ||
} | ||
|
||
func testUserRecentlyOpenedURL() { | ||
let date = Date() | ||
Preferences.General.lastHTTPURLOpenedDate.value = date | ||
let isLikelyDefault = DefaultBrowserHelper.isBraveLikelyDefaultBrowser() | ||
XCTAssertTrue(isLikelyDefault) | ||
} | ||
|
||
func testUserNeverOpenedURL() { | ||
// User never opened a link | ||
let isLikelyDefault = DefaultBrowserHelper.isBraveLikelyDefaultBrowser() | ||
XCTAssertFalse(isLikelyDefault) | ||
} | ||
|
||
func testUserOpenedURL8DaysAgo() { | ||
let date = Date() | ||
Preferences.General.lastHTTPURLOpenedDate.value = date.addingTimeInterval(-8.days) | ||
let isLikelyDefault = DefaultBrowserHelper.isBraveLikelyDefaultBrowser() | ||
XCTAssertTrue(isLikelyDefault) | ||
} | ||
|
||
func testUserOpenedURL30DaysAgo() { | ||
let date = Date() | ||
Preferences.General.lastHTTPURLOpenedDate.value = date.addingTimeInterval(-30.days) | ||
let isLikelyDefault = DefaultBrowserHelper.isBraveLikelyDefaultBrowser() | ||
XCTAssertFalse(isLikelyDefault) | ||
} | ||
} |