Best JavaScript code snippet using appium-xcuitest-driver
_SyncPromise.qunit.js
Source:_SyncPromise.qunit.js
1/*!2 * ${copyright}3 */4sap.ui.require([5 "jquery.sap.global",6 "sap/ui/model/odata/v4/lib/_SyncPromise",7 "sap/ui/test/TestUtils"8], function (jQuery, _SyncPromise, TestUtils) {9 /*global QUnit, sinon */10 /*eslint max-nested-callbacks:[1,5], no-warning-comments: 0 */11 "use strict";12 function assertFulfilled(assert, oSyncPromise, vExpectedResult) {13 assert.strictEqual(oSyncPromise.isFulfilled(), true);14 assert.strictEqual(oSyncPromise.isRejected(), false);15 if (Array.isArray(vExpectedResult)) {16 assert.deepEqual(oSyncPromise.getResult(), vExpectedResult);17 } else {18 assert.strictEqual(oSyncPromise.getResult(), vExpectedResult);19 }20 }21 function assertPending(assert, oSyncPromise) {22 assert.strictEqual(oSyncPromise.isFulfilled(), false);23 assert.strictEqual(oSyncPromise.isRejected(), false);24 assert.strictEqual(oSyncPromise.getResult(), oSyncPromise);25 }26 function assertRejected(assert, oSyncPromise, vExpectedReason) {27 assert.strictEqual(oSyncPromise.isFulfilled(), false);28 assert.strictEqual(oSyncPromise.isRejected(), true);29 assert.strictEqual(oSyncPromise.getResult(), vExpectedReason);30 }31 //*********************************************************************************************32 QUnit.module("sap.ui.model.odata.v4.lib._SyncPromise", {33 beforeEach : function () {34 this.oLogMock = sinon.mock(jQuery.sap.log);35 this.oLogMock.expects("warning").never();36 this.oLogMock.expects("error").never();37 },38 afterEach : function () {39 this.oLogMock.verify();40 }41 });42 //*********************************************************************************************43 [42, undefined, {then : 42}, {then : function () {}}, [_SyncPromise.resolve()]44 ].forEach(function (vResult) {45 QUnit.test("_SyncPromise.resolve with non-Promise value: " + vResult, function (assert) {46 assertFulfilled(assert, _SyncPromise.resolve(vResult), vResult);47 });48 });49 //*********************************************************************************************50 QUnit.test("access to state and result: fulfills", function (assert) {51 var oNewPromise,52 oPromise = Promise.resolve(42),53 oSyncPromise;54 oSyncPromise = _SyncPromise.resolve(oPromise);55 assertPending(assert, oSyncPromise);56 assert.strictEqual(_SyncPromise.resolve(oSyncPromise), oSyncPromise,57 "resolve() does not wrap a _SyncPromise again");58 oNewPromise = oSyncPromise.then(function (iResult) {59 assertFulfilled(assert, oSyncPromise, iResult);60 });61 assertPending(assert, oNewPromise);62 return oPromise.then(function (iResult) {63 // _SyncPromise fulfills as soon as Promise fulfills64 assertFulfilled(assert, oSyncPromise, iResult);65 return oNewPromise;66 });67 });68 //*********************************************************************************************69 QUnit.test("'then' on a fulfilled _SyncPromise", function (assert) {70 var bCalled = false,71 oNewSyncPromise,72 oSyncPromise = _SyncPromise.resolve(42);73 oNewSyncPromise = oSyncPromise74 .then(/* then w/o fnOnFulfilled does not change result */)75 .then("If onFulfilled is not a function, it must be ignored")76 .then(undefined, function () {77 assert.ok(false, "unexpected call to reject callback");78 })79 .then(function (iResult) {80 assertFulfilled(assert, oSyncPromise, iResult);81 assert.strictEqual(bCalled, false, "then called exactly once");82 bCalled = true;83 return "*" + iResult + "*";84 });85 assertFulfilled(assert, oNewSyncPromise, "*42*");86 assert.strictEqual(bCalled, true, "called synchronously");87 oNewSyncPromise.then(function (sResult) {88 assert.strictEqual(sResult, oNewSyncPromise.getResult(), "*42*");89 });90 });91 //*********************************************************************************************92 [93 {wrap : false, reject : false},94 {wrap : true, reject : false},95 {wrap : false, reject : true},96 {wrap : true, reject : true}97 ].forEach(function (oFixture) {98 QUnit.test("sync -> async: " + JSON.stringify(oFixture), function (assert) {99 var oPromise = oFixture.reject ? Promise.reject() : Promise.resolve(),100 oSyncPromise = _SyncPromise.resolve(oPromise);101 return oPromise[oFixture.reject ? "catch" : "then"](function () {102 var oFulfillment = {},103 oNewSyncPromise,104 oResult = new Promise(function (resolve, reject) {105 setTimeout(function () {106 assertPending(assert, oNewSyncPromise); // not yet107 }, 0);108 setTimeout(function () {109 resolve(oFulfillment);110 }, 10);111 });112 function callback() {113 return oResult; // returning a promise makes us async again114 }115 function fail() {116 assert.ok(false, "unexpected call");117 }118 if (oFixture.wrap) {119 oResult = _SyncPromise.resolve(oResult);120 }121 // 'then' on a settled _SyncPromise is called synchronously122 oNewSyncPromise = oFixture.reject123 ? oSyncPromise.then(fail, callback)124 : oSyncPromise.then(callback, fail);125 assert.notStrictEqual(oNewSyncPromise, oResult, "'then' returns a new promise");126 return oNewSyncPromise.then(function (vResult) {127 assertFulfilled(assert, oNewSyncPromise, oFulfillment);128 assert.strictEqual(vResult, oFulfillment);129 });130 });131 });132 });133 //*********************************************************************************************134 [135 {initialReject : false, thenReject : false},136 {initialReject : false, thenReject : true},137 {initialReject : true, thenReject : false},138 {initialReject : true, thenReject : true}139 ].forEach(function (oFixture) {140 QUnit.test("sync -> sync: " + JSON.stringify(oFixture), function (assert) {141 var oResult = {},142 oInitialPromise = oFixture.initialReject ? Promise.reject() : Promise.resolve(),143 oInitialSyncPromise = _SyncPromise.resolve(oInitialPromise),144 sMethod = oFixture.initialReject || oFixture.thenReject ? "catch" : "then",145 oThenPromise = oFixture.thenReject146 ? Promise.reject(oResult)147 : Promise.resolve(oResult),148 oThenSyncPromise = _SyncPromise.resolve(oThenPromise);149 return Promise.all([oInitialPromise, oThenPromise])[sMethod](function () {150 // 'then' on a settled _SyncPromise is called synchronously151 var oNewSyncPromise = oFixture.initialReject152 ? oInitialSyncPromise.then(fail, callback)153 : oInitialSyncPromise.then(callback, fail);154 function callback() {155 // returning a settled _SyncPromise keeps us sync156 return oThenSyncPromise;157 }158 function fail() {159 assert.ok(false, "unexpected call");160 }161 if (oFixture.thenReject) {162 assertRejected(assert, oNewSyncPromise, oResult);163 } else {164 assertFulfilled(assert, oNewSyncPromise, oResult);165 }166 });167 });168 });169 //*********************************************************************************************170 QUnit.test("sync -> sync: throws", function (assert) {171 var oError = new Error(),172 oInitialSyncPromise = _SyncPromise.resolve(),173 // 'then' on a settled _SyncPromise is called synchronously174 oNewSyncPromise = oInitialSyncPromise.then(callback, fail);175 function callback() {176 throw oError;177 }178 function fail() {179 assert.ok(false, "unexpected call");180 }181 assertRejected(assert, oNewSyncPromise, oError);182 });183 //*********************************************************************************************184 QUnit.test("access to state and result: rejects", function (assert) {185 var oNewPromise,186 oReason = {},187 oPromise = Promise.reject(oReason),188 oSyncPromise;189 oSyncPromise = _SyncPromise.resolve(oPromise);190 assertPending(assert, oSyncPromise);191 oNewPromise = oSyncPromise.then(function () {192 assert.ok(false);193 }, function (vReason) {194 assert.strictEqual(vReason, oReason);195 });196 assertPending(assert, oNewPromise);197 return oPromise.catch(function () {198 assertRejected(assert, oSyncPromise, oReason);199 return oNewPromise;200 });201 });202 //*********************************************************************************************203 QUnit.test("'then' on a rejected _SyncPromise", function (assert) {204 var oReason = {},205 oPromise = Promise.reject(oReason),206 oSyncPromise = _SyncPromise.resolve(oPromise);207 return oPromise.catch(function () {208 var bCalled = false,209 oNewSyncPromise;210 oNewSyncPromise = oSyncPromise211 .then(/* then w/o callbacks does not change result */)212 .then(null, "If onRejected is not a function, it must be ignored")213 .then(function () {214 assert.ok(false);215 }, function (vReason) {216 assertRejected(assert, oSyncPromise, oReason);217 assert.strictEqual(vReason, oReason);218 assert.strictEqual(bCalled, false, "then called exactly once");219 bCalled = true;220 return "OK";221 });222 assertFulfilled(assert, oNewSyncPromise, "OK");223 assert.strictEqual(bCalled, true, "called synchronously");224 oNewSyncPromise.then(function (sResult) {225 assert.strictEqual(sResult, oNewSyncPromise.getResult(), "OK");226 });227 });228 });229 //*********************************************************************************************230 QUnit.test("_SyncPromise.all: simple values", function (assert) {231 assertFulfilled(assert, _SyncPromise.all([]), []);232 assertFulfilled(assert, _SyncPromise.all([42]), [42]);233 assertFulfilled(assert, _SyncPromise.all([_SyncPromise.resolve(42)]), [42]);234 return _SyncPromise.all([42]).then(function (aAnswers) {235 assert.deepEqual(aAnswers, [42]);236 });237 });238 //*********************************************************************************************239 QUnit.test("_SyncPromise.all: then", function (assert) {240 var oPromiseAll = _SyncPromise.all([Promise.resolve(42)]),241 oThenResult,242 done = assert.async();243 assertPending(assert, oPromiseAll);244 // code under test: "then" on a _SyncPromise.all()245 oThenResult = oPromiseAll.then(function (aAnswers) {246 assert.strictEqual(aAnswers[0], 42);247 assertFulfilled(assert, oPromiseAll, [42]);248 done();249 });250 assertPending(assert, oThenResult);251 });252 //*********************************************************************************************253 QUnit.test("_SyncPromise.all: catch", function (assert) {254 var oCatchResult,255 oReason = {},256 oPromiseAll = _SyncPromise.all([Promise.reject(oReason)]),257 done = assert.async();258 assertPending(assert, oPromiseAll);259 // code under test: "catch" on a _SyncPromise.all()260 oCatchResult = oPromiseAll.catch(function (oReason0) {261 assert.strictEqual(oReason0, oReason);262 assertRejected(assert, oPromiseAll, oReason);263 done();264 });265 assertPending(assert, oCatchResult);266 });267 //*********************************************************************************************268 [true, false].forEach(function (bWrap) {269 QUnit.test("_SyncPromise.all: one Promise resolves, wrap = " + bWrap, function (assert) {270 var oPromise = Promise.resolve(42),271 oPromiseAll;272 if (bWrap) {273 oPromise = _SyncPromise.resolve(oPromise);274 }275 oPromiseAll = _SyncPromise.all([oPromise]);276 assertPending(assert, oPromiseAll);277 return oPromise.then(function () {278 assertFulfilled(assert, oPromiseAll, [42]);279 });280 });281 });282 //*********************************************************************************************283 QUnit.test("_SyncPromise.all: two Promises resolve", function (assert) {284 var oPromiseAll,285 oPromise0 = Promise.resolve(42), // timeout 0286 oPromise1 = new Promise(function (resolve, reject) {287 setTimeout(function () {288 assertPending(assert, oPromiseAll); // not yet289 }, 5);290 setTimeout(function () {291 resolve("OK");292 }, 10);293 }),294 aPromises = [oPromise0, oPromise1];295 oPromiseAll = _SyncPromise.all(aPromises);296 assertPending(assert, oPromiseAll);297 return Promise.all(aPromises).then(function () {298 assertFulfilled(assert, oPromiseAll, [42, "OK"]);299 assert.deepEqual(aPromises, [oPromise0, oPromise1], "caller's array unchanged");300 });301 });302 //*********************************************************************************************303 QUnit.test("_SyncPromise.all: one Promise rejects", function (assert) {304 var oReason = {},305 oPromise = Promise.reject(oReason),306 oPromiseAll;307 oPromiseAll = _SyncPromise.all([oPromise]);308 assertPending(assert, oPromiseAll);309 return oPromise.catch(function () {310 assertRejected(assert, oPromiseAll, oReason);311 });312 });313 //*********************************************************************************************314 QUnit.test("_SyncPromise.all: two Promises reject", function (assert) {315 var oReason = {},316 oPromiseAll,317 oPromise0 = Promise.reject(oReason), // timeout 0318 oPromise1 = new Promise(function (resolve, reject) {319 setTimeout(function () {320 assertRejected(assert, oPromiseAll, oReason);321 }, 5);322 setTimeout(function () {323 reject("Unexpected");324 }, 10);325 }),326 aPromises = [oPromise0, oPromise1];327 oPromiseAll = _SyncPromise.all(aPromises);328 assertPending(assert, oPromiseAll);329 return oPromise1.catch(function () { // wait for the "slower" promise330 assertRejected(assert, oPromiseAll, oReason); // rejection reason does not change331 assert.deepEqual(aPromises, [oPromise0, oPromise1], "caller's array unchanged");332 });333 });334 //*********************************************************************************************335 QUnit.test("'catch' delegates to 'then'", function (assert) {336 var oNewPromise = {},337 fnOnRejected = function () {},338 oSyncPromise = _SyncPromise.resolve();339 this.mock(oSyncPromise).expects("then")340 .withExactArgs(undefined, fnOnRejected)341 .returns(oNewPromise);342 assert.strictEqual(oSyncPromise.catch(fnOnRejected), oNewPromise);343 });344 //*********************************************************************************************345 QUnit.test("Promise.resolve on _SyncPromise", function (assert) {346 return Promise.resolve(_SyncPromise.resolve(42)).then(function (iResult) {347 assert.strictEqual(iResult, 42);348 });349 });350 //*********************************************************************************************351 QUnit.test("createGetMethod, not throwing", function (assert) {352 var aArguments = ["foo", "bar"],353 oResult = {},354 oSyncPromise = _SyncPromise.resolve(oResult),355 oContext = {356 fetch : function () {357 assert.strictEqual(this, oContext);358 assert.deepEqual(Array.prototype.slice.call(arguments), aArguments);359 return oSyncPromise;360 }361 },362 fnGet;363 // code under test364 // Note: passing the function's name instead of reference allows for dynamic dispatch, thus365 // making a mock for "fetch*" possible in the first place366 fnGet = _SyncPromise.createGetMethod("fetch");367 assert.strictEqual(fnGet.apply(oContext, aArguments), oResult);368 this.mock(oSyncPromise).expects("isFulfilled").returns(false);369 assert.strictEqual(fnGet.apply(oContext, aArguments), undefined);370 });371 //*********************************************************************************************372 QUnit.test("createGetMethod, throwing", function (assert) {373 var aArguments = ["foo", "bar"],374 oResult = {},375 oSyncPromise = _SyncPromise.resolve(oResult),376 oContext = {377 fetch : function () {378 assert.strictEqual(this, oContext);379 assert.deepEqual(Array.prototype.slice.call(arguments), aArguments);380 return oSyncPromise;381 }382 },383 fnGet,384 oSyncPromiseMock = this.mock(oSyncPromise);385 // code under test386 fnGet = _SyncPromise.createGetMethod("fetch", true);387 // fulfilled388 assert.strictEqual(fnGet.apply(oContext, aArguments), oResult);389 // pending390 oSyncPromiseMock.expects("isFulfilled").returns(false);391 oSyncPromiseMock.expects("isRejected").returns(false);392 assert.throws(function () {393 fnGet.apply(oContext, aArguments);394 }, new Error("Result pending"));395 // verify and restore396 oSyncPromiseMock.verify();397 oSyncPromiseMock = this.mock(oSyncPromise);398 // rejected399 oSyncPromiseMock.expects("isFulfilled").returns(false);400 oSyncPromiseMock.expects("isRejected").returns(true);401 assert.throws(function () {402 fnGet.apply(oContext, aArguments);403 }, oResult);404 });405 //*********************************************************************************************406 QUnit.test("createRequestMethod", function (assert) {407 var aArguments = ["foo", "bar"],408 oResult = {},409 oSyncPromise = _SyncPromise.resolve(),410 oContext = {411 fetch : function () {412 assert.strictEqual(this, oContext);413 assert.deepEqual(Array.prototype.slice.call(arguments), aArguments);414 return oSyncPromise;415 }416 },417 fnRequest;418 this.mock(Promise).expects("resolve")419 .withExactArgs(sinon.match.same(oSyncPromise)).returns(oResult);420 // code under test421 fnRequest = _SyncPromise.createRequestMethod("fetch");422 assert.strictEqual(fnRequest.apply(oContext, aArguments), oResult);423 });...
browser_dbg_search-sources-02.js
Source:browser_dbg_search-sources-02.js
1/* Any copyright is dedicated to the Public Domain.2 http://creativecommons.org/publicdomain/zero/1.0/ */3/**4 * Tests more complex functionality of sources filtering (file search).5 */6const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html";7let gTab, gPanel, gDebugger;8let gSources, gSourceUtils, gSearchView, gSearchBox;9function test() {10 // Debug test slaves are a bit slow at this test.11 requestLongerTimeout(3);12 initDebugger(TAB_URL).then(([aTab,, aPanel]) => {13 gTab = aTab;14 gPanel = aPanel;15 gDebugger = gPanel.panelWin;16 gSources = gDebugger.DebuggerView.Sources;17 gSourceUtils = gDebugger.SourceUtils;18 gSearchView = gDebugger.DebuggerView.FilteredSources;19 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;20 waitForSourceShown(gPanel, "-01.js")21 .then(firstSearch)22 .then(secondSearch)23 .then(thirdSearch)24 .then(fourthSearch)25 .then(fifthSearch)26 .then(goDown)27 .then(goDownAndWrap)28 .then(goUpAndWrap)29 .then(goUp)30 .then(returnAndSwitch)31 .then(firstSearch)32 .then(clickAndSwitch)33 .then(() => closeDebuggerAndFinish(gPanel))34 .then(null, aError => {35 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);36 });37 });38}39function firstSearch() {40 let finished = promise.all([41 ensureSourceIs(gPanel, "-01.js"),42 ensureCaretAt(gPanel, 1),43 once(gDebugger, "popupshown"),44 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)45 ]);46 setText(gSearchBox, ".");47 return finished.then(() => promise.all([48 ensureSourceIs(gPanel, "-01.js"),49 ensureCaretAt(gPanel, 1),50 verifyContents([51 "code_script-switching-01.js?a=b",52 "code_test-editor-mode?c=d",53 "doc_editor-mode.html"54 ])55 ]));56}57function secondSearch() {58 let finished = promise.all([59 ensureSourceIs(gPanel, "-01.js"),60 ensureCaretAt(gPanel, 1),61 once(gDebugger, "popupshown"),62 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)63 ]);64 typeText(gSearchBox, "-0");65 return finished.then(() => promise.all([66 ensureSourceIs(gPanel, "-01.js"),67 ensureCaretAt(gPanel, 1),68 verifyContents(["code_script-switching-01.js?a=b"])69 ]));70}71function thirdSearch() {72 let finished = promise.all([73 ensureSourceIs(gPanel, "-01.js"),74 ensureCaretAt(gPanel, 1),75 once(gDebugger, "popupshown"),76 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)77 ]);78 backspaceText(gSearchBox, 1);79 return finished.then(() => promise.all([80 ensureSourceIs(gPanel, "-01.js"),81 ensureCaretAt(gPanel, 1),82 verifyContents([83 "code_script-switching-01.js?a=b",84 "code_test-editor-mode?c=d",85 "doc_editor-mode.html"86 ])87 ]));88}89function fourthSearch() {90 let finished = promise.all([91 ensureSourceIs(gPanel, "-01.js"),92 ensureCaretAt(gPanel, 1),93 once(gDebugger, "popupshown"),94 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),95 waitForSourceShown(gPanel, "test-editor-mode")96 ]);97 setText(gSearchBox, "code_test");98 return finished.then(() => promise.all([99 ensureSourceIs(gPanel, "test-editor-mode"),100 ensureCaretAt(gPanel, 1),101 verifyContents(["code_test-editor-mode?c=d"])102 ]));103}104function fifthSearch() {105 let finished = promise.all([106 ensureSourceIs(gPanel, "test-editor-mode"),107 ensureCaretAt(gPanel, 1),108 once(gDebugger, "popupshown"),109 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),110 waitForSourceShown(gPanel, "-01.js")111 ]);112 backspaceText(gSearchBox, 4);113 return finished.then(() => promise.all([114 ensureSourceIs(gPanel, "-01.js"),115 ensureCaretAt(gPanel, 1),116 verifyContents([117 "code_script-switching-01.js?a=b",118 "code_test-editor-mode?c=d"119 ])120 ]));121}122function goDown() {123 let finished = promise.all([124 ensureSourceIs(gPanel, "-01.js"),125 ensureCaretAt(gPanel, 1),126 waitForSourceShown(gPanel, "test-editor-mode"),127 ]);128 EventUtils.sendKey("DOWN", gDebugger);129 return finished.then(() => promise.all([130 ensureSourceIs(gPanel,"test-editor-mode"),131 ensureCaretAt(gPanel, 1),132 verifyContents([133 "code_script-switching-01.js?a=b",134 "code_test-editor-mode?c=d"135 ])136 ]));137}138function goDownAndWrap() {139 let finished = promise.all([140 ensureSourceIs(gPanel, "test-editor-mode"),141 ensureCaretAt(gPanel, 1),142 waitForSourceShown(gPanel, "-01.js")143 ]);144 EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);145 return finished.then(() => promise.all([146 ensureSourceIs(gPanel,"-01.js"),147 ensureCaretAt(gPanel, 1),148 verifyContents([149 "code_script-switching-01.js?a=b",150 "code_test-editor-mode?c=d"151 ])152 ]));153}154function goUpAndWrap() {155 let finished = promise.all([156 ensureSourceIs(gPanel,"-01.js"),157 ensureCaretAt(gPanel, 1),158 waitForSourceShown(gPanel, "test-editor-mode")159 ]);160 EventUtils.synthesizeKey("G", { metaKey: true }, gDebugger);161 return finished.then(() => promise.all([162 ensureSourceIs(gPanel,"test-editor-mode"),163 ensureCaretAt(gPanel, 1),164 verifyContents([165 "code_script-switching-01.js?a=b",166 "code_test-editor-mode?c=d"167 ])168 ]));169}170function goUp() {171 let finished = promise.all([172 ensureSourceIs(gPanel,"test-editor-mode"),173 ensureCaretAt(gPanel, 1),174 waitForSourceShown(gPanel, "-01.js"),175 ]);176 EventUtils.sendKey("UP", gDebugger);177 return finished.then(() => promise.all([178 ensureSourceIs(gPanel,"-01.js"),179 ensureCaretAt(gPanel, 1),180 verifyContents([181 "code_script-switching-01.js?a=b",182 "code_test-editor-mode?c=d"183 ])184 ]));185}186function returnAndSwitch() {187 let finished = promise.all([188 ensureSourceIs(gPanel,"-01.js"),189 ensureCaretAt(gPanel, 1),190 once(gDebugger, "popuphidden")191 ]);192 EventUtils.sendKey("RETURN", gDebugger);193 return finished.then(() => promise.all([194 ensureSourceIs(gPanel,"-01.js"),195 ensureCaretAt(gPanel, 1)196 ]));197}198function clickAndSwitch() {199 let finished = promise.all([200 ensureSourceIs(gPanel,"-01.js"),201 ensureCaretAt(gPanel, 1),202 once(gDebugger, "popuphidden"),203 waitForSourceShown(gPanel, "test-editor-mode")204 ]);205 EventUtils.sendMouseEvent({ type: "click" }, gSearchView.items[1].target, gDebugger);206 return finished.then(() => promise.all([207 ensureSourceIs(gPanel,"test-editor-mode"),208 ensureCaretAt(gPanel, 1)209 ]));210}211function verifyContents(aMatches) {212 is(gSources.visibleItems.length, 3,213 "The unmatched sources in the widget should not be hidden.");214 is(gSearchView.itemCount, aMatches.length,215 "The filtered sources view should have the right items available.");216 for (let i = 0; i < gSearchView.itemCount; i++) {217 let trimmedLabel = gSourceUtils.trimUrlLength(gSourceUtils.trimUrlQuery(aMatches[i]));218 let trimmedLocation = gSourceUtils.trimUrlLength(EXAMPLE_URL + aMatches[i], 0, "start");219 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label[value=\"" + trimmedLabel + "\"]"),220 "The filtered sources view should have the correct source labels.");221 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label-below[value=\"" + trimmedLocation + "\"]"),222 "The filtered sources view should have the correct source locations.");223 }224}225registerCleanupFunction(function() {226 gTab = null;227 gPanel = null;228 gDebugger = null;229 gSources = null;230 gSourceUtils = null;231 gSearchView = null;232 gSearchBox = null;...
browser_dbg_search-sources-01.js
Source:browser_dbg_search-sources-01.js
1/* Any copyright is dedicated to the Public Domain.2 http://creativecommons.org/publicdomain/zero/1.0/ */3/**4 * Tests basic functionality of sources filtering (file search).5 */6const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";7let gTab, gPanel, gDebugger;8let gSources, gSearchView, gSearchBox;9function test() {10 // Debug test slaves are a bit slow at this test.11 requestLongerTimeout(3);12 initDebugger(TAB_URL).then(([aTab,, aPanel]) => {13 gTab = aTab;14 gPanel = aPanel;15 gDebugger = gPanel.panelWin;16 gSources = gDebugger.DebuggerView.Sources;17 gSearchView = gDebugger.DebuggerView.FilteredSources;18 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;19 waitForSourceShown(gPanel, "-01.js")20 .then(bogusSearch)21 .then(firstSearch)22 .then(secondSearch)23 .then(thirdSearch)24 .then(fourthSearch)25 .then(fifthSearch)26 .then(sixthSearch)27 .then(seventhSearch)28 .then(() => closeDebuggerAndFinish(gPanel))29 .then(null, aError => {30 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);31 });32 });33}34function bogusSearch() {35 let finished = promise.all([36 ensureSourceIs(gPanel, "-01.js"),37 ensureCaretAt(gPanel, 1),38 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND)39 ]);40 setText(gSearchBox, "BOGUS");41 return finished.then(() => promise.all([42 ensureSourceIs(gPanel, "-01.js"),43 ensureCaretAt(gPanel, 1),44 verifyContents({ itemCount: 0, hidden: true })45 ]));46}47function firstSearch() {48 let finished = promise.all([49 ensureSourceIs(gPanel, "-01.js"),50 ensureCaretAt(gPanel, 1),51 once(gDebugger, "popupshown"),52 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),53 waitForSourceShown(gPanel, "-02.js")54 ]);55 setText(gSearchBox, "-02.js");56 return finished.then(() => promise.all([57 ensureSourceIs(gPanel, "-02.js"),58 ensureCaretAt(gPanel, 1),59 verifyContents({ itemCount: 1, hidden: false })60 ]));61}62function secondSearch() {63 let finished = promise.all([64 once(gDebugger, "popupshown"),65 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),66 waitForSourceShown(gPanel, "-01.js")67 ])68 .then(() => {69 let finished = promise.all([70 once(gDebugger, "popupshown"),71 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),72 waitForCaretUpdated(gPanel, 5)73 ])74 .then(() => promise.all([75 ensureSourceIs(gPanel, "-01.js"),76 ensureCaretAt(gPanel, 5),77 verifyContents({ itemCount: 1, hidden: false })78 ]));79 typeText(gSearchBox, ":5");80 return finished;81 });82 setText(gSearchBox, ".*-01\.js");83 return finished;84}85function thirdSearch() {86 let finished = promise.all([87 once(gDebugger, "popupshown"),88 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),89 waitForSourceShown(gPanel, "-02.js")90 ])91 .then(() => {92 let finished = promise.all([93 once(gDebugger, "popupshown"),94 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),95 waitForCaretUpdated(gPanel, 6, 6)96 ])97 .then(() => promise.all([98 ensureSourceIs(gPanel, "-02.js"),99 ensureCaretAt(gPanel, 6, 6),100 verifyContents({ itemCount: 1, hidden: false })101 ]));102 typeText(gSearchBox, "#deb");103 return finished;104 });105 setText(gSearchBox, ".*-02\.js");106 return finished;107}108function fourthSearch() {109 let finished = promise.all([110 once(gDebugger, "popupshown"),111 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),112 waitForSourceShown(gPanel, "-01.js")113 ])114 .then(() => {115 let finished = promise.all([116 once(gDebugger, "popupshown"),117 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),118 waitForCaretUpdated(gPanel, 2, 9),119 ])120 .then(() => promise.all([121 ensureSourceIs(gPanel, "-01.js"),122 ensureCaretAt(gPanel, 2, 9),123 verifyContents({ itemCount: 1, hidden: false })124 // ...because we simply searched for ":" in the current file.125 ]));126 typeText(gSearchBox, "#:"); // # has precedence.127 return finished;128 });129 setText(gSearchBox, ".*-01\.js");130 return finished;131}132function fifthSearch() {133 let finished = promise.all([134 once(gDebugger, "popupshown"),135 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),136 waitForSourceShown(gPanel, "-02.js")137 ])138 .then(() => {139 let finished = promise.all([140 once(gDebugger, "popuphidden"),141 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND),142 waitForCaretUpdated(gPanel, 1, 3)143 ])144 .then(() => promise.all([145 ensureSourceIs(gPanel, "-02.js"),146 ensureCaretAt(gPanel, 1, 3),147 verifyContents({ itemCount: 0, hidden: true })148 // ...because the searched label includes ":5", so nothing is found.149 ]));150 typeText(gSearchBox, ":5#*"); // # has precedence.151 return finished;152 });153 setText(gSearchBox, ".*-02\.js");154 return finished;155}156function sixthSearch() {157 let finished = promise.all([158 ensureSourceIs(gPanel, "-02.js"),159 ensureCaretAt(gPanel, 1, 3),160 once(gDebugger, "popupshown"),161 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),162 waitForCaretUpdated(gPanel, 5)163 ]);164 backspaceText(gSearchBox, 2);165 return finished.then(() => promise.all([166 ensureSourceIs(gPanel, "-02.js"),167 ensureCaretAt(gPanel, 5),168 verifyContents({ itemCount: 1, hidden: false })169 ]));170}171function seventhSearch() {172 let finished = promise.all([173 ensureSourceIs(gPanel, "-02.js"),174 ensureCaretAt(gPanel, 5),175 once(gDebugger, "popupshown"),176 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),177 waitForSourceShown(gPanel, "-01.js"),178 ]);179 backspaceText(gSearchBox, 6);180 return finished.then(() => promise.all([181 ensureSourceIs(gPanel, "-01.js"),182 ensureCaretAt(gPanel, 1),183 verifyContents({ itemCount: 2, hidden: false })184 ]));185}186function verifyContents(aArgs) {187 is(gSources.visibleItems.length, 2,188 "The unmatched sources in the widget should not be hidden.");189 is(gSearchView.itemCount, aArgs.itemCount,190 "No sources should be displayed in the sources container after a bogus search.");191 is(gSearchView.hidden, aArgs.hidden,192 "No sources should be displayed in the sources container after a bogus search.");193}194registerCleanupFunction(function() {195 gTab = null;196 gPanel = null;197 gDebugger = null;198 gSources = null;199 gSearchView = null;200 gSearchBox = null;...
Promise-static-all.js
Source:Promise-static-all.js
1// Copyright 2014 the V8 project authors. All rights reserved.2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.3//4// Redistribution and use in source and binary forms, with or without5// modification, are permitted provided that the following conditions6// are met:7// 1. Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// 2. Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12//13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23// Flags: --harmony24'use strict';25description('Test Promise.all');26var result = undefined;27var p1 = new Promise(function(resolve) { resolve('p1'); });28var p2 = new Promise(function(resolve) { resolve('p2'); });29var p3 = new Promise(function(resolve) { resolve('p3'); });30var p4 = new Promise(function() {});31var p5 = new Promise(function() {});32var p6 = new Promise(function(_, reject) { reject('p6'); });33var p7 = new Promise(function(_, reject) { reject('p7'); });34var p8 = new Promise(function(_, reject) { reject('p8'); });35var p9 = new Promise(function(resolve) { resolve(p2); });36Promise.all([p1, p2, p5]).then(function(result) {37 testFailed('Promise.all([p1, p2, p5]) is fulfilled.');38}, function() {39 testFailed('Promise.all([p1, p2, p5]) is rejected.');40});41Promise.all().then(function() {42 testFailed('Promise.all() is fulfilled.');43}, function() {44 testPassed('Promise.all() is rejected.');45 return Promise.all([]).then(function(localResult) {46 testPassed('Promise.all([]) is fulfilled.');47 result = localResult;48 shouldBe('result.length', '0');49 }, function() {50 testFailed('Promise.all([]) is rejected.');51 });52}).then(function() {53 return Promise.all([p1, p2, p3]).then(function(localResult) {54 testPassed('Promise.all([p1, p2, p3]) is fulfilled.');55 result = localResult;56 shouldBe('result.length', '3');57 shouldBeEqualToString('result[0]', 'p1');58 shouldBeEqualToString('result[1]', 'p2');59 shouldBeEqualToString('result[2]', 'p3');60 }, function() {61 testFailed('Promise.all([p1, p2, p3]) is rejected.');62 });63}).then(function() {64 return Promise.all([p1, p6, p5]).then(function(localResult) {65 testFailed('Promise.all([p1, p6, p5]) is fulfilled.');66 }, function(localResult) {67 testPassed('Promise.all([p1, p6, p5]) is rejected.');68 result = localResult;69 shouldBeEqualToString('result', 'p6');70 });71}).then(function() {72 return Promise.all([p9]).then(function(localResult) {73 testPassed('Promise.all([p9]) is fulfilled.');74 result = localResult;75 shouldBe('result.length', '1');76 shouldBeEqualToString('result[0]', 'p2');77 }, function(result) {78 testFailed('Promise.all([p9]) is rejected.');79 });80}).then(function() {81 // Array hole should not be skipped.82 return Promise.all([p9,,,]).then(function(localResult) {83 testPassed('Promise.all([p9,,,]) is fulfilled.');84 result = localResult;85 shouldBe('result.length', '3');86 shouldBeEqualToString('result[0]', 'p2');87 shouldBe('result[1]', 'undefined');88 shouldBe('result[2]', 'undefined');89 }, function(localResult) {90 testFailed('Promise.all([p9,,,]) is rejected.');91 });92}).then(function() {93 // Immediate value should be converted to a promise object by the94 // ToPromise operation.95 return Promise.all([p9,42]).then(function(localResult) {96 testPassed('Promise.all([p9,42]) is fulfilled.');97 result = localResult;98 shouldBe('result.length', '2');99 shouldBeEqualToString('result[0]', 'p2');100 shouldBe('result[1]', '42');101 }, function(localResult) {102 testFailed('Promise.all([p9,42]) is rejected.');103 });104}).then(function() {105 return Promise.all({}).then(function(localResult) {106 testFailed('Promise.all({}) is fulfilled.');107 }, function(localResult) {108 testPassed('Promise.all({}) is rejected.');109 });110}).then(finishJSTest, finishJSTest);...
each.js
Source:each.js
1"use strict";2module.exports = function(Promise, INTERNAL) {3var PromiseReduce = Promise.reduce;4var PromiseAll = Promise.all;5function promiseAllThis() {6 return PromiseAll(this);7}8function PromiseMapSeries(promises, fn) {9 return PromiseReduce(promises, fn, INTERNAL, INTERNAL);10}11Promise.prototype.each = function (fn) {12 return PromiseReduce(this, fn, INTERNAL, 0)13 ._then(promiseAllThis, undefined, undefined, this, undefined);14};15Promise.prototype.mapSeries = function (fn) {16 return PromiseReduce(this, fn, INTERNAL, INTERNAL);17};18Promise.each = function (promises, fn) {19 return PromiseReduce(promises, fn, INTERNAL, 0)20 ._then(promiseAllThis, undefined, undefined, promises, undefined);21};22Promise.mapSeries = PromiseMapSeries;...
Using AI Code Generation
1const { B } = require('bluebird');2const { remote } = require('webdriverio');3(async () => {4 const browser = await remote({5 capabilities: {6 }7 });8 const p1 = browser.$('#TextField1');9 const p2 = browser.$('#TextField2');10 const p3 = browser.$('#ComputeSumButton');11 const [el1, el2, el3] = await B.Promise.all([p1, p2, p3]);12 await el1.setValue('1');13 await el2.setValue('2');14 await el3.click();15 const p4 = browser.$('#Answer');16 const p5 = p4.getText();17 const [el4, el5] = await B.Promise.all([p4, p5]);18 await browser.deleteSession();19})();20I have tried to use B.Promise.all() method to wait for all promises to be resolved. This is the only way I have found to wait for all promises to be resolved. It seems to work for me. I hope it helps you too. It does help. But I think it is more a workaround than a solution. I would prefer a solution that
Using AI Code Generation
1var B = require('bluebird');2var wd = require('wd');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .then(function () {8 return B.all([9 driver.elementByAccessibilityId('ComputeSumButton'),10 driver.elementByAccessibilityId('show alert')11 ]);12 })13 .then(function (els) {14 return B.all([15 els[0].click(),16 els[1].click()17 ]);18 })19 .then(function () {20 return driver.elementsByClassName('XCUIElementTypeButton');21 })22 .then(function (els) {23 return B.all([24 els[0].click(),25 els[1].click()26 ]);27 })28 .then(function () {29 return driver.elementsByClassName('XCUIElementTypeStaticText');30 })31 .then(function (els) {32 return B.all([33 els[0].text(),34 els[1].text()35 ]);36 })37 .then(function (texts) {38 console.log('texts', texts);39 })40 .fin(function () { return driver.quit(); })41 .done();42var B = require('bluebird');43var wd = require('wd');44var desired = {45};46var driver = wd.promiseChainRemote('localhost', 4723);47 .init(desired)48 .then(function () {49 return B.all([50 driver.elementByAccessibilityId('ComputeSumButton'),51 driver.elementByAccessibilityId('show alert')52 ]);53 })54 .then(function (els) {
Using AI Code Generation
1B.Promise.all([element1, element2]).then(function (elements) {2 console.log(elements);3});4B.all([element1, element2]).then(function (elements) {5 console.log(elements);6});7Promise.all([element1, element2]).then(function (elements) {8 console.log(elements);9});10Promise.all([element1, element2]).then(function (elements) {11 console.log(elements);12});13Promise.all([element1, element2]).then(function (elements) {14 console.log(elements);15});16Promise.all([element1, element2]).then(function (elements) {17 console.log(elements);18});19Promise.all([element1, element2]).then(function (elements) {20 console.log(elements);21});22Promise.all([element1, element2]).then(function (elements) {23 console.log(elements);24});25Promise.all([element1, element2]).then(function (elements) {26 console.log(elements);27});28Promise.all([element1, element2]).then(function (elements) {29 console.log(elements);30});31Promise.all([element1, element2]).then(function (elements) {32 console.log(elements);33});34Promise.all([element1, element2]).then(function (elements) {35 console.log(elements);36});37Promise.all([element1, element2]).then(function (elements) {38 console.log(elements);39});40Promise.all([
Using AI Code Generation
1const B = require('bluebird');2const {exec} = require('child_process');3const cmd1 = 'ls -la';4const cmd2 = 'ls -la';5B.Promise.all(6 [cmd1, cmd2].map(cmd => {7 return new B((resolve, reject) => {8 exec(cmd, (error, stdout, stderr) => {9 if (error) {10 return reject(error);11 }12 resolve(stdout);13 });14 });15 })16 .then(stdout => {17 console.log(stdout);18 })19 .catch(error => {20 console.log(error);21 });22const cmd1 = 'ls -la';23const cmd2 = 'ls -la';24const cmd1 = 'ls -la';25const cmd2 = 'ls -la /random/path';26const cmd1 = 'ls -la /random/path';27const cmd2 = 'ls -la';28const cmd1 = 'ls -la /random/path';29const cmd2 = 'ls -la /random/path';
Using AI Code Generation
1'use strict';2const B = require('bluebird');3var promise = new B(function(resolve, reject) {4 resolve(1);5});6var promiseArray = [];7promiseArray.push(promise);8B.Promise.all(promiseArray).then(function(value) {9 console.log(value);10});
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var B = require('bluebird');3var driver = new webdriver.Builder()4 .forBrowser('selenium')5 .build();6var searchBox = driver.findElement(webdriver.By.name('q'));7searchBox.sendKeys('webdriver');8searchBox.getAttribute('value').then(function(value) {9 console.log('value of search box is: ' + value);10});11var searchBtn = driver.findElement(webdriver.By.name('btnG'));12searchBtn.click();13var searchResults = driver.findElements(webdriver.By.css('.rc .r a'));14B.Promise.all(searchResults).each(function(element) {15 element.getText().then(function(text) {16 console.log('text of search result is: ' + text);17 });18});19driver.quit();
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!!