Skip to content

Commit

Permalink
Add unit test and example
Browse files Browse the repository at this point in the history
  • Loading branch information
vikage committed Oct 31, 2023
1 parent f28d3ca commit 60c761a
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_PATH = https://dev.google.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_PATH = https://release.google.com
Original file line number Diff line number Diff line change
@@ -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)
}

}
13 changes: 13 additions & 0 deletions Tests/Fixtures/TestProject/ContentBlocker/Info.plist
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 10 additions & 0 deletions Tests/Fixtures/TestProject/ContentBlocker/blockerList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "webkit.svg"
}
}
]
19 changes: 18 additions & 1 deletion Tests/Fixtures/TestProject/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ options:
buildPhase: none
abcd:
buildPhase: none
globalTemplateAttributes:
version: legacy
configs:
Debug: debug
Release: release
fileGroups:
- Configs
- FileGroup
Expand Down Expand Up @@ -79,7 +84,9 @@ targets:
legacy:
toolPath: /usr/bin/true
passSettings: true

ContentBlocker:
templates:
- ContentBlockerTemplate
App_macOS:
type: application
platform: macOS
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions Tests/Fixtures/global_template_attributes_test.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down

0 comments on commit 60c761a

Please sign in to comment.