browser/devtools/webconsole/test/browser_webconsole_property_provider.js

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

mercurial