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

Side by Side Diff: chrome/content/tests/elemhide.js

Issue 29356338: Issue 4504 - Speed up element hiding integration tests (Closed) Base URL: https://hg.adblockplus.org/adblockplustests
Patch Set: Created Oct. 7, 2016, 11:25 a.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 | « no previous file | 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
1 (function() 1 (function()
2 { 2 {
3 let server = null; 3 let server = null;
4 let frame = null; 4 let frame = null;
5 5
6 module("Element hiding", { 6 module("Element hiding", {
7 setup: function() 7 setup: function()
8 { 8 {
9 prepareFilterComponents.call(this); 9 prepareFilterComponents.call(this);
10 preparePrefs.call(this); 10 preparePrefs.call(this);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 [["###test1", "foo#@##test1"], ["hidden", "visible"]], 101 [["###test1", "foo#@##test1"], ["hidden", "visible"]],
102 [["###test1", "~foo#@##test1"], ["visible", "visible"]], 102 [["###test1", "~foo#@##test1"], ["visible", "visible"]],
103 [["###test1", "~localhost#@##test1"], ["hidden", "visible"]], 103 [["###test1", "~localhost#@##test1"], ["hidden", "visible"]],
104 [["###test1", "#@##test1"], ["visible", "visible"]], 104 [["###test1", "#@##test1"], ["visible", "visible"]],
105 [["localhost###test1", "#@##test1"], ["visible", "visible"]], 105 [["localhost###test1", "#@##test1"], ["visible", "visible"]],
106 106
107 [["localhost.###test1"], ["visible", "visible"]], 107 [["localhost.###test1"], ["visible", "visible"]],
108 [["localhost.,localhost###test1"], ["hidden", "visible"]], 108 [["localhost.,localhost###test1"], ["hidden", "visible"]],
109 [["localhost.,foo.###test1"], ["visible", "visible"]], 109 [["localhost.,foo.###test1"], ["visible", "visible"]],
110 110
111 [["##div#test1", "@@localhost$generichide"], ["visible", "visible"]], 111 [["###test1", "localhost###test2", "@@||localhost^$document"], ["visible", " visible"]],
112 [["##div#test1", "@@localhost$genericblock"], ["hidden", "visible"]], 112 [["###test1", "localhost###test2", "@@||localhost^$~document"], ["hidden", " hidden"]],
113 [["localhost##div#test1", "@@localhost$generichide"], ["hidden", "visible"]] , 113 [["###test1", "localhost###test2", "@@||localhost^$elemhide"], ["visible", " visible"]],
114 [["~example.com##div#test1", "@@localhost$generichide"], ["visible", "visibl e"]], 114 [["###test1", "localhost###test2", "@@||localhost^$~elemhide"], ["hidden", " hidden"]],
115 [["~example.com##div#test1", "@@localhost$genericblock"], ["hidden", "visibl e"]], 115
116 [["~example.com,localhost##div#test1", "@@localhost$generichide"], ["hidden" , "visible"]], 116 [["###test1", "@@||localhost^$generichide"], ["visible", "visible"]],
117 [["###test1", "@@||localhost^$genericblock"], ["hidden", "visible"]],
118 [["localhost###test1", "@@||localhost^$generichide"], ["hidden", "visible"]] ,
119 [["~example.com###test1", "@@||localhost^$generichide"], ["visible", "visibl e"]],
120 [["~example.com###test1", "@@||localhost^$genericblock"], ["hidden", "visibl e"]],
121 [["~example.com,localhost###test1", "@@||localhost^$generichide"], ["hidden" , "visible"]],
117 ]; 122 ];
118 123
119 function runTest([filters, expected], stage) 124 function runTest(filters, expected)
120 { 125 {
121 for (let filterText of filters) 126 for (let filterText of filters)
122 FilterStorage.addFilter(Filter.fromText(filterText)); 127 FilterStorage.addFilter(Filter.fromText(filterText));
123 128
124 if (stage == 2)
125 FilterStorage.addFilter(Filter.fromText("@@||localhost^$document"));
126 else if (stage == 3)
127 FilterStorage.addFilter(Filter.fromText("@@||localhost^$~document"));
128 else if (stage == 4)
129 FilterStorage.addFilter(Filter.fromText("@@||localhost^$elemhide"));
130
131 // Second and forth runs are whitelisted, nothing should be hidden
132 if (stage == 2 || stage == 4)
133 expected = ["visible", "visible"];
134
135 frame.addEventListener("abp:frameready", function() 129 frame.addEventListener("abp:frameready", function()
136 { 130 {
137 let frameScript = ` 131 let frameScript = `
138 // The "load" event doesn't mean that our styles are applied - these 132 // The "load" event doesn't mean that our styles are applied - these
139 // are only applied after a message roundtrip to parent determining 133 // are only applied after a message roundtrip to parent determining
140 // whether element hiding is enabled. Do the same roundtrip here before 134 // whether element hiding is enabled. Do the same roundtrip here before
141 // checking visibility to make sure timing is right. 135 // checking visibility to make sure timing is right.
142 addMessageListener("pong", function() 136 addMessageListener("pong", function()
143 { 137 {
144 let visibility = [ 138 let visibility = [
(...skipping 11 matching lines...) Expand all
156 equal(visibility[0], expected[0], "First element visible"); 150 equal(visibility[0], expected[0], "First element visible");
157 equal(visibility[1], expected[1], "Second element visible"); 151 equal(visibility[1], expected[1], "Second element visible");
158 152
159 start(); 153 start();
160 }); 154 });
161 frame.messageManager.loadFrameScript("data:text/javascript," + encodeURICo mponent(frameScript), false); 155 frame.messageManager.loadFrameScript("data:text/javascript," + encodeURICo mponent(frameScript), false);
162 }, false, true); 156 }, false, true);
163 frame.setAttribute("src", "http://localhost:1234/test"); 157 frame.setAttribute("src", "http://localhost:1234/test");
164 } 158 }
165 159
166 let stageDescriptions = { 160 for (let [filters, expected] of tests)
167 1: "running without exceptions", 161 asyncTest(filters.join(", "), runTest.bind(null, filters, expected));
168 2: "running with whitelisted document",
169 3: "running with exception not applying to documents",
170 4: "running with element hiding exception",
171 };
172
173 for (let test = 0; test < tests.length; test++)
174 {
175 let [filters, expected] = tests[test];
176 for (let stage = 1; stage in stageDescriptions; stage++)
177 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT est.bind(null, tests[test], stage));
178 }
179 })(); 162 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld