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=HistoryExtensionApiTest.MiscSearch
8 // runHistoryTestFns is defined in ./common.js .
10 function basicSearch() {
11 // basicSearch callback.
12 function basicSearchTestVerification() {
13 removeItemVisitedListener();
14 var query = { 'text': '' };
15 chrome.history.search(query, function(results) {
16 assertEq(1, results.length);
17 assertEq(GOOGLE_URL, results[0].url);
19 // The test has succeeded.
20 chrome.test.succeed();
24 // basicSearch entry point.
25 chrome.history.deleteAll(function() {
26 setItemVisitedListener(basicSearchTestVerification);
27 populateHistory([GOOGLE_URL], function() { });
31 function lengthScopedSearch() {
32 var urls = [GOOGLE_URL, PICASA_URL];
35 function lengthScopedSearchTestVerification() {
36 // Ensure all urls have been added.
38 if (urlsAdded < urls.length)
41 removeItemVisitedListener();
43 var query = { 'text': '', 'maxResults': 1 };
44 chrome.history.search(query, function(results) {
45 assertEq(1, results.length);
46 assertEq(PICASA_URL, results[0].url);
48 // The test has succeeded.
49 chrome.test.succeed();
53 // lengthScopedSearch entry point.
54 chrome.history.deleteAll(function() {
55 setItemVisitedListener(lengthScopedSearchTestVerification);
56 populateHistory(urls, function() { });
60 function fullTextSearch() {
61 chrome.history.deleteAll(function() {
62 // The continuation of the test after the windows have been opened.
63 var validateTest = function() {
64 // Continue with the test.
65 // A title search for www.a.com should find a.
66 var query = { 'text': 'www.a.com' };
67 chrome.history.search(query, function(results) {
68 assertEq(1, results.length);
69 assertEq(A_RELATIVE_URL, results[0].url);
71 // Text in the body of b.html.
72 query = { 'text': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' };
73 chrome.history.search(query, function(results) {
74 assertEq(1, results.length);
75 assertEq(B_RELATIVE_URL, results[0].url);
77 // The test has succeeded.
78 chrome.test.succeed();
83 // Setup a callback object for tab events.
84 var urls = [A_RELATIVE_URL, B_RELATIVE_URL];
87 function listenerCallback() {
88 if (tabIds.length < urls.length) {
92 // Ensure both tabs have completed loading.
93 for (var index = 0, id; id = tabIds[index]; index++) {
94 if (!tabsCompleteData[id] ||
95 tabsCompleteData[id] != 'complete') {
101 tabCompleteCallback = null;
102 chrome.tabs.onUpdated.removeListener(tabsCompleteListener);
104 // Allow indexing to occur.
105 waitAFewSeconds(3, function() {
110 tabCompleteCallback = listenerCallback;
111 chrome.tabs.onUpdated.addListener(tabsCompleteListener);
113 // Navigate to a few pages.
114 urls.forEach(function(url) {
115 chrome.tabs.create({ 'url': url }, function(tab) {