Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: tools/telemetry/third_party/coverage/tests/js/tests.js

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /* Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 */
2 /* For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt */
3
4 // Tests of coverage.py HTML report chunk navigation.
5 /*global coverage, test, module, equals, jQuery, $ */
6
7 // Test helpers
8
9 function selection_is(sel) {
10 raw_selection_is(sel, true);
11 }
12
13 function raw_selection_is(sel, check_highlight) {
14 var beg = sel[0], end = sel[1];
15 equals(coverage.sel_begin, beg);
16 equals(coverage.sel_end, end);
17 if (check_highlight) {
18 equals(coverage.code_container().find(".highlight").length, end-beg);
19 }
20 }
21
22 function build_fixture(spec) {
23 var i, data;
24 $("#fixture-template").tmpl().appendTo("#qunit-fixture");
25 for (i = 0; i < spec.length; i++) {
26 data = {number: i+1, klass: spec.substr(i, 1)};
27 $("#lineno-template").tmpl(data).appendTo("#qunit-fixture .linenos");
28 $("#text-template").tmpl(data).appendTo("#qunit-fixture .text");
29 }
30 coverage.pyfile_ready(jQuery);
31 }
32
33 // Tests
34
35 // Zero-chunk tests
36
37 module("Zero-chunk navigation", {
38 setup: function () {
39 build_fixture("wwww");
40 }
41 });
42
43 test("set_sel defaults", function () {
44 coverage.set_sel(2);
45 equals(coverage.sel_begin, 2);
46 equals(coverage.sel_end, 3);
47 });
48
49 test("No first chunk to select", function () {
50 coverage.to_first_chunk();
51 });
52
53 // One-chunk tests
54
55 $.each([
56 ['rrrrr', [1,6]],
57 ['r', [1,2]],
58 ['wwrrrr', [3,7]],
59 ['wwrrrrww', [3,7]],
60 ['rrrrww', [1,5]]
61 ], function (i, params) {
62
63 // Each of these tests uses a fixture with one highlighted chunks.
64 var id = params[0];
65 var c1 = params[1];
66
67 module("One-chunk navigation - " + id, {
68 setup: function () {
69 build_fixture(id);
70 }
71 });
72
73 test("First chunk", function () {
74 coverage.to_first_chunk();
75 selection_is(c1);
76 });
77
78 test("Next chunk is first chunk", function () {
79 coverage.to_next_chunk();
80 selection_is(c1);
81 });
82
83 test("There is no next chunk", function () {
84 coverage.to_first_chunk();
85 coverage.to_next_chunk();
86 selection_is(c1);
87 });
88
89 test("There is no prev chunk", function () {
90 coverage.to_first_chunk();
91 coverage.to_prev_chunk();
92 selection_is(c1);
93 });
94 });
95
96 // Two-chunk tests
97
98 $.each([
99 ['rrwwrrrr', [1,3], [5,9]],
100 ['rb', [1,2], [2,3]],
101 ['rbbbbbbbbbb', [1,2], [2,12]],
102 ['rrrrrrrrrrb', [1,11], [11,12]],
103 ['wrrwrrrrw', [2,4], [5,9]],
104 ['rrrbbb', [1,4], [4,7]]
105 ], function (i, params) {
106
107 // Each of these tests uses a fixture with two highlighted chunks.
108 var id = params[0];
109 var c1 = params[1];
110 var c2 = params[2];
111
112 module("Two-chunk navigation - " + id, {
113 setup: function () {
114 build_fixture(id);
115 }
116 });
117
118 test("First chunk", function () {
119 coverage.to_first_chunk();
120 selection_is(c1);
121 });
122
123 test("Next chunk is first chunk", function () {
124 coverage.to_next_chunk();
125 selection_is(c1);
126 });
127
128 test("Move to next chunk", function () {
129 coverage.to_first_chunk();
130 coverage.to_next_chunk();
131 selection_is(c2);
132 });
133
134 test("Move to first chunk", function () {
135 coverage.to_first_chunk();
136 coverage.to_next_chunk();
137 coverage.to_first_chunk();
138 selection_is(c1);
139 });
140
141 test("Move to previous chunk", function () {
142 coverage.to_first_chunk();
143 coverage.to_next_chunk();
144 coverage.to_prev_chunk();
145 selection_is(c1);
146 });
147
148 test("Next doesn't move after last chunk", function () {
149 coverage.to_first_chunk();
150 coverage.to_next_chunk();
151 coverage.to_next_chunk();
152 selection_is(c2);
153 });
154
155 test("Prev doesn't move before first chunk", function () {
156 coverage.to_first_chunk();
157 coverage.to_next_chunk();
158 coverage.to_prev_chunk();
159 coverage.to_prev_chunk();
160 selection_is(c1);
161 });
162
163 });
164
165 module("Miscellaneous");
166
167 test("Jump from a line selected", function () {
168 build_fixture("rrwwrr");
169 coverage.set_sel(3);
170 coverage.to_next_chunk();
171 selection_is([5,7]);
172 });
173
174 // Tests of select_line_or_chunk.
175
176 $.each([
177 // The data for each test: a spec for the fixture to build, and an array
178 // of the selection that will be selected by select_line_or_chunk for
179 // each line in the fixture.
180 ['rrwwrr', [[1,3], [1,3], [3,4], [4,5], [5,7], [5,7]]],
181 ['rb', [[1,2], [2,3]]],
182 ['r', [[1,2]]],
183 ['w', [[1,2]]],
184 ['www', [[1,2], [2,3], [3,4]]],
185 ['wwwrrr', [[1,2], [2,3], [3,4], [4,7], [4,7], [4,7]]],
186 ['rrrwww', [[1,4], [1,4], [1,4], [4,5], [5,6], [6,7]]],
187 ['rrrbbb', [[1,4], [1,4], [1,4], [4,7], [4,7], [4,7]]]
188 ], function (i, params) {
189
190 // Each of these tests uses a fixture with two highlighted chunks.
191 var id = params[0];
192 var sels = params[1];
193
194 module("Select line or chunk - " + id, {
195 setup: function () {
196 build_fixture(id);
197 }
198 });
199
200 $.each(sels, function (i, sel) {
201 i++;
202 test("Select line " + i, function () {
203 coverage.select_line_or_chunk(i);
204 raw_selection_is(sel);
205 });
206 });
207 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698