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 */ |
| 61 function checkInterval(checked, start, end) { |
| 62 for (var i = start; i <= end; i++) |
| 63 expectEquals('checkbox-' + i, checked[i - start].id); |
| 64 } |
| 65 |
| 66 /** |
53 * Base fixture for History WebUI testing. | 67 * Base fixture for History WebUI testing. |
54 * @extends {testing.Test} | 68 * @extends {testing.Test} |
55 * @constructor | 69 * @constructor |
56 */ | 70 */ |
57 function BaseHistoryWebUITest() {} | 71 function BaseHistoryWebUITest() {} |
58 | 72 |
59 BaseHistoryWebUITest.prototype = { | 73 BaseHistoryWebUITest.prototype = { |
60 __proto__: testing.Test.prototype, | 74 __proto__: testing.Test.prototype, |
61 | 75 |
62 /** | 76 /** |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 var nextEntry = document.querySelectorAll('.title a')[3]; | 323 var nextEntry = document.querySelectorAll('.title a')[3]; |
310 removeButton.click(); | 324 removeButton.click(); |
311 waitForCallback('historyResult', function() { | 325 waitForCallback('historyResult', function() { |
312 // The next entry after the deleted ones should now be the first. | 326 // The next entry after the deleted ones should now be the first. |
313 expectEquals(document.querySelector('.title a').textContent, | 327 expectEquals(document.querySelector('.title a').textContent, |
314 nextEntry.textContent); | 328 nextEntry.textContent); |
315 testDone(); | 329 testDone(); |
316 }); | 330 }); |
317 }); | 331 }); |
318 }); | 332 }); |
| 333 |
| 334 /** |
| 335 * Test selecting multiple entries using shift click. |
| 336 */ |
| 337 TEST_F('HistoryWebUITest', 'multipleSelect', function() { |
| 338 var checkboxes = document.querySelectorAll( |
| 339 '#results-display input[type=checkbox]'); |
| 340 |
| 341 var getAllChecked = function () { |
| 342 return Array.prototype.slice.call(document.querySelectorAll( |
| 343 '#results-display input[type=checkbox]:checked')); |
| 344 } |
| 345 |
| 346 // Make sure that nothing is checked. |
| 347 expectEquals(0, getAllChecked().length); |
| 348 |
| 349 var shiftClick = function(el) { |
| 350 el.dispatchEvent(new MouseEvent('click', { shiftKey: true })); |
| 351 }; |
| 352 |
| 353 // Check the start. |
| 354 shiftClick($('checkbox-4')); |
| 355 // And the end. |
| 356 shiftClick($('checkbox-9')); |
| 357 |
| 358 // See if they are checked. |
| 359 var checked = getAllChecked(); |
| 360 expectEquals(6, checked.length); |
| 361 checkInterval(checked, 4, 9); |
| 362 |
| 363 // Extend the selection. |
| 364 shiftClick($('checkbox-14')); |
| 365 |
| 366 checked = getAllChecked(); |
| 367 expectEquals(11, checked.length); |
| 368 checkInterval(checked, 4, 14); |
| 369 |
| 370 // Now do a normal click on a higher ID box and a shift click on a lower ID |
| 371 // one (test the other way around). |
| 372 $('checkbox-24').click(); |
| 373 shiftClick($('checkbox-19')); |
| 374 |
| 375 checked = getAllChecked(); |
| 376 expectEquals(17, checked.length); |
| 377 // First set of checkboxes (11). |
| 378 checkInterval(checked, 4, 14); |
| 379 // Second set (6). |
| 380 checkInterval(checked.slice(11), 19, 24); |
| 381 |
| 382 // Test deselection. |
| 383 $('checkbox-26').click(); |
| 384 shiftClick($('checkbox-20')); |
| 385 |
| 386 checked = getAllChecked(); |
| 387 // checkbox-20 to checkbox-24 should be deselected now. |
| 388 expectEquals(12, checked.length); |
| 389 // First set of checkboxes (11). |
| 390 checkInterval(checked, 4, 14); |
| 391 // Only checkbox-19 should still be selected. |
| 392 expectEquals('checkbox-19', checked[11].id); |
| 393 |
| 394 testDone(); |
| 395 }); |
OLD | NEW |