summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/scripts/manifest.js
blob: fbd55682590098a9d24341f2b819fd6d97e7aaf9 (plain)
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
// grab test metadata from a test file
function __result_handler() {

    function __get_metadata() {
	var obj = new Object();
	var author = [];
	var assert = [];
	var help = [];
	var match = [];
	var mismatch = [];
	var flags = [];
	var nodes;

	nodes = document.querySelectorAll('link[rel="author"]');
	for (var i = 0; i < nodes.length; i++) {
	    var href = nodes[i].getAttribute("href");
	    var title = nodes[i].getAttribute("title");
	    var s = title;
	    if (href != null) {
		s += " <" + href + ">";
	    }
	    author.push(s);
	}
	if (nodes.length > 0) obj.author = author;
	nodes = document.querySelectorAll('meta[name="assert"]');
	for (var i = 0; i < nodes.length; i++) {
	    assert.push(nodes[i].getAttribute("content"));
	}
	if (nodes.length > 0) obj.assert = assert;
	nodes = document.querySelectorAll('link[rel="help"]');
	for (var i = 0; i < nodes.length; i++) {
	    help.push(nodes[i].getAttribute("href"));
	}
	if (nodes.length > 0) obj.help = help;
	nodes = document.querySelectorAll('link[rel="match"]');
	for (var i = 0; i < nodes.length; i++) {
	    match.push(nodes[i].getAttribute("href"));
	}
	if (nodes.length > 0) obj.match = match;
	nodes = document.querySelectorAll('link[rel="mismatch"]');
	for (var i = 0; i < nodes.length; i++) {
	    mismatch.push(nodes[i].getAttribute("href"));
	}
	if (nodes.length > 0) obj.match = mismatch;
	nodes = document.querySelectorAll('meta[name="flags"]');
	for (var i = 0; i < nodes.length; i++) {
	    flags.push(nodes[i].getAttribute("content"));
	}
	if (nodes.length > 0) obj.flags = flags;

	return obj;
    }

    var meta = __get_metadata();
    var nodes;

    function copy(obj, prop, arr) {
	if (typeof arr !== "undefined") {
	    var a = [];
	    for (var i = 0; i<arr.length;i++) {
		a[i] = arr[i];
	    }	
	    obj[prop] = a;
	}
    }


    var ret = new Object();
    ret.location = document.location.href;
    ret.type  = "manual";    
    ret.tests = new Object();

    var node = document.querySelector('script[src$="/resources/testharness.js"]');
    if (node !== null) {
	ret.type = "script";
    }

    if (ret.type === "script") {
	if (typeof metadata_generator === "undefined"
	    || Object.keys(metadata_generator.currentMetadata).length === 0)
	    return "WRAPPER:TRY_AGAIN";
	else {
	    for (var key in metadata_generator.currentMetadata) {
		var obj = metadata_generator.currentMetadata[key];
		var newtest = new Object();
		ret.tests[key]= newtest;
		if (typeof obj.help === "undefined") {
		    copy(newtest, "help", meta.help);
		} else if (typeof obj.help === "string") {
		    newtest.help = [ obj.help ];	  
		}
		if (typeof obj.author === "undefined") {
		    copy(newtest, "author", meta.author);
		} else if (typeof obj.author === "string") {
		    newtest.author = [ obj.author ];	  
		}
		if (typeof obj.assert === "undefined") {
		    copy(newtest, "assert", meta.assert);
		} else if (typeof obj.assert === "string") {
		    newtest.assert = [ obj.assert ];	  
		}
		copy(newtest, "match", meta.match);
		copy(newtest, "mismatch", meta.mismatch);
		copy(newtest, "flags", meta.flags);
	    }
	    return ret;
	}
    } else {
	var newtest = meta;
	ret.tests[document.title]= newtest;	

	if (typeof newtest.match !== "undefined"
	    || typeof newtest.mismatch !== "undefined") {
	    ret.type = "reftest";
	}

	return ret;
    }

}

function __give_up() {
    var ret = new Object();
    ret.location = document.location.href;
    ret.type  = "manual";    
    ret.tests = new Object();

    var node = document.querySelector('script[src$="/resources/testharness.js"]');
    if (node !== null) {
	ret.type = "script";
    } else if (typeof newtest.match !== "undefined"
	       || typeof newtest.mismatch !== "undefined") {
	ret.type = "reftest";
    }

    var newtest = __get_metadata();
    ret.tests[document.title]= newtest;	
    
    return ret;
}