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
|
/**
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2014 Loic J. Duros
* Copyright (C) 2014, 2015 Nik Nyby
*
* This file is part of GNU LibreJS.
*
* GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
const jsChecker = require("js_checker/js_checker");
const constants = require("js_checker/constant_types");
var checkTypes = constants.checkTypes;
var init = function() {
var checker = jsChecker.jsChecker();
return checker;
};
exports.testTrivial = function(assert, done) {
var checker = init();
var jsString = "alert('internal script');";
checker.searchJs(jsString,
function() {
// FIXME, should actually be TRIVIAL
assert.equal(checkTypes.TRIVIAL_DEFINES_FUNCTION,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testTrivialWithFuncDef = function(assert, done) {
var jsString = "function blah (arg) { return arg; };";
var checker = init();
checker.searchJs(jsString,
function() {
assert.equal(checkTypes.TRIVIAL_DEFINES_FUNCTION,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testTrivialWithFunc = function(assert, done) {
var checker = init();
var jsString = "var blah = function(arg) { return arg; };";
checker.searchJs(jsString,
function() {
assert.equal(checkTypes.TRIVIAL_DEFINES_FUNCTION,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testANontrivial = function(assert, done) {
var checker = init();
var jsString = "document.createElement('script');";
checker.searchJs(jsString,
function() {
assert.equal(checkTypes.NONTRIVIAL,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testLambdaError1 = function(assert, done) {
var checker = init();
var jsString = "document.write('<scr' + 'ipt type=\"text/javascript\" src=\"' + regs_url + 'fdsfds.dew/' + regs_sitepage + '/1' + regs_rns + '@' + regs_listpos + regs_query + '\"></scr' + 'ipt>');";
checker.searchJs(jsString,
function() {
assert.equal(checkTypes.NONTRIVIAL,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testLambdaError = function(assert, done) {
var jsString = "_version = 11;\nif (navigator.userAgent.indexOf('Mozilla/3') != -1)\nregs_version = 10;\n\n if (regs_version >= 11) {\ndocument.write('<scr' + 'ipt type=\"text/javascript\" src=\"' + regs_url + 'fdsfds.dew/' + regs_sitepage + '/1' + regs_rns + '@' + regs_listpos + regs_query + '\"></scr' + 'ipt>');\n}";
var checker = init();
checker.searchJs(jsString,
function() {
assert.equal(checkTypes.NONTRIVIAL,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testContinueKeyword = function(assert, done) {
var jsString = 'for (var i = 0; i < len; i++) {' +
'if (test) { continue; } }';
var checker = init();
checker.searchJs(jsString,
function() {
// FIXME, should actually be TRIVIAL
assert.equal(checkTypes.TRIVIAL_DEFINES_FUNCTION,
checker.parseTree.freeTrivialCheck.type);
done();
});
};
exports.testIsNotFreeLicensed = function(assert, done) {
var jsString = 'for (var i = 0; i < len; i++) {' +
'if (test) { continue; } }';
var checker = init();
assert.ok(checker.isFreeLicensed(jsString) === false)
done();
};
require('sdk/test').run(exports);
|