- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / history / delete.js
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.
4
5 // History api test for Chrome.
6 // browser_tests.exe --gtest_filter=HistoryApiTest.Delete
7
8 // runHistoryTestFns is defined in ./common.js .
9 runHistoryTestFns([
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) {
15         assertEq(0, count);
16       }));
17     }));
18   },
19
20   function deleteUrl() {
21     function deleteUrlTestVerification() {
22       removeItemRemovedListener();
23
24       var query = { 'text': '' };
25       chrome.history.search(query, function(results) {
26         assertEq(0, results.length);
27
28         // The test has succeeded.
29         chrome.test.succeed();
30       });
31     }
32
33     function onAddedItem() {
34       removeItemVisitedListener();
35
36       var query = { 'text': '' };
37       chrome.history.search(query, function(results) {
38         assertEq(1, results.length);
39         assertEq(GOOGLE_URL, results[0].url);
40
41         chrome.history.deleteUrl({ 'url': GOOGLE_URL });
42       });
43     }
44
45     // deleteUrl entry point.
46     chrome.history.deleteAll(function() {
47       setItemVisitedListener(onAddedItem);
48       setItemRemovedListener(deleteUrlTestVerification);
49       populateHistory([GOOGLE_URL], function() { });
50     });
51   },
52
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
55   // removed.
56   function deleteStartRange() {
57     var urls = [GOOGLE_URL, PICASA_URL];
58
59     function deleteRangeTestVerification() {
60       removeItemRemovedListener();
61
62       var query = { 'text': '' };
63       chrome.history.search(query, function(results) {
64         assertEq(1, results.length);
65         assertEq(PICASA_URL, results[0].url);
66
67         // The test has succeeded.
68         chrome.test.succeed();
69       });
70     }
71
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},
79           function() {});
80       });
81     });
82   },
83
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
86   // removed.
87   function deleteEndRange() {
88     var urls = [GOOGLE_URL, PICASA_URL];
89
90     function deleteRangeTestVerification() {
91       removeItemRemovedListener();
92
93       var query = { 'text': '' };
94       chrome.history.search(query, function(results) {
95         assertEq(1, results.length);
96         assertEq(GOOGLE_URL, results[0].url);
97
98         // The test has succeeded.
99         chrome.test.succeed();
100       });
101     }
102
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},
110           function() {});
111       });
112     });
113   },
114
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];
120
121     function deleteRangeTestVerification() {
122       removeItemRemovedListener();
123
124       var query = { 'text': '' };
125       chrome.history.search(query, function(results) {
126         assertEq(0, results.length);
127
128         // The test has succeeded.
129         chrome.test.succeed();
130       });
131     }
132
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},
140           function() {});
141       });
142     });
143   },
144
145   // Delete a range with start time equal to end time.  See that nothing
146   // is removed.
147   function deleteEmptyRange() {
148     var urls = [GOOGLE_URL, PICASA_URL];
149
150     function deleteRangeTestVerification() {
151       removeItemRemovedListener();
152
153       // Nothing should have been deleted.
154       chrome.test.fail();
155     }
156
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},
164           function() {
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();
170             });
171           });
172       });
173     });
174   }
175 ]);