michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Start by getting an empty directory. michael@0: var dir = do_get_profile(); michael@0: dir.append("temp"); michael@0: dir.create(dir.DIRECTORY_TYPE, -1); michael@0: var path = dir.path + "/"; michael@0: michael@0: // Now create some sample entries. michael@0: var file = dir.clone(); michael@0: file.append("test_file"); michael@0: file.create(file.NORMAL_FILE_TYPE, -1); michael@0: file = dir.clone(); michael@0: file.append("other_file"); michael@0: file.create(file.NORMAL_FILE_TYPE, -1); michael@0: dir.append("test_dir"); michael@0: dir.create(dir.DIRECTORY_TYPE, -1); michael@0: michael@0: var gListener = { michael@0: onSearchResult: function(aSearch, aResult) { michael@0: // Check that we got same search string back. michael@0: do_check_eq(aResult.searchString, "test"); michael@0: // Check that the search succeeded. michael@0: do_check_eq(aResult.searchResult, aResult.RESULT_SUCCESS); michael@0: // Check that we got two results. michael@0: do_check_eq(aResult.matchCount, 2); michael@0: // Check that the first result is the directory we created. michael@0: do_check_eq(aResult.getValueAt(0), "test_dir"); michael@0: // Check that the first result has directory style. michael@0: do_check_eq(aResult.getStyleAt(0), "directory"); michael@0: // Check that the second result is the file we created. michael@0: do_check_eq(aResult.getValueAt(1), "test_file"); michael@0: // Check that the second result has file style. michael@0: do_check_eq(aResult.getStyleAt(1), "file"); michael@0: } michael@0: }; michael@0: michael@0: function run_test() michael@0: { michael@0: Components.classes["@mozilla.org/autocomplete/search;1?name=file"] michael@0: .getService(Components.interfaces.nsIAutoCompleteSearch) michael@0: .startSearch("test", path, null, gListener); michael@0: }