1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/filepicker/test/unit/test_filecomplete.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// Start by getting an empty directory. 1.9 +var dir = do_get_profile(); 1.10 +dir.append("temp"); 1.11 +dir.create(dir.DIRECTORY_TYPE, -1); 1.12 +var path = dir.path + "/"; 1.13 + 1.14 +// Now create some sample entries. 1.15 +var file = dir.clone(); 1.16 +file.append("test_file"); 1.17 +file.create(file.NORMAL_FILE_TYPE, -1); 1.18 +file = dir.clone(); 1.19 +file.append("other_file"); 1.20 +file.create(file.NORMAL_FILE_TYPE, -1); 1.21 +dir.append("test_dir"); 1.22 +dir.create(dir.DIRECTORY_TYPE, -1); 1.23 + 1.24 +var gListener = { 1.25 + onSearchResult: function(aSearch, aResult) { 1.26 + // Check that we got same search string back. 1.27 + do_check_eq(aResult.searchString, "test"); 1.28 + // Check that the search succeeded. 1.29 + do_check_eq(aResult.searchResult, aResult.RESULT_SUCCESS); 1.30 + // Check that we got two results. 1.31 + do_check_eq(aResult.matchCount, 2); 1.32 + // Check that the first result is the directory we created. 1.33 + do_check_eq(aResult.getValueAt(0), "test_dir"); 1.34 + // Check that the first result has directory style. 1.35 + do_check_eq(aResult.getStyleAt(0), "directory"); 1.36 + // Check that the second result is the file we created. 1.37 + do_check_eq(aResult.getValueAt(1), "test_file"); 1.38 + // Check that the second result has file style. 1.39 + do_check_eq(aResult.getStyleAt(1), "file"); 1.40 + } 1.41 +}; 1.42 + 1.43 +function run_test() 1.44 +{ 1.45 + Components.classes["@mozilla.org/autocomplete/search;1?name=file"] 1.46 + .getService(Components.interfaces.nsIAutoCompleteSearch) 1.47 + .startSearch("test", path, null, gListener); 1.48 +}