How to use formTargetFrame method in wpt

Best JavaScript code snippet using wpt

aw-file-upload.directive.js

Source:aw-file-upload.directive.js Github

copy

Full Screen

1"use strict";2// Copyright 2018 Siemens Product Lifecycle Management Software Inc.3/* global define document */4/**5 * Directive to display a file upload6 *7 * @module js/aw-file-upload.directive8 */9define(['app', 'lodash', 'jquery', 'js/eventBus', 'js/awFileNameUtils', 'js/viewModelService', 'js/appCtxService', 'js/on-file-change.directive', 'js/aw-button.directive', 'js/aw-i18n.directive', 'js/localeService'], function (app, _, $, eventBus, awFileNameUtils) {10 'use strict';11 /**12 * Directive to display a file upload.13 *14 * fileChangeAction: the action that will be performed when file changed. typeFilter: the file type filter in15 * file selection dialog. isRequired: boolean flag indicate whether the file input field is required or not.16 * formData: the form data to be post to server URL on form submit.17 *18 * @example <aw-file-upload file-change-action="validateFile" type-filter="image/..." is-required="true">...</aw-file-upload>19 *20 * @member aw-file-upload21 * @memberof NgElementDirectives22 */23 app.directive('awFileUpload', ['viewModelService', 'appCtxService', function (viewModelSvc, appCtxService) {24 return {25 restrict: 'E',26 transclude: true,27 scope: {28 fileChangeAction: '@',29 typeFilter: '@',30 isRequired: '=?',31 formData: '='32 },33 templateUrl: app.getBaseUrlPath() + '/html/aw-file-upload.directive.html',34 replace: true,35 controller: ['$scope', 'localeService', function ($scope, localeSvc) {36 var self = this; // eslint-disable-line no-invalid-this37 $scope.fileUploadBtnLabel = 'ChooseFile';38 $scope.noFileChosenText = 'NoFileChosen';39 localeSvc.getTextPromise('UIMessages').then(function (textBundle) {40 if (textBundle[$scope.fileUploadBtnLabel]) {41 $scope.fileUploadBtnLabel = textBundle[$scope.fileUploadBtnLabel];42 }43 if (textBundle[$scope.noFileChosenText]) {44 $scope.noFileChosenText = textBundle[$scope.noFileChosenText];45 }46 });47 self._frameTemplate = //48 '<iframe name=\'{formTarget}\' tabindex=\'-1\' style=\'position:absolute;width:0;height:0;border:0\'>#document<html><head></head><body></body></html></iframe>';49 var declViewModel = viewModelSvc.getViewModel($scope, true);50 $scope.updateFile = function (event) {51 var fileCtx = appCtxService.getCtx('HostedFileNameContext');52 if (fileCtx) {53 appCtxService.unRegisterCtx('HostedFileNameContext');54 }55 declViewModel.files = event.target.files;56 declViewModel.fileName = awFileNameUtils.getFileFromPath(event.target.value);57 declViewModel.fileNameNoExt = awFileNameUtils.getFileNameWithoutExtension(declViewModel.fileName);58 if ($scope.typeFilter) {59 var validFileExtensions = $scope.typeFilter.split(',');60 var fileExt = awFileNameUtils.getFileExtension(declViewModel.fileName);61 if (fileExt !== '') {62 fileExt = _.replace(fileExt, '.', '');63 }64 declViewModel.validFile = false;65 for (var ndx = 0; ndx < validFileExtensions.length; ndx++) {66 var validFileExt = validFileExtensions[ndx].trim();67 if (validFileExt !== null) {68 validFileExt = _.replace(validFileExt, '.', '');69 if (fileExt !== '' && fileExt.toLowerCase() === validFileExt.toLowerCase()) {70 declViewModel.validFile = true;71 }72 }73 declViewModel.fileExt = fileExt;74 }75 } else {76 declViewModel.validFile = true;77 }78 if (!declViewModel.autoClicking) {79 $scope.$apply();80 }81 if (declViewModel.fileName !== '' && !declViewModel.validFile) {82 eventBus.publish('invalidFileSelected', {});83 } // call action when file selection changed84 if ($scope.fileChangeAction) {85 viewModelSvc.executeCommand(declViewModel, $scope.fileChangeAction, $scope);86 }87 }; // Attach a hidden iframe as the form target to avoid page redirection when submit form88 $scope.formTarget = 'FormPanel_' + app.getBaseUrlPath();89 var initFormTarget = function initFormTarget() {90 var formTargetFrameHtml = self._frameTemplate.replace('{formTarget}', $scope.formTarget);91 var dummy = document.createElement('div');92 dummy.innerHTML = formTargetFrameHtml;93 var formTargetFrame = dummy.firstChild;94 document.body.appendChild(formTargetFrame);95 return formTargetFrame;96 };97 var formTargetFrame = initFormTarget();98 var fileCtx = appCtxService.getCtx('HostedFileNameContext');99 var addObject = appCtxService.getCtx('addObject');100 if (fileCtx && addObject && addObject.showDataSetUploadPanel) {101 declViewModel.fileName = awFileNameUtils.getFileFromPath(fileCtx.filename);102 declViewModel.fileNameNoExt = awFileNameUtils.getFileNameWithoutExtension(declViewModel.fileName);103 var FileExt = awFileNameUtils.getFileExtension(declViewModel.fileName);104 if (FileExt !== '') {105 FileExt = _.replace(FileExt, '.', '');106 }107 declViewModel.fileExt = FileExt;108 if ($scope.fileChangeAction) {109 viewModelSvc.executeCommand(declViewModel, $scope.fileChangeAction, $scope);110 }111 viewModelSvc.executeCommand(declViewModel, 'initiateCreation', $scope);112 } else {113 declViewModel.fileName = null;114 declViewModel.fileNameNoExt = null;115 declViewModel.fileExt = null;116 }117 /**118 * Listen for DnD highlight/unhighlight event from dragAndDropService119 */120 var chooseOrDropFilesDragDropLsnr = eventBus.subscribe('dragDropEvent.highlight', function (eventData) {121 // logger.info('=========DnD event captured in Choose File widget================');122 if (!_.isUndefined(eventData) && !_.isUndefined(eventData.targetElement) && eventData.targetElement.classList) {123 var event = eventData.event;124 var isHighlightFlag = eventData.isHighlightFlag;125 var target = eventData.targetElement;126 var isGlobalArea = eventData.isGlobalArea;127 if (target.classList.contains('aw-widgets-chooseordropfile')) {128 var chooseFileWidget = target.querySelector('.aw-file-upload-fileName');129 if (isHighlightFlag) {130 // on entering a valid cell item within a cellList, apply stlye as in LCS-148724131 chooseFileWidget.classList.add('aw-widgets-dropframe');132 chooseFileWidget.classList.add('aw-theme-dropframe');133 } else {134 chooseFileWidget.classList.remove('aw-theme-dropframe');135 chooseFileWidget.classList.remove('aw-widgets-dropframe');136 }137 } else if (target.classList.contains('aw-file-upload-fileName')) {138 if (isHighlightFlag) {139 // on entering a valid cell item within a cellList, apply stlye as in LCS-148724140 target.classList.add('aw-widgets-dropframe');141 target.classList.add('aw-theme-dropframe');142 } else {143 target.classList.remove('aw-theme-dropframe');144 target.classList.remove('aw-widgets-dropframe');145 }146 }147 }148 });149 $scope.$on('$destroy', function () {150 // Detach iframe when panel unloaded151 if (formTargetFrame) {152 formTargetFrame.onload = null;153 document.body.removeChild(formTargetFrame);154 }155 if (chooseOrDropFilesDragDropLsnr) {156 eventBus.unsubscribe(chooseOrDropFilesDragDropLsnr);157 }158 });159 }]160 };161 }]);...

