dom/wappush/tests/test_sl_pdu_helper.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.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 let SL = {};
michael@0 5 subscriptLoader.loadSubScript("resource://gre/modules/SlPduHelper.jsm", SL);
michael@0 6 SL.debug = do_print;
michael@0 7
michael@0 8 function run_test() {
michael@0 9 run_next_test();
michael@0 10 }
michael@0 11
michael@0 12 /**
michael@0 13 * SL in plain text
michael@0 14 */
michael@0 15 add_test(function test_sl_parse_plain_text() {
michael@0 16 let contentType = "";
michael@0 17 let data = {};
michael@0 18
michael@0 19 contentType = "text/vnd.wap.sl";
michael@0 20 data.array = new Uint8Array([
michael@0 21 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65,
michael@0 22 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x27, 0x31,
michael@0 23 0x2E, 0x30, 0x27, 0x3F, 0x3E, 0x0A, 0x3C, 0x73,
michael@0 24 0x6C, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3D, 0x27,
michael@0 25 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77,
michael@0 26 0x77, 0x77, 0x2E, 0x6F, 0x72, 0x65, 0x69, 0x6C,
michael@0 27 0x6C, 0x79, 0x2E, 0x63, 0x6F, 0x6D, 0x27, 0x2F,
michael@0 28 0x3E
michael@0 29 ]);
michael@0 30 data.offset = 0;
michael@0 31 let result = "<?xml version='1.0'?>\n<sl href='http://www.oreilly.com'/>";
michael@0 32 let msg = SL.PduHelper.parse(data, contentType);
michael@0 33 do_check_eq(msg.content, result);
michael@0 34
michael@0 35 run_next_test();
michael@0 36 });
michael@0 37
michael@0 38 /**
michael@0 39 * SL compressed by WBXML
michael@0 40 */
michael@0 41 add_test(function test_sl_parse_wbxml() {
michael@0 42 let msg = {};
michael@0 43 let contentType = "";
michael@0 44 let data = {};
michael@0 45
michael@0 46 contentType = "application/vnd.wap.slc";
michael@0 47 data.array = new Uint8Array([
michael@0 48 0x03, 0x06, 0x6A, 0x00, 0x85, 0x0A, 0x03, 0x6F,
michael@0 49 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00, 0x85,
michael@0 50 0x01
michael@0 51 ]);
michael@0 52 data.offset = 0;
michael@0 53 let result = "<sl href=\"http://www.oreilly.com/\"/>";
michael@0 54 let msg = SL.PduHelper.parse(data, contentType);
michael@0 55 do_check_eq(msg.content, result);
michael@0 56
michael@0 57 run_next_test();
michael@0 58 });
michael@0 59
michael@0 60 /**
michael@0 61 * SL compressed by WBXML, with public ID stored in string table
michael@0 62 */
michael@0 63 add_test(function test_sl_parse_wbxml_public_id_string_table() {
michael@0 64 let msg = {};
michael@0 65 let contentType = "";
michael@0 66 let data = {};
michael@0 67
michael@0 68 contentType = "application/vnd.wap.slc";
michael@0 69 data.array = new Uint8Array([
michael@0 70 0x03, 0x00, 0x00, 0x6A, 0x1C, 0x2D, 0x2F, 0x2F,
michael@0 71 0x57, 0x41, 0x50, 0x46, 0x4F, 0x52, 0x55, 0x4D,
michael@0 72 0x2F, 0x2F, 0x44, 0x54, 0x44, 0x20, 0x53, 0x4C,
michael@0 73 0x20, 0x31, 0x2E, 0x30, 0x2F, 0x2F, 0x45, 0x4E,
michael@0 74 0x00, 0x85, 0x0A, 0x03, 0x6F, 0x72, 0x65, 0x69,
michael@0 75 0x6C, 0x6C, 0x79, 0x00, 0x85, 0x01
michael@0 76 ]);
michael@0 77 data.offset = 0;
michael@0 78 let result = "<sl href=\"http://www.oreilly.com/\"/>";
michael@0 79 let msg = SL.PduHelper.parse(data, contentType);
michael@0 80 do_check_eq(msg.content, result);
michael@0 81
michael@0 82 run_next_test();
michael@0 83 });
michael@0 84
michael@0 85 /**
michael@0 86 * SL compressed by WBXML with string table
michael@0 87 */
michael@0 88 add_test(function test_sl_parse_wbxml_with_string_table() {
michael@0 89 let msg = {};
michael@0 90 let contentType = "";
michael@0 91 let data = {};
michael@0 92
michael@0 93 contentType = "application/vnd.wap.slc";
michael@0 94 data.array = new Uint8Array([
michael@0 95 0x03, 0x06, 0x6A, 0x08, 0x6F, 0x72, 0x65, 0x69,
michael@0 96 0x6C, 0x6C, 0x79, 0x00, 0x85, 0x0A, 0x83, 0x00,
michael@0 97 0x85, 0x01
michael@0 98 ]);
michael@0 99 data.offset = 0;
michael@0 100 let result = "<sl href=\"http://www.oreilly.com/\"/>";
michael@0 101 let msg = SL.PduHelper.parse(data, contentType);
michael@0 102 do_check_eq(msg.content, result);
michael@0 103
michael@0 104 run_next_test();
michael@0 105 });

mercurial