browser/devtools/webconsole/test/browser_webconsole_property_provider.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Tests the property provider, which is part of the code completion
michael@0 7 // infrastructure.
michael@0 8
michael@0 9 const TEST_URI = "data:text/html;charset=utf8,<p>test the JS property provider";
michael@0 10
michael@0 11 function test() {
michael@0 12 addTab(TEST_URI);
michael@0 13 browser.addEventListener("load", testPropertyProvider, true);
michael@0 14 }
michael@0 15
michael@0 16 function testPropertyProvider() {
michael@0 17 browser.removeEventListener("load", testPropertyProvider, true);
michael@0 18 let tools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
michael@0 19 let JSPropertyProvider = tools.require("devtools/toolkit/webconsole/utils").JSPropertyProvider;
michael@0 20
michael@0 21 let tmp = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
michael@0 22 tmp.addDebuggerToGlobal(tmp);
michael@0 23 let dbg = new tmp.Debugger;
michael@0 24 let dbgWindow = dbg.makeGlobalObjectReference(content);
michael@0 25
michael@0 26 let completion = JSPropertyProvider(dbgWindow, null, "thisIsNotDefined");
michael@0 27 is (completion.matches.length, 0, "no match for 'thisIsNotDefined");
michael@0 28
michael@0 29 // This is a case the PropertyProvider can't handle. Should return null.
michael@0 30 completion = JSPropertyProvider(dbgWindow, null, "window[1].acb");
michael@0 31 is (completion, null, "no match for 'window[1].acb");
michael@0 32
michael@0 33 // A very advanced completion case.
michael@0 34 var strComplete =
michael@0 35 'function a() { }document;document.getElementById(window.locatio';
michael@0 36 completion = JSPropertyProvider(dbgWindow, null, strComplete);
michael@0 37 ok(completion.matches.length == 2, "two matches found");
michael@0 38 ok(completion.matchProp == "locatio", "matching part is 'test'");
michael@0 39 var matches = completion.matches;
michael@0 40 matches.sort();
michael@0 41 ok(matches[0] == "location", "the first match is 'location'");
michael@0 42 ok(matches[1] == "locationbar", "the second match is 'locationbar'");
michael@0 43
michael@0 44 finishTest();
michael@0 45 }
michael@0 46

mercurial