toolkit/modules/tests/browser/browser_Finder.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:cec44fac2fdc
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 const Ci = Components.interfaces;
6
7 let tab, browser;
8
9 function test () {
10 waitForExplicitFinish();
11
12 tab = gBrowser.addTab("data:text/html;base64," +
13 btoa("<body><iframe srcdoc=\"content\"/></iframe>" +
14 "<a href=\"http://test.com\">test link</a>"));
15 browser = gBrowser.getBrowserForTab(tab);
16 gBrowser.selectedTab = tab;
17
18 browser.addEventListener("load", startTests, true);
19 }
20
21 var outlineTest = "sendAsyncMessage(\"OutlineTest\", " +
22 "{ ok : !!content.document." +
23 "getElementsByTagName(\"a\")[0].style.outline }" +
24 ");";
25
26 function startTests () {
27 browser.removeEventListener("load", startTests, true);
28
29 let finder = browser.finder;
30 let listener = {
31 onFindResult: function () {
32 ok(false, "callback wasn't replaced");
33 }
34 };
35 finder.addResultListener(listener);
36
37 listener.onFindResult = function ({result}) {
38 ok(result == Ci.nsITypeAheadFind.FIND_FOUND, "should find string");
39
40 listener.onFindResult = function ({result}) {
41 ok(result == Ci.nsITypeAheadFind.FIND_NOTFOUND, "should not find string");
42
43 let first = true;
44 listener.onFindResult = function ({result}) {
45 ok(result == Ci.nsITypeAheadFind.FIND_FOUND, "should find link");
46
47 browser.messageManager.addMessageListener("OutlineTest", function f(aMessage) {
48 browser.messageManager.removeMessageListener("OutlineTest", f);
49
50
51 if (first) {
52 ok(aMessage.data.ok, "content script should send okay");
53 first = false;
54
55 // Just a simple search for "test link".
56 finder.fastFind("test link", false, false);
57 } else {
58 ok(!aMessage.data.ok, "content script should not send okay");
59 cleanup();
60 }
61 })
62 browser.messageManager.loadFrameScript("data:," + outlineTest, false)
63 }
64 // Search only for links and draw outlines.
65 finder.fastFind("test link", true, true);
66 }
67 finder.highlight(true, "Bla");
68 }
69 finder.highlight(true, "content");
70 }
71
72 function cleanup() {
73 gBrowser.removeTab(tab);
74 finish();
75 }

mercurial