Full Screen

Full Screen

aflprep_send-file-form-helper.js

Source:aflprep_send-file-form-helper.js Github

copy

Full Screen

1'use strict';2function escapeString(string) {3 (x) => {4 let hex = x.charCodeAt(0).toString(16);5 if (hex.length < 2) hex = "0" + hex;6 return `\\x${hex}`;7 },8}9const kTestChars = 'ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ';10const kTestFallbackUtf8 = (11 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +12 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +13 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +14 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"15);16const kTestFallbackIso2022jp = (17 ("ABC~\x1B(J~\\≈¤\x1B$B!&!&\x1B(B•∙·☼\x1B$B!z@1\x1B(B🌟" +18 "\x1B$B@1!z\x1B(B☼·∙•\x1B$B!&!&\x1B(B¤≈\x1B(J\\~\x1B(B~XYZ")19);20const kTestFallbackWindows1252 = (21 "ABC~‾\xA5≈\xA4・・\x95∙\xB7☼★星🌟星★☼\xB7∙\x95・・\xA4≈\xA5‾~XYZ".replace(22 (x) => `&#${x.codePointAt(0)};`,23 )24);25const kTestFallbackXUserDefined = kTestChars.replace(26 (x) => `&#${x.codePointAt(0)};`,27);28const formPostFileUploadTest = ({29 fileNameSource,30 fileBaseName,31 formEncoding,32 expectedEncodedBaseName,33}) => {34 promise_test(async testCase => {35 if (document.readyState !== 'complete') {36 await new Promise(resolve => addEventListener('load', resolve));37 }38 const formTargetFrame = Object.assign(document.createElement('iframe'), {39 name: 'formtargetframe',40 });41 document.body.append(formTargetFrame);42 testCase.add_cleanup(() => {43 document.body.removeChild(formTargetFrame);44 });45 const form = Object.assign(document.createElement('form'), {46 acceptCharset: formEncoding,47 method: 'POST',48 target: formTargetFrame.name,49 });50 document.body.append(form);51 testCase.add_cleanup(() => {52 document.body.removeChild(form);53 });54 form.append(Object.assign(document.createElement('input'), {55 type: 'hidden',56 name: '_charset_',57 }));58 form.append(Object.assign(document.createElement('input'), {59 type: 'hidden',60 name: 'filename',61 value: fileBaseName,62 }));63 form.append(Object.assign(document.createElement('input'), {64 type: 'hidden',65 name: fileBaseName,66 value: 'filename',67 }));68 const fileInput = Object.assign(document.createElement('input'), {69 type: 'file',70 name: 'file',71 });72 form.append(fileInput);73 await new Promise(resolve => {74 const dataTransfer = new DataTransfer;75 dataTransfer.items.add(76 fileInput.files = dataTransfer.files;77 assert_equals(78 baseNameOfFilePath(fileInput.files[0].name),79 baseNameOfFilePath(fileInput.value),80 `The basename of the field's value should match its files[0].name`);81 form.submit();82 formTargetFrame.onload = resolve;83 });84 const formDataText = formTargetFrame.contentDocument.body.textContent;85 const formDataLines = formDataText.split('\n');86 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {87 --formDataLines.length;88 }89 assert_greater_than(90 formDataLines.length,91 2,92 `${fileBaseName}: multipart form data must have at least 3 lines: ${93 JSON.stringify(formDataText)94 }`);95 const boundary = formDataLines[0];96 assert_equals(97 formDataLines[formDataLines.length - 1],98 boundary + '--',99 `${fileBaseName}: multipart form data must end with ${boundary}--: ${100 JSON.stringify(formDataText)101 }`);102 const expectedText = [103 boundary,104 'Content-Disposition: form-data; name="_charset_"',105 '',106 formEncoding,107 boundary,108 'Content-Disposition: form-data; name="filename"',109 '',110 boundary,111 `Content-Disposition: form-data; name="${escapeString(asName)}"`,112 '',113 'filename',114 boundary,115 `Content-Disposition: form-data; name="file"; ` +116 `filename="${escapeString(asFilename)}"`,117 '',118 escapeString(kTestFallbackUtf8),119 boundary + '--',120 ].join('\n');121 assert_true(122 formDataText.startsWith(expectedText),123 `Unexpected multipart-shaped form data received:\n${124 formDataText125 }\nExpected:\n${expectedText}`);126 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...

Full Screen

Full Screen

enctypes-helper.js

Source:enctypes-helper.js Github

copy

Full Screen

1(() => {2 // Using echo-content-escaped.py rather than3 // /fetch/api/resources/echo-content.py to work around WebKit not4 // percent-encoding \x00, which causes the response to be detected as5 // a binary file and served as a download.6 const ACTION_URL = "/FileAPI/file/resources/echo-content-escaped.py";7 const IFRAME_NAME = "formtargetframe";8 // Undoes the escapes from /fetch/api/resources/echo-content.py9 function unescape(str) {10 return str11 .replace(/\r\n?|\n/g, "\r\n")12 .replace(13 /\\x[0-9A-Fa-f]{2}/g,14 (escape) => String.fromCodePoint(parseInt(escape.substring(2), 16)),15 )16 .replace(/\\\\/g, "\\");17 }18 // `expectedBuilder` is a function that takes in the actual form body19 // (necessary to get the multipart/form-data payload) and returns the form20 // body that should be expected.21 // If `testFormData` is false, the form entry will be submitted in for22 // controls. If it is true, it will submitted by modifying the entry list23 // during the `formdata` event.24 async function formSubmissionTest({25 name,26 value,27 expectedBuilder,28 enctype,29 formEncoding,30 testFormData = false,31 testCase,32 }) {33 if (document.readyState !== "complete") {34 await new Promise((resolve) => addEventListener("load", resolve));35 }36 const formTargetFrame = Object.assign(document.createElement("iframe"), {37 name: IFRAME_NAME,38 });39 document.body.append(formTargetFrame);40 testCase.add_cleanup(() => {41 document.body.removeChild(formTargetFrame);42 });43 const form = Object.assign(document.createElement("form"), {44 acceptCharset: formEncoding,45 action: ACTION_URL,46 method: "POST",47 enctype,48 target: IFRAME_NAME,49 });50 document.body.append(form);51 testCase.add_cleanup(() => {52 document.body.removeChild(form);53 });54 if (!testFormData) {55 const input = document.createElement("input");56 input.name = name;57 if (value instanceof File) {58 input.type = "file";59 const dataTransfer = new DataTransfer();60 dataTransfer.items.add(value);61 input.files = dataTransfer.files;62 } else {63 input.type = "hidden";64 input.value = value;65 }66 form.append(input);67 } else {68 form.addEventListener("formdata", (evt) => {69 evt.formData.append(name, value);70 });71 }72 await new Promise((resolve) => {73 form.submit();74 formTargetFrame.onload = resolve;75 });76 const serialized = unescape(77 formTargetFrame.contentDocument.body.textContent,78 );79 const expected = expectedBuilder(serialized);80 assert_equals(serialized, expected);81 }82 // This function returns a function to add individual form tests corresponding83 // to some enctype.84 // `expectedBuilder` is a function that takes two parameters: `expected` (the85 // `expected` value of a test) and `serialized` (the actual form body86 // submitted by the browser), and returns the correct form body that should87 // have been submitted. This is necessary in order to account for th88 // multipart/form-data boundary.89 window.formSubmissionTemplate = (enctype, expectedBuilder) => {90 function form({91 name,92 value,93 expected,94 formEncoding = "utf-8",95 description,96 }) {97 const commonParams = {98 name,99 value,100 expectedBuilder: expectedBuilder.bind(null, expected),101 enctype,102 formEncoding,103 };104 // Normal form105 promise_test(106 (testCase) =>107 formSubmissionTest({108 ...commonParams,109 testCase,110 }),111 `${enctype}: ${description} (normal form)`,112 );113 // formdata event114 promise_test(115 (testCase) =>116 formSubmissionTest({117 ...commonParams,118 testFormData: true,119 testCase,120 }),121 `${enctype}: ${description} (formdata event)`,122 );123 }124 return form;125 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var myForm = new wptb.formTargetFrame('myform');2myForm.submit();3var myForm = new wptb.formTargetWindow('myform');4myForm.submit();5var myForm = new wptb.formTargetFrame('myform');6myForm.submit();7var myForm = new wptb.formTargetWindow('myform');8myForm.submit();9var myForm = new wptb.formTargetFrame('myform');10myForm.submit();11var myForm = new wptb.formTargetWindow('myform');12myForm.submit();13var myForm = new wptb.formTargetFrame('myform');14myForm.submit();15var myForm = new wptb.formTargetWindow('myform');16myForm.submit();17var myForm = new wptb.formTargetFrame('myform');18myForm.submit();19var myForm = new wptb.formTargetWindow('myform');20myForm.submit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest('www.google.com', {4}, function(err, data) {5 if (err) return console.error(err);6 var testId = data.data.testId;7 wpt.formTargetFrame(testId, 'frame1', function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1function formTargetFrame(formName, targetFrame) {2 var form = document.forms[formName];3 if (form) {4 form.target = targetFrame;5 }6}7 <input type="button" value="Open in New Window" onclick="formTargetFrame('testForm','_blank')" />8 <input type="button" value="Open in Same Window" onclick="formTargetFrame('testForm','_self')" />9function formNewWindow(formName) {10 var form = document.forms[formName];11 if (form) {12 var newWindow = window.open('','_blank');13 newWindow.document.write(form.outerHTML);14 newWindow.document.forms[formName].submit();15 }16}17 <input type="button" value="Open in New Window" onclick="formNewWindow('testForm')" />

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.formTargetFrame('test.html');2window.parent.wpt.formComplete('success'); 3window.parent.wpt.formComplete('failure');4wpt.formTargetWindow('test.html');5window.opener.wpt.formComplete('success'); 6window.opener.wpt.formComplete('failure');7window.parent.wpt.formComplete('success'); 8window.parent.wpt.formComplete('failure');

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