Bug 744360 - Part 1: add WspPduHelper, r=philikon

This commit is contained in:
Vicamo Yang 2012-06-01 16:38:19 +08:00
parent 5d303388c9
commit 83e2b94766
9 changed files with 2942 additions and 0 deletions

View File

@ -53,6 +53,7 @@ DIRS += \
power \
settings \
sms \
mms \
src \
locales \
network \

20
dom/mms/Makefile.in Normal file
View File

@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = dom/mms
include $(DEPTH)/config/autoconf.mk
PARALLEL_DIRS = src
ifdef ENABLE_TESTS
XPCSHELL_TESTS = tests
endif
include $(topsrcdir)/config/rules.mk

22
dom/mms/src/Makefile.in Normal file
View File

@ -0,0 +1,22 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = \
$(srcdir) \
$(NULL)
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_B2G_RIL
EXTRA_JS_MODULES = \
ril/wap_consts.js \
ril/WspPduHelper.jsm \
$(NULL)
endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// WSP PDU Type Assignments
// @see WAP-230-WSP-20010705-a Appendix A. Assigned Numbers.
const WSP_PDU_TYPE_PUSH = 0x06;
const ALL_CONST_SYMBOLS = Object.keys(this);
const EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS;

View File

@ -0,0 +1,118 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
let subscriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
/**
* Test whether specified function throws exception with expected
* result.
*
* @param func
* Function to be tested.
* @param exception
* Expected class name of thrown exception. Use null for no throws.
* @param stack
* Optional stack object to be printed. null for Components#stack#caller.
*/
function do_check_throws(func, result, stack)
{
if (!stack)
stack = Components.stack.caller;
try {
func();
} catch (ex) {
if (ex.name == result) {
return;
}
do_throw("expected result " + result + ", caught " + ex, stack);
}
if (result) {
do_throw("expected result " + result + ", none thrown", stack);
}
}
/**
* Internal test function for comparing results.
*
* @param func
* A function under test. It should accept an arguement and return the
* result.
* @param data
* Input data for `func`.
* @param expect
* Expected result.
*/
function wsp_test_func(func, data, expect) {
let result_str = JSON.stringify(func(data));
let expect_str = JSON.stringify(expect);
if (result_str !== expect_str) {
do_throw("expect decoded value: '" + expect_str + "', got '" + result_str + "'");
}
}
/**
* Test customized WSP PDU decoding.
*
* @param func
* Decoding func under test. It should return a decoded value if invoked.
* @param input
* Array of octets as test data.
* @param expect
* Expected decoded value, use null if expecting errors instead.
* @param exception
* Expected class name of thrown exception. Use null for no throws.
*/
function wsp_decode_test_ex(func, input, expect, exception) {
let data = {array: input, offset: 0};
do_check_throws(wsp_test_func.bind(null, func, data, expect), exception);
}
/**
* Test default WSP PDU decoding.
*
* @param target
* Target decoding object, ie. TextValue.
* @param input
* Array of octets as test data.
* @param expect
* Expected decoded value, use null if expecting errors instead.
* @param exception
* Expected class name of thrown exception. Use null for no throws.
*/
function wsp_decode_test(target, input, expect, exception) {
let func = function decode_func(data) {
return target.decode(data);
};
wsp_decode_test_ex(func, input, expect, exception);
}
/**
* @param str
* A string.
* @param noAppendNull
* True to omit terminating NUL octet. Default false.
*
* @return A number array of char codes of characters in `str`.
*/
function strToCharCodeArray(str, noAppendNull) {
let result = [];
for (let i = 0; i < str.length; i++) {
result.push(str.charCodeAt(i));
}
if (!noAppendNull) {
result.push(0);
}
return result;
}

View File

