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