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

Commit

Permalink
Added Unit Tests to test Private vs. Normal Mode.
Browse files Browse the repository at this point in the history
Fixed a bug in `removeAllBrowsingDataForTab` where it only removed select data instead of ALL data.
  • Loading branch information
Brandon-T committed Jul 18, 2019
1 parent 7890d34 commit 37b2b86
Show file tree
Hide file tree
Showing 3 changed files with 452 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@
5DE768B120B4713000FF5533 /* Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FCAE21A1ABB51F800877008 /* Storage.framework */; };
5E3477E922D7771700B0D5F8 /* ResourceDownloader.js in Resources */ = {isa = PBXBuildFile; fileRef = 5E3477E822D7771700B0D5F8 /* ResourceDownloader.js */; };
5E34781022D7A1D200B0D5F8 /* ResourceDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E34780F22D7A1D200B0D5F8 /* ResourceDownloadManager.swift */; };
5E9288CA22DF864C007BE7A6 /* TabSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E9288C922DF864C007BE7A6 /* TabSessionTests.swift */; };
744B0FFE1B4F172E00100422 /* ToolbarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 744B0FFD1B4F172E00100422 /* ToolbarTests.swift */; };
744ED5611DBFEB8D00A2B5BE /* MailtoLinkHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 744ED5601DBFEB8D00A2B5BE /* MailtoLinkHandler.swift */; };
7479B4EF1C5306A200DF000B /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7479B4ED1C5306A200DF000B /* Reachability.swift */; };
Expand Down Expand Up @@ -1877,6 +1878,7 @@
5DE768AF20B4601600FF5533 /* UIColorExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColorExtensions.swift; sourceTree = "<group>"; };
5E3477E822D7771700B0D5F8 /* ResourceDownloader.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = ResourceDownloader.js; sourceTree = "<group>"; };
5E34780F22D7A1D200B0D5F8 /* ResourceDownloadManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceDownloadManager.swift; sourceTree = "<group>"; };
5E9288C922DF864C007BE7A6 /* TabSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSessionTests.swift; sourceTree = "<group>"; };
744B0FFD1B4F172E00100422 /* ToolbarTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToolbarTests.swift; sourceTree = "<group>"; };
744ED5601DBFEB8D00A2B5BE /* MailtoLinkHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MailtoLinkHandler.swift; sourceTree = "<group>"; };
7479B4ED1C5306A200DF000B /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Reachability.swift; path = ThirdParty/Reachability.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4206,6 +4208,7 @@
0A4214E821A6EBCF006B8E39 /* SafeBrowsingTests.swift */,
5953AAEE2226E9D800A92DE1 /* HttpCookieExtensionTest.swift */,
F939FBFD22A596B900D9CD3F /* U2FTests.swift */,
5E9288C922DF864C007BE7A6 /* TabSessionTests.swift */,
);
path = ClientTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -6028,6 +6031,7 @@
AB1B097A21F2F00400E0DD51 /* FavoritesViewControllerTests.swift in Sources */,
2795274A21A890EB00921AA1 /* FingerprintingProtectionTests.swift in Sources */,
0BF42D4F1A7CD09600889E28 /* TestFavicons.swift in Sources */,
5E9288CA22DF864C007BE7A6 /* TabSessionTests.swift in Sources */,
0A4214E921A6EBCF006B8E39 /* SafeBrowsingTests.swift in Sources */,
7BBFEE741BB405D900A305AA /* TabManagerTests.swift in Sources */,
0A4BEFDE221F03C80005551A /* NetworkManagerTests.swift in Sources */,
Expand Down
8 changes: 2 additions & 6 deletions Client/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class TabManager: NSObject {
if tab.isPrivate {
// Only when ALL tabs are dead, we clean up.
// This is because other tabs share the same data-store.
if tabsForCurrentMode.count <= 1 {
if tabs(withType: .private).count <= 1 {
removeAllBrowsingDataForTab(tab)
}
}
Expand Down Expand Up @@ -626,11 +626,7 @@ class TabManager: NSObject {
}

func removeAllBrowsingDataForTab(_ tab: Tab, completionHandler: @escaping () -> Void = {}) {
let dataTypes = Set([WKWebsiteDataTypeCookies,
WKWebsiteDataTypeLocalStorage,
WKWebsiteDataTypeSessionStorage,
WKWebsiteDataTypeWebSQLDatabases,
WKWebsiteDataTypeIndexedDBDatabases])
let dataTypes = WKWebsiteDataStore.allWebsiteDataTypes()
tab.webView?.configuration.websiteDataStore.removeData(ofTypes: dataTypes,
modifiedSince: Date.distantPast,
completionHandler: completionHandler)
Expand Down
Loading

0 comments on commit 37b2b86

Please sign in to comment.