OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @const */ var TOTAL_RESULT_COUNT = 160; | 5 /** @const */ var TOTAL_RESULT_COUNT = 160; |
6 /** @const */ var WAIT_TIMEOUT = 200; | 6 /** @const */ var WAIT_TIMEOUT = 200; |
7 | 7 |
8 /** | 8 /** |
9 * Create a fake history result with the given timestamp. | 9 * Create a fake history result with the given timestamp. |
10 * @param {Number} timestamp Timestamp of the entry, in ms since the epoch. | 10 * @param {Number} timestamp Timestamp of the entry, in ms since the epoch. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 * should be used for all calls from backend stubs to the frontend. | 43 * should be used for all calls from backend stubs to the frontend. |
44 */ | 44 */ |
45 function callFrontendAsync(functionName) { | 45 function callFrontendAsync(functionName) { |
46 var args = Array.prototype.slice.call(arguments, 1); | 46 var args = Array.prototype.slice.call(arguments, 1); |
47 setTimeout(function() { | 47 setTimeout(function() { |
48 window[functionName].apply(window, args); | 48 window[functionName].apply(window, args); |
49 }, 1); | 49 }, 1); |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Checks that all the checkboxes in the [|start|, |end|] interval are checked | |
54 * and that their IDs are properly set. Does that against the checkboxes in | |
55 * |checked|, starting from the |startInChecked| position. | |
56 * @param {Array} checked An array of all the relevant checked checkboxes | |
57 * on this page. | |
58 * @param {Number} start The starting checkbox id. | |
59 * @param {Number} end The ending checkbox id. | |
60 * @param {Number} startInChecked The first position in the |checked| array | |
61 * to check. | |
62 */ | |
63 function checkInterval(checked, start, end, startInChecked) { | |
64 for (var i = start; i <= end; i++) | |
65 expectEquals('checkbox-' + i, checked[i - start + startInChecked].id); | |
66 } | |
67 | |
68 /** | |
53 * Base fixture for History WebUI testing. | 69 * Base fixture for History WebUI testing. |
54 * @extends {testing.Test} | 70 * @extends {testing.Test} |
55 * @constructor | 71 * @constructor |
56 */ | 72 */ |
57 function BaseHistoryWebUITest() {} | 73 function BaseHistoryWebUITest() {} |
58 | 74 |
59 BaseHistoryWebUITest.prototype = { | 75 BaseHistoryWebUITest.prototype = { |
60 __proto__: testing.Test.prototype, | 76 __proto__: testing.Test.prototype, |
61 | 77 |
62 /** | 78 /** |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 var nextEntry = document.querySelectorAll('.title a')[3]; | 325 var nextEntry = document.querySelectorAll('.title a')[3]; |
310 removeButton.click(); | 326 removeButton.click(); |
311 waitForCallback('historyResult', function() { | 327 waitForCallback('historyResult', function() { |
312 // The next entry after the deleted ones should now be the first. | 328 // The next entry after the deleted ones should now be the first. |
313 expectEquals(document.querySelector('.title a').textContent, | 329 expectEquals(document.querySelector('.title a').textContent, |
314 nextEntry.textContent); | 330 nextEntry.textContent); |
315 testDone(); | 331 testDone(); |
316 }); | 332 }); |
317 }); | 333 }); |
318 }); | 334 }); |
335 | |
336 /** | |
337 * Test selecting multiple entries using shift click. | |
338 */ | |
339 TEST_F('HistoryWebUITest', 'multipleSelect', function() { | |
340 var checkboxes = document.querySelectorAll( | |
341 '#results-display input[type=checkbox]'); | |
342 | |
343 // Make sure that nothing is checked. | |
344 expectEquals(0, | |
345 document.querySelectorAll( | |
346 '#results-display input[type=checkbox]:checked').length); | |
Patrick Dubroy
2013/02/06 18:53:07
All of the duplicated querySelectorAll stuff clutt
Sergiu
2013/02/07 10:18:18
Done.
| |
347 | |
348 var getShiftClickEvent = function() { | |
349 return new MouseEvent('click', { shiftKey: true }); | |
350 }; | |
351 | |
352 // Check the start. | |
353 $('checkbox-4').dispatchEvent(getShiftClickEvent()); | |
Patrick Dubroy
2013/02/06 18:53:07
Maybe factor the dispatchEvent out too? Something
Sergiu
2013/02/07 10:18:18
Done.
| |
354 // And the end. | |
355 $('checkbox-9').dispatchEvent(getShiftClickEvent()); | |
356 | |
357 // See if they are checked. | |
358 var checked = document.querySelectorAll( | |
359 '#results-display input[type=checkbox]:checked'); | |
360 expectEquals(6, checked.length); | |
361 checkInterval(checked, 4, 9, 0); | |
362 | |
363 // Extend the selection. | |
364 $('checkbox-14').dispatchEvent(getShiftClickEvent()); | |
365 | |
366 checked = document.querySelectorAll( | |
367 '#results-display input[type=checkbox]:checked'); | |
368 expectEquals(11, checked.length); | |
369 checkInterval(checked, 4, 14, 0); | |
370 | |
371 // Now do a normal click on a higher ID box and a shift click on a lower ID | |
372 // one (test the other way around). | |
373 $('checkbox-24').click(); | |
374 $('checkbox-19').dispatchEvent(getShiftClickEvent()); | |
375 | |
376 checked = document.querySelectorAll( | |
377 '#results-display input[type=checkbox]:checked'); | |
378 expectEquals(17, checked.length); | |
379 // First set of checkboxes (11). | |
380 checkInterval(checked, 4, 14, 0); | |
381 // Second set (6). | |
382 checkInterval(checked, 19, 24, 11); | |
Patrick Dubroy
2013/02/06 18:53:07
It might be more clear if you eliminated the last
Sergiu
2013/02/07 10:18:18
Heh, actually it seems like querySelectorAll retur
| |
383 | |
384 // Test deselection. | |
385 $('checkbox-26').click(); | |
386 $('checkbox-20').dispatchEvent(getShiftClickEvent()); | |
387 | |
388 checked = document.querySelectorAll( | |
389 '#results-display input[type=checkbox]:checked'); | |
390 // checkbox-20 to checkbox-24 should be deselected now. | |
391 expectEquals(12, checked.length); | |
392 // First set of checkboxes (11). | |
393 checkInterval(checked, 4, 14, 0); | |
394 // Only checkbox-19 should still be selected. | |
395 expectEquals('checkbox-19', checked[11].id); | |
396 | |
397 testDone(); | |
398 }); | |
OLD | NEW |