toolkit/components/places/tests/unit/test_413784.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /*
michael@0 8
michael@0 9 Test autocomplete for non-English URLs
michael@0 10
michael@0 11 - add a visit for a page with a non-English URL
michael@0 12 - search
michael@0 13 - test number of matches (should be exactly one)
michael@0 14
michael@0 15 */
michael@0 16
michael@0 17 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 18 getService(Ci.nsINavHistoryService);
michael@0 19 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
michael@0 20 getService(Ci.nsINavBookmarksService);
michael@0 21
michael@0 22 // create test data
michael@0 23 var searchTerm = "ユニコード";
michael@0 24 var decoded = "http://www.foobar.com/" + searchTerm + "/";
michael@0 25 var url = uri(decoded);
michael@0 26
michael@0 27 function AutoCompleteInput(aSearches) {
michael@0 28 this.searches = aSearches;
michael@0 29 }
michael@0 30
michael@0 31 AutoCompleteInput.prototype = {
michael@0 32 constructor: AutoCompleteInput,
michael@0 33
michael@0 34 searches: null,
michael@0 35
michael@0 36 minResultsForPopup: 0,
michael@0 37 timeout: 10,
michael@0 38 searchParam: "",
michael@0 39 textValue: "",
michael@0 40 disableAutoComplete: false,
michael@0 41 completeDefaultIndex: false,
michael@0 42
michael@0 43 get searchCount() {
michael@0 44 return this.searches.length;
michael@0 45 },
michael@0 46
michael@0 47 getSearchAt: function(aIndex) {
michael@0 48 return this.searches[aIndex];
michael@0 49 },
michael@0 50
michael@0 51 onSearchBegin: function() {},
michael@0 52 onSearchComplete: function() {},
michael@0 53
michael@0 54 popupOpen: false,
michael@0 55
michael@0 56 popup: {
michael@0 57 setSelectedIndex: function(aIndex) {},
michael@0 58 invalidate: function() {},
michael@0 59
michael@0 60 // nsISupports implementation
michael@0 61 QueryInterface: function(iid) {
michael@0 62 if (iid.equals(Ci.nsISupports) ||
michael@0 63 iid.equals(Ci.nsIAutoCompletePopup))
michael@0 64 return this;
michael@0 65
michael@0 66 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 67 }
michael@0 68 },
michael@0 69
michael@0 70 // nsISupports implementation
michael@0 71 QueryInterface: function(iid) {
michael@0 72 if (iid.equals(Ci.nsISupports) ||
michael@0 73 iid.equals(Ci.nsIAutoCompleteInput))
michael@0 74 return this;
michael@0 75
michael@0 76 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 function run_test()
michael@0 81 {
michael@0 82 do_test_pending();
michael@0 83 promiseAddVisits(url).then(continue_test);
michael@0 84 }
michael@0 85
michael@0 86 function continue_test()
michael@0 87 {
michael@0 88 var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
michael@0 89 getService(Components.interfaces.nsIAutoCompleteController);
michael@0 90
michael@0 91 // Make an AutoCompleteInput that uses our searches
michael@0 92 // and confirms results on search complete
michael@0 93 var input = new AutoCompleteInput(["history"]);
michael@0 94
michael@0 95 controller.input = input;
michael@0 96
michael@0 97 var numSearchesStarted = 0;
michael@0 98 input.onSearchBegin = function() {
michael@0 99 numSearchesStarted++;
michael@0 100 do_check_eq(numSearchesStarted, 1);
michael@0 101 };
michael@0 102
michael@0 103 input.onSearchComplete = function() {
michael@0 104 do_check_eq(numSearchesStarted, 1);
michael@0 105 do_check_eq(controller.searchStatus,
michael@0 106 Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
michael@0 107
michael@0 108 // test that we found the entry we added
michael@0 109 do_check_eq(controller.matchCount, 1);
michael@0 110
michael@0 111 // Make sure the url is the same according to spec, so it can be deleted
michael@0 112 do_check_eq(controller.getValueAt(0), url.spec);
michael@0 113
michael@0 114 do_test_finished();
michael@0 115 };
michael@0 116
michael@0 117 controller.startSearch(searchTerm);
michael@0 118 }

mercurial