| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 function queryHistoryImpl(args, beginTime, history) { | 170 function queryHistoryImpl(args, beginTime, history) { |
| 171 var searchText = args[0]; | 171 var searchText = args[0]; |
| 172 var offset = args[1]; | 172 var offset = args[1]; |
| 173 var range = args[2]; | 173 var range = args[2]; |
| 174 var endTime = args[3] || Number.MAX_VALUE; | 174 var endTime = args[3] || Number.MAX_VALUE; |
| 175 var maxCount = args[4]; | 175 var maxCount = args[4]; |
| 176 | 176 |
| 177 var results = []; |
| 178 if (searchText) { |
| 179 for (var k = 0; k < history.length; k++) { |
| 180 // Search only by title in this stub. |
| 181 if (history[k].title.indexOf(searchText) != -1) |
| 182 results.push(history[k]); |
| 183 } |
| 184 } else { |
| 185 results = history; |
| 186 } |
| 187 |
| 177 // Advance past all entries newer than the specified end time. | 188 // Advance past all entries newer than the specified end time. |
| 178 var i = 0; | 189 var i = 0; |
| 179 while (i < history.length && history[i].time >= endTime) | 190 // Finished is set from the history database so this behavior may not be |
| 191 // completely identical. |
| 192 var finished = true; |
| 193 while (i < results.length && results[i].time >= endTime) |
| 180 ++i; | 194 ++i; |
| 181 | 195 |
| 182 var results = new Array(); | |
| 183 if (beginTime) { | 196 if (beginTime) { |
| 184 var j = i; | 197 var j = i; |
| 185 while (j < history.length && history[j].time >= beginTime) | 198 while (j < results.length && results[j].time >= beginTime) |
| 186 ++j; | 199 ++j; |
| 187 | 200 |
| 188 results = history.slice(i, j); | 201 finished = (j == results.length); |
| 202 results = results.slice(i, j); |
| 189 } else { | 203 } else { |
| 190 results = history.slice(i); | 204 results = results.slice(i); |
| 191 } | 205 } |
| 192 | 206 |
| 193 if (maxCount) | 207 if (maxCount) { |
| 208 finished = (maxCount >= results.length); |
| 194 results = results.slice(0, maxCount); | 209 results = results.slice(0, maxCount); |
| 210 } |
| 195 | 211 |
| 196 var queryStartTime = ''; | 212 var queryStartTime = ''; |
| 197 var queryEndTime = ''; | 213 var queryEndTime = ''; |
| 198 if (results.length) { | 214 if (results.length) { |
| 199 queryStartTime = results[results.length - 1].dateRelativeDay; | 215 queryStartTime = results[results.length - 1].dateRelativeDay; |
| 200 queryEndTime = results[0].dateRelativeDay; | 216 queryEndTime = results[0].dateRelativeDay; |
| 201 } else if (beginTime) { | 217 } else if (beginTime) { |
| 202 queryStartTime = Date(beginTime); | 218 queryStartTime = Date(beginTime); |
| 203 queryEndTime = Date(endTime); | 219 queryEndTime = Date(endTime); |
| 204 } | 220 } |
| 205 | 221 |
| 206 callFrontendAsync( | 222 callFrontendAsync( |
| 207 'historyResult', | 223 'historyResult', |
| 208 { | 224 { |
| 209 term: searchText, | 225 term: searchText, |
| 210 finished: (history.length <= i + results.length), | 226 finished: finished, |
| 211 queryStartTime: queryStartTime, | 227 queryStartTime: queryStartTime, |
| 212 queryEndTime: queryEndTime | 228 queryEndTime: queryEndTime |
| 213 }, | 229 }, |
| 214 results); | 230 results); |
| 215 } | 231 } |
| 216 | 232 |
| 217 /** | 233 /** |
| 218 * Fixture for History WebUI testing which returns some fake history results | 234 * Fixture for History WebUI testing which returns some fake history results |
| 219 * to the frontend. | 235 * to the frontend. |
| 220 * @extends {BaseHistoryWebUITest} | 236 * @extends {BaseHistoryWebUITest} |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 // checkbox-20 to checkbox-24 should be deselected now. | 510 // checkbox-20 to checkbox-24 should be deselected now. |
| 495 expectEquals(12, checked.length); | 511 expectEquals(12, checked.length); |
| 496 // First set of checkboxes (11). | 512 // First set of checkboxes (11). |
| 497 checkInterval(checked, 4, 14); | 513 checkInterval(checked, 4, 14); |
| 498 // Only checkbox-19 should still be selected. | 514 // Only checkbox-19 should still be selected. |
| 499 expectEquals('checkbox-19', checked[11].id); | 515 expectEquals('checkbox-19', checked[11].id); |
| 500 | 516 |
| 501 testDone(); | 517 testDone(); |
| 502 }); | 518 }); |
| 503 | 519 |
| 520 TEST_F('HistoryWebUITest', 'searchHistory', function() { |
| 521 var getResultCount = function() { |
| 522 return document.querySelectorAll('.entry').length; |
| 523 }; |
| 524 // See that all the elements are there. |
| 525 expectEquals(RESULTS_PER_PAGE, getResultCount()); |
| 526 |
| 527 // See that the search works. |
| 528 $('search-field').value = 'Thu Oct 02 2008'; |
| 529 $('search-button').click(); |
| 530 |
| 531 waitForCallback('historyResult', function() { |
| 532 expectEquals(31, getResultCount()); |
| 533 |
| 534 // Clear the search. |
| 535 $('search-field').value = ''; |
| 536 $('search-button').click(); |
| 537 waitForCallback('historyResult', function() { |
| 538 expectEquals(RESULTS_PER_PAGE, getResultCount()); |
| 539 testDone(); |
| 540 }); |
| 541 }); |
| 542 }); |
| 543 |
| 504 function setPageState(searchText, page, groupByDomain, range, offset) { | 544 function setPageState(searchText, page, groupByDomain, range, offset) { |
| 505 window.location = '#' + PageState.getHashString( | 545 window.location = '#' + PageState.getHashString( |
| 506 searchText, page, groupByDomain, range, offset); | 546 searchText, page, groupByDomain, range, offset); |
| 507 } | 547 } |
| 508 | 548 |
| 509 function RangeHistoryWebUITest() {} | 549 function RangeHistoryWebUITest() {} |
| 510 | 550 |
| 511 RangeHistoryWebUITest.prototype = { | 551 RangeHistoryWebUITest.prototype = { |
| 512 __proto__: HistoryWebUITest.prototype, | 552 __proto__: HistoryWebUITest.prototype, |
| 513 | 553 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 703 |
| 664 waitForCallback('historyResult', function() { | 704 waitForCallback('historyResult', function() { |
| 665 // See if the correct number of days is shown. | 705 // See if the correct number of days is shown. |
| 666 var resultsDisplay = $('results-display'); | 706 var resultsDisplay = $('results-display'); |
| 667 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); | 707 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); |
| 668 assertEquals(1, resultsDisplay.querySelectorAll('div').length); | 708 assertEquals(1, resultsDisplay.querySelectorAll('div').length); |
| 669 | 709 |
| 670 testDone(); | 710 testDone(); |
| 671 }); | 711 }); |
| 672 }); | 712 }); |
| OLD | NEW |