toolkit/devtools/webconsole/test/unit/test_js_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.

     1 /* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
     2 // Any copyright is dedicated to the Public Domain.
     3 // http://creativecommons.org/publicdomain/zero/1.0/
     5 "use strict";
     6 const { devtools } = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
     7 let JSPropertyProvider = devtools.require("devtools/toolkit/webconsole/utils").JSPropertyProvider;
     9 Components.utils.import("resource://gre/modules/jsdebugger.jsm");
    10 addDebuggerToGlobal(this);
    12 function run_test() {
    13   const testArray = 'var testArray = [\
    14     {propA: "A"},\
    15     {\
    16       propB: "B", \
    17       propC: [\
    18         {propD: "D"}\
    19       ]\
    20     },\
    21     [\
    22       {propE: "E"}\
    23     ]\
    24   ];'
    26   const testObject = 'var testObject = {"propA": [{"propB": "B"}]}';
    28   let sandbox = Components.utils.Sandbox("http://example.com");
    29   let dbg = new Debugger;
    30   let dbgObject = dbg.addDebuggee(sandbox);
    31   Components.utils.evalInSandbox(testArray, sandbox);
    32   Components.utils.evalInSandbox(testObject, sandbox);
    34   let results = JSPropertyProvider(dbgObject, null, "testArray[0].");
    35   do_print("Test that suggestions are given for 'foo[n]' where n is an integer.");
    36   test_has_result(results, "propA");
    38   do_print("Test that suggestions are given for multidimensional arrays.");
    39   results = JSPropertyProvider(dbgObject, null, "testArray[2][0].");
    40   test_has_result(results, "propE");
    42   do_print("Test that suggestions are not given for index that's out of bounds.");
    43   results = JSPropertyProvider(dbgObject, null, "testArray[10].");
    44   do_check_null(results);
    46   do_print("Test that no suggestions are given if an index is not numerical somewhere in the chain.");
    47   results = JSPropertyProvider(dbgObject, null, "testArray[0]['propC'][0].");
    48   do_check_null(results);
    50   results = JSPropertyProvider(dbgObject, null, "testObject['propA'][0].");
    51   do_check_null(results);
    53   results = JSPropertyProvider(dbgObject, null, "testArray[0]['propC'].");
    54   do_check_null(results);
    56   results = JSPropertyProvider(dbgObject, null, "testArray[][1].");
    57   do_check_null(results);
    58 }
    60 /**
    61  * A helper that ensures (required) results were found.
    62  * @param Object aResults
    63  *        The results returned by JSPropertyProvider.
    64  * @param String aRequiredSuggestion
    65  *        A suggestion that must be found from the results.
    66  */
    67 function test_has_result(aResults, aRequiredSuggestion) {
    68   do_check_neq(aResults, null);
    69   do_check_true(aResults.matches.length > 0);
    70   do_check_true(aResults.matches.indexOf(aRequiredSuggestion) !== -1);
    71 }

mercurial