Best JavaScript code snippet using storybook-root
url-test.js
Source: url-test.js
1var settings = hammerhead.settings;2var urlUtils = hammerhead.utils.url;3var sharedUrlUtils = hammerhead.sharedUtils.url;4var destLocation = hammerhead.utils.destLocation;5var browserUtils = hammerhead.utils.browser;6var nativeMethods = hammerhead.nativeMethods;7var nodeSandbox = hammerhead.sandbox.node;8var Promise = hammerhead.Promise;9var PROXY_PORT = 1337;10var PROXY_HOSTNAME = '127.0.0.1';11var PROXY_HOST = PROXY_HOSTNAME + ':' + PROXY_PORT;12function getProxyUrl (url, resourceType, protocol, windowId) {13 return urlUtils.getProxyUrl(url, {14 proxyHostname: PROXY_HOSTNAME,15 proxyPort: PROXY_PORT,16 sessionId: 'sessionId',17 resourceType: resourceType,18 proxyProtocol: protocol || 'http:',19 windowId: windowId,20 });21}22test('getCrossDomainIframeProxyUrl (GH-749)', function () {23 var destUrl = 'test.html';24 var storedCrossDomainport = settings.get().crossDomainProxyPort;25 settings.get().crossDomainProxyPort = '5555';26 strictEqual(urlUtils.getCrossDomainIframeProxyUrl(destUrl),27 'http:/β/β' + location.hostname + ':5555' + '/βsessionId!i!s*example.com/βhttps:/β/βexample.com/β' + destUrl);28 settings.get().crossDomainProxyPort = storedCrossDomainport;29});30test('resolveUrlAsDest', function () {31 strictEqual(urlUtils.resolveUrlAsDest('/βindex.html#hash'), 'https:/β/βexample.com/βindex.html#hash');32 strictEqual(urlUtils.resolveUrlAsDest('javascript:0;'), 'javascript:0;');33 strictEqual(urlUtils.resolveUrlAsDest('/βindex.html?param=value#hash'), 'https:/β/βexample.com/βindex.html?param=value#hash');34 strictEqual(urlUtils.resolveUrlAsDest('https:/β/βtwitter.com/βindex.html?param=value#hash'), 'https:/β/βtwitter.com/βindex.html?param=value#hash');35 strictEqual(urlUtils.resolveUrlAsDest('/β/βtwitter.com/βindex.html?param=value#hash'), 'https:/β/βtwitter.com/βindex.html?param=value#hash');36 strictEqual(urlUtils.resolveUrlAsDest('http:/β/βg.tbcdn.cn/β??kissy/βk/β1.4.2/βseed-min.js'), 'http:/β/βg.tbcdn.cn/β??kissy/βk/β1.4.2/βseed-min.js');37});38test('isSupportedProtocol', function () {39 ok(urlUtils.isSupportedProtocol('http:/β/βexample.org'));40 ok(urlUtils.isSupportedProtocol('https:/β/βexample.org'));41 ok(urlUtils.isSupportedProtocol('file:/β/β/βC:/βindex.htm'));42 ok(urlUtils.isSupportedProtocol('/β/βexample.org'));43 ok(urlUtils.isSupportedProtocol('/βsome/βpath'));44 ok(urlUtils.isSupportedProtocol('path'));45 ok(urlUtils.isSupportedProtocol('./β'));46 ok(urlUtils.isSupportedProtocol('../β../β'));47 ok(urlUtils.isSupportedProtocol('?t'));48 ok(!urlUtils.isSupportedProtocol('#42'));49 ok(!urlUtils.isSupportedProtocol(' data:asdasdasdasdasdasd'));50 ok(!urlUtils.isSupportedProtocol('chrome-extension:/β/βgoogle.com/βimage.png'));51});52test('formatUrl', function () {53 strictEqual(urlUtils.formatUrl({ hostname: 'localhost', partAfterHost: '/βpath' }), '/βpath');54 strictEqual(urlUtils.formatUrl({ port: '1400', partAfterHost: '/βpath' }), '/βpath');55 strictEqual(urlUtils.formatUrl({56 hostname: 'localhost',57 port: '1400',58 protocol: 'http:',59 }), 'http:/β/βlocalhost:1400');60 var parsedUrl = {61 hostname: 'localhost',62 port: '1400',63 protocol: 'http:',64 auth: 'test:test',65 };66 strictEqual(urlUtils.formatUrl(parsedUrl), 'http:/β/βtest:test@localhost:1400');67 parsedUrl = {68 hostname: 'localhost',69 port: '1400',70 protocol: 'http:',71 auth: 'test',72 partAfterHost: '/βpath',73 };74 strictEqual(urlUtils.formatUrl(parsedUrl), 'http:/β/βtest@localhost:1400/βpath');75});76test('isRelativeUrl', function () {77 ok(!sharedUrlUtils.isRelativeUrl('http:/β/βexample.com'));78 ok(sharedUrlUtils.isRelativeUrl('/βtest.html'));79 ok(!sharedUrlUtils.isRelativeUrl('file:/β/β/βC:/βindex.htm'));80 ok(sharedUrlUtils.isRelativeUrl('C:\\index.htm'));81});82module('parse url');83test('newline characters', function () {84 var url = 'http:/β/βexa\nmple.com/β?par\n=val';85 var parsingResult = urlUtils.parseUrl(url);86 strictEqual(parsingResult.hostname, 'example.com');87 strictEqual(parsingResult.partAfterHost, '/β?par=val');88});89test('tabulation characters', function () {90 var url = 'http:/β/βexa\tmple.com/β?par\t=val';91 var parsingResult = urlUtils.parseUrl(url);92 strictEqual(parsingResult.hostname, 'example.com');93 strictEqual(parsingResult.partAfterHost, '/β?par=val');94});95test('hash after host', function () {96 var url = '/β/βtest.example.com#42';97 var parsingResult = urlUtils.parseUrl(url);98 ok(!parsingResult.protocol);99 strictEqual(parsingResult.hostname, 'test.example.com');100 strictEqual(parsingResult.partAfterHost, '#42');101});102test('question mark disappears', function () {103 var url = 'http:/β/βgoogle.ru:345/βpath?';104 var parsedUrl = urlUtils.parseUrl(url);105 strictEqual(parsedUrl.partAfterHost, '/βpath?');106 strictEqual(urlUtils.formatUrl(parsedUrl), url);107 url = 'http:/β/βyandex.ru:234/βpath';108 parsedUrl = urlUtils.parseUrl(url);109 strictEqual(parsedUrl.partAfterHost, '/βpath');110 strictEqual(urlUtils.formatUrl(parsedUrl), url);111});112test('additional slashes after scheme (GH-739)', function () {113 var url = 'http:/β/β/β/β/βexample.com/β';114 var parsingResult = urlUtils.parseUrl(url);115 strictEqual(parsingResult.hostname, 'example.com');116 urlUtils.parseUrl('/β/β/β/βmail.ru');117});118test('additional slashes before path', function () {119 var url = '/β/β/β/β/βexample.com/β';120 var parsingResult = urlUtils.parseUrl(url);121 strictEqual(parsingResult.hostname, 'example.com');122});123test('auth', function () {124 strictEqual(urlUtils.parseUrl('http:/β/βusername:password@example.com').auth, 'username:password');125 strictEqual(urlUtils.parseUrl('http:/β/βusername@example.com').auth, 'username');126 strictEqual(urlUtils.parseUrl('http:/β/βexample.com').auth, void 0);127});128test('scope', function () {129 strictEqual(urlUtils.getScope('http:/β/βexample.com'), '/β');130 strictEqual(urlUtils.getScope('http:/β/βexample.com/β'), '/β');131 strictEqual(urlUtils.getScope('http:/β/βexample.com/βimg.gif'), '/β');132 strictEqual(urlUtils.getScope('http:/β/βexample.com/βpath/βto/βws.js'), '/βpath/βto/β');133 strictEqual(urlUtils.getScope('http:/β/βexample.com/βpath/β?z=9'), '/βpath/β');134 strictEqual(urlUtils.getScope('http:/β/βexample.com/βpath?z=9'), '/β');135 strictEqual(urlUtils.getScope('/βpath/β?z=9'), '/βpath/β');136 strictEqual(urlUtils.getScope('../βpath/βsw.js'), '/βpath/β');137 /β/β GH-2524138 strictEqual(urlUtils.getScope('http:/β/βexample.com/βpath/βsw.js?https:/β/βsome.url/βanother-path'), '/βpath/β');139 strictEqual(urlUtils.getScope('/βpath/βsw.js?v=arg=/βanother-path'), '/βpath/β');140 strictEqual(urlUtils.getScope('/βpath/βsw.js?'), '/βpath/β');141});142module('get proxy url');143test('already proxied', function () {144 var destUrl = 'http:/β/βtest.example.com/β';145 var proxyUrl = getProxyUrl(destUrl);146 var newUrl = getProxyUrl(proxyUrl, 'i');147 strictEqual(urlUtils.parseProxyUrl(newUrl).resourceType, 'i');148});149test('destination with query, path, hash and host', function () {150 var destUrl = 'http:/β/βtest.example.com/βpa/βth/βPage?param1=value¶m2=¶m3#testHash';151 var proxyUrl = getProxyUrl(destUrl);152 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);153});154test('destination with host only', function () {155 var destUrl = 'http:/β/βtest.example.com/β';156 var proxyUrl = getProxyUrl(destUrl);157 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);158});159test('destination with https protocol', function () {160 var destUrl = 'https:/β/βtest.example.com:53/β';161 var proxyUrl = getProxyUrl(destUrl);162 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);163});164test('relative path', function () {165 var proxyUrl = urlUtils.getProxyUrl('/βImage1.jpg');166 strictEqual(proxyUrl, 'http:/β/β' + location.host + '/βsessionId/βhttps:/β/βexample.com/βImage1.jpg');167 var parsedUrl = urlUtils.parseUrl('share?id=1kjQMWh7IcHdTBbTv6otRvCGYr-p02q206M7aR7dmog0');168 ok(!parsedUrl.hostname);169 ok(!parsedUrl.host);170 ok(!parsedUrl.hash);171 ok(!parsedUrl.port);172 ok(!parsedUrl.protocol);173 strictEqual(parsedUrl.partAfterHost, 'share?id=1kjQMWh7IcHdTBbTv6otRvCGYr-p02q206M7aR7dmog0');174});175if (window.navigator.platform.toLowerCase() === 'win32' && !browserUtils.isFirefox) {176 test('relative file path', function () {177 var destUrl = 'C:\\index.htm';178 var proxyUrl = urlUtils.getProxyUrl(destUrl);179 strictEqual(proxyUrl, 'http:/β/β' + location.host + '/βsessionId/βfile:/β/β/βC:/βindex.htm');180 });181}182test('contains successive question marks in query', function () {183 var destUrl = 'http:/β/βtest.example.com/β??dirs/β???files/β';184 var proxyUrl = urlUtils.getProxyUrl(destUrl, {185 proxyHostname: '127.0.0.1',186 proxyPort: PROXY_PORT,187 sessionId: 'sessionId',188 });189 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);190});191test('destination with port', function () {192 var destUrl = 'http:/β/βtest.example.com:53/β';193 var proxyUrl = getProxyUrl(destUrl);194 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);195});196test('undefined or null', function () {197 /β/β NOTE: In Safari, a.href = null leads to the empty url, not <current_url>/βnull.198 if (!browserUtils.isSafari)199 strictEqual(getProxyUrl(null), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βnull');200 strictEqual(getProxyUrl(void 0), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βundefined');201});202test('remove unnecessary slashes form the begin of the url', function () {203 var proxy = urlUtils.getProxyUrl('/β/β/β/β/βexample.com', {204 proxyHostname: 'localhost',205 proxyPort: '5555',206 sessionId: 'sessionId',207 resourceType: 'resourceType',208 });209 strictEqual(proxy, 'http:/β/βlocalhost:5555/βsessionId!resourceType/βhttps:/β/βexample.com');210});211test('should ensure triple starting slashes in a scheme-less file URLs', function () {212 var storedLocation = destLocation.getLocation();213 destLocation.forceLocation(urlUtils.getProxyUrl('file:/β/β/βhome/βtestcafe/βsite'));214 var opts = { proxyHostname: 'localhost' };215 strictEqual(urlUtils.getProxyUrl('/β/β/β/β/βhome/βtestcafe/βsite2', opts), 'http:/β/βlocalhost:2000/βsessionId/βfile:/β/β/βhome/βtestcafe/βsite2');216 strictEqual(urlUtils.getProxyUrl('/β/β/β/β/βD:/βtestcafe/βsite2', opts), 'http:/β/βlocalhost:2000/βsessionId/βfile:/β/β/βD:/βtestcafe/βsite2');217 strictEqual(urlUtils.getProxyUrl('/β/βD:/βtestcafe/βsite2', opts), 'http:/β/βlocalhost:2000/βsessionId/βfile:/β/β/βD:/βtestcafe/βsite2');218 destLocation.forceLocation(storedLocation);219});220test('convert destination host and protocol to lower case', function () {221 /β/β BUG: GH-1222 var proxy = getProxyUrl('hTtp:/β/βeXamPle.Com:123/βpaTh/βImage?Name=Value&#Hash');223 ok(proxy.indexOf('http:/β/βexample.com:123/βpaTh/βImage?Name=Value&#Hash') !== -1);224});225test('unexpected trailing slash (GH-342)', function () {226 var proxyUrl = getProxyUrl('http:/β/βexample.com');227 ok(!/β\/β$/β.test(proxyUrl));228 proxyUrl = getProxyUrl('http:/β/βexample.com/β');229 ok(/β\/β$/β.test(proxyUrl));230});231test('special pages (GH-339)', function () {232 sharedUrlUtils.SPECIAL_PAGES.forEach(function (url) {233 var proxyUrl = getProxyUrl(url);234 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + url);235 });236});237test('convert a charset to lower case (GH-752)', function () {238 var url = 'http:/β/βexample.com';239 var opts = {240 sessionId: 'sessionId',241 charset: 'UTF-8',242 proxyHostname: 'localhost',243 proxyPort: '5555',244 };245 strictEqual(sharedUrlUtils.getProxyUrl(url, opts), 'http:/β/βlocalhost:5555/βsessionId!utf-8/β' + url);246});247test('windowId', function () {248 var destUrl = 'http:/β/βexample.com';249 var proxyUrl = getProxyUrl(destUrl, null, null, '123456789');250 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId' + '*123456789/β' + destUrl);251});252test('getPageProxyUrl', function () {253 var sameDomainUrl = 'https:/β/βexample.com/β';254 var crossDomainUrl = 'https:/β/βdevexpress.com/β';255 var proxySameDomainHost = location.host;256 var proxyCrossDomainHost = location.hostname + ':' + settings.get().crossDomainProxyPort;257 strictEqual(urlUtils.getPageProxyUrl(sameDomainUrl, 'windowId'),258 'http:/β/β' + proxySameDomainHost + '/βsessionId*windowId/β' + sameDomainUrl);259 strictEqual(urlUtils.getPageProxyUrl(crossDomainUrl, 'windowId'),260 'http:/β/β' + proxyCrossDomainHost + '/βsessionId*windowId/β' + crossDomainUrl);261 strictEqual(urlUtils.getPageProxyUrl('http:/β/β' + proxySameDomainHost + '/βsessionId*pa/β' + sameDomainUrl, 'windowId'),262 'http:/β/β' + proxySameDomainHost + '/βsessionId*windowId/β' + sameDomainUrl);263 strictEqual(urlUtils.getPageProxyUrl('http:/β/β' + proxySameDomainHost + '/βsessionId*pa!if/β' + sameDomainUrl, 'windowId'),264 'http:/β/β' + proxySameDomainHost + '/βsessionId*windowId!f/β' + sameDomainUrl);265 strictEqual(urlUtils.getPageProxyUrl('http:/β/β' + proxyCrossDomainHost + '/βsessionId*pa!i/β' + sameDomainUrl, 'windowId'),266 'http:/β/β' + proxySameDomainHost + '/βsessionId*windowId/β' + sameDomainUrl);267});268module('https proxy protocol');269test('destination with host only', function () {270 var destUrl = 'http:/β/βtest.example.com/β';271 var proxyUrl = getProxyUrl(destUrl, '', 'https:');272 strictEqual(proxyUrl, 'https:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);273});274test('relative path', function () {275 var proxyUrl = getProxyUrl('/βImage1.jpg', '', 'https:');276 strictEqual(proxyUrl, 'https:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βImage1.jpg');277});278test('special pages', function () {279 sharedUrlUtils.SPECIAL_PAGES.forEach(function (url) {280 var proxyUrl = getProxyUrl(url, '', 'https:');281 strictEqual(proxyUrl, 'https:/β/β' + PROXY_HOST + '/βsessionId/β' + url);282 });283});284test('parse proxy url', function () {285 var proxyUrl = 'https:/β/β' + PROXY_HOST + '/βsessionId/βhttp:/β/βtest.example.com:53/βPA/βTH/β?#testHash';286 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);287 strictEqual(parsingResult.destUrl, 'http:/β/βtest.example.com:53/βPA/βTH/β?#testHash');288 strictEqual(parsingResult.destResourceInfo.protocol, 'http:');289 strictEqual(parsingResult.destResourceInfo.host, 'test.example.com:53');290 strictEqual(parsingResult.destResourceInfo.hostname, 'test.example.com');291 strictEqual(parsingResult.destResourceInfo.port, '53');292 strictEqual(parsingResult.destResourceInfo.partAfterHost, '/βPA/βTH/β?#testHash');293 strictEqual(parsingResult.sessionId, 'sessionId');294});295module('parse proxy url');296test('http', function () {297 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttp:/β/βtest.example.com:53/βPA/βTH/β?#testHash';298 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);299 strictEqual(parsingResult.destUrl, 'http:/β/βtest.example.com:53/βPA/βTH/β?#testHash');300 strictEqual(parsingResult.destResourceInfo.protocol, 'http:');301 strictEqual(parsingResult.destResourceInfo.host, 'test.example.com:53');302 strictEqual(parsingResult.destResourceInfo.hostname, 'test.example.com');303 strictEqual(parsingResult.destResourceInfo.port, '53');304 strictEqual(parsingResult.destResourceInfo.partAfterHost, '/βPA/βTH/β?#testHash');305 strictEqual(parsingResult.sessionId, 'sessionId');306});307test('https', function () {308 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βtest.example.com:53/βPA/βTH/β?#testHash';309 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);310 strictEqual(parsingResult.destUrl, 'https:/β/βtest.example.com:53/βPA/βTH/β?#testHash');311 strictEqual(parsingResult.destResourceInfo.protocol, 'https:');312 strictEqual(parsingResult.destResourceInfo.host, 'test.example.com:53');313 strictEqual(parsingResult.destResourceInfo.hostname, 'test.example.com');314 strictEqual(parsingResult.destResourceInfo.port, '53');315 strictEqual(parsingResult.destResourceInfo.partAfterHost, '/βPA/βTH/β?#testHash');316 strictEqual(parsingResult.sessionId, 'sessionId');317});318test('non-proxy URL', function () {319 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βPA/βTH/β?someParam=value';320 var destUrlInfo = urlUtils.parseProxyUrl(proxyUrl);321 ok(!destUrlInfo);322});323test('successive question marks', function () {324 var proxyUrl = 'http:/β/β' + PROXY_HOST +325 '/βsessionId/βhttp:/β/βtest.example.com:53??dirs/β???files/β&#testHash';326 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);327 strictEqual(parsingResult.destUrl, 'http:/β/βtest.example.com:53??dirs/β???files/β&#testHash');328 strictEqual(parsingResult.destResourceInfo.protocol, 'http:');329 strictEqual(parsingResult.destResourceInfo.host, 'test.example.com:53');330 strictEqual(parsingResult.destResourceInfo.hostname, 'test.example.com');331 strictEqual(parsingResult.destResourceInfo.port, '53');332 strictEqual(parsingResult.destResourceInfo.partAfterHost, '??dirs/β???files/β&#testHash');333 strictEqual(parsingResult.sessionId, 'sessionId');334});335test('single question mark', function () {336 var url = 'http:/β/βac-gb.marketgid.com/βp/βj/β2865/β11?';337 var proxyUtrl = urlUtils.getProxyUrl(url, {338 proxyHostname: 'hostname',339 proxyPort: 1111,340 sessionId: 'sessionId',341 });342 strictEqual(url, urlUtils.formatUrl(urlUtils.parseProxyUrl(proxyUtrl).destResourceInfo));343});344test('special pages (GH-339)', function () {345 sharedUrlUtils.SPECIAL_PAGES.forEach(function (url) {346 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + url;347 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);348 strictEqual(parsingResult.destUrl, url);349 strictEqual(parsingResult.destResourceInfo.protocol, 'about:');350 strictEqual(parsingResult.destResourceInfo.host, '');351 strictEqual(parsingResult.destResourceInfo.hostname, '');352 strictEqual(parsingResult.destResourceInfo.port, '');353 strictEqual(parsingResult.destResourceInfo.partAfterHost, '');354 strictEqual(parsingResult.sessionId, 'sessionId');355 });356});357test('special page with hash (GH-1671)', function () {358 var specialPageUrlWithHash = 'about:error#hash';359 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + specialPageUrlWithHash;360 var parsingResult = urlUtils.parseProxyUrl(proxyUrl);361 strictEqual(parsingResult.destUrl, specialPageUrlWithHash);362 strictEqual(parsingResult.destResourceInfo.protocol, 'about:');363 strictEqual(parsingResult.destResourceInfo.host, '');364 strictEqual(parsingResult.destResourceInfo.hostname, '');365 strictEqual(parsingResult.destResourceInfo.port, '');366 strictEqual(parsingResult.destResourceInfo.partAfterHost, '');367 strictEqual(parsingResult.sessionId, 'sessionId');368});369test('hash with whitespace (GH-971)', function () {370 var url = 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttp:/β/βsome.domain.com/βpath/β#word word';371 var parsingResult = urlUtils.parseProxyUrl(url);372 strictEqual(parsingResult.sessionId, 'sessionId');373 strictEqual(parsingResult.destUrl, 'http:/β/βsome.domain.com/βpath/β#word word');374 strictEqual(parsingResult.destResourceInfo.partAfterHost, '/βpath/β#word word');375});376test('windowId', function () {377 var proxyUrl = 'http:/β/β' + PROXY_HOST + '/βsessionId*123456789/βhttp:/β/βexample.com';378 var parsedProxyUrl = urlUtils.parseProxyUrl(proxyUrl);379 strictEqual(parsedProxyUrl.destUrl, 'http:/β/βexample.com');380 strictEqual(parsedProxyUrl.sessionId, 'sessionId');381 strictEqual(parsedProxyUrl.resourceType, null);382 strictEqual(parsedProxyUrl.windowId, '123456789');383});384module('change proxy url');385test('destination URL part', function () {386 var proxyUrl = 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βtest.example.com:53/β#testHash';387 var changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorPortSetter, '34');388 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βtest.example.com:34/β#testHash');389 changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorHostSetter, 'newhost:99');390 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βnewhost:99/β#testHash');391 changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorHostnameSetter, 'newhostname');392 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βnewhostname:53/β#testHash');393 changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorProtocolSetter, 'https:');394 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttps:/β/βtest.example.com:53/β#testHash');395 changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorPathnameSetter, 'test1.html');396 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βtest.example.com:53/βtest1.html#testHash');397 changed = urlUtils.changeDestUrlPart(proxyUrl, nativeMethods.anchorSearchSetter, '?hl=ru&tab=wn');398 strictEqual(changed, 'http:/β/βlocalhost:1337/βsessionId/βhttp:/β/βtest.example.com:53/β?hl=ru&tab=wn#testHash');399});400module('regression');401test('location.port must return the empty string (T262593)', function () {402 eval(processScript([403 /β/β NOTE: From att.com, iframesrc === https:/β/βatt.com:null/β?IFRAME.404 'var port = (document.location.port == "") ? "" : (":" + document.location.port);',405 'var iframesrc = document.location.protocol + "/β/β" + document.location.hostname + port + "/β" + "?IFRAME";',406 ].join('\n')));407 /β/β eslint-disable-next-line no-undef408 strictEqual(iframesrc, 'https:/β/βexample.com/β?IFRAME');409});410test('a correct proxy URL should be obtained from a destination that has a URL in its path (GH-471)', function () {411 var destUrl = 'https:/β/βexample.com/βpath/βpath/βsdfjhsdkjf/βhttp:/β/βexample.com/βimage.png';412 var proxyUrl = getProxyUrl(destUrl);413 strictEqual(proxyUrl, 'http:/β/β' + PROXY_HOST + '/βsessionId/β' + destUrl);414});415module('getProxyUrl in a document with "base" tag');416test('add, update and remove the "base" tag (GH-371)', function () {417 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');418 var baseEl = document.createElement('base');419 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');420 baseEl.setAttribute('href', 'http:/β/βsubdomain.example.com');421 document.head.appendChild(baseEl);422 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttp:/β/βsubdomain.example.com/βimage.png');423 baseEl.setAttribute('href', 'http:/β/βexample2.com');424 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttp:/β/βexample2.com/βimage.png');425 baseEl.removeAttribute('href');426 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');427 baseEl.parentNode.removeChild(baseEl);428 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');429});430test('recreating a document with the "base" tag (GH-371)', function () {431 var src = getSameDomainPageUrl('../β../βdata/βsame-domain/βresolving-url-after-document-recreation.html');432 return createTestIframe({ src: src })433 .then(function (iframe) {434 var iframeDocument = iframe.contentDocument;435 var anchor = iframeDocument.getElementsByTagName('a')[0];436 var proxyUrl = 'http:/β/β' + location.hostname + ':' + location.port +437 '/βsessionId!i/βhttp:/β/βsubdomain.example.com/βindex.html';438 strictEqual(nativeMethods.anchorHrefGetter.call(anchor), proxyUrl);439 });440});441test('setting up an href attribute for a non-added to DOM "base" tag should not cause urlResolver to update. (GH-415)', function () {442 var baseEl = document.createElement('base');443 baseEl.setAttribute('href', 'http:/β/βsubdomain.example.com');444 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');445});446test('"base" tag with an empty href attribute (GH-422)', function () {447 var base = document.createElement('base');448 document.head.appendChild(base);449 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');450 base.setAttribute('href', '');451 strictEqual(getProxyUrl('image.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βimage.png');452});453test('"base" tag with an href attribute that is set to a relative url (GH-422)', function () {454 var base = document.createElement('base');455 document.head.appendChild(base);456 base.setAttribute('href', '/βtest1/βtest2/βtest3');457 strictEqual(getProxyUrl('../βimage.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βexample.com/βtest1/βimage.png');458 base.parentNode.removeChild(base);459});460test('resolving url after writing the "base" tag (GH-526)', function () {461 var src = getSameDomainPageUrl('../β../βdata/βsame-domain/βresolving-url-after-writing-base-tag.html');462 return createTestIframe({ src: src })463 .then(function (iframe) {464 var anchor = iframe.contentDocument.querySelector('a');465 var proxyUrl = urlUtils.getProxyUrl('http:/β/βexample.com/βrelative', {466 proxyHostname: location.hostname,467 proxyPort: location.port,468 sessionId: 'sessionId',469 resourceType: 'i',470 });471 strictEqual(nativeMethods.anchorHrefGetter.call(anchor), proxyUrl);472 });473});474test('"base" tag with an href attribute that is set to a protocol relative url (GH-568)', function () {475 var base = document.createElement('base');476 document.head.appendChild(base);477 base.setAttribute('href', '/β/βtest.com');478 strictEqual(getProxyUrl('/βimage.png'), 'http:/β/β' + PROXY_HOST + '/βsessionId/βhttps:/β/βtest.com/βimage.png');479 base.parentNode.removeChild(base);480});481test('resolving a url in a tag that is written along with a "base" tag (GH-644)', function () {482 var iframe = document.createElement('iframe');483 iframe.id = 'test902345';484 document.body.appendChild(iframe);485 iframe.contentDocument.write(486 '<base href="/βsubpath/β"/β>',487 '<!DOCTYPE html>',488 '<html>',489 '<head><script src="scripts/βscr.js"><' + '/βscript></βhead>',490 '...',491 '</βhtml>' /β/β eslint-disable-line comma-dangle492 );493 strictEqual(nativeMethods.scriptSrcGetter.call(iframe.contentDocument.querySelector('script')),494 'http:/β/β' + location.host + '/βsessionId!s/βhttps:/β/βexample.com/βsubpath/βscripts/βscr.js');495 document.body.removeChild(iframe);496});497test('only first base tag should be affected', function () {498 var storedProcessElement = nodeSandbox._processElement;499 var nativeIframe = nativeMethods.createElement.call(document, 'iframe');500 var proxiedIframe = null;501 nodeSandbox._processElement = function (el) {502 if (el !== nativeIframe)503 storedProcessElement.call(nodeSandbox, el);504 };505 function checkTestCase (name, fn) {506 fn(nativeIframe.contentDocument);507 fn(proxiedIframe.contentDocument);508 var nativeAnchor = nativeIframe.contentDocument.querySelector('a');509 var proxiedAnchor = proxiedIframe.contentDocument.querySelector('a');510 nativeAnchor.setAttribute('href', 'path');511 proxiedAnchor.setAttribute('href', 'path');512 strictEqual(urlUtils.parseProxyUrl(nativeMethods.anchorHrefGetter.call(proxiedAnchor)).destUrl, nativeAnchor.href, name);513 }514 return createTestIframe()515 .then(function (iframe) {516 proxiedIframe = iframe;517 return new Promise(function (resolve) {518 const nativeAddEventListener = nativeMethods.documentAddEventListener || nativeMethods.addEventListener;519 nativeAddEventListener.call(nativeIframe, 'load', resolve);520 nativeMethods.appendChild.call(document.body, nativeIframe);521 });522 })523 .then(function () {524 checkTestCase('append first base', function (doc) {525 var anchor = doc.createElement('a');526 var base = doc.createElement('base');527 anchor.textContent = 'link';528 base.setAttribute('href', 'https:/β/βexample.com/β123/β');529 doc.head.appendChild(base);530 doc.body.appendChild(anchor);531 });532 checkTestCase('create base', function (doc) {533 doc.createElement('base');534 });535 checkTestCase('create base and set attribute', function (doc) {536 doc.createElement('base').setAttribute('href', 'http:/β/βexample.com/βbase/β');537 });538 checkTestCase('append second base', function (doc) {539 var base = doc.createElement('base');540 base.setAttribute('href', 'https:/β/βexample.com/βsome/β');541 doc.head.appendChild(base);542 });543 checkTestCase('change first base', function (doc) {544 var base = doc.querySelectorAll('base')[0];545 base.setAttribute('href', 'https:/β/βexample.com/βsomething/β');546 });547 checkTestCase('change second base', function (doc) {548 var base = doc.querySelectorAll('base')[1];549 base.setAttribute('href', 'https:/β/βexample.com/βsomething/β');550 });551 checkTestCase('remove second base', function (doc) {552 var base = doc.querySelectorAll('base')[1];553 doc.head.removeChild(base);554 });555 checkTestCase('append second base', function (doc) {556 var base = doc.createElement('base');557 base.setAttribute('href', 'https:/β/βexample.com/βsome/β');558 doc.head.appendChild(base);559 });560 checkTestCase('remove first base', function (doc) {561 var base = doc.querySelectorAll('base')[0];562 doc.head.removeChild(base);563 });564 checkTestCase('append base to fragment', function (doc) {565 var fragment = doc.createDocumentFragment();566 var base = doc.createElement('base');567 base.setAttribute('href', 'https:/β/βexample.com/βfragment/β');568 fragment.appendChild(base);569 });570 checkTestCase('innerHtml', function (doc) {571 doc.head.innerHTML = '<base href="https:/β/βexample.com/βinner-html/β">';572 });573 checkTestCase('insert first base without href', function (doc) {574 var base = doc.createElement('base');575 document.head.insertBefore(base, document.head.firstChild);576 });577 })578 .then(function () {579 nativeMethods.removeChild.call(document.body, nativeIframe);580 nodeSandbox._processElement = storedProcessElement;581 });...
parsing_pb.js
Source: parsing_pb.js
1/β/β source: parsing.proto2/β**3 * @fileoverview4 * @enhanceable5 * @suppress {missingRequire} reports error on implicit type usages.6 * @suppress {messageConventions} JS Compiler reports an error if a variable or7 * field starts with 'MSG_' and isn't a translatable message.8 * @public9 */β10/β/β GENERATED CODE -- DO NOT EDIT!11/β* eslint-disable */β12/β/β @ts-nocheck13var jspb = require('google-protobuf');14var goog = jspb;15var global = Function('return this')();16goog.exportSymbol('proto.parsing.ParsingRequest', null, global);17goog.exportSymbol('proto.parsing.ParsingResponse', null, global);18goog.exportSymbol('proto.parsing.ParsingResult', null, global);19/β**20 * Generated by JsPbCodeGenerator.21 * @param {Array=} opt_data Optional initial data array, typically from a22 * server response, or constructed directly in Javascript. The array is used23 * in place and becomes part of the constructed object. It is not cloned.24 * If no data is provided, the constructed object will be empty, but still25 * valid.26 * @extends {jspb.Message}27 * @constructor28 */β29proto.parsing.ParsingRequest = function(opt_data) {30 jspb.Message.initialize(this, opt_data, 0, -1, null, null);31};32goog.inherits(proto.parsing.ParsingRequest, jspb.Message);33if (goog.DEBUG && !COMPILED) {34 /β**35 * @public36 * @override37 */β38 proto.parsing.ParsingRequest.displayName = 'proto.parsing.ParsingRequest';39}40/β**41 * Generated by JsPbCodeGenerator.42 * @param {Array=} opt_data Optional initial data array, typically from a43 * server response, or constructed directly in Javascript. The array is used44 * in place and becomes part of the constructed object. It is not cloned.45 * If no data is provided, the constructed object will be empty, but still46 * valid.47 * @extends {jspb.Message}48 * @constructor49 */β50proto.parsing.ParsingResult = function(opt_data) {51 jspb.Message.initialize(this, opt_data, 0, -1, null, null);52};53goog.inherits(proto.parsing.ParsingResult, jspb.Message);54if (goog.DEBUG && !COMPILED) {55 /β**56 * @public57 * @override58 */β59 proto.parsing.ParsingResult.displayName = 'proto.parsing.ParsingResult';60}61/β**62 * Generated by JsPbCodeGenerator.63 * @param {Array=} opt_data Optional initial data array, typically from a64 * server response, or constructed directly in Javascript. The array is used65 * in place and becomes part of the constructed object. It is not cloned.66 * If no data is provided, the constructed object will be empty, but still67 * valid.68 * @extends {jspb.Message}69 * @constructor70 */β71proto.parsing.ParsingResponse = function(opt_data) {72 jspb.Message.initialize(this, opt_data, 0, -1, proto.parsing.ParsingResponse.repeatedFields_, null);73};74goog.inherits(proto.parsing.ParsingResponse, jspb.Message);75if (goog.DEBUG && !COMPILED) {76 /β**77 * @public78 * @override79 */β80 proto.parsing.ParsingResponse.displayName = 'proto.parsing.ParsingResponse';81}82if (jspb.Message.GENERATE_TO_OBJECT) {83/β**84 * Creates an object representation of this proto.85 * Field names that are reserved in JavaScript and will be renamed to pb_name.86 * Optional fields that are not set will be set to undefined.87 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.88 * For the list of reserved names please see:89 * net/βproto2/βcompiler/βjs/βinternal/βgenerator.cc#kKeyword.90 * @param {boolean=} opt_includeInstance Deprecated. whether to include the91 * JSPB instance for transitional soy proto support:92 * http:/β/βgoto/βsoy-param-migration93 * @return {!Object}94 */β95proto.parsing.ParsingRequest.prototype.toObject = function(opt_includeInstance) {96 return proto.parsing.ParsingRequest.toObject(opt_includeInstance, this);97};98/β**99 * Static version of the {@see toObject} method.100 * @param {boolean|undefined} includeInstance Deprecated. Whether to include101 * the JSPB instance for transitional soy proto support:102 * http:/β/βgoto/βsoy-param-migration103 * @param {!proto.parsing.ParsingRequest} msg The msg instance to transform.104 * @return {!Object}105 * @suppress {unusedLocalVariables} f is only used for nested messages106 */β107proto.parsing.ParsingRequest.toObject = function(includeInstance, msg) {108 var f, obj = {109 input: jspb.Message.getFieldWithDefault(msg, 1, "")110 };111 if (includeInstance) {112 obj.$jspbMessageInstance = msg;113 }114 return obj;115};116}117/β**118 * Deserializes binary data (in protobuf wire format).119 * @param {jspb.ByteSource} bytes The bytes to deserialize.120 * @return {!proto.parsing.ParsingRequest}121 */β122proto.parsing.ParsingRequest.deserializeBinary = function(bytes) {123 var reader = new jspb.BinaryReader(bytes);124 var msg = new proto.parsing.ParsingRequest;125 return proto.parsing.ParsingRequest.deserializeBinaryFromReader(msg, reader);126};127/β**128 * Deserializes binary data (in protobuf wire format) from the129 * given reader into the given message object.130 * @param {!proto.parsing.ParsingRequest} msg The message object to deserialize into.131 * @param {!jspb.BinaryReader} reader The BinaryReader to use.132 * @return {!proto.parsing.ParsingRequest}133 */β134proto.parsing.ParsingRequest.deserializeBinaryFromReader = function(msg, reader) {135 while (reader.nextField()) {136 if (reader.isEndGroup()) {137 break;138 }139 var field = reader.getFieldNumber();140 switch (field) {141 case 1:142 var value = /β** @type {string} */β (reader.readString());143 msg.setInput(value);144 break;145 default:146 reader.skipField();147 break;148 }149 }150 return msg;151};152/β**153 * Serializes the message to binary data (in protobuf wire format).154 * @return {!Uint8Array}155 */β156proto.parsing.ParsingRequest.prototype.serializeBinary = function() {157 var writer = new jspb.BinaryWriter();158 proto.parsing.ParsingRequest.serializeBinaryToWriter(this, writer);159 return writer.getResultBuffer();160};161/β**162 * Serializes the given message to binary data (in protobuf wire163 * format), writing to the given BinaryWriter.164 * @param {!proto.parsing.ParsingRequest} message165 * @param {!jspb.BinaryWriter} writer166 * @suppress {unusedLocalVariables} f is only used for nested messages167 */β168proto.parsing.ParsingRequest.serializeBinaryToWriter = function(message, writer) {169 var f = undefined;170 f = message.getInput();171 if (f.length > 0) {172 writer.writeString(173 1,174 f175 );176 }177};178/β**179 * optional string input = 1;180 * @return {string}181 */β182proto.parsing.ParsingRequest.prototype.getInput = function() {183 return /β** @type {string} */β (jspb.Message.getFieldWithDefault(this, 1, ""));184};185/β**186 * @param {string} value187 * @return {!proto.parsing.ParsingRequest} returns this188 */β189proto.parsing.ParsingRequest.prototype.setInput = function(value) {190 return jspb.Message.setProto3StringField(this, 1, value);191};192if (jspb.Message.GENERATE_TO_OBJECT) {193/β**194 * Creates an object representation of this proto.195 * Field names that are reserved in JavaScript and will be renamed to pb_name.196 * Optional fields that are not set will be set to undefined.197 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.198 * For the list of reserved names please see:199 * net/βproto2/βcompiler/βjs/βinternal/βgenerator.cc#kKeyword.200 * @param {boolean=} opt_includeInstance Deprecated. whether to include the201 * JSPB instance for transitional soy proto support:202 * http:/β/βgoto/βsoy-param-migration203 * @return {!Object}204 */β205proto.parsing.ParsingResult.prototype.toObject = function(opt_includeInstance) {206 return proto.parsing.ParsingResult.toObject(opt_includeInstance, this);207};208/β**209 * Static version of the {@see toObject} method.210 * @param {boolean|undefined} includeInstance Deprecated. Whether to include211 * the JSPB instance for transitional soy proto support:212 * http:/β/βgoto/βsoy-param-migration213 * @param {!proto.parsing.ParsingResult} msg The msg instance to transform.214 * @return {!Object}215 * @suppress {unusedLocalVariables} f is only used for nested messages216 */β217proto.parsing.ParsingResult.toObject = function(includeInstance, msg) {218 var f, obj = {219 word: jspb.Message.getFieldWithDefault(msg, 1, ""),220 position: jspb.Message.getFieldWithDefault(msg, 2, 0),221 index: jspb.Message.getFieldWithDefault(msg, 3, 0),222 identified: jspb.Message.getBooleanFieldWithDefault(msg, 4, false),223 entity: jspb.Message.getFieldWithDefault(msg, 5, ""),224 id: jspb.Message.getFieldWithDefault(msg, 6, 0)225 };226 if (includeInstance) {227 obj.$jspbMessageInstance = msg;228 }229 return obj;230};231}232/β**233 * Deserializes binary data (in protobuf wire format).234 * @param {jspb.ByteSource} bytes The bytes to deserialize.235 * @return {!proto.parsing.ParsingResult}236 */β237proto.parsing.ParsingResult.deserializeBinary = function(bytes) {238 var reader = new jspb.BinaryReader(bytes);239 var msg = new proto.parsing.ParsingResult;240 return proto.parsing.ParsingResult.deserializeBinaryFromReader(msg, reader);241};242/β**243 * Deserializes binary data (in protobuf wire format) from the244 * given reader into the given message object.245 * @param {!proto.parsing.ParsingResult} msg The message object to deserialize into.246 * @param {!jspb.BinaryReader} reader The BinaryReader to use.247 * @return {!proto.parsing.ParsingResult}248 */β249proto.parsing.ParsingResult.deserializeBinaryFromReader = function(msg, reader) {250 while (reader.nextField()) {251 if (reader.isEndGroup()) {252 break;253 }254 var field = reader.getFieldNumber();255 switch (field) {256 case 1:257 var value = /β** @type {string} */β (reader.readString());258 msg.setWord(value);259 break;260 case 2:261 var value = /β** @type {number} */β (reader.readInt32());262 msg.setPosition(value);263 break;264 case 3:265 var value = /β** @type {number} */β (reader.readInt32());266 msg.setIndex(value);267 break;268 case 4:269 var value = /β** @type {boolean} */β (reader.readBool());270 msg.setIdentified(value);271 break;272 case 5:273 var value = /β** @type {string} */β (reader.readString());274 msg.setEntity(value);275 break;276 case 6:277 var value = /β** @type {number} */β (reader.readInt64());278 msg.setId(value);279 break;280 default:281 reader.skipField();282 break;283 }284 }285 return msg;286};287/β**288 * Serializes the message to binary data (in protobuf wire format).289 * @return {!Uint8Array}290 */β291proto.parsing.ParsingResult.prototype.serializeBinary = function() {292 var writer = new jspb.BinaryWriter();293 proto.parsing.ParsingResult.serializeBinaryToWriter(this, writer);294 return writer.getResultBuffer();295};296/β**297 * Serializes the given message to binary data (in protobuf wire298 * format), writing to the given BinaryWriter.299 * @param {!proto.parsing.ParsingResult} message300 * @param {!jspb.BinaryWriter} writer301 * @suppress {unusedLocalVariables} f is only used for nested messages302 */β303proto.parsing.ParsingResult.serializeBinaryToWriter = function(message, writer) {304 var f = undefined;305 f = message.getWord();306 if (f.length > 0) {307 writer.writeString(308 1,309 f310 );311 }312 f = message.getPosition();313 if (f !== 0) {314 writer.writeInt32(315 2,316 f317 );318 }319 f = message.getIndex();320 if (f !== 0) {321 writer.writeInt32(322 3,323 f324 );325 }326 f = message.getIdentified();327 if (f) {328 writer.writeBool(329 4,330 f331 );332 }333 f = message.getEntity();334 if (f.length > 0) {335 writer.writeString(336 5,337 f338 );339 }340 f = message.getId();341 if (f !== 0) {342 writer.writeInt64(343 6,344 f345 );346 }347};348/β**349 * optional string word = 1;350 * @return {string}351 */β352proto.parsing.ParsingResult.prototype.getWord = function() {353 return /β** @type {string} */β (jspb.Message.getFieldWithDefault(this, 1, ""));354};355/β**356 * @param {string} value357 * @return {!proto.parsing.ParsingResult} returns this358 */β359proto.parsing.ParsingResult.prototype.setWord = function(value) {360 return jspb.Message.setProto3StringField(this, 1, value);361};362/β**363 * optional int32 position = 2;364 * @return {number}365 */β366proto.parsing.ParsingResult.prototype.getPosition = function() {367 return /β** @type {number} */β (jspb.Message.getFieldWithDefault(this, 2, 0));368};369/β**370 * @param {number} value371 * @return {!proto.parsing.ParsingResult} returns this372 */β373proto.parsing.ParsingResult.prototype.setPosition = function(value) {374 return jspb.Message.setProto3IntField(this, 2, value);375};376/β**377 * optional int32 index = 3;378 * @return {number}379 */β380proto.parsing.ParsingResult.prototype.getIndex = function() {381 return /β** @type {number} */β (jspb.Message.getFieldWithDefault(this, 3, 0));382};383/β**384 * @param {number} value385 * @return {!proto.parsing.ParsingResult} returns this386 */β387proto.parsing.ParsingResult.prototype.setIndex = function(value) {388 return jspb.Message.setProto3IntField(this, 3, value);389};390/β**391 * optional bool identified = 4;392 * @return {boolean}393 */β394proto.parsing.ParsingResult.prototype.getIdentified = function() {395 return /β** @type {boolean} */β (jspb.Message.getBooleanFieldWithDefault(this, 4, false));396};397/β**398 * @param {boolean} value399 * @return {!proto.parsing.ParsingResult} returns this400 */β401proto.parsing.ParsingResult.prototype.setIdentified = function(value) {402 return jspb.Message.setProto3BooleanField(this, 4, value);403};404/β**405 * optional string entity = 5;406 * @return {string}407 */β408proto.parsing.ParsingResult.prototype.getEntity = function() {409 return /β** @type {string} */β (jspb.Message.getFieldWithDefault(this, 5, ""));410};411/β**412 * @param {string} value413 * @return {!proto.parsing.ParsingResult} returns this414 */β415proto.parsing.ParsingResult.prototype.setEntity = function(value) {416 return jspb.Message.setProto3StringField(this, 5, value);417};418/β**419 * optional int64 id = 6;420 * @return {number}421 */β422proto.parsing.ParsingResult.prototype.getId = function() {423 return /β** @type {number} */β (jspb.Message.getFieldWithDefault(this, 6, 0));424};425/β**426 * @param {number} value427 * @return {!proto.parsing.ParsingResult} returns this428 */β429proto.parsing.ParsingResult.prototype.setId = function(value) {430 return jspb.Message.setProto3IntField(this, 6, value);431};432/β**433 * List of repeated fields within this message type.434 * @private {!Array<number>}435 * @const436 */β437proto.parsing.ParsingResponse.repeatedFields_ = [1];438if (jspb.Message.GENERATE_TO_OBJECT) {439/β**440 * Creates an object representation of this proto.441 * Field names that are reserved in JavaScript and will be renamed to pb_name.442 * Optional fields that are not set will be set to undefined.443 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.444 * For the list of reserved names please see:445 * net/βproto2/βcompiler/βjs/βinternal/βgenerator.cc#kKeyword.446 * @param {boolean=} opt_includeInstance Deprecated. whether to include the447 * JSPB instance for transitional soy proto support:448 * http:/β/βgoto/βsoy-param-migration449 * @return {!Object}450 */β451proto.parsing.ParsingResponse.prototype.toObject = function(opt_includeInstance) {452 return proto.parsing.ParsingResponse.toObject(opt_includeInstance, this);453};454/β**455 * Static version of the {@see toObject} method.456 * @param {boolean|undefined} includeInstance Deprecated. Whether to include457 * the JSPB instance for transitional soy proto support:458 * http:/β/βgoto/βsoy-param-migration459 * @param {!proto.parsing.ParsingResponse} msg The msg instance to transform.460 * @return {!Object}461 * @suppress {unusedLocalVariables} f is only used for nested messages462 */β463proto.parsing.ParsingResponse.toObject = function(includeInstance, msg) {464 var f, obj = {465 resultsList: jspb.Message.toObjectList(msg.getResultsList(),466 proto.parsing.ParsingResult.toObject, includeInstance)467 };468 if (includeInstance) {469 obj.$jspbMessageInstance = msg;470 }471 return obj;472};473}474/β**475 * Deserializes binary data (in protobuf wire format).476 * @param {jspb.ByteSource} bytes The bytes to deserialize.477 * @return {!proto.parsing.ParsingResponse}478 */β479proto.parsing.ParsingResponse.deserializeBinary = function(bytes) {480 var reader = new jspb.BinaryReader(bytes);481 var msg = new proto.parsing.ParsingResponse;482 return proto.parsing.ParsingResponse.deserializeBinaryFromReader(msg, reader);483};484/β**485 * Deserializes binary data (in protobuf wire format) from the486 * given reader into the given message object.487 * @param {!proto.parsing.ParsingResponse} msg The message object to deserialize into.488 * @param {!jspb.BinaryReader} reader The BinaryReader to use.489 * @return {!proto.parsing.ParsingResponse}490 */β491proto.parsing.ParsingResponse.deserializeBinaryFromReader = function(msg, reader) {492 while (reader.nextField()) {493 if (reader.isEndGroup()) {494 break;495 }496 var field = reader.getFieldNumber();497 switch (field) {498 case 1:499 var value = new proto.parsing.ParsingResult;500 reader.readMessage(value,proto.parsing.ParsingResult.deserializeBinaryFromReader);501 msg.addResults(value);502 break;503 default:504 reader.skipField();505 break;506 }507 }508 return msg;509};510/β**511 * Serializes the message to binary data (in protobuf wire format).512 * @return {!Uint8Array}513 */β514proto.parsing.ParsingResponse.prototype.serializeBinary = function() {515 var writer = new jspb.BinaryWriter();516 proto.parsing.ParsingResponse.serializeBinaryToWriter(this, writer);517 return writer.getResultBuffer();518};519/β**520 * Serializes the given message to binary data (in protobuf wire521 * format), writing to the given BinaryWriter.522 * @param {!proto.parsing.ParsingResponse} message523 * @param {!jspb.BinaryWriter} writer524 * @suppress {unusedLocalVariables} f is only used for nested messages525 */β526proto.parsing.ParsingResponse.serializeBinaryToWriter = function(message, writer) {527 var f = undefined;528 f = message.getResultsList();529 if (f.length > 0) {530 writer.writeRepeatedMessage(531 1,532 f,533 proto.parsing.ParsingResult.serializeBinaryToWriter534 );535 }536};537/β**538 * repeated ParsingResult results = 1;539 * @return {!Array<!proto.parsing.ParsingResult>}540 */β541proto.parsing.ParsingResponse.prototype.getResultsList = function() {542 return /β** @type{!Array<!proto.parsing.ParsingResult>} */β (543 jspb.Message.getRepeatedWrapperField(this, proto.parsing.ParsingResult, 1));544};545/β**546 * @param {!Array<!proto.parsing.ParsingResult>} value547 * @return {!proto.parsing.ParsingResponse} returns this548*/β549proto.parsing.ParsingResponse.prototype.setResultsList = function(value) {550 return jspb.Message.setRepeatedWrapperField(this, 1, value);551};552/β**553 * @param {!proto.parsing.ParsingResult=} opt_value554 * @param {number=} opt_index555 * @return {!proto.parsing.ParsingResult}556 */β557proto.parsing.ParsingResponse.prototype.addResults = function(opt_value, opt_index) {558 return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.parsing.ParsingResult, opt_index);559};560/β**561 * Clears the list making it empty but non-null.562 * @return {!proto.parsing.ParsingResponse} returns this563 */β564proto.parsing.ParsingResponse.prototype.clearResultsList = function() {565 return this.setResultsList([]);566};...
DicomFileInspector.js
Source: DicomFileInspector.js
1import dcmjs from 'dcmjs';2import DicomValueRepresentations from '../β../βconstants/βDicomValueRepresentations';3const { DicomMetaDictionary, DicomDict, DicomMessage } = dcmjs.data;4const { cleanTags } = dcmjs.anonymizer;5export default class DicomFileInspector {6 constructor(fileObject, deIdentificationConfiguration) {7 this.fileObject = fileObject;8 this.deIdentificationConfiguration = deIdentificationConfiguration;9 this.uids = [];10 }11 async getBufferForTest() {12 return this.readDicomFile(this.fileObject);13 }14 async analyzeFile() {15 try {16 const reader = await this.__pFileReader(this.fileObject.fileObject);17 const arrayBuffer = reader.result;18 const parsingResult = this.readDicomFile(arrayBuffer);19 return parsingResult;20 } catch (e) {21 console.log("DicomFileInspector.analyzeFile : " + e.toString());22 }23 }24 getUids() {25 return this.uids;26 }27 async __pFileReader(file) {28 return new Promise((resolve, reject) => {29 var fileReader = new FileReader();30 fileReader.readAsArrayBuffer(file);31 fileReader.onload = () => {32 resolve(fileReader);33 }34 fileReader.onerror = (error) => {35 console.log("DicomFileInspector.__pFileReader: " + error);36 reject(error);37 }38 });39 }40 readDicomFile(arrayBuffer) {41 let uidArray = [];42 let identities = [];43 let dataSet;44 try {45 dataSet = DicomMessage.readFile(arrayBuffer);46 } catch (e) {47 console.log("DicomFileInspector.readDicomFile.readFile: " + e.toString());48 }49 try {50 let parsingResultMeta = this.parseDicomData(dataSet.meta);51 if (parsingResultMeta.uidArray) {52 uidArray = uidArray.concat(parsingResultMeta.uidArray);53 }54 } catch (e) {55 console.log("DicomFileInspector.readDicomFile.this.dataSet.meta: " + e.toString());56 } try {57 let parsingResult = this.parseDicomData(dataSet.dict);58 if (parsingResult.uidArray) {59 uidArray = uidArray.concat(parsingResult.uidArray);60 }61 if (parsingResult.identities) {62 identities = identities.concat(parsingResult.identities);63 }64 } catch (e) {65 console.log("DicomFileInspector.readDicomFile this.dataSet.dict: " + e.toString());66 }67 return {68 uidArray,69 identities70 };71 }72 parseDicomData(dataSetDict) {73 let uidArray = [];74 const identityRemoved = this.isPatientIdentityRemoved(dataSetDict);75 let identities = [];76 for (let propertyName in dataSetDict) {77 const element = dataSetDict[propertyName];78 if (element.vr) {79 const vr = element.vr;80 switch (vr) {81 case DicomValueRepresentations.SQ:82 for (let seqElement of element.Value) {83 let parsingResult = this.parseDicomData(seqElement);84 if (parsingResult.uidArray) {85 uidArray = uidArray.concat(parsingResult.uidArray);86 }87 if (parsingResult.identities) {88 identities = identities.concat(parsingResult.identities);89 }90 }91 break;92 case DicomValueRepresentations.UI:93 /β/β filter just tags that are supposed to be replaced by configuration94 if (this.deIdentificationConfiguration.isUidReplacementCandidate(propertyName)) {95 if (Array.isArray(element.Value)) {96 uidArray = uidArray.concat(element.Value);97 } else {98 uidArray.push(element.Value);99 }100 }101 break;102 case DicomValueRepresentations.PN:103 const identityData = {};104 let value = element.Value;105 /β/β unwrap array value if there is just one item106 if (Array.isArray(value)) {107 identities = identities.concat(value);108 } else {109 identities.push(value);110 }111 break;112 default:113 /β/β console.log(`tag: ${propertyName} - value: ${element.Value}`)114 break;115 }116 }117 }118 return {119 uidArray,120 identities: identities.filter(element => { return element !== "" })121 };122 }123 isPatientIdentityRemoved(dataSetDict) {124 const element = dataSetDict['00120062'];125 if (element != undefined) {126 if (element.value === 'YES') {127 return true;128 }129 }130 return false;131 }...
Using AI Code Generation
1var storybookRoot = require('storybook-root');2var path = require('path');3var storybookPath = path.join(__dirname, 'path/βto/βstorybook');4var storybook = storybookRoot(storybookPath);5storybook.parsingResult(function(err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});12var storybook = require('storybook');13var path = require('path');14var storybookPath = path.join(__dirname, 'path/βto/βstorybook');15var storybook = storybookRoot(storybookPath);16storybook.parsingResult(function(err, result) {17 if (err) {18 console.log(err);19 } else {20 console.log(result);21 }22});23var storybook = require('storybook');24var path = require('path');25var storybookPath = path.join(__dirname, 'path/βto/βstorybook');26var storybook = storybookRoot(storybookPath);27storybook.parsingResult(function(err, result) {28 if (err) {29 console.log(err);30 } else {31 console.log(result);32 }33});34var storybook = require('storybook');35var path = require('path');36var storybookPath = path.join(__dirname, 'path/βto/βstorybook');37var storybook = storybookRoot(storybookPath);38storybook.parsingResult(function(err, result) {39 if (err) {40 console.log(err);41 } else {42 console.log(result);43 }44});45var storybook = require('storybook');46var path = require('path');47var storybookPath = path.join(__dirname, 'path/βto/βstorybook');48var storybook = storybookRoot(storybookPath);49storybook.parsingResult(function(err, result) {50 if (err) {51 console.log(err);52 } else {53 console.log(result);54 }55});56var storybook = require('storybook');57var path = require('path');
Using AI Code Generation
1import { parsingResult } from 'storybook-root';2import { storiesOf } from '@storybook/βreact';3storiesOf('Test', module).add('Test', () => {4 parsingResult('test');5 return <div>test</βdiv>;6});7import { configure } from '@storybook/βreact';8import 'storybook-root/βdist/βindex.css';9import 'storybook-root/βdist/βindex.js';10const req = require.context('../βsrc', true, /β\.stories\.js$/β);11function loadStories() {12 req.keys().forEach(filename => req(filename));13}14configure(loadStories, module);15const path = require('path');16const rootPath = path.resolve(__dirname, '../β');17module.exports = ({ config }) => {18 config.resolve.alias = {19 'storybook-root': path.resolve(rootPath, 'src/β'),20 };21 return config;22};23import { parsingResult } from 'storybook-root';24parsingResult('test');25body {26 background: #f0f0f0;27}28import { storiesOf } from '@storybook/βreact';29import { parsingResult } from 'storybook-root';30storiesOf('Test', module).add('Test', () => {31 parsingResult('test');32 return <div>test</βdiv>;33});34import { parsingResult } from 'storybook-root';35parsingResult('test');36import { storiesOf } from '@storybook/βreact';37import { parsingResult } from 'storybook-root';38storiesOf('Test', module).add('Test', () => {39 parsingResult('test');40 return <div>test</βdiv>;41});42import { parsingResult } from 'storybook-root';43parsingResult('test');44import { storiesOf } from '@storybook/βreact';45import { parsingResult } from 'storybook-root';46storiesOf('Test', module).add('Test', () => {47 parsingResult('test');48 return <div>test</βdiv>;49});50import { parsingResult } from 'storybook-root';51parsingResult('test');52import { storiesOf } from '@storybook/βreact';53import {
Using AI Code Generation
1import { parsingResult } from 'storybook-root';2const result = parsingResult('some string');3import { parsingResult } from 'storybook-root';4const result = parsingResult('some string');5import { parsingResult } from 'storybook-root';6const result = parsingResult('some string');7import { parsingResult } from 'storybook-root';8const result = parsingResult('some string');9import { parsingResult } from 'storybook-root';10const result = parsingResult('some string');11import { parsingResult } from 'storybook-root';12const result = parsingResult('some string');13import { parsingResult } from 'storybook-root';14const result = parsingResult('some string');15import { parsingResult } from 'storybook-root';16const result = parsingResult('some string');17import { parsingResult } from 'storybook-root';18const result = parsingResult('some string');19import { parsingResult } from 'storybook-root';20const result = parsingResult('some string');21import { parsingResult } from 'storybook-root
Using AI Code Generation
1import { parsingResult } from 'storybook-root'2const result = parsingResult()3console.log(result)4import { configure } from '@storybook/βreact';5import { setOptions } from '@storybook/βaddon-options';6import { addParameters } from '@storybook/βreact';7import { withInfo } from '@storybook/βaddon-info';8import { withOptions } from '@storybook/βaddon-options';9import { setDefaults } from 'storybook-addon-jsx';10import { setDefaults as setOptionsDefaults } from '@storybook/βaddon-options';11import { setDefaults as setInfoDefaults } from '@storybook/βaddon-info';12import { parsingResult } from 'storybook-root';13setOptionsDefaults({14 name: parsingResult().name,15 url: parsingResult().url,16});17setInfoDefaults({18 styles: stylesheet => {19 stylesheet.infoBody = {20 };21 stylesheet.infoStory = {22 };23 return stylesheet;24 },25});26setDefaults({27});28addParameters({29 options: {30 name: parsingResult().name,31 url: parsingResult().url,32 },33});34addParameters({35 info: {36 styles: stylesheet => {37 stylesheet.infoBody = {38 };39 stylesheet.infoStory = {40 };
Using AI Code Generation
1const { parsingResult } = require('storybook-root')2const { stories } = parsingResult3console.log(stories)4import Button from './βButton';5export default { title: 'Button' };6export const withText = () => <Button>Hello Button</βButton>;7export const withEmoji = () => <Button><span role="img" aria-label="so cool">π π π π―</βspan></βButton>;8import Button from './βButton';9export default { title: 'Button' };10export const withText = () => <Button>Hello Button</βButton>;11export const withEmoji = () => <Button><span role="img" aria-label="so cool">π π π π―</βspan></βButton>;12import Button from './βButton';13export default { title: 'Button' };14export const withText = () => <Button>Hello Button</βButton>;15export const withEmoji = () => <Button><span role="img" aria-label="so cool">π π π π―</βspan></βButton>;
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
In todayβs world, an organizationβs most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today donβt have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesnβt make life easier for users, theyβll leave for a better solution.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the applicationβs state when running tests.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!