michael@0: /* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */ michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/publicdomain/zero/1.0/ michael@0: michael@0: "use strict"; michael@0: const { devtools } = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: let JSPropertyProvider = devtools.require("devtools/toolkit/webconsole/utils").JSPropertyProvider; michael@0: michael@0: Components.utils.import("resource://gre/modules/jsdebugger.jsm"); michael@0: addDebuggerToGlobal(this); michael@0: michael@0: function run_test() { michael@0: const testArray = 'var testArray = [\ michael@0: {propA: "A"},\ michael@0: {\ michael@0: propB: "B", \ michael@0: propC: [\ michael@0: {propD: "D"}\ michael@0: ]\ michael@0: },\ michael@0: [\ michael@0: {propE: "E"}\ michael@0: ]\ michael@0: ];' michael@0: michael@0: const testObject = 'var testObject = {"propA": [{"propB": "B"}]}'; michael@0: michael@0: let sandbox = Components.utils.Sandbox("http://example.com"); michael@0: let dbg = new Debugger; michael@0: let dbgObject = dbg.addDebuggee(sandbox); michael@0: Components.utils.evalInSandbox(testArray, sandbox); michael@0: Components.utils.evalInSandbox(testObject, sandbox); michael@0: michael@0: let results = JSPropertyProvider(dbgObject, null, "testArray[0]."); michael@0: do_print("Test that suggestions are given for 'foo[n]' where n is an integer."); michael@0: test_has_result(results, "propA"); michael@0: michael@0: do_print("Test that suggestions are given for multidimensional arrays."); michael@0: results = JSPropertyProvider(dbgObject, null, "testArray[2][0]."); michael@0: test_has_result(results, "propE"); michael@0: michael@0: do_print("Test that suggestions are not given for index that's out of bounds."); michael@0: results = JSPropertyProvider(dbgObject, null, "testArray[10]."); michael@0: do_check_null(results); michael@0: michael@0: do_print("Test that no suggestions are given if an index is not numerical somewhere in the chain."); michael@0: results = JSPropertyProvider(dbgObject, null, "testArray[0]['propC'][0]."); michael@0: do_check_null(results); michael@0: michael@0: results = JSPropertyProvider(dbgObject, null, "testObject['propA'][0]."); michael@0: do_check_null(results); michael@0: michael@0: results = JSPropertyProvider(dbgObject, null, "testArray[0]['propC']."); michael@0: do_check_null(results); michael@0: michael@0: results = JSPropertyProvider(dbgObject, null, "testArray[][1]."); michael@0: do_check_null(results); michael@0: } michael@0: michael@0: /** michael@0: * A helper that ensures (required) results were found. michael@0: * @param Object aResults michael@0: * The results returned by JSPropertyProvider. michael@0: * @param String aRequiredSuggestion michael@0: * A suggestion that must be found from the results. michael@0: */ michael@0: function test_has_result(aResults, aRequiredSuggestion) { michael@0: do_check_neq(aResults, null); michael@0: do_check_true(aResults.matches.length > 0); michael@0: do_check_true(aResults.matches.indexOf(aRequiredSuggestion) !== -1); michael@0: }