Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: qunit/tests/filterValidation.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Patch Set: Addressed comments Created Nov. 20, 2014, 3:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « qunit/index.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 (function()
2 {
3 var filterValidation = require("filterValidation");
4 var parseFilter = filterValidation.parseFilter;
5 var parseFilters = filterValidation.parseFilters;
6
7 var filterClasses = require("filterClasses");
8 var BlockingFilter = filterClasses.BlockingFilter;
9 var ElemHideFilter = filterClasses.ElemHideFilter;
10 var CommentFilter = filterClasses.CommentFilter;
11
12 module("Filter validation");
13
14 test("Detecting invalid filters", function()
15 {
16 throws(parseFilter.bind(null, "||example.com^$unknown"), "unknown option");
17 throws(parseFilter.bind(null, "[foobar]"), "filter list header");
18 throws(parseFilter.bind(null, "##[foo"), "invalid selector");
19
20 throws(parseFilters.bind(null, "!comment\r\n||example.com^\n\n##/"), /\b4\b/ , "error contains corresponding line number");
21 });
22
23 test("Allowing valid filters", function()
24 {
25 var text, filter;
26
27 text = "||example.com^";
28 filter = parseFilter(text);
29 ok(filter instanceof BlockingFilter, "blocking filter");
30 equal(filter.text, text, "blocking filter text");
31
32 text = '##div:first-child a[src="http://example.com"] > .foo + #bar'
33 filter = parseFilter(text);
34 ok(filter instanceof ElemHideFilter, "elemhide filter");
35 equal(filter.text, text, "elemhide filter text");
36
37 text = "! foo bar"
38 filter = parseFilter(text);
39 ok(filter instanceof CommentFilter, "comment filter");
40 equal(filter.text, text, "comment filter text");
41
42 equal(parseFilter(""), null, "empty filter");
43 });
44
45 test("Normalizing filters", function()
46 {
47 var ws = " \t\r\n";
48
49 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).text, "@@||example.com^", "unnecessary spaces");
50 equal(parseFilter(ws), null, "only spaces");
51 });
52
53 test("Parsing multiple filters", function()
54 {
55 var filters = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n");
56
57 equal(filters.length, 3, "there are 3 filters");
Wladimir Palant 2014/11/20 16:58:20 Nit: You are duplicating the expected result in th
Sebastian Noack 2014/11/21 08:08:08 Done, and improved a few other messages as well.
58
59 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking");
60 equal(filters[0].text, "||example.com^", "1st filter text matches");
61
62 ok(filters[1] instanceof ElemHideFilter, "2nd filter is elemhide");
63 equal(filters[1].text, "###foobar", "2nd filter text matches");
64
65 ok(filters[2] instanceof CommentFilter, "3rd filter is comment");
66 equal(filters[2].text, "! foo bar", "3rd filter text matches");
67 });
68
69 test("Parsing multiple filters, stripping filter list headers", function()
70 {
71 var filters = parseFilters("[foobar]\n \n||example.com^\r\n! foo bar\n", tru e);
72
73 equal(filters.length, 2, "there are 2 filters");
74
75 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking");
76 equal(filters[0].text, "||example.com^", "1st filter text matches");
77
78 ok(filters[1] instanceof CommentFilter, "2nd filter is comment");
79 equal(filters[1].text, "! foo bar", "2nd filter text matches");
80 });
81 })();
OLDNEW
« no previous file with comments | « qunit/index.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld