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 // Search only by title in this stub. | |
Patrick Dubroy
2013/04/03 14:12:33
nit: I'd move this comment down above the "if hist
Sergiu
2013/04/03 17:04:39
Done.
| |
178 var results = []; | |
179 if (searchText) { | |
180 for (var k = 0; k < history.length; k++) { | |
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 while (i < results.length && results[i].time >= endTime) |
180 ++i; | 191 ++i; |
181 | 192 |
182 var results = new Array(); | |
183 if (beginTime) { | 193 if (beginTime) { |
184 var j = i; | 194 var j = i; |
185 while (j < history.length && history[j].time >= beginTime) | 195 while (j < results.length && results[j].time >= beginTime) |
186 ++j; | 196 ++j; |
187 | 197 |
188 results = history.slice(i, j); | 198 results = results.slice(i, j); |
189 } else { | 199 } else { |
190 results = history.slice(i); | 200 results = results.slice(i); |
191 } | 201 } |
192 | 202 |
193 if (maxCount) | 203 if (maxCount) |
194 results = results.slice(0, maxCount); | 204 results = results.slice(0, maxCount); |
195 | 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), |
Patrick Dubroy
2013/04/03 14:12:33
Might as well make this correct too.
Sergiu
2013/04/03 17:04:39
Done.
| |
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 |