-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestregions.js
167 lines (123 loc) · 4.84 KB
/
testregions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
$(function () {
function prefixOM(name) {
return PrefixFree.Prefix.toLowerCase() + name.replace(/^[a-z]/, function($0){ return $0.toUpperCase(); });
}
function prefixMethod(obj, method) {
if (obj[method]) {
return obj[method].bind(obj);
} else {
return obj[prefixOM(method)].bind(obj);
}
}
var $flow, $region;
function setup(){
$flow = $('<div />').css("flow-into", "article");
$region = $('<div />').css("flow-from", "article");
$("body").append($flow, $region)
}
function teardown(){
$flow.remove();
$region.remove();
}
module("CSS Regions basic")
test("Named flow - content should be pulled to a flow", function(){
setup();
ok($flow.css("flow-into") == "article");
teardown();
})
test("Region - should consume from flow", function(){
setup();
ok($region.css("flow-from") == "article");
teardown();
})
test("Region properties - region-overflow property", function() {
setup();
equal($region.css('region-overflow'), 'auto', 'Initial default value for region-overflow');
$region.css('region-overflow', 'break');
equal($region.css('region-overflow'), 'break', 'region-overflow: break');
teardown();
})
//TODO Rework and re-enable tests once we get a resolution on intended test & current
// implementation behavior.
module("CSS OM");
test("Document should return a flow by name", function(){
setup();
ok(prefixMethod(document, "getFlowByName")("article"));
teardown();
})
test("NamedFlow should have overflow property", function(){
setup();
ok(prefixMethod(document, "getFlowByName")("article").overflow === false);
teardown();
})
test("NamedFlow should have contentNodes property", function() {
setup();
var namedFlow = prefixMethod(document, "getFlowByName")("article");
ok(namedFlow.contentNodes, "NamedFlow.contentNodes");
equal(namedFlow.contentNodes.length, 1, "NamedFlow.contentNodes has one node")
teardown();
})
test("NamedFlow should have getRegionsByContentNode() function", function() {
setup();
var namedFlow = prefixMethod(document, "getFlowByName")("article");
equal(typeof(namedFlow.getRegionsByContentNode), "function", "NamedFlow.getRegionsByContentNode is a function");
teardown();
})
test("NamedFlow getRegionsByContentNode() should return NodeList", function() {
setup();
$flow.html('Foo');
var namedFlow = prefixMethod(document, "getFlowByName")("article");
var theRegions = namedFlow.getRegionsByContentNode($flow.contents()[0]);
equal(theRegions.length, 1, "One region for the content");
equal(theRegions[0], $region.get(0), "Same region is returned");
teardown();
})
test("Element should have regionOverflow property", function(){
setup();
$region.css(
{
"width": "20px",
"height": "20px"
}
);
// lots of content, expect overflow
$flow.html("Long text Long text Long text Long text ");
ok($region[0][prefixOM("regionOverflow")] == "overflow");
// less content, expect fit
$flow.html("x");
ok($region[0][prefixOM("regionOverflow")] == "fit");
// no content, expect empty
$flow.html("");
ok($region[0][prefixOM("regionOverflow")] == "empty");
teardown();
})
//TODO Write tests for getRegionFlowRanges() once this gets implemented
asyncTest("regionLayoutUpdate event is thrown", function(){
function handler(ev) {
$region.unbind(prefixOM("regionLayoutUpdate"), handler);
equal(ev.target, $region[0], "Event.target points to the region");
teardown();
start();
}
setup();
$region.css(
{
"width": "20px",
"height": "20px"
}
);
$flow.html("M");
$region.bind(prefixOM("regionLayoutUpdate"), handler);
$flow.html("Long text long text long text long long long longer very longer text");
})
module("Region styling");
test("Basic @region rule support", function() {
for (var prop in window) {
if (window.hasOwnProperty(prop) && prop.indexOf("CSSRegionRule") != -1) {
ok(prop, "Found CSSRegionRule constructor, @region rules seem to be supported")
return;
}
}
ok(false, "Couldn't find CSSRegionRule constructor on document.");
});
})