Chromium Code Reviews| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Advance past all entries newer than the specified end time. | 177 // Advance past all entries newer than the specified end time. |
| 178 var i = 0; | 178 var i = 0; |
| 179 while (i < history.length && history[i].time >= endTime) | 179 while (i < history.length && history[i].time >= endTime) |
| 180 ++i; | 180 ++i; |
| 181 | 181 |
| 182 var results = new Array(); | 182 var results = new Array(); |
|
Patrick Dubroy
2013/04/03 09:52:10
Oh, I just noticed this. Should be "[]" instead of
Sergiu
2013/04/03 13:43:39
Done.
| |
| 183 if (beginTime) { | 183 if (beginTime) { |
| 184 var j = i; | 184 var j = i; |
| 185 while (j < history.length && history[j].time >= beginTime) | 185 while (j < history.length && history[j].time >= beginTime) |
| 186 ++j; | 186 ++j; |
| 187 | 187 |
| 188 results = history.slice(i, j); | 188 results = history.slice(i, j); |
| 189 } else { | 189 } else { |
| 190 results = history.slice(i); | 190 results = history.slice(i); |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (maxCount) | 193 if (maxCount) |
| 194 results = results.slice(0, maxCount); | 194 results = results.slice(0, maxCount); |
| 195 | 195 |
| 196 // Search only by title in this stub. | |
| 197 if (searchText) { | |
|
Patrick Dubroy
2013/04/03 09:52:10
I feel like this should probably be moved to above
Sergiu
2013/04/03 13:43:39
Makes sense, fixed.
| |
| 198 var newResults = new Array(); | |
|
Patrick Dubroy
2013/04/03 09:52:10
Use "[]" instead of the Array constructor.
Sergiu
2013/04/03 13:43:39
Done.
| |
| 199 for (var k = 0; k < results.length; k++) { | |
| 200 if (results[k].title.indexOf(searchText) != -1) | |
| 201 newResults.push(results[k]); | |
| 202 } | |
| 203 results = newResults; | |
| 204 } | |
| 205 | |
| 196 var queryStartTime = ''; | 206 var queryStartTime = ''; |
| 197 var queryEndTime = ''; | 207 var queryEndTime = ''; |
| 198 if (results.length) { | 208 if (results.length) { |
| 199 queryStartTime = results[results.length - 1].dateRelativeDay; | 209 queryStartTime = results[results.length - 1].dateRelativeDay; |
| 200 queryEndTime = results[0].dateRelativeDay; | 210 queryEndTime = results[0].dateRelativeDay; |
| 201 } else if (beginTime) { | 211 } else if (beginTime) { |
| 202 queryStartTime = Date(beginTime); | 212 queryStartTime = Date(beginTime); |
| 203 queryEndTime = Date(endTime); | 213 queryEndTime = Date(endTime); |
| 204 } | 214 } |
| 205 | 215 |
| 206 callFrontendAsync( | 216 callFrontendAsync( |
| 207 'historyResult', | 217 'historyResult', |
| 208 { | 218 { |
| 209 term: searchText, | 219 term: searchText, |
| 210 finished: (history.length <= i + results.length), | 220 finished: (searchText || history.length <= i + results.length), |
| 211 queryStartTime: queryStartTime, | 221 queryStartTime: queryStartTime, |
| 212 queryEndTime: queryEndTime | 222 queryEndTime: queryEndTime |
| 213 }, | 223 }, |
| 214 results); | 224 results); |
| 215 } | 225 } |
| 216 | 226 |
| 217 /** | 227 /** |
| 218 * Fixture for History WebUI testing which returns some fake history results | 228 * Fixture for History WebUI testing which returns some fake history results |
| 219 * to the frontend. | 229 * to the frontend. |
| 220 * @extends {BaseHistoryWebUITest} | 230 * @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. | 504 // checkbox-20 to checkbox-24 should be deselected now. |
| 495 expectEquals(12, checked.length); | 505 expectEquals(12, checked.length); |
| 496 // First set of checkboxes (11). | 506 // First set of checkboxes (11). |
| 497 checkInterval(checked, 4, 14); | 507 checkInterval(checked, 4, 14); |
| 498 // Only checkbox-19 should still be selected. | 508 // Only checkbox-19 should still be selected. |
| 499 expectEquals('checkbox-19', checked[11].id); | 509 expectEquals('checkbox-19', checked[11].id); |
| 500 | 510 |
| 501 testDone(); | 511 testDone(); |
| 502 }); | 512 }); |
| 503 | 513 |
| 514 TEST_F('HistoryWebUITest', 'searchHistory', function() { | |
| 515 var getResultCount = function() { | |
| 516 return document.querySelectorAll('.entry').length; | |
| 517 }; | |
| 518 // See that all the elements are there. | |
| 519 expectEquals(RESULTS_PER_PAGE, getResultCount()); | |
| 520 | |
| 521 // See that the search works. | |
| 522 $('search-field').value = 'Thu Oct 02 2008'; | |
| 523 $('search-button').click(); | |
| 524 | |
| 525 waitForCallback('historyResult', function() { | |
| 526 expectEquals(31, getResultCount()); | |
| 527 | |
| 528 // Clear the search. | |
| 529 $('search-field').value = ''; | |
| 530 $('search-button').click(); | |
| 531 waitForCallback('historyResult', function() { | |
| 532 expectEquals(RESULTS_PER_PAGE, getResultCount()); | |
| 533 testDone(); | |
| 534 }); | |
| 535 }); | |
| 536 }); | |
| 537 | |
| 504 function setPageState(searchText, page, groupByDomain, range, offset) { | 538 function setPageState(searchText, page, groupByDomain, range, offset) { |
| 505 window.location = '#' + PageState.getHashString( | 539 window.location = '#' + PageState.getHashString( |
| 506 searchText, page, groupByDomain, range, offset); | 540 searchText, page, groupByDomain, range, offset); |
| 507 } | 541 } |
| 508 | 542 |
| 509 function RangeHistoryWebUITest() {} | 543 function RangeHistoryWebUITest() {} |
| 510 | 544 |
| 511 RangeHistoryWebUITest.prototype = { | 545 RangeHistoryWebUITest.prototype = { |
| 512 __proto__: HistoryWebUITest.prototype, | 546 __proto__: HistoryWebUITest.prototype, |
| 513 | 547 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 | 697 |
| 664 waitForCallback('historyResult', function() { | 698 waitForCallback('historyResult', function() { |
| 665 // See if the correct number of days is shown. | 699 // See if the correct number of days is shown. |
| 666 var resultsDisplay = $('results-display'); | 700 var resultsDisplay = $('results-display'); |
| 667 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); | 701 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); |
| 668 assertEquals(1, resultsDisplay.querySelectorAll('div').length); | 702 assertEquals(1, resultsDisplay.querySelectorAll('div').length); |
| 669 | 703 |
| 670 testDone(); | 704 testDone(); |
| 671 }); | 705 }); |
| 672 }); | 706 }); |
| OLD | NEW |