@ -0,0 +1,814 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
let WSP = {};
subscriptLoader.loadSubScript("resource://gre/modules/WspPduHelper.jsm", WSP);
WSP.debug = do_print;
function run_test() {
run_next_test();
}
//
// Test target: ensureHeader
//
add_test(function test_ensureHeader() {
do_check_throws(function () {
WSP.ensureHeader({}, "no-such-property");
}, "FatalCodeError"
);
run_next_test();
});
//
// Test target: skipValue()
//
add_test(function test_skipValue() {
// Test for zero-valued first octet:
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, [0], null
);
// Test first octet < 31
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, [1, 2], [2]
);
// Test first octet = 31
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, [31, 0], null
);
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, [31, 1, 2], [2]
);
// Test first octet <= 127
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, strToCharCodeArray("Hello world!"), "Hello world!"
);
// Test first octet >= 128
wsp_decode_test_ex(function (data) {
return WSP.skipValue(data);
}, [0x80 | 0x01], 0x01
);
run_next_test();
});
//
// Test target: Octet
//
//// Octet.decode ////
add_test(function test_Octet_decode() {
wsp_decode_test(WSP.Octet, [1], 1);
wsp_decode_test(WSP.Octet, [], null, "RangeError");
run_next_test();
});
//// Octet.decodeMultiple ////
add_test(function test_Octet_decodeMultiple() {
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeMultiple(data, 3);
}, [0, 1, 2], [0, 1, 2], null
);
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeMultiple(data, 3);
}, new Uint8Array([0, 1, 2]), new Uint8Array([0, 1, 2]), null
);
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeMultiple(data, 4);
}, [0, 1, 2], null, "RangeError"
);
run_next_test();
});
//// Octet.decodeEqualTo ////
add_test(function test_Octet_decodeEqualTo() {
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeEqualTo(data, 1);
}, [1], 1, null
);
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeEqualTo(data, 2);
}, [1], null, "CodeError"
);
wsp_decode_test_ex(function (data) {
return WSP.Octet.decodeEqualTo(data, 2);
}, [], null, "RangeError"
);
run_next_test();
});
//
// Test target: Text
//
//// Text.decode ////
add_test(function test_Text_decode() {
for (let i = 0; i < 256; i++) {
if (i == 0) {
wsp_decode_test(WSP.Text, [0], null, "NullCharError");
} else if ((i < WSP.CTLS) || (i == WSP.DEL)) {
wsp_decode_test(WSP.Text, [i], null, "CodeError");
} else {
wsp_decode_test(WSP.Text, [i], String.fromCharCode(i));
}
}
// Test \r\n(SP|HT)* sequence:
wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \t", true), " ");
wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \t"), " ");
wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \tA"), " ");
run_next_test();
});
//
// Test target: NullTerminatedTexts
//
//// NullTerminatedTexts.decode ////
add_test(function test_NullTerminatedTexts_decode() {
// Test incompleted string:
wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(" ", true), null, "RangeError");
// Test control char:
wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(" \n"), null, "CodeError");
// Test normal string:
wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(""), "");
wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray("oops"), "oops");
// Test \r\n(SP|HT)* sequence:
wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray("A\r\n \t \t \tB"), "A B");
run_next_test();
});
//
// Test target: Token
//
//// Token.decode ////
add_test(function test_Token_decode() {
let seps = "()<>@,;:\\\"/[]?={} \t";
for (let i = 0; i < 256; i++) {
if (i == 0) {
wsp_decode_test(WSP.Token, [i], null, "NullCharError");
} else if ((i < WSP.CTLS) || (i >= WSP.ASCIIS)
|| (seps.indexOf(String.fromCharCode(i)) >= 0)) {
wsp_decode_test(WSP.Token, [i], null, "CodeError");
} else {
wsp_decode_test(WSP.Token, [i], String.fromCharCode(i));
}
}
run_next_test();
});
//
// Test target: URIC
//
//// URIC.decode ////
add_test(function test_URIC_decode() {
let uric = "!#$%&'()*+,-./0123456789:;=?@ABCDEFGHIJKLMN"
+ "OPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~";
for (let i = 0; i < 256; i++) {
if (i == 0) {
wsp_decode_test(WSP.URIC, [i], null, "NullCharError");
} else if (uric.indexOf(String.fromCharCode(i)) >= 0) {
wsp_decode_test(WSP.URIC, [i], String.fromCharCode(i));
} else {
wsp_decode_test(WSP.URIC, [i], null, "CodeError");
}
}
run_next_test();
});
//
// Test target: TextString
//
//// TextString.decode ////
add_test(function test_TextString_decode() {
// Test quoted string
wsp_decode_test(WSP.TextString, [127, 128, 0], String.fromCharCode(128));
// Test illegal quoted string
wsp_decode_test(WSP.TextString, [127, 32, 0], null, "CodeError");
// Test illegal unquoted string
wsp_decode_test(WSP.TextString, [128, 0], null, "CodeError");
// Test normal string
wsp_decode_test(WSP.TextString, [32, 0], " ");
run_next_test();
});
//
// Test target: TokenText
//
//// TokenText.decode ////
add_test(function test_TokenText_decode() {
wsp_decode_test(WSP.TokenText, [65], null, "RangeError");
wsp_decode_test(WSP.TokenText, [0], "");
wsp_decode_test(WSP.TokenText, [65, 0], "A");
run_next_test();
});
//
// Test target: QuotedString
//
//// QuotedString.decode ////
add_test(function test_QuotedString_decode() {
// Test non-quoted string
wsp_decode_test(WSP.QuotedString, [32, 0], null, "CodeError");
// Test incompleted string
wsp_decode_test(WSP.QuotedString, [34, 32], null, "RangeError");
wsp_decode_test(WSP.QuotedString, [34, 32, 0], " ");
run_next_test();
});
//
// Test target: ShortInteger
//
//// ShortInteger.decode ////
add_test(function test_ShortInteger_decode() {
for (let i = 0; i < 256; i++) {
if (i & 0x80) {
wsp_decode_test(WSP.ShortInteger, [i], i & 0x7F);
} else {
wsp_decode_test(WSP.ShortInteger, [i], null, "CodeError");
}
}
run_next_test();
});
//
// Test target: LongInteger
//
//// LongInteger.decode ////
function LongInteger_testcases(target) {
// Test LongInteger of zero octet
wsp_decode_test(target, [0, 0], null, "CodeError");
wsp_decode_test(target, [1, 0x80], 0x80);
wsp_decode_test(target, [2, 0x80, 2], 0x8002);
wsp_decode_test(target, [3, 0x80, 2, 3], 0x800203);
wsp_decode_test(target, [4, 0x80, 2, 3, 4], 0x80020304);
wsp_decode_test(target, [5, 0x80, 2, 3, 4, 5], 0x8002030405);
wsp_decode_test(target, [6, 0x80, 2, 3, 4, 5, 6], 0x800203040506);
// Test LongInteger of more than 6 octets
wsp_decode_test(target, [7, 0x80, 2, 3, 4, 5, 6, 7], [0x80, 2, 3, 4, 5, 6, 7]);
// Test LongInteger of more than 30 octets
wsp_decode_test(target, [31], null, "CodeError");
}
add_test(function test_LongInteger_decode() {
LongInteger_testcases(WSP.LongInteger);
run_next_test();
});
//
// Test target: UintVar
//
//// UintVar.decode ////
add_test(function test_UintVar_decode() {
wsp_decode_test(WSP.UintVar, [0x80], null, "RangeError");
// Test up to max 53 bits integer
wsp_decode_test(WSP.UintVar, [0x7F], 0x7F);
wsp_decode_test(WSP.UintVar, [0xFF, 0x7F], 0x3FFF);
wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0x7F], 0x1FFFFF);
wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0x7F], 0xFFFFFFF);
wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x7FFFFFFFF);
wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x3FFFFFFFFFF);
wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x1FFFFFFFFFFFF);
wsp_decode_test(WSP.UintVar, [0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x1FFFFFFFFFFFFF);
wsp_decode_test(WSP.UintVar, [0x01, 0x02], 1);
wsp_decode_test(WSP.UintVar, [0x80, 0x01, 0x02], 1);
wsp_decode_test(WSP.UintVar, [0x80, 0x80, 0x80, 0x01, 0x2], 1);
run_next_test();
});
//
// Test target: ConstrainedEncoding (decodeAlternatives)
//
//// ConstrainedEncoding.decode ////
add_test(function test_ConstrainedEncoding_decode() {
wsp_decode_test(WSP.ConstrainedEncoding, [0x80], 0);
wsp_decode_test(WSP.ConstrainedEncoding, [32, 0], " ");
run_next_test();
});
//
// Test target: ValueLength
//
//// ValueLength.decode ////
add_test(function test_ValueLength_decode() {
for (let i = 0; i < 256; i++) {
if (i < 31) {
wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], i);
} else if (i == 31) {
wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], 0x7FF);
} else {
wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], null, "CodeError");
}
}
run_next_test();
});
//
// Test target: NoValue
//
//// NoValue.decode ////
add_test(function test_NoValue_decode() {
wsp_decode_test(WSP.NoValue, [0], null);
for (let i = 1; i < 256; i++) {
wsp_decode_test(WSP.NoValue, [i], null, "CodeError");
}
run_next_test();
});
//
// Test target: TextValue
//
//// TextValue.decode ////
add_test(function test_TextValue_decode() {
wsp_decode_test(WSP.TextValue, [0], null);
wsp_decode_test(WSP.TextValue, [65, 0], "A");
wsp_decode_test(WSP.TextValue, [32, 0], null, "CodeError");
wsp_decode_test(WSP.TextValue, [34, 32, 0], " ");
run_next_test();
});
//
// Test target: IntegerValue
//
//// IntegerValue.decode ////
add_test(function test_IntegerValue_decode() {
for (let i = 128; i < 256; i++) {
wsp_decode_test(WSP.IntegerValue, [i], i & 0x7F);
}
LongInteger_testcases(WSP.IntegerValue);
run_next_test();
});
//
// Test target: DateValue
//
//// DateValue.decode ////
add_test(function test_DateValue_decode() {
wsp_decode_test(WSP.DateValue, [0, 0], null, "CodeError");
wsp_decode_test(WSP.DateValue, [1, 0x80], new Date(0x80 * 1000));
wsp_decode_test(WSP.DateValue, [31], null, "CodeError");
run_next_test();
});
//
// Test target: DeltaSecondsValue
//
// DeltaSecondsValue is only an alias of IntegerValue.
//
// Test target: QValue
//
//// QValue.decode ////
add_test(function test_QValue_decode() {
wsp_decode_test(WSP.QValue, [0], null, "CodeError");
wsp_decode_test(WSP.QValue, [1], 0);
wsp_decode_test(WSP.QValue, [100], 0.99);
wsp_decode_test(WSP.QValue, [101], 0.001);
wsp_decode_test(WSP.QValue, [0x88, 0x4B], 0.999);
wsp_decode_test(WSP.QValue, [0x88, 0x4C], null, "CodeError");
run_next_test();
});
//
// Test target: VersionValue
//
//// VersionValue.decode ////
add_test(function test_VersionValue_decode() {
for (let major = 1; major < 8; major++) {
let version = (major << 4) | 0x0F;
wsp_decode_test(WSP.VersionValue, [0x80 | version], version);
wsp_decode_test(WSP.VersionValue, [major + 0x30, 0], version);
for (let minor = 0; minor < 15; minor++) {
version = (major << 4) | minor;
wsp_decode_test(WSP.VersionValue, [0x80 | version], version);
if (minor >= 10) {
wsp_decode_test(WSP.VersionValue, [major + 0x30, 0x2E, 0x31, (minor - 10) + 0x30, 0], version);
} else {
wsp_decode_test(WSP.VersionValue, [major + 0x30, 0x2E, minor + 0x30, 0], version);
}
}
}
run_next_test();
});
//
// Test target: UriValue
//
//// UriValue.decode ////
add_test(function test_UriValue_decode() {
wsp_decode_test(WSP.UriValue, [97], null, "RangeError");
wsp_decode_test(WSP.UriValue, [0], "");
wsp_decode_test(WSP.UriValue, [65, 0], "A");
run_next_test();
});
//
// Test target: Parameter
//
//// Parameter.decodeTypedParameter ////
add_test(function test_Parameter_decodeTypedParameter() {
// Test for array-typed return value from IntegerValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [7, 0, 0, 0, 0, 0, 0, 0], null, "CodeError"
);
// Test for number-typed return value from IntegerValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0, 0], {name: "q", value: null}
);
// Test for NotWellKnownEncodingError
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0xFF], null, "NotWellKnownEncodingError"
);
// Test for parameter specific decoder
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0, 100], {name: "q", value: 0.99}
);
// Test for TextValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0x10, 48, 46, 57, 57, 0], {name: "secure", value: "0.99"}
);
// Test for TextString
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0x19, 60, 115, 109, 105, 108, 62, 0], {name: "start", value: "<smil>"}
);
// Test for skipValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeTypedParameter(data);
}, [1, 0x19, 128], null
);
run_next_test();
});
//// Parameter.decodeUntypedParameter ////
add_test(function test_Parameter_decodeUntypedParameter() {
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeUntypedParameter(data);
}, [1], null, "CodeError"
);
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeUntypedParameter(data);
}, [65, 0, 0], {name: "a", value: null}
);
// Test for IntegerValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeUntypedParameter(data);
}, [65, 0, 1, 0], {name: "a", value: 0}
);
// Test for TextValue
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeUntypedParameter(data);
}, [65, 0, 66, 0], {name: "a", value: "B"}
);
run_next_test();
});
//// Parameter.decode ////
add_test(function test_Parameter_decode() {
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decode(data);
}, [1, 0x19, 60, 115, 109, 105, 108, 62, 0], {name: "start", value: "<smil>"}
);
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decode(data);
}, [65, 0, 66, 0], {name: "a", value: "B"}
);
run_next_test();
});
//// Parameter.decodeMultiple ////
add_test(function test_Parameter_decodeMultiple() {
wsp_decode_test_ex(function (data) {
return WSP.Parameter.decodeMultiple(data, 13);
}, [1, 0x19, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0], {start: "<smil>", a: "B"}
);
run_next_test();
});
//
// Test target: Header
//
//// Header.decode ////
add_test(function test_Header_decode() {
wsp_decode_test(WSP.Header, [0x34 | 0x80, 0x80], {name: "push-flag", value: 0});
wsp_decode_test(WSP.Header, [65, 0, 66, 0], {name: "a", value: "B"});
run_next_test();
});
//
// Test target: WellKnownHeader
//
//// WellKnownHeader.decode ////
add_test(function test_WellKnownHeader_decode() {
wsp_decode_test(WSP.WellKnownHeader, [0xFF], null, "NotWellKnownEncodingError");
let (entry = WSP.WSP_HEADER_FIELDS["push-flag"]) {
// Test for Short-Integer
wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 0x80],
{name: entry.name, value: 0});
// Test for NoValue
wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 0],
{name: entry.name, value: null});
// Test for TokenText
wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 65, 0],
{name: entry.name, value: "A"});
// Test for QuotedString
wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 34, 128, 0],
{name: entry.name, value: String.fromCharCode(128)});
// Test for skipValue
wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 2, 0, 0], null);
}
run_next_test();
});
//
// Test target: ApplicationHeader
//
//// ApplicationHeader.decode ////
add_test(function test_ApplicationHeader_decode() {
wsp_decode_test(WSP.ApplicationHeader, [5, 0, 66, 0], null, "CodeError");
wsp_decode_test(WSP.ApplicationHeader, [65, 0, 66, 0], {name: "a", value: "B"});
// Test for skipValue
wsp_decode_test(WSP.ApplicationHeader, [65, 0, 2, 0, 0], null);
run_next_test();
});
//
// Test target: FieldName
//
//// FieldName.decode ////
add_test(function test_FieldName_decode() {
wsp_decode_test(WSP.FieldName, [0], "");
wsp_decode_test(WSP.FieldName, [65, 0], "a");
wsp_decode_test(WSP.FieldName, [97, 0], "a");
let (entry = WSP.WSP_HEADER_FIELDS["content-length"]) {
wsp_decode_test(WSP.FieldName, [entry.number | 0x80], entry.name);
}
wsp_decode_test(WSP.FieldName, [0xFF], null, "NotWellKnownEncodingError");
run_next_test();
});
//
// Test target: AcceptCharsetValue
//
//// AcceptCharsetValue.decode ////
add_test(function test_AcceptCharsetValue_decode() {
wsp_decode_test(WSP.AcceptCharsetValue, [0xFF], null, "CodeError");
// Test for Any-Charset
wsp_decode_test(WSP.AcceptCharsetValue, [128], {charset: "*"});
// Test for Constrained-Charset
wsp_decode_test(WSP.AcceptCharsetValue, [65, 0], {charset: "A"});
let (entry = WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) {
wsp_decode_test(WSP.AcceptCharsetValue, [entry.number | 0x80], {charset: entry.name});
}
// Test for Accept-Charset-General-Form
wsp_decode_test(WSP.AcceptCharsetValue, [1, 128], {charset: "*"});
let (entry = WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) {
wsp_decode_test(WSP.AcceptCharsetValue, [2, 1, entry.number], {charset: entry.name});
wsp_decode_test(WSP.AcceptCharsetValue, [1, entry.number | 0x80], {charset: entry.name});
}
wsp_decode_test(WSP.AcceptCharsetValue, [3, 65, 0, 100], {charset: "A", q: 0.99});
run_next_test();
});
//
// Test target: WellKnownCharset
//
//// WellKnownCharset.decode ////
add_test(function test_WellKnownCharset_decode() {
wsp_decode_test(WSP.WellKnownCharset, [0xFF], null, "NotWellKnownEncodingError");
// Test for Any-Charset
wsp_decode_test(WSP.WellKnownCharset, [128], {charset: "*"});
// Test for number-typed return value from IntegerValue
wsp_decode_test(WSP.WellKnownCharset, [1, 3], {charset: "ansi_x3.4-1968"});
// Test for array-typed return value from IntegerValue
wsp_decode_test(WSP.WellKnownCharset, [7, 0, 0, 0, 0, 0, 0, 0, 3], null, "CodeError");
run_next_test();
});
//
// Test target: ContentTypeValue
//
//// ContentTypeValue.decodeConstrainedMedia ////
add_test(function test_ContentTypeValue_decodeConstrainedMedia() {
// Test for string-typed return value from ConstrainedEncoding
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeConstrainedMedia(data);
}, [65, 0], {media: "a", params: null}
);
// Test for number-typed return value from ConstrainedEncoding
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeConstrainedMedia(data);
}, [0x33 | 0x80], {media: "application/vnd.wap.multipart.related", params: null}
);
// Test for NotWellKnownEncodingError
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeConstrainedMedia(data);
}, [0x80], null, "NotWellKnownEncodingError"
);
run_next_test();
});
//// ContentTypeValue.decodeMedia ////
add_test(function test_ContentTypeValue_decodeMedia() {
// Test for NullTerminatedTexts
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeMedia(data);
}, [65, 0], "a"
);
// Test for IntegerValue
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeMedia(data);
}, [0x3E | 0x80], "application/vnd.wap.mms-message"
);
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeMedia(data);
}, [0x80], null, "NotWellKnownEncodingError"
);
run_next_test();
});
//// ContentTypeValue.decodeMediaType ////
add_test(function test_ContentTypeValue_decodeMediaType() {
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeMediaType(data, 1);
}, [0x3E | 0x80],
{media: "application/vnd.wap.mms-message", params: null}
);
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeMediaType(data, 14);
}, [0x3E | 0x80, 1, 0x19, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0],
{media: "application/vnd.wap.mms-message", params: {start: "<smil>", a: "B"}}
);
run_next_test();
});
//// ContentTypeValue.decodeContentGeneralForm ////
add_test(function test_ContentTypeValue_decodeContentGeneralForm() {
wsp_decode_test_ex(function (data) {
return WSP.ContentTypeValue.decodeContentGeneralForm(data);
}, [14, 0x3E | 0x80, 1, 0x19, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0],
{media: "application/vnd.wap.mms-message", params: {start: "<smil>", a: "B"}}
);
run_next_test();
});
//// ContentTypeValue.decode ////
add_test(function test_ContentTypeValue_decode() {
wsp_decode_test(WSP.ContentTypeValue,
[14, 0x3E | 0x80, 1, 0x19, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0],
{media: "application/vnd.wap.mms-message", params: {start: "<smil>", a: "B"}}
);
wsp_decode_test(WSP.ContentTypeValue, [0x33 | 0x80],
{media: "application/vnd.wap.multipart.related", params: null}
);
run_next_test();
});
//
// Test target: ApplicationIdValue
//
//// ApplicationIdValue.decode ////
add_test(function test_ApplicationIdValue_decode() {
wsp_decode_test(WSP.ApplicationIdValue, [0], "");
wsp_decode_test(WSP.ApplicationIdValue, [65, 0], "A");
wsp_decode_test(WSP.ApplicationIdValue, [97, 0], "a");
let (entry = WSP.OMNA_PUSH_APPLICATION_IDS["x-wap-application:mms.ua"]) {
wsp_decode_test(WSP.ApplicationIdValue, [entry.number | 0x80], entry.urn);
wsp_decode_test(WSP.ApplicationIdValue, [1, entry.number], entry.urn);
}
wsp_decode_test(WSP.ApplicationIdValue, [0xFF], null, "NotWellKnownEncodingError");
run_next_test();
});
//
// Test target: PduHelper
//
//// PduHelper.parseHeaders ////
add_test(function test_PduHelper_parseHeaders() {
wsp_decode_test_ex(function (data) {
return WSP.PduHelper.parseHeaders(data, data.array.length);
}, [0x80 | 0x05, 2, 0x23, 0x28, 0x80 | 0x2F, 0x80 | 0x04],
{"age": 9000, "x-wap-application-id": "x-wap-application:mms.ua"}
);
run_next_test();
});

View File

@ -0,0 +1,5 @@
[DEFAULT]
head = header_helpers.js
tail =
[test_wsp_pdu_helper.js]

View File

@ -11,6 +11,7 @@
[include:image/test/unit/xpcshell.ini]
[include:dom/plugins/test/unit/xpcshell.ini]
[include:dom/sms/tests/xpcshell.ini]
[include:dom/mms/tests/xpcshell.ini]
[include:dom/src/json/test/unit/xpcshell.ini]
[include:dom/system/gonk/tests/xpcshell.ini]
[include:dom/tests/unit/xpcshell.ini]