michael@0: /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; js-indent-level: 2; -*- */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function run_test() michael@0: { michael@0: Cu.import("resource://gre/modules/jsdebugger.jsm"); michael@0: addDebuggerToGlobal(this); michael@0: let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Components.interfaces.mozIJSSubScriptLoader); michael@0: loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js"); michael@0: michael@0: test_LSA_disconnect(); michael@0: test_LSA_grip(); michael@0: test_LSA_onSubstring(); michael@0: } michael@0: michael@0: const TEST_STRING = "This is a very long string!"; michael@0: michael@0: function makeMockLongStringActor() michael@0: { michael@0: let string = TEST_STRING; michael@0: let actor = new LongStringActor(string); michael@0: actor.actorID = "longString1"; michael@0: actor.registeredPool = { michael@0: longStringActors: { michael@0: longString1: actor michael@0: } michael@0: }; michael@0: return actor; michael@0: } michael@0: michael@0: function test_LSA_disconnect() michael@0: { michael@0: let actor = makeMockLongStringActor(); michael@0: do_check_eq(actor.registeredPool.longStringActors[actor.actorID], actor); michael@0: michael@0: actor.disconnect(); michael@0: do_check_eq(actor.registeredPool.longStringActors[actor.actorID], void 0); michael@0: } michael@0: michael@0: function test_LSA_substring() michael@0: { michael@0: let actor = makeMockLongStringActor(); michael@0: do_check_eq(actor._substring(0, 4), TEST_STRING.substring(0, 4)); michael@0: do_check_eq(actor._substring(6, 9), TEST_STRING.substring(6, 9)); michael@0: do_check_eq(actor._substring(0, TEST_STRING.length), TEST_STRING); michael@0: } michael@0: michael@0: function test_LSA_grip() michael@0: { michael@0: let actor = makeMockLongStringActor(); michael@0: michael@0: let grip = actor.grip(); michael@0: do_check_eq(grip.type, "longString"); michael@0: do_check_eq(grip.initial, TEST_STRING.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH)); michael@0: do_check_eq(grip.length, TEST_STRING.length); michael@0: do_check_eq(grip.actor, actor.actorID); michael@0: } michael@0: michael@0: function test_LSA_onSubstring() michael@0: { michael@0: let actor = makeMockLongStringActor(); michael@0: let response; michael@0: michael@0: // From the start michael@0: response = actor.onSubstring({ michael@0: start: 0, michael@0: end: 4 michael@0: }); michael@0: do_check_eq(response.from, actor.actorID); michael@0: do_check_eq(response.substring, TEST_STRING.substring(0, 4)); michael@0: michael@0: // In the middle michael@0: response = actor.onSubstring({ michael@0: start: 5, michael@0: end: 8 michael@0: }); michael@0: do_check_eq(response.from, actor.actorID); michael@0: do_check_eq(response.substring, TEST_STRING.substring(5, 8)); michael@0: michael@0: // Whole string michael@0: response = actor.onSubstring({ michael@0: start: 0, michael@0: end: TEST_STRING.length michael@0: }); michael@0: do_check_eq(response.from, actor.actorID); michael@0: do_check_eq(response.substring, TEST_STRING); michael@0: michael@0: // Negative index michael@0: response = actor.onSubstring({ michael@0: start: -5, michael@0: end: TEST_STRING.length michael@0: }); michael@0: do_check_eq(response.from, actor.actorID); michael@0: do_check_eq(response.substring, michael@0: TEST_STRING.substring(-5, TEST_STRING.length)); michael@0: michael@0: // Past the end michael@0: response = actor.onSubstring({ michael@0: start: TEST_STRING.length - 5, michael@0: end: 100 michael@0: }); michael@0: do_check_eq(response.from, actor.actorID); michael@0: do_check_eq(response.substring, michael@0: TEST_STRING.substring(TEST_STRING.length - 5, 100)); michael@0: }