@harmonyos-arkts/d2h 0.1.35 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/agents/android-to-hmos-00-orchestrator.md +1 -1
- package/agents/d2h.md +1 -1
- package/assets/agc-apiclient.json +10 -0
- package/dist/bin/install-opencode.js +6 -1
- package/dist/src/metrics-plugin.js +36 -1
- package/package.json +2 -1
- package/skills/language/h5/d2h-webview-analyse/SKILL.md +309 -0
- package/skills/language/h5/d2h-webview-analyse/scripts/analyse_android_webview.py +3625 -0
- package/skills/language/h5/d2h-webview-jsbridge/SKILL.md +140 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/adaptation.md +235 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/containers-and-triage.md +30 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/detection-rules.md +69 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/report-system.md +69 -0
- package/skills/language/h5/d2h-webview-jsbridge/scripts/scan_web_jsbridge.py +2080 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/build.gradle +3 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/src/main/assets/dsbridge.js +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/src/main/java/demo/DsActivity.java +19 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/empty-app/app/src/main/kotlin/demo/Screen.kt +5 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/build.gradle +3 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/assets/www/WebViewJavascriptBridge.js +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/assets/www/index.html +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/java/demo/WebActivity.java +79 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/assets/WebViewJavascriptBridge.js +4 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/assets/page.html +2 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/kotlin/demo/Bridge.kt +23 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/kotlin/demo/WVJBWebView.kt +27 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/xml-app/app/src/main/java/demo/MainActivity.java +8 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/xml-app/app/src/main/res/layout/main.xml +9 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/run_tests.py +237 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package demo;
|
|
2
|
+
|
|
3
|
+
import android.webkit.JavascriptInterface;
|
|
4
|
+
import wendu.dsbridge.DWebView;
|
|
5
|
+
|
|
6
|
+
public class DsActivity {
|
|
7
|
+
void setup(DWebView dWebView) {
|
|
8
|
+
dWebView.addJavascriptObject(new DsApi(), "app");
|
|
9
|
+
dWebView.hasJavascriptMethod("app.getVersion");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class DsApi {
|
|
14
|
+
@JavascriptInterface
|
|
15
|
+
public String getVersion(Object args) { return "1.0.0"; }
|
|
16
|
+
|
|
17
|
+
@JavascriptInterface
|
|
18
|
+
public void fetchOrder(Object args) { }
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// lzyzsd JsBridge H5 SDK (fixture)
|
|
2
|
+
// @version 1.0.4
|
|
3
|
+
var messagingIframe = document.createElement('iframe');
|
|
4
|
+
messagingIframe.src = 'yy://__queue_message__/';
|
|
5
|
+
function callHandler(handlerName, data, responseCallback) { }
|
|
6
|
+
readyEvent.initEvent('WebViewJavascriptBridgeReady');
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package demo;
|
|
2
|
+
|
|
3
|
+
import android.webkit.WebView;
|
|
4
|
+
import android.webkit.WebSettings;
|
|
5
|
+
import android.webkit.JavascriptInterface;
|
|
6
|
+
import android.webkit.RenderProcessGoneDetail;
|
|
7
|
+
import android.webkit.WebViewClient;
|
|
8
|
+
import com.github.lzyzsd.jsbridge.BridgeWebView;
|
|
9
|
+
import com.github.lzyzsd.jsbridge.BridgeHandler;
|
|
10
|
+
|
|
11
|
+
public class WebActivity {
|
|
12
|
+
private static final String CONST_BRIDGE = "ConstBridge";
|
|
13
|
+
|
|
14
|
+
void setup(WebView webView) {
|
|
15
|
+
WebSettings s = webView.getSettings();
|
|
16
|
+
s.setJavaScriptEnabled(true);
|
|
17
|
+
s.setDomStorageEnabled(true);
|
|
18
|
+
s.setAcceptThirdPartyCookies(true);
|
|
19
|
+
webView.addJavascriptInterface(new JsApi(), "JsBridge");
|
|
20
|
+
webView.addJavascriptInterface("RevBridge", new JsApi());
|
|
21
|
+
webView.addJavascriptInterface(new Object() {
|
|
22
|
+
@JavascriptInterface
|
|
23
|
+
public void notice(String info) { }
|
|
24
|
+
}, CONST_BRIDGE);
|
|
25
|
+
webView.loadUrl("file:///android_asset/www/index.html");
|
|
26
|
+
webView.evaluateJavascript("window.__ready && window.__ready()", null);
|
|
27
|
+
webView.loadDataWithBaseURL("https://example.com/", "<html></html>", "text/html", "utf-8", null);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
31
|
+
if (url.startsWith("myapp://pay")) { pay(url); return true; }
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void setupBridge(BridgeWebView bridge) {
|
|
36
|
+
bridge.registerHandler("submitFromWeb", new BridgeHandler() {
|
|
37
|
+
public void handler(String d, Object cb) { }
|
|
38
|
+
});
|
|
39
|
+
bridge.callHandler("showInHtml", "{}", null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void pay(String url) { }
|
|
43
|
+
|
|
44
|
+
void setRenderClient(WebView webView, androidx.webkit.WebViewRenderProcessClient client) {
|
|
45
|
+
androidx.webkit.WebViewCompat.setWebViewRenderProcessClient(webView, client);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class WebService extends android.app.Service {
|
|
50
|
+
@Override
|
|
51
|
+
public android.os.IBinder onBind(android.content.Intent intent) { return null; }
|
|
52
|
+
|
|
53
|
+
void warm(WebView view) {
|
|
54
|
+
view.loadUrl("https://example.com/warm");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class DeepLinks {
|
|
59
|
+
String intentUrl = "intent://scan/#Intent;scheme=zxing;end";
|
|
60
|
+
void addPath(Object loader) { loader.addPathHandler("/assets/", null); }
|
|
61
|
+
void cookie() {
|
|
62
|
+
android.webkit.CookieManager.getInstance().setCookie("https://example.com", "sid=1; Path=/");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class CrashSafeClient extends WebViewClient {
|
|
67
|
+
@Override
|
|
68
|
+
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
|
|
69
|
+
return true; // 已处理,避免应用崩溃
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class JsApi {
|
|
74
|
+
@JavascriptInterface
|
|
75
|
+
public String getUserInfo(String token) { return "{}"; }
|
|
76
|
+
|
|
77
|
+
@JavascriptInterface
|
|
78
|
+
public void openPage(String params) { }
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package demo
|
|
2
|
+
|
|
3
|
+
import android.webkit.JavascriptInterface
|
|
4
|
+
|
|
5
|
+
class YouTubeBridge {
|
|
6
|
+
interface Callbacks {
|
|
7
|
+
fun onReady()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@JavascriptInterface
|
|
11
|
+
fun sendReady() { }
|
|
12
|
+
|
|
13
|
+
@JavascriptInterface
|
|
14
|
+
fun sendStateChange(state: String) { }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class PlayerView : android.webkit.WebView {
|
|
18
|
+
private val bridge = YouTubeBridge()
|
|
19
|
+
|
|
20
|
+
fun setup() {
|
|
21
|
+
addJavascriptInterface(bridge, "YouTubePlayerBridge")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package demo
|
|
2
|
+
|
|
3
|
+
import android.webkit.WebView
|
|
4
|
+
import android.webkit.WebSettings
|
|
5
|
+
import android.webkit.JavascriptInterface
|
|
6
|
+
|
|
7
|
+
private const val BRIDGE_NAME = "WVJBInterface"
|
|
8
|
+
|
|
9
|
+
class WVJBWebView : WebView {
|
|
10
|
+
fun init() {
|
|
11
|
+
addJavascriptInterface(this, "main")
|
|
12
|
+
addJavascriptInterface(object : Any() {
|
|
13
|
+
@JavascriptInterface
|
|
14
|
+
fun notice(info: String) { }
|
|
15
|
+
}, BRIDGE_NAME)
|
|
16
|
+
settings.javaScriptEnabled = true
|
|
17
|
+
settings.domStorageEnabled = true
|
|
18
|
+
settings.cacheMode = WebSettings.LOAD_NO_CACHE
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@JavascriptInterface
|
|
26
|
+
fun schemeEnterFullscreen() { }
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:layout_width="match_parent"
|
|
4
|
+
android:layout_height="match_parent">
|
|
5
|
+
<WebView
|
|
6
|
+
android:id="@+id/web"
|
|
7
|
+
android:layout_width="match_parent"
|
|
8
|
+
android:layout_height="match_parent" />
|
|
9
|
+
</LinearLayout>
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""d2h-webview-jsbridge 测试基线:fixtures 断言 + 真实工程冒烟(存在才跑)。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
python3 tests/run_tests.py
|
|
7
|
+
python3 tests/run_tests.py -v # 打印每个断言
|
|
8
|
+
环境变量:
|
|
9
|
+
H5_REAL_PROJECTS=<目录> 真实工程根目录(默认 /Users/admin/Desktop/h5skill,不存在则跳过)
|
|
10
|
+
"""
|
|
11
|
+
import importlib.util
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
16
|
+
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
|
17
|
+
REAL_ROOT = Path(__import__("os").environ.get("H5_REAL_PROJECTS", "/Users/admin/Desktop/h5skill"))
|
|
18
|
+
VERBOSE = "-v" in sys.argv
|
|
19
|
+
|
|
20
|
+
spec = importlib.util.spec_from_file_location("scan", ROOT / "scripts" / "scan_web_jsbridge.py")
|
|
21
|
+
scan = importlib.util.module_from_spec(spec)
|
|
22
|
+
spec.loader.exec_module(scan)
|
|
23
|
+
|
|
24
|
+
FAILS = []
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def check(name, cond, detail=""):
|
|
28
|
+
if cond:
|
|
29
|
+
if VERBOSE:
|
|
30
|
+
print(f" ok {name}")
|
|
31
|
+
else:
|
|
32
|
+
FAILS.append(f"{name} {detail}")
|
|
33
|
+
print(f" FAIL {name} {detail}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def report(project: Path):
|
|
37
|
+
return scan.build_report(project)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def ns_map(rep):
|
|
41
|
+
return {e["namespace"]: sorted(m["method"] for m in e["methods"])
|
|
42
|
+
for e in rep["bridge_methods"]["javascript_interfaces"]}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# ---------------- fixtures ----------------
|
|
46
|
+
|
|
47
|
+
def test_java_app():
|
|
48
|
+
print("[java-app]")
|
|
49
|
+
rep = report(FIXTURES / "java-app")
|
|
50
|
+
check("containers", rep["summary"]["containers"] == ["system_webview"], rep["summary"]["containers"])
|
|
51
|
+
js = rep["summary"]["jsbridge"]
|
|
52
|
+
for want in ("native_addJavascriptInterface", "url_scheme", "native_evaluate", "lzyzsd_jsbridge"):
|
|
53
|
+
check(f"jsbridge has {want}", want in js, js)
|
|
54
|
+
check("namespaces", ns_map(rep) == {
|
|
55
|
+
"JsBridge": ["getUserInfo", "openPage"],
|
|
56
|
+
"RevBridge": ["getUserInfo", "openPage"],
|
|
57
|
+
"ConstBridge": ["notice"],
|
|
58
|
+
}, ns_map(rep))
|
|
59
|
+
check("registerHandler", [h["name"] for h in rep["bridge_methods"]["register_handlers"]] == ["submitFromWeb"])
|
|
60
|
+
check("callHandler", "showInHtml" in [h["name"] for h in rep["bridge_methods"]["native_call_handlers"]])
|
|
61
|
+
check("local entry", [e["url"] for e in rep["local_h5_entries"]] == ["file:///android_asset/www/index.html"],
|
|
62
|
+
rep["local_h5_entries"])
|
|
63
|
+
check("injected_js", any("__ready" in j["script"] for j in rep["injected_js"]))
|
|
64
|
+
check("sdk lzyzsd", any(v["sdk"] == "lzyzsd" for v in rep["h5_sdk_versions"]), rep["h5_sdk_versions"])
|
|
65
|
+
check("wvjb style", (rep.get("h5_wvjb_style") or {}).get("style") == "lzyzsd_android", rep.get("h5_wvjb_style"))
|
|
66
|
+
settings = {k: {x["value"] for x in v} for k, v in rep["web_settings"].items()}
|
|
67
|
+
check("javascript enabled", settings.get("setJavaScriptEnabled") == {"true"}, settings)
|
|
68
|
+
check("third party cookie", settings.get("setAcceptThirdPartyCookies") == {"true"}, settings)
|
|
69
|
+
check("risk dedupe", len(rep["summary"]["risk_flags"]) == len(set(rep["summary"]["risk_flags"])))
|
|
70
|
+
caps = [f["feature"] for f in rep["chrome_capabilities"]]
|
|
71
|
+
check("render crash recovery", "onRenderProcessGone" in caps and "WebViewRenderProcessClient" in caps, caps)
|
|
72
|
+
check("loadDataWithBaseURL", "loadDataWithBaseURL" in caps, caps)
|
|
73
|
+
check("const namespace resolved", "ConstBridge" in ns_map(rep), ns_map(rep))
|
|
74
|
+
check("reversed api namespace", ns_map(rep).get("RevBridge") == ["getUserInfo", "openPage"], ns_map(rep))
|
|
75
|
+
check("service webview", any(s["klass"] == "WebService" for s in rep["background_webviews"]),
|
|
76
|
+
rep["background_webviews"])
|
|
77
|
+
check("deep link", any("intent://scan" in d["url"] for d in rep["deep_links"]), rep["deep_links"])
|
|
78
|
+
check("cookie", any(c["key"] == "sid" for c in rep["cookies"]), rep["cookies"])
|
|
79
|
+
check("asset loader path", any(a["path"] == "/assets/" for a in rep["asset_loader_paths"]),
|
|
80
|
+
rep["asset_loader_paths"])
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_kotlin_app():
|
|
84
|
+
print("[kotlin-app]")
|
|
85
|
+
rep = report(FIXTURES / "kotlin-app")
|
|
86
|
+
check("containers", rep["summary"]["containers"] == ["system_webview"], rep["summary"]["containers"])
|
|
87
|
+
check("namespaces", ns_map(rep) == {
|
|
88
|
+
"main": ["schemeEnterFullscreen"],
|
|
89
|
+
"WVJBInterface": ["notice"],
|
|
90
|
+
"YouTubePlayerBridge": ["sendReady", "sendStateChange"],
|
|
91
|
+
}, ns_map(rep))
|
|
92
|
+
check("wendux bridge", "wendux_wvjb" in rep["summary"]["jsbridge"], rep["summary"]["jsbridge"])
|
|
93
|
+
check("sdk wendux", any(v["sdk"] == "wendux_wvjb" for v in rep["h5_sdk_versions"]), rep["h5_sdk_versions"])
|
|
94
|
+
check("wvjb style ios", (rep.get("h5_wvjb_style") or {}).get("style") == "ios", rep.get("h5_wvjb_style"))
|
|
95
|
+
styles = [s.get("match_style") for s in rep["url_schemes"] if s.get("match_style")]
|
|
96
|
+
check("full intercept", any("全量拦截" in s for s in styles), styles)
|
|
97
|
+
settings = {k: {x["value"] for x in v} for k, v in rep["web_settings"].items()}
|
|
98
|
+
check("kotlin property settings", settings.get("setJavaScriptEnabled") == {"true"}, settings)
|
|
99
|
+
check("cache mode", settings.get("setCacheMode") == {"WebSettings.LOAD_NO_CACHE"}, settings)
|
|
100
|
+
check("no leftovers", rep["bridge_methods"]["ji_classes_without_namespace"] == [],
|
|
101
|
+
rep["bridge_methods"]["ji_classes_without_namespace"])
|
|
102
|
+
check("nested interface attribution", ns_map(rep).get("YouTubePlayerBridge") == ["sendReady", "sendStateChange"],
|
|
103
|
+
ns_map(rep))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_dsbridge_app():
|
|
107
|
+
print("[dsbridge-app]")
|
|
108
|
+
rep = report(FIXTURES / "dsbridge-app")
|
|
109
|
+
check("dsbridge detected", "dsbridge" in rep["summary"]["jsbridge"], rep["summary"]["jsbridge"])
|
|
110
|
+
check("ds namespace", ns_map(rep).get("app") == ["fetchOrder", "getVersion"], ns_map(rep))
|
|
111
|
+
check("ds sdk version", any(v["sdk"] == "dsbridge.v3" for v in rep["h5_sdk_versions"]),
|
|
112
|
+
rep["h5_sdk_versions"])
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_xml_app():
|
|
116
|
+
print("[xml-app]")
|
|
117
|
+
rep = report(FIXTURES / "xml-app")
|
|
118
|
+
check("container from xml", rep["summary"]["containers"] == ["system_webview"], rep["summary"]["containers"])
|
|
119
|
+
xmls = [e for c in rep["containers"] for e in c["evidence"].get("xml", [])]
|
|
120
|
+
check("xml evidence", any(e["file"].endswith("main.xml") for e in xmls), xmls)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_empty_app():
|
|
124
|
+
print("[empty-app]")
|
|
125
|
+
rep = report(FIXTURES / "empty-app")
|
|
126
|
+
check("no containers", rep["summary"]["containers"] == [], rep["summary"]["containers"])
|
|
127
|
+
check("no jsbridge", rep["summary"]["jsbridge"] == [], rep["summary"]["jsbridge"])
|
|
128
|
+
check("no bridge methods", rep["summary"]["bridge_method_count"] == 0)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# ---------------- 真实工程冒烟(存在才跑) ----------------
|
|
132
|
+
|
|
133
|
+
def real(name):
|
|
134
|
+
p = REAL_ROOT / name
|
|
135
|
+
return p if p.is_dir() else None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_real_projects():
|
|
139
|
+
cases = []
|
|
140
|
+
|
|
141
|
+
p = real("AgentWeb")
|
|
142
|
+
if p:
|
|
143
|
+
cases.append((p, "AgentWeb", lambda r: (
|
|
144
|
+
"agentweb" in r["summary"]["containers"]
|
|
145
|
+
and all("\n" not in e["namespace"] and len(e["namespace"]) < 100
|
|
146
|
+
for e in r["bridge_methods"]["javascript_interfaces"]))))
|
|
147
|
+
|
|
148
|
+
p = real("ByWebView")
|
|
149
|
+
if p:
|
|
150
|
+
cases.append((p, "ByWebView", lambda r: (
|
|
151
|
+
set(ns_map(r).get("injectedObject") or []) == {"imageClick", "startFunction", "showSource", "textClick"}
|
|
152
|
+
and "WVJBInterface" in ns_map(r))))
|
|
153
|
+
|
|
154
|
+
p = real("JsBridge")
|
|
155
|
+
if p:
|
|
156
|
+
cases.append((p, "JsBridge", lambda r: len(r.get("lzyzsd_fork_extensions", [])) == 3))
|
|
157
|
+
|
|
158
|
+
p = real("WebViewTvLive")
|
|
159
|
+
if p:
|
|
160
|
+
cases.append((p, "WebViewTvLive", lambda r: (
|
|
161
|
+
ns_map(r).get("main") == ["disablePlayCheck", "enablePlayCheck", "loadUrl",
|
|
162
|
+
"notifyVideoPlaying", "schemeEnterFullscreen", "setVideoSize"]
|
|
163
|
+
and any(f["feature"] == "onShowCustomView" for f in r["chrome_capabilities"]))))
|
|
164
|
+
|
|
165
|
+
p = real("android-youtube-player")
|
|
166
|
+
if p:
|
|
167
|
+
cases.append((p, "android-youtube-player", lambda r: (
|
|
168
|
+
{"sendReady", "sendStateChange", "sendVideoCurrentTime"}
|
|
169
|
+
<= set(ns_map(r).get("YouTubePlayerBridge") or [])
|
|
170
|
+
and "loadDataWithBaseURL" in [f["feature"] for f in r["chrome_capabilities"]]
|
|
171
|
+
and any(h["file"].endswith("ayp_youtube_player.html") for h in r["h5_assets"]))))
|
|
172
|
+
|
|
173
|
+
p = real("ImmichFrame_Android")
|
|
174
|
+
if p:
|
|
175
|
+
cases.append((p, "ImmichFrame_Android", lambda r: (
|
|
176
|
+
r["web_settings"].get("setJavaScriptEnabled") and
|
|
177
|
+
any("showError" in j["script"] for j in r["injected_js"]))))
|
|
178
|
+
|
|
179
|
+
if not cases:
|
|
180
|
+
print("[real projects] skipped(未找到真实工程目录)")
|
|
181
|
+
return
|
|
182
|
+
for p, name, pred in cases:
|
|
183
|
+
print(f"[real:{name}]")
|
|
184
|
+
r = report(p)
|
|
185
|
+
try:
|
|
186
|
+
ok = bool(pred(r))
|
|
187
|
+
except Exception as ex: # noqa: BLE001
|
|
188
|
+
ok = False
|
|
189
|
+
print(f" (predicate error: {ex})")
|
|
190
|
+
check(name, ok)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_conclusions():
|
|
194
|
+
"""conclusion.json 的桥方法清单必须是 scan 结果的子集(防结论漏项/写错)。"""
|
|
195
|
+
if not REAL_ROOT.is_dir():
|
|
196
|
+
return
|
|
197
|
+
import json as _json
|
|
198
|
+
for d in sorted(REAL_ROOT.glob("*-h5-report")):
|
|
199
|
+
cj = next(d.glob("*conclusion.json"), None)
|
|
200
|
+
scan_json = next(d.glob("*-scan/web-jsbridge-report.json"), None)
|
|
201
|
+
if not cj or not scan_json:
|
|
202
|
+
continue
|
|
203
|
+
c = _json.loads(cj.read_text())
|
|
204
|
+
rep = _json.loads(scan_json.read_text())
|
|
205
|
+
print(f"[conclusion:{c.get('project')}]")
|
|
206
|
+
ns_scan = {e["namespace"]: {m["method"] for m in e["methods"]}
|
|
207
|
+
for e in rep["bridge_methods"]["javascript_interfaces"]}
|
|
208
|
+
for b in c.get("bridges", []):
|
|
209
|
+
for ns, methods in (b.get("namespaces") or {}).items():
|
|
210
|
+
if ns not in ns_scan:
|
|
211
|
+
continue
|
|
212
|
+
missing = {m for m in methods if isinstance(m, str)} - ns_scan[ns]
|
|
213
|
+
check(f"{c.get('project')}:{ns} methods subset", not missing, sorted(missing))
|
|
214
|
+
for h in c.get("h5_files", []):
|
|
215
|
+
pth = Path(c.get("project_path", "")) / h["path"]
|
|
216
|
+
check(f"{c.get('project')}: h5 file exists {h['path']}", pth.exists())
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def main():
|
|
220
|
+
test_java_app()
|
|
221
|
+
test_kotlin_app()
|
|
222
|
+
test_dsbridge_app()
|
|
223
|
+
test_xml_app()
|
|
224
|
+
test_empty_app()
|
|
225
|
+
test_real_projects()
|
|
226
|
+
test_conclusions()
|
|
227
|
+
print()
|
|
228
|
+
if FAILS:
|
|
229
|
+
print(f"FAILED ({len(FAILS)}):")
|
|
230
|
+
for f in FAILS:
|
|
231
|
+
print(" -", f)
|
|
232
|
+
sys.exit(1)
|
|
233
|
+
print("ALL PASS")
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
if __name__ == "__main__":
|
|
237
|
+
main()
|