Skip to content

Commit 60c761a

Browse files
committed
Add unit test and example
1 parent f28d3ca commit 60c761a

File tree

8 files changed

+102
-1
lines changed

8 files changed

+102
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_PATH = https://dev.google.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_PATH = https://release.google.com
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// ContentBlockerRequestHandler.swift
3+
// ContentBlocker
4+
//
5+
// Created by Thanh Vu on 31/10/2023.
6+
//
7+
8+
import UIKit
9+
import MobileCoreServices
10+
11+
class ContentBlockerRequestHandler: NSObject, NSExtensionRequestHandling {
12+
13+
func beginRequest(with context: NSExtensionContext) {
14+
let attachment = NSItemProvider(contentsOf: Bundle.main.url(forResource: "blockerList", withExtension: "json"))!
15+
16+
let item = NSExtensionItem()
17+
item.attachments = [attachment]
18+
19+
context.completeRequest(returningItems: [item], completionHandler: nil)
20+
}
21+
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.Safari.content-blocker</string>
9+
<key>NSExtensionPrincipalClass</key>
10+
<string>$(PRODUCT_MODULE_NAME).ContentBlockerRequestHandler</string>
11+
</dict>
12+
</dict>
13+
</plist>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"action": {
4+
"type": "block"
5+
},
6+
"trigger": {
7+
"url-filter": "webkit.svg"
8+
}
9+
}
10+
]

Tests/Fixtures/TestProject/project.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ options:
1616
buildPhase: none
1717
abcd:
1818
buildPhase: none
19+
globalTemplateAttributes:
20+
version: legacy
21+
configs:
22+
Debug: debug
23+
Release: release
1924
fileGroups:
2025
- Configs
2126
- FileGroup
@@ -79,7 +84,9 @@ targets:
7984
legacy:
8085
toolPath: /usr/bin/true
8186
passSettings: true
82-
87+
ContentBlocker:
88+
templates:
89+
- ContentBlockerTemplate
8390
App_macOS:
8491
type: application
8592
platform: macOS
@@ -497,6 +504,16 @@ schemes:
497504
targetTemplates:
498505
MyTemplate:
499506
scheme: {}
507+
ContentBlockerTemplate:
508+
platform: iOS
509+
type: app-extension
510+
settings:
511+
CODE_SIGN_IDENTITY: Apple Development
512+
configFiles:
513+
Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
514+
Release: ContentBlocker/Configs/${version}/Release.xcconfig
515+
sources:
516+
- ContentBlocker
500517
aggregateTargets:
501518
SuperTarget:
502519
attributes:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
targetTemplates:
2+
ContentBlockerTemplate:
3+
platform: iOS
4+
type: app-extension
5+
settings:
6+
CODE_SIGN_IDENTITY: Apple Development
7+
configFiles:
8+
Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
9+
Release: ContentBlocker/Configs/${version}/Release.xcconfig
10+
sources:
11+
- ContentBlocker
12+
13+
globalTemplateAttributes:
14+
version: legacy
15+
16+
name: Demo
17+
options:
18+
createIntermediateGroups: True
19+
targets:
20+
Demo:
21+
type: application
22+
platform: iOS
23+
deploymentTarget: "10.0"
24+
sources:
25+
- DemoXcodeGenGlobalTemplateAttribute
26+
ContentBlocker:
27+
templates:
28+
- ContentBlockerTemplate

Tests/ProjectSpecTests/SpecLoadingTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ class SpecLoadingTests: XCTestCase {
285285
]
286286
try expect(project.targets.last?.sources) == ["SomeTarget", "doesWin", "templateVariable"]
287287
}
288+
289+
$0.it("lookup global template attributes") {
290+
let path = fixturePath + "global_template_attributes_test.yml"
291+
292+
let project = try loadSpec(path: path)
293+
let extensionTarget = project.targets.first!
294+
try expect(extensionTarget.configFiles["Debug"]) == "ContentBlocker/Configs/legacy/Debug.xcconfig"
295+
try expect(extensionTarget.configFiles["Release"]) == "ContentBlocker/Configs/legacy/Release.xcconfig"
296+
}
288297
}
289298
}
290299

0 commit comments

Comments
 (0)