Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chrome/test/data/extensions/api_test/history/test.js

Issue 1530002: Move history API out of experimental. Allow extensions to override history page. (Closed)
Patch Set: Rebase for commit. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // History api test for Chrome. 1 // History api test for Chrome.
2 // browser_tests.exe --gtest_filter=ExtensionApiTest.History 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.History
3 3
4 var pass = chrome.test.callbackPass; 4 var pass = chrome.test.callbackPass;
5 var fail = chrome.test.callbackFail; 5 var fail = chrome.test.callbackFail;
6 var assertEq = chrome.test.assertEq; 6 var assertEq = chrome.test.assertEq;
7 7
8 var GOOGLE_URL = 'http://www.google.com/'; 8 var GOOGLE_URL = 'http://www.google.com/';
9 var PICASA_URL = 'http://www.picasa.com/'; 9 var PICASA_URL = 'http://www.picasa.com/';
10 var A_RELATIVE_URL = 10 var A_RELATIVE_URL =
(...skipping 16 matching lines...) Expand all
27 * object 'itemVisited' stores the last item received. 27 * object 'itemVisited' stores the last item received.
28 */ 28 */
29 var itemVisitedCallback = null; 29 var itemVisitedCallback = null;
30 function itemVisitedListener(visited) { 30 function itemVisitedListener(visited) {
31 if (null != itemVisitedCallback) { 31 if (null != itemVisitedCallback) {
32 itemVisitedCallback(visited); 32 itemVisitedCallback(visited);
33 }; 33 };
34 }; 34 };
35 35
36 function removeItemVisitedListener() { 36 function removeItemVisitedListener() {
37 chrome.experimental.history.onVisited.removeListener(itemVisitedListener); 37 chrome.history.onVisited.removeListener(itemVisitedListener);
38 itemVisitedCallback = null; 38 itemVisitedCallback = null;
39 } 39 }
40 40
41 function setItemVisitedListener(callback) { 41 function setItemVisitedListener(callback) {
42 chrome.experimental.history.onVisited.addListener(itemVisitedListener); 42 chrome.history.onVisited.addListener(itemVisitedListener);
43 itemVisitedCallback = callback; 43 itemVisitedCallback = callback;
44 } 44 }
45 45
46 function setNextItemVisitedListener(callback) { 46 function setNextItemVisitedListener(callback) {
47 itemVisitedCallback = callback; 47 itemVisitedCallback = callback;
48 } 48 }
49 49
50 /** 50 /**
51 * An object used for listening to the chrome.history.onVisitRemoved events. The 51 * An object used for listening to the chrome.history.onVisitRemoved events. The
52 * global object 'itemRemovedInfo' stores the information from the last callback. 52 * global object 'itemRemovedInfo' stores the information from the last callback.
53 */ 53 */
54 var itemRemovedCallback = null; 54 var itemRemovedCallback = null;
55 function itemRemovedListener(removed) { 55 function itemRemovedListener(removed) {
56 if (null != itemRemovedCallback) { 56 if (null != itemRemovedCallback) {
57 itemRemovedCallback(removed); 57 itemRemovedCallback(removed);
58 }; 58 };
59 }; 59 };
60 60
61 function removeItemRemovedListener() { 61 function removeItemRemovedListener() {
62 chrome.experimental.history.onVisited.removeListener(itemRemovedListener); 62 chrome.history.onVisited.removeListener(itemRemovedListener);
63 itemRemovedCallback = null; 63 itemRemovedCallback = null;
64 } 64 }
65 65
66 function setItemRemovedListener(callback) { 66 function setItemRemovedListener(callback) {
67 chrome.experimental.history.onVisitRemoved.addListener(itemRemovedListener); 67 chrome.history.onVisitRemoved.addListener(itemRemovedListener);
68 itemRemovedCallback = callback; 68 itemRemovedCallback = callback;
69 } 69 }
70 70
71 function setNextItemRemovedListener(callback) { 71 function setNextItemRemovedListener(callback) {
72 itemRemovedCallback = callback; 72 itemRemovedCallback = callback;
73 } 73 }
74 74
75 /** 75 /**
76 * An object used for listening to the chrome.history.onVisitRemoved events. Set 76 * An object used for listening to the chrome.history.onVisitRemoved events. Set
77 * 'tabCompleteCallback' to a function to add extra processing to the callback. 77 * 'tabCompleteCallback' to a function to add extra processing to the callback.
(...skipping 11 matching lines...) Expand all
89 }; 89 };
90 }; 90 };
91 91
92 /** 92 /**
93 * Queries the entire history for items, calling the closure with an argument 93 * Queries the entire history for items, calling the closure with an argument
94 * specifying the the number of items in the query. 94 * specifying the the number of items in the query.
95 * @param {function(number)} callback The closure. 95 * @param {function(number)} callback The closure.
96 */ 96 */
97 function countItemsInHistory(callback) { 97 function countItemsInHistory(callback) {
98 var query = {'text': ''}; 98 var query = {'text': ''};
99 chrome.experimental.history.search(query, function(results) { 99 chrome.history.search(query, function(results) {
100 callback(results.length); 100 callback(results.length);
101 }); 101 });
102 }; 102 };
103 103
104 /** 104 /**
105 * Populates the history by calling addUrl for each url in the array urls. 105 * Populates the history by calling addUrl for each url in the array urls.
106 * @param {Array.<string>} urls The array of urls to populate the history. 106 * @param {Array.<string>} urls The array of urls to populate the history.
107 * @param {function} callback Closure. 107 * @param {function} callback Closure.
108 */ 108 */
109 function populateHistory(urls, callback) { 109 function populateHistory(urls, callback) {
110 urls.forEach(function(url) { 110 urls.forEach(function(url) {
111 chrome.experimental.history.addUrl({ 'url': url }); 111 chrome.history.addUrl({ 'url': url });
112 }); 112 });
113 callback(); 113 callback();
114 }; 114 };
115 115
116 chrome.test.runTests([ 116 chrome.test.runTests([
117 // All the tests require a blank state to start from. This test is run 117 // All the tests require a blank state to start from. This test is run
118 // first to insure that state can be acheived. 118 // first to insure that state can be acheived.
119 function clearHistory() { 119 function clearHistory() {
120 chrome.experimental.history.deleteAll(pass(function() { 120 chrome.history.deleteAll(pass(function() {
121 countItemsInHistory(pass(function(count) { 121 countItemsInHistory(pass(function(count) {
122 assertEq(0, count); 122 assertEq(0, count);
123 })); 123 }));
124 })); 124 }));
125 }, 125 },
126 126
127 function basicSearch() { 127 function basicSearch() {
128 // basicSearch callback. 128 // basicSearch callback.
129 function basicSearchTestVerification() { 129 function basicSearchTestVerification() {
130 removeItemVisitedListener(); 130 removeItemVisitedListener();
131 var query = { 'text': '' }; 131 var query = { 'text': '' };
132 chrome.experimental.history.search(query, function(results) { 132 chrome.history.search(query, function(results) {
133 assertEq(1, results.length); 133 assertEq(1, results.length);
134 assertEq(GOOGLE_URL, results[0].url); 134 assertEq(GOOGLE_URL, results[0].url);
135 135
136 // The test has succeeded. 136 // The test has succeeded.
137 chrome.test.succeed(); 137 chrome.test.succeed();
138 }); 138 });
139 }; 139 };
140 140
141 // basicSearch entry point. 141 // basicSearch entry point.
142 chrome.experimental.history.deleteAll(function() { 142 chrome.history.deleteAll(function() {
143 setItemVisitedListener(basicSearchTestVerification); 143 setItemVisitedListener(basicSearchTestVerification);
144 populateHistory([GOOGLE_URL], function() { }); 144 populateHistory([GOOGLE_URL], function() { });
145 }); 145 });
146 }, 146 },
147 147
148 function timeScopedSearch() { 148 function timeScopedSearch() {
149 var startDate = {}; 149 var startDate = {};
150 var endDate = {}; 150 var endDate = {};
151 151
152 function timeScopedSearchTestVerification() { 152 function timeScopedSearchTestVerification() {
153 removeItemVisitedListener(); 153 removeItemVisitedListener();
154 154
155 var query = { 'text': '', 155 var query = { 'text': '',
156 'startTime': startDate.getTime(), 156 'startTime': startDate.getTime(),
157 'endTime': endDate.getTime() }; 157 'endTime': endDate.getTime() };
158 chrome.experimental.history.search(query, function(results) { 158 chrome.history.search(query, function(results) {
159 assertEq(1, results.length); 159 assertEq(1, results.length);
160 assertEq(GOOGLE_URL, results[0].url); 160 assertEq(GOOGLE_URL, results[0].url);
161 161
162 // The test has succeeded. 162 // The test has succeeded.
163 chrome.test.succeed(); 163 chrome.test.succeed();
164 }); 164 });
165 }; 165 };
166 166
167 function onAddedItem() { 167 function onAddedItem() {
168 // Set the next test callback. 168 // Set the next test callback.
169 setNextItemVisitedListener(timeScopedSearchTestVerification); 169 setNextItemVisitedListener(timeScopedSearchTestVerification);
170 170
171 // Chrome has seconds resolution, so we must wait in order to search 171 // Chrome has seconds resolution, so we must wait in order to search
172 // a range. 172 // a range.
173 waitAFewSeconds(2, function() { 173 waitAFewSeconds(2, function() {
174 endDate = new Date(); 174 endDate = new Date();
175 endDate.setTime(endDate.getTime() - 500); 175 endDate.setTime(endDate.getTime() - 500);
176 populateHistory([PICASA_URL], function() { }); 176 populateHistory([PICASA_URL], function() { });
177 }); 177 });
178 }; 178 };
179 179
180 // timeScopedSearch entry point. 180 // timeScopedSearch entry point.
181 chrome.experimental.history.deleteAll(function() { 181 chrome.history.deleteAll(function() {
182 // Set the test callback. 182 // Set the test callback.
183 setItemVisitedListener(onAddedItem); 183 setItemVisitedListener(onAddedItem);
184 // Set the start time a few seconds in the past. 184 // Set the start time a few seconds in the past.
185 startDate = new Date(); 185 startDate = new Date();
186 startDate.setTime(startDate.getTime() - 1000); 186 startDate.setTime(startDate.getTime() - 1000);
187 populateHistory([GOOGLE_URL], function() { }); 187 populateHistory([GOOGLE_URL], function() { });
188 }); 188 });
189 }, 189 },
190 190
191 function searchWithIntegerTimes() { 191 function searchWithIntegerTimes() {
192 chrome.experimental.history.deleteAll(function() { 192 chrome.history.deleteAll(function() {
193 // Search with an integer time range. 193 // Search with an integer time range.
194 var query = { 'text': '', 194 var query = { 'text': '',
195 'startTime': 0, 195 'startTime': 0,
196 'endTime': 12345678 }; 196 'endTime': 12345678 };
197 chrome.experimental.history.search(query, function(results) { 197 chrome.history.search(query, function(results) {
198 assertEq(0, results.length); 198 assertEq(0, results.length);
199 chrome.test.succeed(); 199 chrome.test.succeed();
200 }); 200 });
201 }); 201 });
202 }, 202 },
203 203
204 // Give time epochs x,y,z and history events A,B which occur in the sequence 204 // Give time epochs x,y,z and history events A,B which occur in the sequence
205 // x A y B z, this test scopes the search to the interval [y,z] to test that 205 // x A y B z, this test scopes the search to the interval [y,z] to test that
206 // [x,y) is excluded. The previous test scoped to the interval [x,y]. 206 // [x,y) is excluded. The previous test scoped to the interval [x,y].
207 function timeScopedSearch2() { 207 function timeScopedSearch2() {
208 var startDate = {}; 208 var startDate = {};
209 var endDate = {}; 209 var endDate = {};
210 210
211 function timeScopedSearch2TestVerification() { 211 function timeScopedSearch2TestVerification() {
212 removeItemVisitedListener(); 212 removeItemVisitedListener();
213 213
214 endDate = new Date(); 214 endDate = new Date();
215 endDate.setTime(endDate.getTime() + 1000); 215 endDate.setTime(endDate.getTime() + 1000);
216 var query = { 'text': '', 216 var query = { 'text': '',
217 'startTime': startDate.getTime(), 217 'startTime': startDate.getTime(),
218 'endTime': endDate.getTime() }; 218 'endTime': endDate.getTime() };
219 chrome.experimental.history.search(query, function(results) { 219 chrome.history.search(query, function(results) {
220 assertEq(1, results.length); 220 assertEq(1, results.length);
221 assertEq(PICASA_URL, results[0].url); 221 assertEq(PICASA_URL, results[0].url);
222 222
223 // The test has succeeded. 223 // The test has succeeded.
224 chrome.test.succeed(); 224 chrome.test.succeed();
225 }); 225 });
226 }; 226 };
227 227
228 function onAddedItem() { 228 function onAddedItem() {
229 // Set the next test callback. 229 // Set the next test callback.
230 setNextItemVisitedListener(timeScopedSearch2TestVerification); 230 setNextItemVisitedListener(timeScopedSearch2TestVerification);
231 231
232 // Chrome has seconds resolution, so we must wait in order to search 232 // Chrome has seconds resolution, so we must wait in order to search
233 // a range. 233 // a range.
234 waitAFewSeconds(2, function() { 234 waitAFewSeconds(2, function() {
235 startDate = new Date(); 235 startDate = new Date();
236 startDate.setTime(startDate.getTime() - 1000); 236 startDate.setTime(startDate.getTime() - 1000);
237 populateHistory([PICASA_URL], function() { }); 237 populateHistory([PICASA_URL], function() { });
238 }); 238 });
239 }; 239 };
240 240
241 // timeScopedSearch entry point. 241 // timeScopedSearch entry point.
242 chrome.experimental.history.deleteAll(function() { 242 chrome.history.deleteAll(function() {
243 // Set the test callback. 243 // Set the test callback.
244 setItemVisitedListener(onAddedItem); 244 setItemVisitedListener(onAddedItem);
245 populateHistory([GOOGLE_URL], function() { }); 245 populateHistory([GOOGLE_URL], function() { });
246 }); 246 });
247 }, 247 },
248 248
249 function lengthScopedSearch() { 249 function lengthScopedSearch() {
250 var urls = [GOOGLE_URL, PICASA_URL]; 250 var urls = [GOOGLE_URL, PICASA_URL];
251 var urlsAdded = 0; 251 var urlsAdded = 0;
252 252
253 function lengthScopedSearchTestVerification() { 253 function lengthScopedSearchTestVerification() {
254 // Ensure all urls have been added. 254 // Ensure all urls have been added.
255 urlsAdded += 1; 255 urlsAdded += 1;
256 if (urlsAdded < urls.length) 256 if (urlsAdded < urls.length)
257 return; 257 return;
258 258
259 removeItemVisitedListener(); 259 removeItemVisitedListener();
260 260
261 var query = { 'text': '', 'maxResults': 1 }; 261 var query = { 'text': '', 'maxResults': 1 };
262 chrome.experimental.history.search(query, function(results) { 262 chrome.history.search(query, function(results) {
263 assertEq(1, results.length); 263 assertEq(1, results.length);
264 assertEq(PICASA_URL, results[0].url); 264 assertEq(PICASA_URL, results[0].url);
265 265
266 // The test has succeeded. 266 // The test has succeeded.
267 chrome.test.succeed(); 267 chrome.test.succeed();
268 }); 268 });
269 }; 269 };
270 270
271 // lengthScopedSearch entry point. 271 // lengthScopedSearch entry point.
272 chrome.experimental.history.deleteAll(function() { 272 chrome.history.deleteAll(function() {
273 setItemVisitedListener(lengthScopedSearchTestVerification); 273 setItemVisitedListener(lengthScopedSearchTestVerification);
274 populateHistory(urls, function() { }); 274 populateHistory(urls, function() { });
275 }); 275 });
276 }, 276 },
277 277
278 function fullTextSearch() { 278 function fullTextSearch() {
279 chrome.experimental.history.deleteAll(function() { 279 chrome.history.deleteAll(function() {
280 // The continuation of the test after the windows have been opened. 280 // The continuation of the test after the windows have been opened.
281 var validateTest = function() { 281 var validateTest = function() {
282 // Continue with the test. 282 // Continue with the test.
283 // A title search for www.a.com should find a. 283 // A title search for www.a.com should find a.
284 var query = { 'text': 'www.a.com' }; 284 var query = { 'text': 'www.a.com' };
285 chrome.experimental.history.search(query, function(results) { 285 chrome.history.search(query, function(results) {
286 assertEq(1, results.length); 286 assertEq(1, results.length);
287 assertEq(A_RELATIVE_URL, results[0].url); 287 assertEq(A_RELATIVE_URL, results[0].url);
288 288
289 // Text in the body of b.html. 289 // Text in the body of b.html.
290 query = { 'text': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' }; 290 query = { 'text': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' };
291 chrome.experimental.history.search(query, function(results) { 291 chrome.history.search(query, function(results) {
292 assertEq(1, results.length); 292 assertEq(1, results.length);
293 assertEq(B_RELATIVE_URL, results[0].url); 293 assertEq(B_RELATIVE_URL, results[0].url);
294 294
295 // The test has succeeded. 295 // The test has succeeded.
296 chrome.test.succeed(); 296 chrome.test.succeed();
297 }); 297 });
298 }); 298 });
299 }; 299 };
300 300
301 // Setup a callback object for tab events. 301 // Setup a callback object for tab events.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 }); 337 });
338 }, 338 },
339 339
340 function getVisits() { 340 function getVisits() {
341 // getVisits callback. 341 // getVisits callback.
342 function getVisitsTestVerification() { 342 function getVisitsTestVerification() {
343 removeItemVisitedListener(); 343 removeItemVisitedListener();
344 344
345 // Verify that we received the url. 345 // Verify that we received the url.
346 var query = { 'text': '' }; 346 var query = { 'text': '' };
347 chrome.experimental.history.search(query, function(results) { 347 chrome.history.search(query, function(results) {
348 assertEq(1, results.length); 348 assertEq(1, results.length);
349 assertEq(GOOGLE_URL, results[0].url); 349 assertEq(GOOGLE_URL, results[0].url);
350 350
351 var id = results[0].id; 351 var id = results[0].id;
352 chrome.experimental.history.getVisits({ 'url': GOOGLE_URL }, function(re sults) { 352 chrome.history.getVisits({ 'url': GOOGLE_URL }, function(results) {
353 assertEq(1, results.length); 353 assertEq(1, results.length);
354 assertEq(id, results[0].id); 354 assertEq(id, results[0].id);
355 355
356 // The test has succeeded. 356 // The test has succeeded.
357 chrome.test.succeed(); 357 chrome.test.succeed();
358 }); 358 });
359 }); 359 });
360 }; 360 };
361 361
362 // getVisits entry point. 362 // getVisits entry point.
363 chrome.experimental.history.deleteAll(function() { 363 chrome.history.deleteAll(function() {
364 setItemVisitedListener(getVisitsTestVerification); 364 setItemVisitedListener(getVisitsTestVerification);
365 populateHistory([GOOGLE_URL], function() { }); 365 populateHistory([GOOGLE_URL], function() { });
366 }); 366 });
367 }, 367 },
368 368
369 function deleteUrl() { 369 function deleteUrl() {
370 function deleteUrlTestVerification() { 370 function deleteUrlTestVerification() {
371 removeItemRemovedListener(); 371 removeItemRemovedListener();
372 372
373 var query = { 'text': '' }; 373 var query = { 'text': '' };
374 chrome.experimental.history.search(query, function(results) { 374 chrome.history.search(query, function(results) {
375 assertEq(0, results.length); 375 assertEq(0, results.length);
376 376
377 // The test has succeeded. 377 // The test has succeeded.
378 chrome.test.succeed(); 378 chrome.test.succeed();
379 }); 379 });
380 }; 380 };
381 381
382 function onAddedItem() { 382 function onAddedItem() {
383 removeItemVisitedListener(); 383 removeItemVisitedListener();
384 384
385 var query = { 'text': '' }; 385 var query = { 'text': '' };
386 chrome.experimental.history.search(query, function(results) { 386 chrome.history.search(query, function(results) {
387 assertEq(1, results.length); 387 assertEq(1, results.length);
388 assertEq(GOOGLE_URL, results[0].url); 388 assertEq(GOOGLE_URL, results[0].url);
389 389
390 chrome.experimental.history.deleteUrl({ 'url': GOOGLE_URL }); 390 chrome.history.deleteUrl({ 'url': GOOGLE_URL });
391 }); 391 });
392 }; 392 };
393 393
394 // deleteUrl entry point. 394 // deleteUrl entry point.
395 chrome.experimental.history.deleteAll(function() { 395 chrome.history.deleteAll(function() {
396 setItemVisitedListener(onAddedItem); 396 setItemVisitedListener(onAddedItem);
397 setItemRemovedListener(deleteUrlTestVerification); 397 setItemRemovedListener(deleteUrlTestVerification);
398 populateHistory([GOOGLE_URL], function() { }); 398 populateHistory([GOOGLE_URL], function() { });
399 }); 399 });
400 }, 400 },
401 401
402 function deleteRange() { 402 function deleteRange() {
403 var urls = [GOOGLE_URL, PICASA_URL]; 403 var urls = [GOOGLE_URL, PICASA_URL];
404 var startDate = {}; 404 var startDate = {};
405 var endDate = {}; 405 var endDate = {};
406 var itemsAdded = 0; 406 var itemsAdded = 0;
407 407
408 function deleteRangeTestVerification() { 408 function deleteRangeTestVerification() {
409 removeItemRemovedListener(); 409 removeItemRemovedListener();
410 410
411 var query = { 'text': '' }; 411 var query = { 'text': '' };
412 chrome.experimental.history.search(query, function(results) { 412 chrome.history.search(query, function(results) {
413 assertEq(1, results.length); 413 assertEq(1, results.length);
414 assertEq(PICASA_URL, results[0].url); 414 assertEq(PICASA_URL, results[0].url);
415 415
416 // The test has succeeded. 416 // The test has succeeded.
417 chrome.test.succeed(); 417 chrome.test.succeed();
418 }); 418 });
419 }; 419 };
420 420
421 function onAddedItem() { 421 function onAddedItem() {
422 itemsAdded += 1; 422 itemsAdded += 1;
423 423
424 if (itemsAdded < urls.length) { 424 if (itemsAdded < urls.length) {
425 // Chrome has seconds resolution, so we must wait to search a range. 425 // Chrome has seconds resolution, so we must wait to search a range.
426 waitAFewSeconds(2, function() { 426 waitAFewSeconds(2, function() {
427 endDate = new Date(); 427 endDate = new Date();
428 endDate.setTime(endDate.getTime() - 1000); 428 endDate.setTime(endDate.getTime() - 1000);
429 populateHistory([urls[itemsAdded]], function() { }); 429 populateHistory([urls[itemsAdded]], function() { });
430 }); 430 });
431 return; 431 return;
432 }; 432 };
433 433
434 removeItemVisitedListener(); 434 removeItemVisitedListener();
435 chrome.experimental.history.deleteRange({ 'startTime': startDate.getTime() , 435 chrome.history.deleteRange({ 'startTime': startDate.getTime(),
436 'endTime': endDate.getTime() }, 436 'endTime': endDate.getTime() },
437 function() { }); 437 function() { });
438 }; 438 };
439 439
440 // deletRange entry point. 440 // deletRange entry point.
441 chrome.experimental.history.deleteAll(function() { 441 chrome.history.deleteAll(function() {
442 setItemVisitedListener(onAddedItem); 442 setItemVisitedListener(onAddedItem);
443 setItemRemovedListener(deleteRangeTestVerification); 443 setItemRemovedListener(deleteRangeTestVerification);
444 444
445 startDate = new Date(); 445 startDate = new Date();
446 startDate.setTime(startDate.getTime() - 1000); 446 startDate.setTime(startDate.getTime() - 1000);
447 447
448 populateHistory([urls[itemsAdded]], function() { }); 448 populateHistory([urls[itemsAdded]], function() { });
449 }); 449 });
450 }, 450 },
451 451
452 // Suppose we have time epochs x,y,z and history events A,B which occur in the 452 // Suppose we have time epochs x,y,z and history events A,B which occur in the
453 // sequence x A y B z. The previous deleteRange test deleted the range [x,y], 453 // sequence x A y B z. The previous deleteRange test deleted the range [x,y],
454 // this test deletes the range [y,z]. 454 // this test deletes the range [y,z].
455 function deleteRange2() { 455 function deleteRange2() {
456 var urls = [GOOGLE_URL, PICASA_URL]; 456 var urls = [GOOGLE_URL, PICASA_URL];
457 var startDate = {}; 457 var startDate = {};
458 var endDate = {}; 458 var endDate = {};
459 var itemsAdded = 0; 459 var itemsAdded = 0;
460 460
461 function deleteRange2TestVerification() { 461 function deleteRange2TestVerification() {
462 removeItemRemovedListener(); 462 removeItemRemovedListener();
463 463
464 var query = { 'text': '' }; 464 var query = { 'text': '' };
465 chrome.experimental.history.search(query, function(results) { 465 chrome.history.search(query, function(results) {
466 assertEq(1, results.length); 466 assertEq(1, results.length);
467 assertEq(GOOGLE_URL, results[0].url); 467 assertEq(GOOGLE_URL, results[0].url);
468 468
469 // The test has succeeded. 469 // The test has succeeded.
470 chrome.test.succeed(); 470 chrome.test.succeed();
471 }); 471 });
472 }; 472 };
473 473
474 function onAddedItem() { 474 function onAddedItem() {
475 itemsAdded += 1; 475 itemsAdded += 1;
476 476
477 if (itemsAdded < urls.length) { 477 if (itemsAdded < urls.length) {
478 // Chrome has seconds resolution, so we must wait to search a range. 478 // Chrome has seconds resolution, so we must wait to search a range.
479 waitAFewSeconds(2, function() { 479 waitAFewSeconds(2, function() {
480 startDate = new Date(); 480 startDate = new Date();
481 startDate.setTime(startDate.getTime() - 1000); 481 startDate.setTime(startDate.getTime() - 1000);
482 populateHistory([urls[itemsAdded]], function() { }); 482 populateHistory([urls[itemsAdded]], function() { });
483 }); 483 });
484 return; 484 return;
485 }; 485 };
486 486
487 removeItemVisitedListener(); 487 removeItemVisitedListener();
488 488
489 endDate = new Date(); 489 endDate = new Date();
490 endDate.setTime(endDate.getTime() + 1000); 490 endDate.setTime(endDate.getTime() + 1000);
491 chrome.experimental.history.deleteRange({ 'startTime': startDate.getTime() , 491 chrome.history.deleteRange({ 'startTime': startDate.getTime(),
492 'endTime': endDate.getTime() }, 492 'endTime': endDate.getTime() },
493 function() { }); 493 function() { });
494 }; 494 };
495 495
496 // deletRange entry point. 496 // deletRange entry point.
497 chrome.experimental.history.deleteAll(function() { 497 chrome.history.deleteAll(function() {
498 setItemVisitedListener(onAddedItem); 498 setItemVisitedListener(onAddedItem);
499 setItemRemovedListener(deleteRange2TestVerification); 499 setItemRemovedListener(deleteRange2TestVerification);
500 populateHistory([urls[itemsAdded]], function() { }); 500 populateHistory([urls[itemsAdded]], function() { });
501 }); 501 });
502 }, 502 },
503 ]); 503 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698