michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests the property provider, which is part of the code completion michael@0: // infrastructure. michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,

test the JS property provider"; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", testPropertyProvider, true); michael@0: } michael@0: michael@0: function testPropertyProvider() { michael@0: browser.removeEventListener("load", testPropertyProvider, true); michael@0: let tools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; michael@0: let JSPropertyProvider = tools.require("devtools/toolkit/webconsole/utils").JSPropertyProvider; michael@0: michael@0: let tmp = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); michael@0: tmp.addDebuggerToGlobal(tmp); michael@0: let dbg = new tmp.Debugger; michael@0: let dbgWindow = dbg.makeGlobalObjectReference(content); michael@0: michael@0: let completion = JSPropertyProvider(dbgWindow, null, "thisIsNotDefined"); michael@0: is (completion.matches.length, 0, "no match for 'thisIsNotDefined"); michael@0: michael@0: // This is a case the PropertyProvider can't handle. Should return null. michael@0: completion = JSPropertyProvider(dbgWindow, null, "window[1].acb"); michael@0: is (completion, null, "no match for 'window[1].acb"); michael@0: michael@0: // A very advanced completion case. michael@0: var strComplete = michael@0: 'function a() { }document;document.getElementById(window.locatio'; michael@0: completion = JSPropertyProvider(dbgWindow, null, strComplete); michael@0: ok(completion.matches.length == 2, "two matches found"); michael@0: ok(completion.matchProp == "locatio", "matching part is 'test'"); michael@0: var matches = completion.matches; michael@0: matches.sort(); michael@0: ok(matches[0] == "location", "the first match is 'location'"); michael@0: ok(matches[1] == "locationbar", "the second match is 'locationbar'"); michael@0: michael@0: finishTest(); michael@0: } michael@0: