Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #941 from brave/release_1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Mar 8, 2019
2 parents 9b2cfb2 + 098e605 commit 49adc90
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@
A83E5B1E1C1DAAAA0026D912 /* UIPasteboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A83E5AB61C1D993D0026D912 /* UIPasteboardExtensions.swift */; };
A9072B801D07B34100459960 /* NoImageModeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9072B7F1D07B34100459960 /* NoImageModeHelper.swift */; };
A93067E81D0FE18E00C49C6E /* NightModeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93067E71D0FE18E00C49C6E /* NightModeHelper.swift */; };
AB1B097A21F2F00400E0DD51 /* FavoritesViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1B097921F2F00400E0DD51 /* FavoritesViewControllerTests.swift */; };
C400467C1CF4E43E00B08303 /* BackForwardListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C400467B1CF4E43E00B08303 /* BackForwardListViewController.swift */; };
C40046FA1CF8E0B200B08303 /* BackForwardListAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40046F91CF8E0B200B08303 /* BackForwardListAnimator.swift */; };
C4E3984C1D21F2FD004E89BA /* TabTrayButtonExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E3984B1D21F2FD004E89BA /* TabTrayButtonExtensions.swift */; };
Expand Down Expand Up @@ -1830,6 +1831,7 @@
A83E5B1C1C1DA8D80026D912 /* UIPasteboardExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIPasteboardExtensionsTests.swift; sourceTree = "<group>"; };
A9072B7F1D07B34100459960 /* NoImageModeHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoImageModeHelper.swift; sourceTree = "<group>"; };
A93067E71D0FE18E00C49C6E /* NightModeHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NightModeHelper.swift; sourceTree = "<group>"; };
AB1B097921F2F00400E0DD51 /* FavoritesViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesViewControllerTests.swift; sourceTree = "<group>"; };
C400467B1CF4E43E00B08303 /* BackForwardListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackForwardListViewController.swift; sourceTree = "<group>"; };
C40046F91CF8E0B200B08303 /* BackForwardListAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackForwardListAnimator.swift; sourceTree = "<group>"; };
C4E3984B1D21F2FD004E89BA /* TabTrayButtonExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TabTrayButtonExtensions.swift; path = ../Browser/TabTrayButtonExtensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3953,6 +3955,7 @@
E696FE501C47F86E00EC007C /* AuthenticatorTests.swift */,
F84B21D91A090F8100AAB793 /* ClientTests.swift */,
D3D488581ABB54CD00A93597 /* FileAccessorTests.swift */,
AB1B097921F2F00400E0DD51 /* FavoritesViewControllerTests.swift */,
281B2BE91ADF4D90002917DC /* MockProfile.swift */,
E683F0A51E92E0820035D990 /* MockableHistory.swift */,
2FDB10921A9FBEC5006CF312 /* PrefsTests.swift */,
Expand Down Expand Up @@ -5723,6 +5726,7 @@
3BFCBF201E04B1C50070C042 /* UIImageViewExtensionsTests.swift in Sources */,
E683F0A61E92E0820035D990 /* MockableHistory.swift in Sources */,
A83E5B1E1C1DAAAA0026D912 /* UIPasteboardExtensions.swift in Sources */,
AB1B097A21F2F00400E0DD51 /* FavoritesViewControllerTests.swift in Sources */,
2795274A21A890EB00921AA1 /* FingerprintingProtectionTests.swift in Sources */,
0BF42D4F1A7CD09600889E28 /* TestFavicons.swift in Sources */,
0A4214E921A6EBCF006B8E39 /* SafeBrowsingTests.swift in Sources */,
Expand Down Expand Up @@ -8152,7 +8156,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)";
MOZ_INTERNAL_URL_SCHEME = "firefox-internal";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = (
"-ObjC",
Expand Down Expand Up @@ -8548,7 +8551,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)";
MOZ_INTERNAL_URL_SCHEME = fennec;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -8950,7 +8952,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)";
MOZ_INTERNAL_URL_SCHEME = "firefox-beta";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = (
"-ObjC",
Expand Down Expand Up @@ -9173,7 +9174,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)";
MOZ_INTERNAL_URL_SCHEME = fennec;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
Expand Down
17 changes: 11 additions & 6 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ extension BrowserViewController: QRCodeViewControllerDelegate {

extension BrowserViewController: SettingsDelegate {
func settingsOpenURLInNewTab(_ url: URL) {
self.openURLInNewTab(url, isPrivileged: false)
let forcedPrivate = PrivateBrowsingManager.shared.isPrivateBrowsing
self.openURLInNewTab(url, isPrivate: forcedPrivate, isPrivileged: false)
}

func settingsOpenURLs(_ urls: [URL]) {
Expand Down Expand Up @@ -1562,9 +1563,13 @@ extension BrowserViewController: URLBarDelegate {
}

func urlBar(_ urlBar: URLBarView, didSubmitText text: String) {
processAddressBar(text: text, visitType: nil)
}

func processAddressBar(text: String, visitType: VisitType?) {
if let fixupURL = URIFixup.getURL(text) {
// The user entered a URL, so use it.
finishEditingAndSubmit(fixupURL, visitType: VisitType.typed)
finishEditingAndSubmit(fixupURL, visitType: visitType ?? .typed)
return
}

Expand All @@ -1585,7 +1590,7 @@ extension BrowserViewController: URLBarDelegate {
urlString.replaceSubrange(range, with: escapedQuery)

if let url = URL(string: urlString) {
self.finishEditingAndSubmit(url, visitType: VisitType.typed)
self.finishEditingAndSubmit(url, visitType: visitType ?? .typed)
return
}
}
Expand Down Expand Up @@ -2096,7 +2101,7 @@ extension BrowserViewController: TabManagerDelegate {
}

/// List of schemes that are allowed to be opened in new tabs.
private let schemesAllowedToBeOpenedAsPopups = ["http", "https", "javascript", "data", "about"]
private let schemesAllowedToBeOpenedAsPopups = ["http", "https", "javascript", "about"]

extension BrowserViewController: WKUIDelegate {
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
Expand Down Expand Up @@ -2892,8 +2897,8 @@ extension BrowserViewController: HomeMenuControllerDelegate {

extension BrowserViewController: TopSitesDelegate {

func didSelectUrl(url: URL) {
finishEditingAndSubmit(url, visitType: .bookmark)
func didSelect(input: String) {
processAddressBar(text: input, visitType: .bookmark)
}

func didTapDuckDuckGoCallout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ extension BrowserViewController: WKNavigationDelegate {
// If the content type is not HTML, create a temporary document so it can be downloaded and
// shared to external applications later. Otherwise, clear the old temporary document.
if let tab = tabManager[webView] {
if response.mimeType != MIMEType.HTML, let request = request {
if response.mimeType?.isKindOfHTML == false, let request = request {
tab.temporaryDocument = TemporaryDocument(preflightResponse: response, request: request)
} else {
tab.temporaryDocument = nil
Expand Down
18 changes: 9 additions & 9 deletions Client/Frontend/Browser/HomePanel/FavoritesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Data

private let log = Logger.browserLogger

protocol TopSitesDelegate: class {
func didSelectUrl(url: URL)
protocol TopSitesDelegate: AnyObject {
func didSelect(input: String)
func didTapDuckDuckGoCallout()
}

Expand All @@ -27,7 +27,7 @@ class FavoritesViewController: UIViewController, Themeable {
weak var delegate: TopSitesDelegate?

// MARK: - Favorites collection view properties
private lazy var collection: UICollectionView = {
private (set) internal lazy var collection: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 6
Expand All @@ -46,7 +46,7 @@ class FavoritesViewController: UIViewController, Themeable {
}
return view
}()
private lazy var dataSource: FavoritesDataSource = { return FavoritesDataSource() }()
private let dataSource: FavoritesDataSource

private let braveShieldStatsView = BraveShieldStatsView(frame: CGRect.zero).then {
$0.autoresizingMask = [.flexibleWidth]
Expand All @@ -73,8 +73,9 @@ class FavoritesViewController: UIViewController, Themeable {

private let profile: Profile

init(profile: Profile) {
init(profile: Profile, dataSource: FavoritesDataSource = FavoritesDataSource()) {
self.profile = profile
self.dataSource = dataSource

super.init(nibName: nil, bundle: nil)
NotificationCenter.default.do {
Expand Down Expand Up @@ -235,9 +236,9 @@ extension FavoritesViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let fav = dataSource.favoriteBookmark(at: indexPath)

guard let urlString = fav?.url, let url = URL(string: urlString) else { return }
guard let urlString = fav?.url else { return }

delegate?.didSelectUrl(url: url)
delegate?.didSelect(input: urlString)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
Expand Down Expand Up @@ -315,8 +316,7 @@ extension FavoritesViewController: FavoriteCellDelegate {
keyboardType2: .URL) { callbackTitle, callbackUrl in
if let cTitle = callbackTitle, !cTitle.isEmpty, let cUrl = callbackUrl, !cUrl.isEmpty {
if URL(string: cUrl) != nil {
fav.update(customTitle: cTitle,
url: cUrl)
fav.update(customTitle: cTitle, url: cUrl)
}
}
self.dataSource.isEditing = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ class FavoritesDataSource: NSObject, UICollectionViewDataSource {
cell.accessibilityLabel = cell.textLabel.text

cell.toggleEditButton(isEditing)

guard let urlString = fav.url, let url = URL(string: urlString) else {
log.error("configureCell url is nil")
return UICollectionViewCell()
}

return cell
}
Expand Down
9 changes: 8 additions & 1 deletion Client/Frontend/Browser/OpenInHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ struct MIMEType {
static let PlainText = "text/plain"
static let PNG = "image/png"
static let WebP = "image/webp"
static let xHTML = "application/xhtml+xml"

private static let webViewViewableTypes: [String] = [MIMEType.Bitmap, MIMEType.GIF, MIMEType.JPEG, MIMEType.HTML, MIMEType.PDF, MIMEType.PlainText, MIMEType.PNG, MIMEType.WebP]
private static let webViewViewableTypes: [String] = [MIMEType.Bitmap, MIMEType.GIF, MIMEType.JPEG, MIMEType.HTML, MIMEType.PDF, MIMEType.PlainText, MIMEType.PNG, MIMEType.WebP, MIMEType.xHTML]

static func canShowInWebView(_ mimeType: String) -> Bool {
return webViewViewableTypes.contains(mimeType.lowercased())
Expand All @@ -37,6 +38,12 @@ struct MIMEType {
}
}

extension String {
var isKindOfHTML: Bool {
return [MIMEType.HTML, MIMEType.xHTML].contains(self)
}
}

protocol OpenInHelper {
init?(request: URLRequest?, response: URLResponse, canShowInWebView: Bool, forceDownload: Bool, browserViewController: BrowserViewController)
func open()
Expand Down
1 change: 0 additions & 1 deletion Client/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<key>CFBundleURLSchemes</key>
<array>
<string>brave</string>
<string>$(MOZ_INTERNAL_URL_SCHEME)</string>
</array>
</dict>
</array>
Expand Down
145 changes: 145 additions & 0 deletions ClientTests/FavoritesViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// 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 http://mozilla.org/MPL/2.0/.

import XCTest
@testable import Data
@testable import Client

class FavoritesViewControllerTests: XCTestCase {

var dataSource: MockFavoritesDataSource!
var delegate: MockTopSitesDelegate!
var vc: FavoritesViewController!
var collectionView: UICollectionView!

override func setUp() {
super.setUp()

delegate = MockTopSitesDelegate()
dataSource = MockFavoritesDataSource()
vc = FavoritesViewController(profile: MockProfile(), dataSource: dataSource)
vc.delegate = delegate
collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
}

override func tearDown() {
dataSource = nil
delegate = nil
vc = nil
collectionView = nil

super.tearDown()
}

func testFavoritesViewControllerLoadsView() {
let viewController = FavoritesViewController(profile: MockProfile(), dataSource: MockFavoritesDataSource())
XCTAssertNotNil(viewController.view, "Unable to load view")
XCTAssertNotNil(viewController.view.subviews.first { $0 is UICollectionView }, "`UICollectionView` missing from `FavoritesViewController` view.")
XCTAssertNil(viewController.linkNavigationDelegate)
XCTAssertNil(viewController.delegate)
}

func testTopSiteDelegate_ReceivesString() {
let index = IndexPath(item: 0, section: 0)
let I_LOVE_CHOCOLATE = "I Love Chocolate"
dataSource.bookmarks[index] = createBookmark(I_LOVE_CHOCOLATE)

// Firing `UICollectionView` delegate method
vc.collectionView(collectionView, didSelectItemAt: index)

XCTAssertEqual(delegate.input, I_LOVE_CHOCOLATE, "The Favorites destination is incorrect.")
XCTAssertFalse(delegate.isReturningURL, "Favorites should work for any string NOT just URL's.")
}

func testTopSiteDelegate_ReceivesFullURL() {
let index = IndexPath(item: 0, section: 0)
let HTTPS_BRAVE_COM = "https://www.brave.com"
dataSource.bookmarks[index] = createBookmark(HTTPS_BRAVE_COM)

vc.collectionView(collectionView, didSelectItemAt: index)

XCTAssertEqual(delegate.input, HTTPS_BRAVE_COM, "The Favorites destination is incorrect.")
XCTAssertTrue(delegate.isReturningURL, "Favorites should work for URL's.")
}

func testTopSiteDelegate_ReceivesURLWithoutScheme() {
let index = IndexPath(item: 0, section: 0)
let BRAVE_COM = "brave.com"
dataSource.bookmarks[index] = createBookmark(BRAVE_COM)

vc.collectionView(collectionView, didSelectItemAt: index)

XCTAssertEqual(delegate.input, BRAVE_COM, "The Favorites destination is incorrect.")
XCTAssertTrue(delegate.isReturningURL, "Favorites should work for URL's without a scheme.")
}

func testTopSiteDelegate_EmptyString() {
let index = IndexPath(item: 0, section: 0)
let EMPTY_STRING = ""
dataSource.bookmarks[index] = createBookmark(EMPTY_STRING)

vc.collectionView(collectionView, didSelectItemAt: index)

XCTAssertEqual(delegate.input, EMPTY_STRING, "The Favorites destination is incorrect.")
XCTAssertTrue(delegate.didSelectInputString)
XCTAssertFalse(delegate.isReturningURL)
}

func testTopSiteDelegate_NilURL() {
let index = IndexPath(item: 0, section: 0)
let NIL_URL: String? = nil
dataSource.bookmarks[index] = createBookmark(NIL_URL)

vc.collectionView(collectionView, didSelectItemAt: index)

XCTAssertEqual(delegate.input, NIL_URL, "The Favorites destination is incorrect.")
XCTAssertFalse(delegate.didSelectInputString)
}

fileprivate func createBookmark(_ urlString: String? = nil) -> Bookmark? {
return Bookmark(context: DataController.viewContext).then {
$0.url = urlString
}
}
}

class MockFavoritesDataSource: FavoritesDataSource {

var bookmarks = [IndexPath: Bookmark]()

var _isEditing: Bool = false
override var isEditing: Bool {
get { return _isEditing }
set { _isEditing = newValue }
}

override init() {
}

override func favoriteBookmark(at indexPath: IndexPath) -> Bookmark? {
return bookmarks[indexPath]
}
}

class MockTopSitesDelegate: TopSitesDelegate {

var didSelectInputString = false
var didTapCallout = false
var input: String?

func didSelect(input: String) {
didSelectInputString = true
self.input = input
}

func didTapDuckDuckGoCallout() {
didTapCallout = true
}

/// Checks that there is a `urlString` AND is it able to be created into a `URL`.
var isReturningURL: Bool {
guard let input = self.input else { return false }
return URL(string: input) != nil
}
}
2 changes: 2 additions & 0 deletions ClientTests/SearchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class SearchTests: XCTestCase {
checkInvalidURL("创业咖啡")
checkInvalidURL("创业咖啡 中国")
checkInvalidURL("创业咖啡. 中国")
checkInvalidURL("data:text/html;base64,SGVsbG8gV29ybGQhCg==")
checkInvalidURL("data://https://www.example.com,fake example.com")
}

func testURIFixupPunyCode() {
Expand Down
Loading

0 comments on commit 49adc90

Please sign in to comment.