contentScript: "new " + function WorkerScope() { let id1 = setTimeout(function() { self.postMessage("failed"); }, 10); let id2 = setTimeout(function() { self.postMessage("done"); }, 100); clearTimeout(id1); },
function triggerReturn(immediate) { lastTriggerReturn = new Date().getTime(); console.log("Receiving triggerReturn in main.js"); if (eventTriggeringEnabled) { if (immediate) { timers.setTimeout(tryToTrigger, 0); } else { var interval = config.getMaxDelayBetweenEvents() - config.getMinDelayBetweenEvents(); var randFromInterval = commonUtil.randInt(interval + 1); var delay = config.getMinDelayBetweenEvents() + randFromInterval; console.log("Will trigger next event after " + delay + " ms"); timers.setTimeout(tryToTrigger, delay); } } }
browser.addEventListener("pagehide", function onpagehide() { browser.removeEventListener("pagehide", onpagehide, false); // Now any event sent to this worker should throw test.assertRaises( function () { worker.postMessage("data"); }, "The page is currently hidden and can no longer be used until it" + " is visible again.", "postMessage should throw when the page is hidden in history" ); test.assertRaises( function () { worker.port.emit("event"); }, "The page is currently hidden and can no longer be used until it" + " is visible again.", "port.emit should throw when the page is hidden in history" ); // Display the page with attached content script back in order to resume // its timeout and receive the expected message. // We have to delay this in order to not break the history. // We delay for a non-zero amount of time in order to ensure that we // do not receive the message immediatly, so that the timeout is // actually disabled setTimeout(function () { worker.on("message", function (data) { test.assert(data, "timeout restored"); done(); }); browser.goForward(); }, 500); }, false);
_asyncBuildPlacesCache: Task.async(function*() { if (simplePrefs.prefs["query.cache"]) { if (this._populatingCache && !this._populatingCache.places) { this._populatingCache.places = true; let opt = {replace: true}; yield Promise.all([ this._memoized.getTopFrecentSites(opt), this._memoized.getRecentBookmarks(opt), this._memoized.getRecentLinks(opt), this._memoized.getHighlightsLinks(opt), this._memoized.getHistorySize(opt), this._memoized.getBookmarksSize(opt), ]); this._populatingCache.places = false; Services.obs.notifyObservers(null, "activity-streams-places-cache-complete", null); } // Call myself when cache expires to repopulate. // This is needed because some of the queries are time dependent (for example, // highlights excludes links from the past 30 minutes). if (this._placesCacheTimeoutID) { clearTimeout(this._placesCacheTimeoutID); } this._placesCacheTimeoutID = setTimeout(() => { this._asyncBuildPlacesCache(); }, this.options.placesCacheTimeout); } }),
function getValueFromClosestPeers() { for (var i = 0; i < REPLICATION_FACTOR; i++) { closestServer.get(ORIGIN_SERVER, function(err, pageText, signature) { if (err) { assert.ok(false, ORIGIN_SERVER + ' should be replicated to this peer'); } else { var publicKeyCache = new PublicKeyCache(); var publicKey = publicKeyCache.keyForHostname(ORIGIN_SERVER, function(publicKey) { var valid = verifier.verify(publicKey, pageText, signature); assert.ok(valid, 'peers should return valid content'); if (valid) { ++numPeersThatHaveStoredTheValue; } } ); } }); // wait to get all the values timers.setTimeout(function() { assert.equal(REPLICATION_FACTOR, numPeersThatHaveStoredTheValue, 'The content should have replicated to ' + REPLICATION_FACTOR + ' peers. It was replicated to ' + numPeersThatHaveStoredTheValue); done(); }, STORE_TIMEOUT); } }
this.onSelectResult = function(selectedItems) { log.debug("Invoking Tools"); var uris = []; for (let item in selectedItems) { let resultData = selectedItems[item].resultData; try { // Brute force async timers.setTimeout(function() { log.debug("Invoking tool: " + resultData.id); ko.toolbox2.invokeTool(resultData.data.tool.koTool); }, 0) } catch(e) { log.exception(e, "Failed to invoke tool: "); } } commando.hideCommando(); }
function firstClick() { button.disabled = true; getPrefCred(); clearInterval(loopID); setTimeout(enableButton, 10000) }
function onTabReady(tab) { if (/^about:/.test(tab.url)) { return; } let tabId = tab.id; timers.setTimeout(() => { tabInfo.get(tabId).jsSources.forEach((url) => { let details = { url: url, tabId: tabId }; scanner.scan(details); }); }, 1000); // Add an unload listener to the tab's page in order to reset the button badge on back/forward cache (bfCache) function onUnload() { if (tabs.activeTab.id == tabId) { console.log("unload"); updateButton(null); tabUtil.getTabContentWindow(firefox.getBrowserTabElement(tabId)).removeEventListener("unload", onUnload); } } tabUtil.getTabContentWindow(firefox.getBrowserTabElement(tabId)).addEventListener("unload", onUnload); console.log("tab ready: " + tabId); }
onOpen: function(window) { setTimeout(function () { assert.ok(!called, "Unloaded windows instance is destroyed and inactive"); window.close(done); }); }
function wait(ms) { let deferred = promise.defer(); timers.setTimeout(() => { deferred.resolve(); }, ms); return deferred.promise; }
function applySuggestion(error, replacement, contextLeft, contextRight) { replaceWorker = tabs.activeTab.attach({ contentScriptFile: self.data.url("replaceText.js"), }); replaceWorker.port.emit("applySuggestion", error, replacement, contextLeft, contextRight, _("applySuggestionNoTextField")); timer.setTimeout(recheck, RECHECKDELAY); }
onUntrack: window => { if (window === myWindow) { assert.pass("onUntrack() called with our test window"); wt.unload(); timer.setTimeout(done); } }
function play(audio){ var soundPlayer = pageworker.Page({ contentURL: "./blank.html", contentScript: "new Audio('" + audio + "').play();" }); setTimeout(function(){soundPlayer.destroy();},5000); };
Css.setClassTimed = function(elt, name, timeout = 1300) { if (elt.__setClassTimeout) { // then we are already waiting to remove the class mark context.clearTimeout(elt.__setClassTimeout); } else { // then we are not waiting to remove the mark elt.classList.add(name); } // xxxHonza: FIXME if (false/*!Xml.isVisible(elt)*/) { if (elt.__invisibleAtSetPoint) { elt.__invisibleAtSetPoint--; } else { elt.__invisibleAtSetPoint = 5; } } else { delete elt.__invisibleAtSetPoint; } elt.__setClassTimeout = setTimeout(function() { delete elt.__setClassTimeout; if (elt.__invisibleAtSetPoint) { // then user can't see it, try again later Css.setClassTimed(elt, name, context, timeout); } else { // may be zero delete elt.__invisibleAtSetPoint; elt.classList.remove(name); } }, timeout); };
var blur = () => { log.debug("Panel blur"); interacting = false; panel.timeout = timers.setTimeout(this.hideNotification.bind(this, notif), 1000); };
let id = setInterval(function() { self.postMessage("intreval") clearInterval(id) setTimeout(function() { self.postMessage("done") }, 100) }, 10);
function sendTabdata() { var tabdata = makeTabObject(); panel.port.emit('currentTabInfo',tabdata ); if( !tabdata.value || !tabdata.value.stage || tabdata.value.stage == 'search' || tabdata.value.stage == 'mark' ) { setTimeout(sendTabdata,100); } }
this.autoObserver = function(event) { if(event.type == 'http-on-examine-response') { var httpChannel = event.subject.QueryInterface(Ci.nsIHttpChannel); // dunno why I can't access Origin via getRequestHeader, so I use visit instead : var Origin = null; httpChannel.visitRequestHeaders(function(header, value){ if (header == "Origin") { origin = new URL.URL(value); } }); if (origin == null) return; if (InjectCors.isAutoReferrer(InjectCors.getAutoReferrers(), origin)) { var headers = InjectCors.getHeaders(); InjectCors.addHeadersToResponse(headers, httpChannel); if (greenIconTimeout !== null){ Timers.clearTimeout(greenIconTimeout); } greenIconTimeout = Timers.setTimeout(function(){ button.icon = "./force_cors_inactive.png"; }, 2000); button.icon = "./force_cors_auto.png"; } } };
return new Promise(resolve => { const { loader } = this; if (loader) { this.loader = null; unload(loader, reason); setTimeout(() => { for (let uri of Object.keys(loader.sandboxes)) { try { Cu.nukeSandbox(loader.sandboxes[uri]); } catch (e) { // This will throw for shared sandboxes. } delete loader.sandboxes[uri]; delete loader.modules[uri]; } try { Cu.nukeSandbox(loader.sharedGlobalSandbox); } catch (e) { Cu.reportError(e); } resolve(); }, 1000); } else { resolve(); } });
return new Promise(resolve => { const experiment = options.experiment; const uiTimeout = setTimeout(uiClosed, options.duration || 60000); const label = options.interval === 'eol' ? _('survey_launch_survey_label', experiment.title) : _('survey_show_rating_label', experiment.title); let experimentRating = null; const { notifyBox, box } = createNotificationBox({ label, image: experiment.thumbnail, child: win => createRatingUI(win.document, uiClosed), persistence: options.persistence, pulse: true, callback: () => { clearTimeout(uiTimeout); resolve(experimentRating); } }); function uiClosed(rating) { experimentRating = rating; notifyBox.removeNotification(box); } });
exports.CookieTracker.prototype.scheduleExpiration = function(cookie, tracking) { var handler = this.onExpired; var key = this.cookieToKey(cookie); var handles = this.expirationHandles; this.cancelExpiration(cookie); this.expirationHandles[key] = timers.setTimeout(function(){delete handles[key]; handler(cookie, tracking, false)}, this.gracePeriod * 1000); }
return new Promise(resolve => { const { notifyBox, box } = createNotificationBox({ label: _('share_label'), image: 'resource://@testpilot-addon/data/icon-64.png', persistence: 10, buttons: [ { label: _('share_button'), callback: () => { tabs.open({ url }); } } ], callback: () => { clearTimeout(uiTimeout); resolve(); } }); const uiTimeout = setTimeout( () => { notifyBox.removeNotification(box); }, 60000 ); });
servers[1].get(key, function(err, pageText, signature) { if (err) { assert.ok(false, 'The pageText and signature should be returned to servers[1]'); } else { // wait for the store command to be received by the closest peer // to the key timers.setTimeout(function() { closestServer.get(key, function(err, pText, sig) { if (err) { assert.ok(false, 'The pageText and signature should have been stored in the ' + 'peer with the id closest to the key, after server[1] found ' + 'the value, but not from this peer.'); } else { assert.equal(pageText, pText, 'The pageText should be stored in the closest node'); assert.equal(signature, sig, 'The signature should be stored in the closest node'); } done(); }); }, STORE_TIMEOUT); } });
return new Promise(resolve => { let clicked = false; const { experiment, duration } = options; const { notifyBox, box } = createNotificationBox({ label: _('survey_rating_thank_you', experiment.title), image: experiment.thumbnail, buttons: [ { label: _('survey_rating_survey_button'), callback: () => { clicked = true; } } ], callback: () => { clearTimeout(uiTimeout); resolve(clicked); } }); const uiTimeout = setTimeout( () => { notifyBox.removeNotification(box); }, duration || 60000 ); });
}).then(function (resolve, reject) { hotkeyWorker.onerror = reject; assert.pass("successfully registered hotkeys"); //Todo: something to test that the hotkeys are registered hotkeyWorker.postMessage("detach"); setTimeout(resolve, 500); }).then(function(resolve,reject){
socketapi.exec(function(res) { assert.ok(res.error === undefined, "server socket.udp.udpBind no error"); // start client side and listen for responses timers.setTimeout(cli, 0); socketapi.exec(function(res) { assert.ok((res.error === undefined), "server socket.udp.udpRecvFromStart no error"); if (res.data && res.data === "foo") { // got ping - send pong assert.ok(true, "server socket.udp.udpRecvFromStart got ping"); // add the host to the server list so that we can send // data back manifest.neighbors['server'] = {}; manifest.neighbors['server'][res.address] = true; socketapi.exec(function(res) { assert.ok(res.error === undefined, "server socket.udp.udpSendTo no error"); }, getreq('udpSendTo',[s,res.data,res.address,res.port]),manifest); } }, getreq('udpRecvFromStart', [s, true], true),manifest); }, getreq('udpBind',[s, 0, PORT, true]),manifest);
loadPlaceholders: function () { var self = this; console.log('BW: Loading data for ' + self.urls[0]); new Request({ url: self.urls[0], onComplete: function (response) { if (response.text.length < 100 || response.status < 200 || response.status >= 300) { if (self.urls.length > 1) { console.log('BW: ' + self.urls[0] + ' failed. Popping.'); self.urls.shift(); timers.setTimeout(self.loadPlaceholders.bind(self), 1); } else { console.log('BW: ' + self.urls[0] + ' failed. Nothing left to pop.'); } return; } var result = response.text.split('\n'); result = result.map(function (x) { return x.trim(); }).filter(function (x) { return !x.startsWith('#') && (x !== ''); }); self.PLACEHOLDERS = result; } }).get(); timers.setTimeout(self.loadPlaceholders.bind(self), 4 * 60 * 60 * 1000); },
mainWin.addEventListener("load", function pageLoaded() { timer.setTimeout(function delayedTest() { var currentWidth = mainWin.innerWidth; test.assert( originalWidth != currentWidth); test.done(); },500); },false);
worker.port.once('message-event', function(msg) { if (callback) { // first event on port will fire callback after 200ms delay //console.log('starting attach callback timer', msg.event, Date.now()); timer.setTimeout(callback.bind(this, tab), 200); } });
exports.callScript = function (tab, script, message, payload, timeout) { if (timeout === undefined) { timeout = 7000; } exports.addScript(tab, script); let browser = getBrowser(tab); let messages = browser.framescripterEnabledScripts[script]; let browserMM = browser.messageManager; if (! messages[message]) { browserMM.addMessageListener(message + ":return", callScriptReturner); messages[message] = true; logDebug("Adding frame listener for:", message + ":return"); } let deferred = defer(); let id = makeId(); pendingDeferreds[id] = deferred; payload.callId = id; logDebug("Sending [" + message + ":call]/" + id + " with payload:", payload); browserMM.sendAsyncMessage(message + ":call", payload); if (timeout) { pendingTimeouts[id] = setTimeout(function () { if (pendingDeferreds[id]) { // The promise has not yet completed var deferred = pendingDeferreds[id]; delete pendingDeferreds[id]; delete pendingTimeouts[id]; logDebug("Script timed out:", script, message, "after:", timeout); deferred.reject(new Error("Timeout after " + timeout + "ms in " + message)); } else { logDebug("Timeout ran despite deferred being completed, for:", script, message); } }, timeout); } return deferred.promise; };