Skip to content

Commit f33b5d5

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pr-package-update-004
2 parents c2e36db + fabd2e9 commit f33b5d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5134
-1154
lines changed

example/tests/early_inject_content_test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@
6363
// ============ 早期脚本环境检查 ============
6464
console.log("\n%c--- 早期脚本环境检查 ---", "color: orange; font-weight: bold;");
6565

66-
test("检查 document.head 不存在", () => {
66+
await test("检查 document.head 不存在", () => {
6767
console.log("document.head 存在:", !!document.head);
6868
console.log("document.head 值:", document.head);
6969
// 早期脚本运行时 document.head 应该不存在
7070
assertTrue(document.head === null || document.head === undefined, "早期脚本运行时 document.head 应该不存在");
7171
});
7272

73-
test("检查 document.body 不存在", () => {
73+
await test("检查 document.body 不存在", () => {
7474
console.log("document.body 存在:", !!document.body);
7575
console.log("document.body 值:", document.body);
7676
// 早期脚本运行时 document.body 应该不存在
7777
assertTrue(document.body === null || document.body === undefined, "早期脚本运行时 document.body 应该不存在");
7878
});
7979

80-
test("检查可用的DOM节点应该是HTML元素", () => {
80+
await test("检查可用的DOM节点应该是HTML元素", () => {
8181
const firstElement = document.querySelector("*");
8282
console.log("querySelector('*') 找到的第一个元素:", firstElement?.tagName);
8383
assertTrue(firstElement !== null, "应该能找到第一个DOM节点");
@@ -94,7 +94,7 @@
9494
// ============ CSP绕过测试 ============
9595
console.log("\n%c--- CSP绕过测试 ---", "color: orange; font-weight: bold;");
9696

97-
test("CSP绕过 - 内联脚本", () => {
97+
await test("CSP绕过 - 内联脚本", () => {
9898
const script = document.createElement("script");
9999
script.textContent = 'console.log("Content环境绕过CSP测试");';
100100
// 早期脚本运行时 document.head 和 document.body 不存在
@@ -110,7 +110,7 @@
110110
// ============ GM_addElement/GM_addStyle 测试 ============
111111
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");
112112

113-
test("GM_addElement", () => {
113+
await test("GM_addElement", () => {
114114
const element = GM_addElement("div", {
115115
textContent: "GM_addElement测试元素",
116116
style: "display:none;",
@@ -122,7 +122,7 @@
122122
console.log("返回元素:", element);
123123
});
124124

125-
test("GM_addStyle", () => {
125+
await test("GM_addStyle", () => {
126126
const styleElement = GM_addStyle(`
127127
.gm-style-test {
128128
color: #10b981 !important;
@@ -136,7 +136,7 @@
136136
// ============ GM_log 测试 ============
137137
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");
138138

139-
test("GM_log", () => {
139+
await test("GM_log", () => {
140140
GM_log("测试日志输出", { type: "test", value: 123 });
141141
// GM_log本身不返回值,只要不抛出异常就算成功
142142
assertTrue(true, "GM_log应该能正常输出");
@@ -145,7 +145,7 @@
145145
// ============ GM_info 测试 ============
146146
console.log("\n%c--- GM_info 测试 ---", "color: orange; font-weight: bold;");
147147

148-
test("GM_info", () => {
148+
await test("GM_info", () => {
149149
assertTrue(typeof GM_info === "object", "GM_info应该是对象");
150150
assertTrue(!!GM_info.script, "GM_info.script应该存在");
151151
assertTrue(!!GM_info.script.name, "GM_info.script.name应该存在");
@@ -161,33 +161,33 @@
161161
assert("content环境测试值", value, "应该正确保存和读取字符串");
162162
});
163163

164-
test("GM_setValue - 数字", () => {
164+
await test("GM_setValue - 数字", () => {
165165
GM_setValue("test_number", 12345);
166166
const value = GM_getValue("test_number");
167167
assert(12345, value, "应该正确保存和读取数字");
168168
});
169169

170-
test("GM_setValue - 对象", () => {
170+
await test("GM_setValue - 对象", () => {
171171
const obj = { name: "ScriptCat", type: "content" };
172172
GM_setValue("test_object", obj);
173173
const value = GM_getValue("test_object", {});
174174
assert("ScriptCat", value.name, "对象的name属性应该正确");
175175
assert("content", value.type, "对象的type属性应该正确");
176176
});
177177

178-
test("GM_getValue - 默认值", () => {
178+
await test("GM_getValue - 默认值", () => {
179179
const value = GM_getValue("non_existent_key", "默认值");
180180
assert("默认值", value, "不存在的键应该返回默认值");
181181
});
182182

183-
test("GM_listValues", () => {
183+
await test("GM_listValues", () => {
184184
const keys = GM_listValues();
185185
assertTrue(Array.isArray(keys), "GM_listValues应该返回数组");
186186
assertTrue(keys.length >= 3, "应该至少有3个存储键");
187187
console.log("存储的键:", keys);
188188
});
189189

190-
test("GM_deleteValue", () => {
190+
await test("GM_deleteValue", () => {
191191
GM_setValue("test_delete", "to_be_deleted");
192192
assert("to_be_deleted", GM_getValue("test_delete"), "值应该存在");
193193
GM_deleteValue("test_delete");

0 commit comments

Comments
 (0)