How to use parsingResult method in storybook-root

Best JavaScript code snippet using storybook-root

url-test.js

Source:url-test.js Github

copy

Full Screen

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&param2=&param3#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 });...

Full Screen

Full Screen

parsing_pb.js

Source:parsing_pb.js Github

copy

Full Screen

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};...

Full Screen

Full Screen

DicomFileInspector.js

Source:DicomFileInspector.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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');

Full Screen

Using AI Code Generation

copy

Full Screen

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 {

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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 };

Full Screen

Using AI Code Generation

copy

Full Screen

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>;

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful