Skip to content

Commit 327b4e4

Browse files
committed
migrate to htmlRunner
1 parent 7fdc857 commit 327b4e4

File tree

10 files changed

+177
-287
lines changed

10 files changed

+177
-287
lines changed

src/browser/cssom/CSSParser.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn finalize(self: *CSSParser, arena: Allocator, declarations: *std.ArrayListUnma
199199
}
200200

201201
const testing = @import("../../testing.zig");
202-
test "CSSParser - Simple property" {
202+
test "Browser: CSS.Parser - Simple property" {
203203
defer testing.reset();
204204

205205
const text = "color: red;";
@@ -213,7 +213,7 @@ test "CSSParser - Simple property" {
213213
try testing.expectEqual(false, declarations[0].is_important);
214214
}
215215

216-
test "CSSParser - Property with !important" {
216+
test "Browser: CSS.Parser - Property with !important" {
217217
defer testing.reset();
218218
const text = "margin: 10px !important;";
219219
const allocator = testing.arena_allocator;
@@ -226,7 +226,7 @@ test "CSSParser - Property with !important" {
226226
try testing.expectEqual(true, declarations[0].is_important);
227227
}
228228

229-
test "CSSParser - Multiple properties" {
229+
test "Browser: CSS.Parser - Multiple properties" {
230230
defer testing.reset();
231231
const text = "color: red; font-size: 12px; margin: 5px !important;";
232232
const allocator = testing.arena_allocator;
@@ -248,7 +248,7 @@ test "CSSParser - Multiple properties" {
248248
try testing.expectEqual(true, declarations[2].is_important);
249249
}
250250

251-
test "CSSParser - Quoted value with semicolon" {
251+
test "Browser: CSS.Parser - Quoted value with semicolon" {
252252
defer testing.reset();
253253
const text = "content: \"Hello; world!\";";
254254
const allocator = testing.arena_allocator;
@@ -261,7 +261,7 @@ test "CSSParser - Quoted value with semicolon" {
261261
try testing.expectEqual(false, declarations[0].is_important);
262262
}
263263

264-
test "CSSParser - URL value" {
264+
test "Browser: CSS.Parser - URL value" {
265265
defer testing.reset();
266266
const text = "background-image: url(\"test.png\");";
267267
const allocator = testing.arena_allocator;
@@ -274,7 +274,7 @@ test "CSSParser - URL value" {
274274
try testing.expectEqual(false, declarations[0].is_important);
275275
}
276276

277-
test "CSSParser - Whitespace handling" {
277+
test "Browser: CSS.Parser - Whitespace handling" {
278278
defer testing.reset();
279279
const text = " color : purple ; margin : 10px ; ";
280280
const allocator = testing.arena_allocator;

src/browser/cssom/CSSRuleList.zig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ pub fn get_length(self: *CSSRuleList) u32 {
4747
}
4848

4949
const testing = @import("../../testing.zig");
50-
test "Browser.CSS.CSSRuleList" {
51-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
52-
defer runner.deinit();
53-
54-
try runner.testCases(&.{
55-
.{ "let list = new CSSRuleList()", "undefined" },
56-
.{ "list instanceof CSSRuleList", "true" },
57-
.{ "list.length", "0" },
58-
.{ "list.item(0)", "null" },
59-
}, .{});
50+
test "Browser: CSS.CSSRuleList" {
51+
try testing.htmlRunner("cssom/css_rule_list.html");
6052
}

src/browser/cssom/CSSStyleDeclaration.zig

Lines changed: 34 additions & 140 deletions
Large diffs are not rendered by default.

src/browser/cssom/CSSStyleSheet.zig

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@ pub fn _replaceSync(self: *CSSStyleSheet, text: []const u8) !void {
9292
}
9393

9494
const testing = @import("../../testing.zig");
95-
test "Browser.CSS.StyleSheet" {
96-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
97-
defer runner.deinit();
98-
99-
try runner.testCases(&.{
100-
.{ "let css = new CSSStyleSheet()", "undefined" },
101-
.{ "css instanceof CSSStyleSheet", "true" },
102-
.{ "css.cssRules.length", "0" },
103-
.{ "css.ownerRule", "null" },
104-
.{ "let index1 = css.insertRule('body { color: red; }', 0)", "undefined" },
105-
.{ "index1", "0" },
106-
.{ "css.cssRules.length", "1" },
107-
108-
.{
109-
\\ let replaced = false;
110-
\\ css.replace('body{}').then(() => replaced = true);
111-
,
112-
null,
113-
},
114-
// microtasks are run between each statement
115-
.{ "replaced", "true" },
116-
}, .{});
95+
test "Browser: CSS.StyleSheet" {
96+
try testing.htmlRunner("cssom/css_stylesheet.html");
11797
}

src/browser/webcomponents/custom_element_registry.zig

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/browser/xmlserializer/xmlserializer.zig

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ pub const XMLSerializer = struct {
4545
};
4646

4747
const testing = @import("../../testing.zig");
48-
test "Browser.XMLSerializer" {
49-
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
50-
defer runner.deinit();
51-
52-
try runner.testCases(&.{
53-
.{ "const s = new XMLSerializer()", "undefined" },
54-
.{ "s.serializeToString(document.getElementById('para'))", "<p id=\"para\"> And</p>" },
55-
}, .{});
56-
}
57-
test "Browser.XMLSerializer with DOCTYPE" {
58-
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "<!DOCTYPE html><html><head></head><body></body></html>" });
59-
defer runner.deinit();
60-
61-
try runner.testCases(&.{
62-
.{ "new XMLSerializer().serializeToString(document.doctype)", "<!DOCTYPE html>" },
63-
}, .{});
48+
test "Browser: XMLSerializer" {
49+
try testing.htmlRunner("xmlserializer.html");
6450
}

src/tests/cssom/css_rule_list.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script src="../testing.js"></script>
2+
<script id=css_rule_list>
3+
let list = new CSSRuleList();
4+
testing.expectEqual(true, list instanceof CSSRuleList);
5+
testing.expectEqual(0, list.length);
6+
testing.expectEqual(null, list.item(0));
7+
</script>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<script src="../testing.js"></script>
2+
<script id=css_style_declaration>
3+
let style = document.createElement('div').style;
4+
style.cssText = 'color: red; font-size: 12px; margin: 5px !important;';
5+
testing.expectEqual(3, style.length);
6+
7+
testing.expectEqua;('red', style.getPropertyValue('color'));
8+
testing.expectEqua;('12px', style.getPropertyValue('font-size'));
9+
testing.expectEqua;('', style.getPropertyValue('unknown-property'));
10+
11+
testing.expectEqual('important', style.getPropertyPriority('margin'));
12+
testing.expectEqual('', style.getPropertyPriority('color'));
13+
testing.expectEqual('', style.getPropertyPriority('unknown-property'));
14+
15+
testing.expectEqual('color', style.item(0));
16+
testing.expectEqual('font-size', style.item(1));
17+
testing.expectEqual('margin', style.item(2));
18+
testing.expectEqual('', style.item(3));
19+
20+
style.setProperty('background-color', 'blue');
21+
testing.expectEqual('blue', style.getPropertyValue('background-color'));
22+
testing.expectEqual(4, style.length);
23+
24+
style.setProperty('color', 'green');
25+
testing.expectEqual('green', style.color);
26+
testing.expectEqual('green', style.getPropertyValue('color'));
27+
testing.expectEqual(4, style.length);
28+
29+
style.setProperty('padding', '10px', 'important');
30+
testing.expectEqual('10px', style.getPropertyValue('padding'));
31+
testing.expectEqual('important', style.getPropertyPriority('padding'));
32+
33+
style.setProperty('border', '1px solid black', 'IMPORTANT');
34+
testing.expectEqual('important', style.getPropertyPriority('border'));
35+
</script>
36+
37+
<script id=removeProperty>
38+
testing.expectEqual('green', style.removeProperty('color'));
39+
testing.expectEqual('', style.getPropertyValue('color'));
40+
testing.expectEqual(5, style.length)
41+
42+
testing.expectEqual('', style.removeProperty('unknown-property'));
43+
</script>
44+
45+
<script id=includes>
46+
testing.expectEqual(false, style.cssText.includes('font-size: 10px;'));
47+
testing.expectEqual(true, style.cssText.includes('font-size: 12px;'));
48+
testing.expectEqual(true, style.cssText.includes('margin: 5px !important;'));
49+
testing.expectEqual(true, style.cssText.includes('padding: 10px !important;'));
50+
testing.expectEqual(true, style.cssText.includes('border: 1px solid black !important;'));
51+
</script>
52+
53+
<script id=special_char">
54+
style.cssText = 'color: purple; text-align: center;';
55+
testing.expectEqual(2, style.length);
56+
testing.expectEqual('purple', style.getPropertyValue('color'));
57+
testing.expectEqual('center', style.getPropertyValue('text-align'));
58+
testing.expectEqual('', style.getPropertyValue('font-size'));
59+
60+
style.setProperty('cont', 'Hello; world!');
61+
testing.expectEqual('Hello; world!', style.getPropertyValue('cont'));
62+
63+
style.cssText = 'content: "Hello; world!"; background-image: url("test.png");';
64+
testing.expectEqual('"Hello; world!"', style.getPropertyValue('content'));
65+
testing.expectEqual('url("test.png")', style.getPropertyValue('background-image'));
66+
</script>
67+
68+
<script id=cssFloat">
69+
testing.expectEqual('', style.cssFloat);
70+
style.cssFloat = 'left';
71+
testing.expectEqual('left', style.cssFloat);
72+
testing.expectEqual('left', style.getPropertyValue('float'));
73+
74+
style.cssFloat = 'right';
75+
testing.expectEqual('right', style.cssFloat);
76+
testing.expectEqual('right', style.getPropertyValue('float'));
77+
78+
style.cssFloat = null;
79+
testing.expectEqual('', style.cssFloat);
80+
testing.expectEqual('', style.getPropertyValue('float'));
81+
</script>
82+
83+
<script id=misc>
84+
style.setProperty('display', '');
85+
testing.expectEqual('', style.getPropertyValue('display'));
86+
87+
style.cssText = ' color : purple ; margin : 10px ; ';
88+
testing.expectEqual('purple', style.getPropertyValue('color'));
89+
testing.expectEqual('10px', style.getPropertyValue('margin'));
90+
91+
style.setProperty('border-bottom-left-radius', '5px');
92+
testing.expectEqual('5px', style.getPropertyValue('border-bottom-left-radius'));
93+
94+
testing.expectEqual('visible', style.visibility);
95+
testing.expectEqual('visible', style.getPropertyValue('visibility'));
96+
97+
testing.expectEqual('10px', style.margin);
98+
style.margin = 'auto';
99+
testing.expectEqual('auto', style.margin);
100+
</script>
101+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script src="../testing.js"></script>
2+
<script id=css_stylesheet>
3+
let css = new CSSStyleSheet()
4+
testing.expectEqual(true, css instanceof CSSStyleSheet);
5+
testing.expectEqual(0, css.cssRules.length);
6+
testing.expectEqual(null, css.ownerRule);
7+
8+
let index1 = css.insertRule('body { color: red; }', 0);
9+
testing.expectEqual(0, index1);
10+
testing.expectEqual(1, css.cssRules.length);
11+
12+
let replaced = false;
13+
css.replace('body{}').then(() => replaced = true);
14+
testing.eventually(() => testing.expectEqual(true, replaced));
15+
</script>

src/tests/xmlserializer.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<script src="testing.js"></script>
3+
<p id="para"> And</p>
4+
<script id=xmlserializer>
5+
const s = new XMLSerializer();
6+
testing.expectEqual('<p id="para"> And</p>', s.serializeToString($('#para')));
7+
testing.expectEqual('<!DOCTYPE html>', s.serializeToString(document.doctype));
8+
</script>

0 commit comments

Comments
 (0)