browser/devtools/webconsole/test/browser_webconsole_property_provider.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_property_provider.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests the property provider, which is part of the code completion
    1.10 +// infrastructure.
    1.11 +
    1.12 +const TEST_URI = "data:text/html;charset=utf8,<p>test the JS property provider";
    1.13 +
    1.14 +function test() {
    1.15 +  addTab(TEST_URI);
    1.16 +  browser.addEventListener("load", testPropertyProvider, true);
    1.17 +}
    1.18 +
    1.19 +function testPropertyProvider() {
    1.20 +  browser.removeEventListener("load", testPropertyProvider, true);
    1.21 +  let tools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
    1.22 +  let JSPropertyProvider = tools.require("devtools/toolkit/webconsole/utils").JSPropertyProvider;
    1.23 +
    1.24 +  let tmp = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
    1.25 +  tmp.addDebuggerToGlobal(tmp);
    1.26 +  let dbg = new tmp.Debugger;
    1.27 +  let dbgWindow = dbg.makeGlobalObjectReference(content);
    1.28 +
    1.29 +  let completion = JSPropertyProvider(dbgWindow, null, "thisIsNotDefined");
    1.30 +  is (completion.matches.length, 0, "no match for 'thisIsNotDefined");
    1.31 +
    1.32 +  // This is a case the PropertyProvider can't handle. Should return null.
    1.33 +  completion = JSPropertyProvider(dbgWindow, null, "window[1].acb");
    1.34 +  is (completion, null, "no match for 'window[1].acb");
    1.35 +
    1.36 +  // A very advanced completion case.
    1.37 +  var strComplete =
    1.38 +    'function a() { }document;document.getElementById(window.locatio';
    1.39 +  completion = JSPropertyProvider(dbgWindow, null, strComplete);
    1.40 +  ok(completion.matches.length == 2, "two matches found");
    1.41 +  ok(completion.matchProp == "locatio", "matching part is 'test'");
    1.42 +  var matches = completion.matches;
    1.43 +  matches.sort();
    1.44 +  ok(matches[0] == "location", "the first match is 'location'");
    1.45 +  ok(matches[1] == "locationbar", "the second match is 'locationbar'");
    1.46 +
    1.47 +  finishTest();
    1.48 +}
    1.49 +

mercurial