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 | XPCOMUtils.defineLazyModuleGetter(this, "Promise", |
michael@0 | 2 | "resource://gre/modules/Promise.jsm"); |
michael@0 | 3 | XPCOMUtils.defineLazyModuleGetter(this, "Task", |
michael@0 | 4 | "resource://gre/modules/Task.jsm"); |
michael@0 | 5 | Components.utils.import("resource://gre/modules/Timer.jsm", this); |
michael@0 | 6 | |
michael@0 | 7 | let gTabs = []; |
michael@0 | 8 | |
michael@0 | 9 | registerCleanupFunction(function() { |
michael@0 | 10 | for (let tab of gTabs) { |
michael@0 | 11 | if (!tab) |
michael@0 | 12 | continue; |
michael@0 | 13 | gBrowser.removeTab(tab); |
michael@0 | 14 | } |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | Task.spawn(function() { |
michael@0 | 21 | info("Check correct 'Phrase not found' on new tab"); |
michael@0 | 22 | |
michael@0 | 23 | // Create a tab to run the test. |
michael@0 | 24 | yield promiseTestPageLoad(); |
michael@0 | 25 | |
michael@0 | 26 | // Search for the first word. |
michael@0 | 27 | yield promiseFindFinished("--- THIS SHOULD NEVER MATCH ---", false); |
michael@0 | 28 | let findbar = gBrowser.getFindBar(); |
michael@0 | 29 | is(findbar._findStatusDesc.textContent, findbar._notFoundStr, |
michael@0 | 30 | "Findbar status text should be 'Phrase not found'"); |
michael@0 | 31 | |
michael@0 | 32 | // Create second tab. |
michael@0 | 33 | yield promiseTestPageLoad(); |
michael@0 | 34 | |
michael@0 | 35 | // Search for a string that WILL be found, with 'Highlight All' on |
michael@0 | 36 | yield promiseFindFinished("s", true); |
michael@0 | 37 | ok(!gBrowser.getFindBar()._findStatusDesc.textContent, |
michael@0 | 38 | "Findbar status should be empty"); |
michael@0 | 39 | |
michael@0 | 40 | finish(); |
michael@0 | 41 | }); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function promiseTestPageLoad() { |
michael@0 | 45 | let deferred = Promise.defer(); |
michael@0 | 46 | |
michael@0 | 47 | let tab = gBrowser.selectedTab = gBrowser.addTab("data:text/html;charset=utf-8,The letter s."); |
michael@0 | 48 | gTabs.push(tab); |
michael@0 | 49 | let browser = gBrowser.selectedBrowser; |
michael@0 | 50 | browser.addEventListener("load", function listener() { |
michael@0 | 51 | if (browser.currentURI.spec == "about:blank") |
michael@0 | 52 | return; |
michael@0 | 53 | info("Page loaded: " + browser.currentURI.spec); |
michael@0 | 54 | browser.removeEventListener("load", listener, true); |
michael@0 | 55 | |
michael@0 | 56 | deferred.resolve(); |
michael@0 | 57 | }, true); |
michael@0 | 58 | |
michael@0 | 59 | return deferred.promise; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function promiseFindFinished(searchText, highlightOn) { |
michael@0 | 63 | let deferred = Promise.defer(); |
michael@0 | 64 | |
michael@0 | 65 | let findbar = gBrowser.getFindBar(); |
michael@0 | 66 | findbar.startFind(findbar.FIND_NORMAL); |
michael@0 | 67 | let highlightElement = findbar.getElement("highlight"); |
michael@0 | 68 | if (highlightElement.checked != highlightOn) |
michael@0 | 69 | highlightElement.click(); |
michael@0 | 70 | executeSoon(() => { |
michael@0 | 71 | findbar._findField.value = searchText; |
michael@0 | 72 | |
michael@0 | 73 | let resultListener; |
michael@0 | 74 | let findTimeout = setTimeout(() => foundOrTimedout(null), 2000); |
michael@0 | 75 | let foundOrTimedout = function(aData) { |
michael@0 | 76 | if (aData === null) |
michael@0 | 77 | info("Result listener not called, timeout reached."); |
michael@0 | 78 | clearTimeout(findTimeout); |
michael@0 | 79 | findbar.browser.finder.removeResultListener(resultListener); |
michael@0 | 80 | deferred.resolve(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | resultListener = { |
michael@0 | 84 | onFindResult: foundOrTimedout |
michael@0 | 85 | }; |
michael@0 | 86 | findbar.browser.finder.addResultListener(resultListener); |
michael@0 | 87 | findbar._find(); |
michael@0 | 88 | }); |
michael@0 | 89 | |
michael@0 | 90 | return deferred.promise; |
michael@0 | 91 | } |