1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/tests/browser/browser_Finder.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const Ci = Components.interfaces; 1.9 + 1.10 +let tab, browser; 1.11 + 1.12 +function test () { 1.13 + waitForExplicitFinish(); 1.14 + 1.15 + tab = gBrowser.addTab("data:text/html;base64," + 1.16 + btoa("<body><iframe srcdoc=\"content\"/></iframe>" + 1.17 + "<a href=\"http://test.com\">test link</a>")); 1.18 + browser = gBrowser.getBrowserForTab(tab); 1.19 + gBrowser.selectedTab = tab; 1.20 + 1.21 + browser.addEventListener("load", startTests, true); 1.22 +} 1.23 + 1.24 +var outlineTest = "sendAsyncMessage(\"OutlineTest\", " + 1.25 + "{ ok : !!content.document." + 1.26 + "getElementsByTagName(\"a\")[0].style.outline }" + 1.27 + ");"; 1.28 + 1.29 +function startTests () { 1.30 + browser.removeEventListener("load", startTests, true); 1.31 + 1.32 + let finder = browser.finder; 1.33 + let listener = { 1.34 + onFindResult: function () { 1.35 + ok(false, "callback wasn't replaced"); 1.36 + } 1.37 + }; 1.38 + finder.addResultListener(listener); 1.39 + 1.40 + listener.onFindResult = function ({result}) { 1.41 + ok(result == Ci.nsITypeAheadFind.FIND_FOUND, "should find string"); 1.42 + 1.43 + listener.onFindResult = function ({result}) { 1.44 + ok(result == Ci.nsITypeAheadFind.FIND_NOTFOUND, "should not find string"); 1.45 + 1.46 + let first = true; 1.47 + listener.onFindResult = function ({result}) { 1.48 + ok(result == Ci.nsITypeAheadFind.FIND_FOUND, "should find link"); 1.49 + 1.50 + browser.messageManager.addMessageListener("OutlineTest", function f(aMessage) { 1.51 + browser.messageManager.removeMessageListener("OutlineTest", f); 1.52 + 1.53 + 1.54 + if (first) { 1.55 + ok(aMessage.data.ok, "content script should send okay"); 1.56 + first = false; 1.57 + 1.58 + // Just a simple search for "test link". 1.59 + finder.fastFind("test link", false, false); 1.60 + } else { 1.61 + ok(!aMessage.data.ok, "content script should not send okay"); 1.62 + cleanup(); 1.63 + } 1.64 + }) 1.65 + browser.messageManager.loadFrameScript("data:," + outlineTest, false) 1.66 + } 1.67 + // Search only for links and draw outlines. 1.68 + finder.fastFind("test link", true, true); 1.69 + } 1.70 + finder.highlight(true, "Bla"); 1.71 + } 1.72 + finder.highlight(true, "content"); 1.73 +} 1.74 + 1.75 +function cleanup() { 1.76 + gBrowser.removeTab(tab); 1.77 + finish(); 1.78 +}