Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit a4775ef

Browse files
authored
Bug 1431490 - Scheme step to copy a test db into the Client bundle (#3648)
Include a test case to show how it is used. The test case is a db with 1 bookmark.
1 parent 94ec850 commit a4775ef

File tree

8 files changed

+107
-9
lines changed

8 files changed

+107
-9
lines changed

Client.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@
752752
EB2A633C1F3B513E004EF8B0 /* disconnect-analytics.json in Resources */ = {isa = PBXBuildFile; fileRef = EB2A63361F3B5134004EF8B0 /* disconnect-analytics.json */; };
753753
EB2A633E1F3B514A004EF8B0 /* disconnect-content.json in Resources */ = {isa = PBXBuildFile; fileRef = EB2A63371F3B5135004EF8B0 /* disconnect-content.json */; };
754754
EB2A633F1F3B514B004EF8B0 /* disconnect-social.json in Resources */ = {isa = PBXBuildFile; fileRef = EB2A63391F3B5135004EF8B0 /* disconnect-social.json */; };
755+
EB3A38A02032673E004C6E67 /* DatabaseFixtureTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB3A38912032673D004C6E67 /* DatabaseFixtureTest.swift */; };
755756
EBA31D791F7999030055463D /* SyncPingCentre.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA31D781F7999030055463D /* SyncPingCentre.swift */; };
756757
EBA31D7B1F79990C0055463D /* SyncTelemetryEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA31D7A1F79990C0055463D /* SyncTelemetryEvents.swift */; };
757758
EBA31D7D1F79996E0055463D /* SyncTelemetryUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA31D7C1F79996E0055463D /* SyncTelemetryUtils.swift */; };
@@ -2083,6 +2084,7 @@
20832084
EB2A63371F3B5135004EF8B0 /* disconnect-content.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "disconnect-content.json"; sourceTree = "<group>"; };
20842085
EB2A63381F3B5135004EF8B0 /* disconnect-advertising.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "disconnect-advertising.json"; sourceTree = "<group>"; };
20852086
EB2A63391F3B5135004EF8B0 /* disconnect-social.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "disconnect-social.json"; sourceTree = "<group>"; };
2087+
EB3A38912032673D004C6E67 /* DatabaseFixtureTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFixtureTest.swift; sourceTree = "<group>"; };
20862088
EBA31D781F7999030055463D /* SyncPingCentre.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncPingCentre.swift; sourceTree = "<group>"; };
20872089
EBA31D7A1F79990C0055463D /* SyncTelemetryEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncTelemetryEvents.swift; sourceTree = "<group>"; };
20882090
EBA31D7C1F79996E0055463D /* SyncTelemetryUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncTelemetryUtils.swift; sourceTree = "<group>"; };
@@ -2877,6 +2879,7 @@
28772879
3BFE4B081D342FB900DDF53F /* XCUITests */ = {
28782880
isa = PBXGroup;
28792881
children = (
2882+
EB3A38912032673D004C6E67 /* DatabaseFixtureTest.swift */,
28802883
0BC9C9C31F26F54D000E8AB5 /* SiteLoadTest.swift */,
28812884
3D71C89D1F5703A1008D8646 /* CopiedLinksTests.swift */,
28822885
3DEFED071F55EBE300F8620C /* TrackingProtectionTests.swift */,
@@ -5474,6 +5477,7 @@
54745477
0B305E1B1E3A98A900BE0767 /* BookmarkingTests.swift in Sources */,
54755478
D81127D81F84023B0050841D /* PhotonActionSheetTest.swift in Sources */,
54765479
3BFE4B501D34673D00DDF53F /* ThirdPartySearchTest.swift in Sources */,
5480+
EB3A38A02032673E004C6E67 /* DatabaseFixtureTest.swift in Sources */,
54775481
2CF9D9AA20067FA10083DF2A /* BrowsingPDFTests.swift in Sources */,
54785482
0BC9C9C41F26F54D000E8AB5 /* SiteLoadTest.swift in Sources */,
54795483
2C4A07DC20246EAD0083E320 /* DragAndDropTests.swift in Sources */,

Client.xcodeproj/xcshareddata/xcschemes/Fennec_Enterprise_UITests.xcscheme

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "0820"
4-
version = "1.3">
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<PostActions>
9+
<ExecutionAction
10+
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
11+
<ActionContent
12+
title = "Run Script"
13+
scriptText = "sh &quot;${SRCROOT}/test-fixtures/scheme-postbuild.sh&quot; || exit 1">
14+
<EnvironmentBuildable>
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "F84B21BD1A090F8100AAB793"
18+
BuildableName = "Client.app"
19+
BlueprintName = "Client"
20+
ReferencedContainer = "container:Client.xcodeproj">
21+
</BuildableReference>
22+
</EnvironmentBuildable>
23+
</ActionContent>
24+
</ExecutionAction>
25+
</PostActions>
826
<BuildActionEntries>
927
<BuildActionEntry
1028
buildForTesting = "YES"

Client.xcodeproj/xcshareddata/xcschemes/Fennec_Enterprise_XCUITests.xcscheme

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "0820"
4-
version = "1.3">
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<PostActions>
9+
<ExecutionAction
10+
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
11+
<ActionContent
12+
title = "Run Script"
13+
scriptText = "sh &quot;${SRCROOT}/test-fixtures/scheme-postbuild.sh&quot; || exit 1">
14+
<EnvironmentBuildable>
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "F84B21BD1A090F8100AAB793"
18+
BuildableName = "Client.app"
19+
BlueprintName = "Client"
20+
ReferencedContainer = "container:Client.xcodeproj">
21+
</BuildableReference>
22+
</EnvironmentBuildable>
23+
</ActionContent>
24+
</ExecutionAction>
25+
</PostActions>
826
<BuildActionEntries>
927
<BuildActionEntry
1028
buildForTesting = "YES"

Client/Application/TestAppDelegate.swift

+28-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ class TestAppDelegate: AppDelegate {
1717

1818
var profile: BrowserProfile
1919
let launchArguments = ProcessInfo.processInfo.arguments
20+
21+
launchArguments.forEach { arg in
22+
if arg.starts(with: LaunchArguments.LoadDatabasePrefix) {
23+
if launchArguments.contains(LaunchArguments.ClearProfile) {
24+
fatalError("Clearing profile and loading a test database is not a supported combination.")
25+
}
26+
27+
// Grab the name of file in the bundle's test-fixtures dir, and copy it to the runtime app dir.
28+
let filename = arg.replacingOccurrences(of: LaunchArguments.LoadDatabasePrefix, with: "")
29+
let input = URL(fileURLWithPath: Bundle(for: TestAppDelegate.self).path(forResource: filename, ofType: nil, inDirectory: "test-fixtures")!)
30+
let profileDir = "\(appRootDir())/profile.testProfile"
31+
try? FileManager.default.createDirectory(atPath: profileDir, withIntermediateDirectories: false, attributes: nil)
32+
let output = URL(fileURLWithPath: "\(profileDir)/browser.db")
33+
try! FileManager.default.copyItem(at: input, to: output)
34+
}
35+
}
36+
2037
if launchArguments.contains(LaunchArguments.ClearProfile) {
2138
// Use a clean profile for each test session.
2239
log.debug("Deleting all files in 'Documents' directory to clear the profile")
@@ -68,13 +85,7 @@ class TestAppDelegate: AppDelegate {
6885
}
6986

7087
// Clear the documents directory
71-
var rootPath: String = ""
72-
let sharedContainerIdentifier = AppInfo.sharedContainerIdentifier
73-
if let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: sharedContainerIdentifier) {
74-
rootPath = url.path
75-
} else {
76-
rootPath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
77-
}
88+
let rootPath = appRootDir()
7889
let manager = FileManager.default
7990
let documents = URL(fileURLWithPath: rootPath)
8091
let docContents = try! manager.contentsOfDirectory(atPath: rootPath)
@@ -93,4 +104,14 @@ class TestAppDelegate: AppDelegate {
93104
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
94105
}
95106

107+
func appRootDir() -> String {
108+
var rootPath = ""
109+
let sharedContainerIdentifier = AppInfo.sharedContainerIdentifier
110+
if let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: sharedContainerIdentifier) {
111+
rootPath = url.path
112+
} else {
113+
rootPath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
114+
}
115+
return rootPath
116+
}
96117
}

Shared/LaunchArguments.swift

+3
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ public struct LaunchArguments {
99
public static let SkipIntro = "FIREFOX_SKIP_INTRO"
1010
public static let SkipWhatsNew = "FIREFOX_SKIP_WHATS_NEW"
1111
public static let ClearProfile = "FIREFOX_CLEAR_PROFILE"
12+
13+
// After the colon, put the name of the file to load from test bundle
14+
public static let LoadDatabasePrefix = "FIREFOX_LOAD_DB_NAMED:"
1215
}

XCUITests/DatabaseFixtureTest.swift

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import XCTest
6+
7+
class DatabaseFixtureTest: BaseTestCase {
8+
func testDatabaseFixture() {
9+
let file = "testDatabaseFixture-browser.db"
10+
let arg = LaunchArguments.LoadDatabasePrefix + file
11+
app.terminate()
12+
restart(app, args: [LaunchArguments.SkipIntro, LaunchArguments.SkipWhatsNew, arg])
13+
14+
// app will now start with prepopulated database
15+
16+
navigator.browserPerformAction(.openBookMarksOption)
17+
let list = app.tables["Bookmarks List"].cells.count
18+
XCTAssertEqual(list, 1, "There should be an entry in the bookmarks list")
19+
}
20+
}

test-fixtures/scheme-postbuild.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# UITests and XCUITests run this as a post-build step, to copy all files from
3+
# test-fixtures into the app bundle, so they can be loaded by Client.app under
4+
# test, for instance for having pregenerated prefs or pregenerated browser.db.
5+
#
6+
# XCUITests in particular need this method of due to black-boxing of the host app.
7+
# The Xcode-provided method to load test bundles does not work for App Groups.
8+
#
9+
10+
echo "••• Populate test-fixtures dir in Client.app bundle •••"
11+
fixtures="${SRCROOT}/test-fixtures"
12+
[[ -e $fixtures ]] || exit 1
13+
outpath="${TARGET_BUILD_DIR}/Client.app"
14+
rsync -zvrt --update "$fixtures" "$outpath"
1.53 MB
Binary file not shown.

0 commit comments

Comments
 (0)