test_request-utils-js-getFormattedProtocol.js (5186B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test devtools/client/netmonitor/src/utils/request-utils.js function 5 // |getFormattedProtocol| 6 7 "use strict"; 8 9 const { require } = ChromeUtils.importESModule( 10 "resource://devtools/shared/loader/Loader.sys.mjs" 11 ); 12 const { 13 getFormattedProtocol, 14 } = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); 15 16 function run_test() { 17 const http_1p1_value_http1p1 = { 18 httpVersion: "HTTP/1.1", 19 responseHeaders: { 20 headers: [ 21 { 22 name: "X-Firefox-Spdy", 23 value: "HTTP/1.1", 24 }, 25 ], 26 }, 27 }; 28 29 const http_1p1_value_http_no_slash_1p1 = { 30 httpVersion: "HTTP/1.1", 31 responseHeaders: { 32 headers: [ 33 { 34 name: "X-Firefox-Spdy", 35 value: "http1.1", 36 }, 37 ], 38 }, 39 }; 40 41 const http_1p1_value_http1p11 = { 42 httpVersion: "HTTP/1.1", 43 responseHeaders: { 44 headers: [ 45 { 46 name: "X-Firefox-Spdy", 47 value: "http/1.11", 48 }, 49 ], 50 }, 51 }; 52 53 const http_2p0_value_h2 = { 54 httpVersion: "HTTP/2.0", 55 responseHeaders: { 56 headers: [ 57 { 58 name: "X-Firefox-Spdy", 59 value: "h2", 60 }, 61 ], 62 }, 63 }; 64 65 const http_1p1_value_h1 = { 66 httpVersion: "HTTP/1.1", 67 responseHeaders: { 68 headers: [ 69 { 70 name: "X-Firefox-Spdy", 71 value: "h1", 72 }, 73 ], 74 }, 75 }; 76 77 const http_1p1_value_h2 = { 78 httpVersion: "HTTP/1.1", 79 responseHeaders: { 80 headers: [ 81 { 82 name: "X-Firefox-Spdy", 83 value: "h2", 84 }, 85 ], 86 }, 87 }; 88 89 const http_1p1_value_empty_string = { 90 httpVersion: "HTTP/1.1", 91 responseHeaders: { 92 headers: [ 93 { 94 name: "X-Firefox-Spdy", 95 value: "", 96 }, 97 ], 98 }, 99 }; 100 101 const http_2p0_value_empty_string = { 102 httpVersion: "HTTP/2.0", 103 responseHeaders: { 104 headers: [ 105 { 106 name: "X-Firefox-Spdy", 107 value: "", 108 }, 109 ], 110 }, 111 }; 112 113 const http_2p0_value_2p0 = { 114 httpVersion: "HTTP/2.0", 115 responseHeaders: { 116 headers: [ 117 { 118 name: "X-Firefox-Spdy", 119 value: "HTTP/2.0", 120 }, 121 ], 122 }, 123 }; 124 125 const http_3p0_value_h3 = { 126 httpVersion: "HTTP/3.0", 127 responseHeaders: { 128 headers: [ 129 { 130 name: "X-Firefox-Spdy", 131 value: "h3", 132 }, 133 ], 134 }, 135 }; 136 137 const http_3p0_value_h3p0 = { 138 httpVersion: "HTTP/3.0", 139 responseHeaders: { 140 headers: [ 141 { 142 name: "X-Firefox-Spdy", 143 value: "h3.0", 144 }, 145 ], 146 }, 147 }; 148 149 const http_3p0_value_http_3p0 = { 150 httpVersion: "HTTP/3.0", 151 responseHeaders: { 152 headers: [ 153 { 154 name: "X-Firefox-Spdy", 155 value: "http/3.0", 156 }, 157 ], 158 }, 159 }; 160 161 const http_3p0_value_3p0 = { 162 httpVersion: "HTTP/3.0", 163 responseHeaders: { 164 headers: [ 165 { 166 name: "X-Firefox-Spdy", 167 value: "3.0", 168 }, 169 ], 170 }, 171 }; 172 173 const http_4p0_value_h4 = { 174 httpVersion: "HTTP/4.0", 175 responseHeaders: { 176 headers: [ 177 { 178 name: "X-Firefox-Spdy", 179 value: "h4", 180 }, 181 ], 182 }, 183 }; 184 185 info("Testing httpValue:HTTP/1.1, value:http/1.1"); 186 equal(getFormattedProtocol(http_1p1_value_http1p1), "HTTP/1.1"); 187 188 info("Testing httpValue:HTTP/1.1, value:http1.1"); 189 equal( 190 getFormattedProtocol(http_1p1_value_http_no_slash_1p1), 191 "HTTP/1.1+http1.1" 192 ); 193 194 info("Testing httpValue:HTTP/1.1, value:http/1.11"); 195 equal(getFormattedProtocol(http_1p1_value_http1p11), "HTTP/1.1+http/1.11"); 196 197 info("Testing httpValue:HTTP/2.0, value:h2"); 198 equal(getFormattedProtocol(http_2p0_value_h2), "HTTP/2.0"); 199 200 info("Testing httpValue:HTTP/1.1, value:h1"); 201 equal(getFormattedProtocol(http_1p1_value_h1), "HTTP/1.1+h1"); 202 203 info("Testing httpValue:HTTP/1.1, value:h2"); 204 equal(getFormattedProtocol(http_1p1_value_h2), "HTTP/1.1+h2"); 205 206 info("Testing httpValue:HTTP/1.1, value:http1.1"); 207 equal( 208 getFormattedProtocol(http_1p1_value_http_no_slash_1p1), 209 "HTTP/1.1+http1.1" 210 ); 211 212 info("Testing httpValue:HTTP/1.1, value:''"); 213 equal(getFormattedProtocol(http_1p1_value_empty_string), "HTTP/1.1"); 214 215 info("Testing httpValue:HTTP/2.0, value:''"); 216 equal(getFormattedProtocol(http_2p0_value_empty_string), "HTTP/2.0"); 217 218 info("Testing httpValue:HTTP/2.0, value:HTTP/2.0"); 219 equal(getFormattedProtocol(http_2p0_value_2p0), "HTTP/2.0+HTTP/2.0"); 220 221 info("Testing httpValue:HTTP/3.0, value:h3"); 222 equal(getFormattedProtocol(http_3p0_value_h3), "HTTP/3.0"); 223 224 info("Testing httpValue:HTTP/3.0, value:h3.0"); 225 equal(getFormattedProtocol(http_3p0_value_h3p0), "HTTP/3.0"); 226 227 info("Testing httpValue:HTTP/3.0, value:http/3.0"); 228 equal(getFormattedProtocol(http_3p0_value_http_3p0), "HTTP/3.0+http/3.0"); 229 230 info("Testing httpValue:HTTP/3.0, value:3.0"); 231 equal(getFormattedProtocol(http_3p0_value_3p0), "HTTP/3.0+3.0"); 232 233 info("Testing httpValue:HTTP/4.0, value:h4"); 234 equal(getFormattedProtocol(http_4p0_value_h4), "HTTP/4.0"); 235 }