Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | Cu.import("resource://gre/modules/PriorityUrlProvider.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | function run_test() { |
michael@0 | 8 | run_next_test(); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | add_task(function* search_engine_match() { |
michael@0 | 12 | let engine = yield promiseDefaultSearchEngine(); |
michael@0 | 13 | let token = engine.getResultDomain(); |
michael@0 | 14 | let match = yield PriorityUrlProvider.getMatch(token.substr(0, 1)); |
michael@0 | 15 | do_check_eq(match.url, engine.searchForm); |
michael@0 | 16 | do_check_eq(match.title, engine.name); |
michael@0 | 17 | do_check_eq(match.iconUrl, engine.iconURI ? engine.iconURI.spec : null); |
michael@0 | 18 | do_check_eq(match.reason, "search"); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | add_task(function* no_match() { |
michael@0 | 22 | do_check_eq(null, yield PriorityUrlProvider.getMatch("test")); |
michael@0 | 23 | }); |
michael@0 | 24 | |
michael@0 | 25 | add_task(function* hide_search_engine_nomatch() { |
michael@0 | 26 | let engine = yield promiseDefaultSearchEngine(); |
michael@0 | 27 | let token = engine.getResultDomain(); |
michael@0 | 28 | let promiseTopic = promiseSearchTopic("engine-changed"); |
michael@0 | 29 | Services.search.removeEngine(engine); |
michael@0 | 30 | yield promiseTopic; |
michael@0 | 31 | do_check_true(engine.hidden); |
michael@0 | 32 | do_check_eq(null, yield PriorityUrlProvider.getMatch(token.substr(0, 1))); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | add_task(function* add_search_engine_match() { |
michael@0 | 36 | let promiseTopic = promiseSearchTopic("engine-added"); |
michael@0 | 37 | do_check_eq(null, yield PriorityUrlProvider.getMatch("bacon")); |
michael@0 | 38 | Services.search.addEngineWithDetails("bacon", "", "bacon", "Search Bacon", |
michael@0 | 39 | "GET", "http://www.bacon.moz/?search={searchTerms}"); |
michael@0 | 40 | yield promiseSearchTopic; |
michael@0 | 41 | let match = yield PriorityUrlProvider.getMatch("bacon"); |
michael@0 | 42 | do_check_eq(match.url, "http://www.bacon.moz"); |
michael@0 | 43 | do_check_eq(match.title, "bacon"); |
michael@0 | 44 | do_check_eq(match.iconUrl, null); |
michael@0 | 45 | do_check_eq(match.reason, "search"); |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | add_task(function* remove_search_engine_nomatch() { |
michael@0 | 49 | let engine = Services.search.getEngineByName("bacon"); |
michael@0 | 50 | let promiseTopic = promiseSearchTopic("engine-removed"); |
michael@0 | 51 | Services.search.removeEngine(engine); |
michael@0 | 52 | yield promiseTopic; |
michael@0 | 53 | do_check_eq(null, yield PriorityUrlProvider.getMatch("bacon")); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | function promiseDefaultSearchEngine() { |
michael@0 | 57 | let deferred = Promise.defer(); |
michael@0 | 58 | Services.search.init( () => { |
michael@0 | 59 | deferred.resolve(Services.search.defaultEngine); |
michael@0 | 60 | }); |
michael@0 | 61 | return deferred.promise; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function promiseSearchTopic(expectedVerb) { |
michael@0 | 65 | let deferred = Promise.defer(); |
michael@0 | 66 | Services.obs.addObserver( function observe(subject, topic, verb) { |
michael@0 | 67 | do_log_info("browser-search-engine-modified: " + verb); |
michael@0 | 68 | if (verb == expectedVerb) { |
michael@0 | 69 | Services.obs.removeObserver(observe, "browser-search-engine-modified"); |
michael@0 | 70 | deferred.resolve(); |
michael@0 | 71 | } |
michael@0 | 72 | }, "browser-search-engine-modified", false); |
michael@0 | 73 | return deferred.promise; |
michael@0 | 74 | } |