Add unit test and example

This commit is contained in:
Thanh Vu 2023-10-31 20:52:26 +07:00
parent f28d3caa3b
commit 60c761a9ce
8 changed files with 102 additions and 1 deletions

View File

@ -0,0 +1 @@
API_PATH = https://dev.google.com

View File

@ -0,0 +1 @@
API_PATH = https://release.google.com

View File

@ -0,0 +1,22 @@
//
// ContentBlockerRequestHandler.swift
// ContentBlocker
//
// Created by Thanh Vu on 31/10/2023.
//
import UIKit
import MobileCoreServices
class ContentBlockerRequestHandler: NSObject, NSExtensionRequestHandling {
func beginRequest(with context: NSExtensionContext) {
let attachment = NSItemProvider(contentsOf: Bundle.main.url(forResource: "blockerList", withExtension: "json"))!
let item = NSExtensionItem()
item.attachments = [attachment]
context.completeRequest(returningItems: [item], completionHandler: nil)
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.content-blocker</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ContentBlockerRequestHandler</string>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,10 @@
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "webkit.svg"
}
}
]

View File

@ -16,6 +16,11 @@ options:
buildPhase: none
abcd:
buildPhase: none
globalTemplateAttributes:
version: legacy
configs:
Debug: debug
Release: release
fileGroups:
- Configs
- FileGroup
@ -79,7 +84,9 @@ targets:
legacy:
toolPath: /usr/bin/true
passSettings: true
ContentBlocker:
templates:
- ContentBlockerTemplate
App_macOS:
type: application
platform: macOS
@ -497,6 +504,16 @@ schemes:
targetTemplates:
MyTemplate:
scheme: {}
ContentBlockerTemplate:
platform: iOS
type: app-extension
settings:
CODE_SIGN_IDENTITY: Apple Development
configFiles:
Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Release: ContentBlocker/Configs/${version}/Release.xcconfig
sources:
- ContentBlocker
aggregateTargets:
SuperTarget:
attributes:

View File

@ -0,0 +1,28 @@
targetTemplates:
ContentBlockerTemplate:
platform: iOS
type: app-extension
settings:
CODE_SIGN_IDENTITY: Apple Development
configFiles:
Debug: ContentBlocker/Configs/${version}/Debug.xcconfig
Release: ContentBlocker/Configs/${version}/Release.xcconfig
sources:
- ContentBlocker
globalTemplateAttributes:
version: legacy
name: Demo
options:
createIntermediateGroups: True
targets:
Demo:
type: application
platform: iOS
deploymentTarget: "10.0"
sources:
- DemoXcodeGenGlobalTemplateAttribute
ContentBlocker:
templates:
- ContentBlockerTemplate

View File

@ -285,6 +285,15 @@ class SpecLoadingTests: XCTestCase {
]
try expect(project.targets.last?.sources) == ["SomeTarget", "doesWin", "templateVariable"]
}
$0.it("lookup global template attributes") {
let path = fixturePath + "global_template_attributes_test.yml"
let project = try loadSpec(path: path)
let extensionTarget = project.targets.first!
try expect(extensionTarget.configFiles["Debug"]) == "ContentBlocker/Configs/legacy/Debug.xcconfig"
try expect(extensionTarget.configFiles["Release"]) == "ContentBlocker/Configs/legacy/Release.xcconfig"
}
}
}