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