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
3 // found in the LICENSE file.
5 // History api test for Chrome.
6 // browser_tests.exe --gtest_filter=HistoryApiTest.Delete
8 // runHistoryTestFns is defined in ./common.js .
10 // All the tests require a blank state to start from. If this fails,
11 // expect all other history tests (HistoryExtensionApiTest.*) to fail.
12 function clearHistory() {
13 chrome.history.deleteAll(pass(function() {
14 countItemsInHistory(pass(function(count) {
20 function deleteUrl() {
21 function deleteUrlTestVerification() {
22 removeItemRemovedListener();
24 var query = { 'text': '' };
25 chrome.history.search(query, function(results) {
26 assertEq(0, results.length);
28 // The test has succeeded.
29 chrome.test.succeed();
33 function onAddedItem() {
34 removeItemVisitedListener();
36 var query = { 'text': '' };
37 chrome.history.search(query, function(results) {
38 assertEq(1, results.length);
39 assertEq(GOOGLE_URL, results[0].url);
41 chrome.history.deleteUrl({ 'url': GOOGLE_URL });
45 // deleteUrl entry point.
46 chrome.history.deleteAll(function() {
47 setItemVisitedListener(onAddedItem);
48 setItemRemovedListener(deleteUrlTestVerification);
49 populateHistory([GOOGLE_URL], function() { });
53 // Suppose we have time epochs x,y,z and history events A,B which occur
54 // in the sequence x A y B z. Delete range [x,y], check that only A is
56 function deleteStartRange() {
57 var urls = [GOOGLE_URL, PICASA_URL];
59 function deleteRangeTestVerification() {
60 removeItemRemovedListener();
62 var query = { 'text': '' };
63 chrome.history.search(query, function(results) {
64 assertEq(1, results.length);
65 assertEq(PICASA_URL, results[0].url);
67 // The test has succeeded.
68 chrome.test.succeed();
72 chrome.history.deleteAll(function() {
73 setItemRemovedListener(deleteRangeTestVerification);
74 addUrlsWithTimeline(urls, function(eventTimes) {
75 // Remove the range covering the first URL:
76 chrome.history.deleteRange(
77 {'startTime': eventTimes.before,
78 'endTime': eventTimes.between},
84 // Suppose we have time epochs x,y,z and history events A,B which occur
85 // in the sequence x A y B z. Delete range [y,z], check that only B is
87 function deleteEndRange() {
88 var urls = [GOOGLE_URL, PICASA_URL];
90 function deleteRangeTestVerification() {
91 removeItemRemovedListener();
93 var query = { 'text': '' };
94 chrome.history.search(query, function(results) {
95 assertEq(1, results.length);
96 assertEq(GOOGLE_URL, results[0].url);
98 // The test has succeeded.
99 chrome.test.succeed();
103 chrome.history.deleteAll(function() {
104 setItemRemovedListener(deleteRangeTestVerification);
105 addUrlsWithTimeline(urls, function(eventTimes) {
106 // Remove the range covering the second URL:
107 chrome.history.deleteRange(
108 {'startTime': eventTimes.between,
109 'endTime': eventTimes.after},
115 // Suppose we have time epochs x,y,z and history events A,B which occur
116 // in the sequence x A y B z. Delete range [x,z], check that both A
117 // and B are removed.
118 function deleteWholeRange() {
119 var urls = [GOOGLE_URL, PICASA_URL];
121 function deleteRangeTestVerification() {
122 removeItemRemovedListener();
124 var query = { 'text': '' };
125 chrome.history.search(query, function(results) {
126 assertEq(0, results.length);
128 // The test has succeeded.
129 chrome.test.succeed();
133 chrome.history.deleteAll(function() {
134 setItemRemovedListener(deleteRangeTestVerification);
135 addUrlsWithTimeline(urls, function(eventTimes) {
136 // Remove the range covering both URLs:
137 chrome.history.deleteRange(
138 {'startTime': eventTimes.before,
139 'endTime': eventTimes.after},
145 // Delete a range with start time equal to end time. See that nothing
147 function deleteEmptyRange() {
148 var urls = [GOOGLE_URL, PICASA_URL];
150 function deleteRangeTestVerification() {
151 removeItemRemovedListener();
153 // Nothing should have been deleted.
157 chrome.history.deleteAll(function() {
158 setItemRemovedListener(deleteRangeTestVerification);
159 addUrlsWithTimeline(urls, function(eventTimes) {
160 // Remove an empty range.
161 chrome.history.deleteRange(
162 {'startTime': eventTimes.between,
163 'endTime': eventTimes.between},
165 var query = { 'text': '' };
166 chrome.history.search(query, function(results) {
167 // Nothing should have been deleted.
168 assertEq(2, results.length);
169 chrome.test.succeed();