How to use waitForPageShow method in wpt

Best JavaScript code snippet using wpt

browser_readerMode.js

Source:browser_readerMode.js Github

copy

Full Screen

1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4/**5 * Test that the reader mode button appears and works properly on6 * reader-able content.7 */8const TEST_PREFS = [9 ["reader.parse-on-load.enabled", true],10];11const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");12var readerButton = document.getElementById("reader-mode-button");13add_task(function* test_reader_button() {14 registerCleanupFunction(function() {15 // Reset test prefs.16 TEST_PREFS.forEach(([name, value]) => {17 Services.prefs.clearUserPref(name);18 });19 while (gBrowser.tabs.length > 1) {20 gBrowser.removeCurrentTab();21 }22 });23 // Set required test prefs.24 TEST_PREFS.forEach(([name, value]) => {25 Services.prefs.setBoolPref(name, value);26 });27 Services.prefs.setBoolPref("browser.reader.detectedFirstArticle", false);28 let tab = gBrowser.selectedTab = gBrowser.addTab();29 is_element_hidden(readerButton, "Reader mode button is not present on a new tab");30 ok(!UITour.isInfoOnTarget(window, "readerMode-urlBar"),31 "Info panel shouldn't appear without the reader mode button");32 ok(!Services.prefs.getBoolPref("browser.reader.detectedFirstArticle"),33 "Shouldn't have detected the first article");34 // We're going to show the reader mode intro popup, make sure we wait for it:35 let tourPopupShownPromise =36 BrowserTestUtils.waitForEvent(document.getElementById("UITourTooltip"), "popupshown");37 // Point tab to a test page that is reader-able.38 let url = TEST_PATH + "readerModeArticle.html";39 yield promiseTabLoadEvent(tab, url);40 yield promiseWaitForCondition(() => !readerButton.hidden);41 yield tourPopupShownPromise;42 is_element_visible(readerButton, "Reader mode button is present on a reader-able page");43 ok(UITour.isInfoOnTarget(window, "readerMode-urlBar"),44 "Info panel should be anchored at the reader mode button");45 ok(Services.prefs.getBoolPref("browser.reader.detectedFirstArticle"),46 "Should have detected the first article");47 // Switch page into reader mode.48 readerButton.click();49 yield promiseTabLoadEvent(tab);50 ok(!UITour.isInfoOnTarget(window, "readerMode-urlBar"), "Info panel should have closed");51 let readerUrl = gBrowser.selectedBrowser.currentURI.spec;52 ok(readerUrl.startsWith("about:reader"), "about:reader loaded after clicking reader mode button");53 is_element_visible(readerButton, "Reader mode button is present on about:reader");54 is(gURLBar.value, readerUrl, "gURLBar value is about:reader URL");55 is(gURLBar.textValue, url.substring("http://".length), "gURLBar is displaying original article URL");56 // Check selected value for URL bar57 yield new Promise((resolve, reject) => {58 waitForClipboard(url, function () {59 gURLBar.focus();60 gURLBar.select();61 goDoCommand("cmd_copy");62 }, resolve, reject);63 });64 info("Got correct URL when copying");65 // Switch page back out of reader mode.66 let promisePageShow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");67 readerButton.click();68 yield promisePageShow;69 is(gBrowser.selectedBrowser.currentURI.spec, url,70 "Back to the original page after clicking active reader mode button");71 ok(gBrowser.selectedBrowser.canGoForward,72 "Moved one step back in the session history.");73 // Load a new tab that is NOT reader-able.74 let newTab = gBrowser.selectedTab = gBrowser.addTab();75 yield promiseTabLoadEvent(newTab, "about:robots");76 yield promiseWaitForCondition(() => readerButton.hidden);77 is_element_hidden(readerButton, "Reader mode button is not present on a non-reader-able page");78 // Switch back to the original tab to make sure reader mode button is still visible.79 gBrowser.removeCurrentTab();80 yield promiseWaitForCondition(() => !readerButton.hidden);81 is_element_visible(readerButton, "Reader mode button is present on a reader-able page");82});83add_task(function* test_getOriginalUrl() {84 let { ReaderMode } = Cu.import("resource://gre/modules/ReaderMode.jsm", {});85 let url = "http://foo.com/article.html";86 is(ReaderMode.getOriginalUrl("about:reader?url=" + encodeURIComponent(url)), url, "Found original URL from encoded URL");87 is(ReaderMode.getOriginalUrl("about:reader?foobar"), null, "Did not find original URL from malformed reader URL");88 is(ReaderMode.getOriginalUrl(url), null, "Did not find original URL from non-reader URL");89 let badUrl = "http://foo.com/?;$%^^";90 is(ReaderMode.getOriginalUrl("about:reader?url=" + encodeURIComponent(badUrl)), badUrl, "Found original URL from encoded malformed URL");91 is(ReaderMode.getOriginalUrl("about:reader?url=" + badUrl), badUrl, "Found original URL from non-encoded malformed URL");92});93add_task(function* test_reader_view_element_attribute_transform() {94 registerCleanupFunction(function() {95 while (gBrowser.tabs.length > 1) {96 gBrowser.removeCurrentTab();97 }98 });99 function observeAttribute(element, attribute, triggerFn, checkFn) {100 return new Promise(resolve => {101 let observer = new MutationObserver((mutations) => {102 mutations.forEach( mu => {103 if (element.getAttribute(attribute) !== mu.oldValue) {104 checkFn();105 resolve();106 observer.disconnect();107 }108 });109 });110 observer.observe(element, {111 attributes: true,112 attributeOldValue: true,113 attributeFilter: [attribute]114 });115 triggerFn();116 });117 }118 let command = document.getElementById("View:ReaderView");119 let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);120 is(command.hidden, true, "Command element should have the hidden attribute");121 info("Navigate a reader-able page");122 let waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");123 yield observeAttribute(command, "hidden",124 () => {125 let url = TEST_PATH + "readerModeArticle.html";126 tab.linkedBrowser.loadURI(url);127 },128 () => {129 is(command.hidden, false, "Command's hidden attribute should be false on a reader-able page");130 }131 );132 yield waitForPageshow;133 info("Navigate a non-reader-able page");134 waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");135 yield observeAttribute(command, "hidden",136 () => {137 let url = TEST_PATH + "readerModeArticleHiddenNodes.html";138 tab.linkedBrowser.loadURI(url);139 },140 () => {141 is(command.hidden, true, "Command's hidden attribute should be true on a non-reader-able page");142 }143 );144 yield waitForPageshow;145 info("Navigate a reader-able page");146 waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");147 yield observeAttribute(command, "hidden",148 () => {149 let url = TEST_PATH + "readerModeArticle.html";150 tab.linkedBrowser.loadURI(url);151 },152 () => {153 is(command.hidden, false, "Command's hidden attribute should be false on a reader-able page");154 }155 );156 yield waitForPageshow;157 info("Enter Reader Mode");158 waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");159 yield observeAttribute(readerButton, "readeractive",160 () => {161 readerButton.click();162 },163 () => {164 is(readerButton.getAttribute("readeractive"), "true", "readerButton's readeractive attribute should be true when entering reader mode");165 }166 );167 yield waitForPageshow;168 info("Exit Reader Mode");169 waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");170 yield observeAttribute(readerButton, "readeractive",171 () => {172 readerButton.click();173 },174 () => {175 is(readerButton.getAttribute("readeractive"), "", "readerButton's readeractive attribute should be empty when reader mode is exited");176 }177 );178 yield waitForPageshow;179 info("Navigate a non-reader-able page");180 waitForPageshow = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");181 yield observeAttribute(command, "hidden",182 () => {183 let url = TEST_PATH + "readerModeArticleHiddenNodes.html";184 tab.linkedBrowser.loadURI(url);185 },186 () => {187 is(command.hidden, true, "Command's hidden attribute should be true on a non-reader-able page");188 }189 );190 yield waitForPageshow;...

Full Screen

Full Screen

browser_isSynthetic.js

Source:browser_isSynthetic.js Github

copy

Full Screen

...15 Ci.nsISupportsWeakReference])16}17const FILES = gTestPath.replace("browser_isSynthetic.js", "")18 .replace("chrome://mochitests/content/", "http://example.com/");19function waitForPageShow(browser) {20 return ContentTask.spawn(browser, null, function*() {21 Cu.import("resource://gre/modules/PromiseUtils.jsm");22 yield new Promise(resolve => {23 let listener = () => {24 removeEventListener("pageshow", listener, true);25 resolve();26 }27 addEventListener("pageshow", listener, true);28 });29 });30}31add_task(function*() {32 let tab = gBrowser.addTab("about:blank");33 let browser = tab.linkedBrowser;34 yield BrowserTestUtils.browserLoaded(browser);35 let listener = new LocationChangeListener(browser);36 is(browser.isSyntheticDocument, false, "Should not be synthetic");37 let loadPromise = waitForPageShow(browser);38 browser.loadURI("data:text/html;charset=utf-8,<html/>");39 yield loadPromise;40 is(listener.wasSynthetic, false, "Should not be synthetic");41 is(browser.isSyntheticDocument, false, "Should not be synthetic");42 loadPromise = waitForPageShow(browser);43 browser.loadURI(FILES + "empty.png");44 yield loadPromise;45 is(listener.wasSynthetic, true, "Should be synthetic");46 is(browser.isSyntheticDocument, true, "Should be synthetic");47 loadPromise = waitForPageShow(browser);48 browser.goBack();49 yield loadPromise;50 is(listener.wasSynthetic, false, "Should not be synthetic");51 is(browser.isSyntheticDocument, false, "Should not be synthetic");52 loadPromise = waitForPageShow(browser);53 browser.goForward();54 yield loadPromise;55 is(listener.wasSynthetic, true, "Should be synthetic");56 is(browser.isSyntheticDocument, true, "Should be synthetic");57 listener.destroy();58 gBrowser.removeTab(tab);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = require('wpt');3wpt.waitForPageShow(function() {4 wpt.waitForPageShow(function() {5 console.log('page is fully loaded');6 console.log('page is fully loaded');7 });8});9var wpt = require('wpt');10var wpt = require('wpt');11wpt.waitForPageShow(function() {12 wpt.waitForPageShow(function() {13 console.log('page is fully loaded');14 console.log('page is fully loaded');15 });16});17var wpt = require('wpt');18var wpt = require('wpt');19wpt.waitForPageShow(function() {20 wpt.waitForPageShow(function() {21 console.log('page is fully loaded');22 console.log('page is fully loaded');23 });24});25var wpt = require('wpt');26var wpt = require('wpt');27wpt.waitForPageShow(function() {28 wpt.waitForPageShow(function() {29 console.log('page is fully loaded');30 console.log('page is fully loaded');31 });32});33var wpt = require('wpt');34var wpt = require('wpt');35wpt.waitForPageShow(function() {36 wpt.waitForPageShow(function() {37 console.log('page is fully loaded');38 console.log('page is fully loaded');39 });40});41var wpt = require('wpt');42var wpt = require('wpt');43wpt.waitForPageShow(function() {44 wpt.waitForPageShow(function() {45 console.log('page is fully loaded');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptb = require('wptb');2wptb.waitForPageShow(function() {3});4var wptb = require('wptb');5wptb.waitForPageShow(function() {6});7var wptb = require('wptb');8wptb.waitForPageShow(function() {9});10var wptb = require('wptb');11wptb.waitForPageShow(function() {12});13var wptb = require('wptb');14wptb.waitForPageShow(function() {15});16var wptb = require('wptb');17wptb.waitForPageShow(function() {18});19var wptb = require('wptb');20wptb.waitForPageShow(function() {21});22var wptb = require('wptb');23wptb.waitForPageShow(function() {24});25var wptb = require('wptb');26wptb.waitForPageShow(function() {27});28var wptb = require('wptb');29wptb.waitForPageShow(function() {30});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptb = require('wptb');2wptb.waitForPageShow(function() {3 console.log('page is now shown');4});5var wptb = require('wptb');6wptb.waitForPageShow(function() {7 console.log('page is now shown');8});9var wptb = require('wptb');10wptb.waitForPageShow(function() {11 console.log('page is now shown');12});13var wptb = require('wptb');14wptb.waitForPageShow(function() {15 console.log('page is now shown');16});17var wptb = require('wptb');18wptb.waitForPageShow(function() {19 console.log('page is now shown');20});21var wptb = require('wptb');22wptb.waitForPageShow(function() {23 console.log('page is now shown');24});25var wptb = require('wptb');26wptb.waitForPageShow(function() {27 console.log('page is now shown');28});29var wptb = require('wptb');30wptb.waitForPageShow(function() {31 console.log('page is now shown');32});33var wptb = require('wptb');34wptb.waitForPageShow(function() {35 console.log('page is now shown');36});37var wptb = require('wptb');38wptb.waitForPageShow(function() {39 console.log('page is now shown');40});41var wptb = require('wptb');42wptb.waitForPageShow(function() {43 console.log('page is now shown');44});45var wptb = require('wptb');46wptb.waitForPageShow(function() {47 console.log('

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2wptdriver.waitForPageShow(function() {3 wptdriver.log('page show event fired');4});5var wptdriver = require('wptdriver');6wptdriver.waitForPageShow(function() {7 wptdriver.log('page show event fired');8});9var wptdriver = require('wptdriver');10wptdriver.waitForPageShow(function() {11 wptdriver.log('page show event fired');12});13var wptdriver = require('wptdriver');14wptdriver.waitForPageShow(function() {15 wptdriver.log('page show event fired');16});17var wptdriver = require('wptdriver');18wptdriver.waitForPageShow(function() {19 wptdriver.log('page show event fired');20});21var wptdriver = require('wptdriver');22wptdriver.waitForPageShow(function() {23 wptdriver.log('page show event fired');24});25var wptdriver = require('wptdriver');26wptdriver.waitForPageShow(function() {27 wptdriver.log('page show event fired');28});29var wptdriver = require('wptdriver');30wptdriver.waitForPageShow(function() {31 wptdriver.log('page show event fired');32});33var wptdriver = require('wptdriver');34wptdriver.waitForPageShow(function() {35 wptdriver.log('page show event fired');36});37var wptdriver = require('wptdriver');38wptdriver.waitForPageShow(function() {39 wptdriver.log('page show event fired');40});

Full Screen

Using AI Code Generation

copy

Full Screen

1waitForPageShow(function() {2});3function waitForPageShow(callback) {4 if (document.readyState === 'complete') {5 callback();6 } else {7 window.addEventListener('pageshow', function pageShow() {8 window.removeEventListener('pageshow', pageShow);9 callback();10 });11 }12}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-driver');2wpt.waitForPageShow(function() {3});4var wpt = require('wpt-driver');5wpt.waitForPageShow(function() {6});7var wpt = require('wpt-driver');8wpt.waitForPageShow(function() {9});10var wpt = require('wpt-driver');11wpt.waitForPageShow(function() {12});13var wpt = require('wpt-driver');14wpt.waitForPageShow(function() {15});16var wpt = require('wpt-driver');17wpt.waitForPageShow(function() {18});19var wpt = require('wpt-driver');20wpt.waitForPageShow(function() {21});22var wpt = require('wpt-driver');23wpt.waitForPageShow(function() {24});25var wpt = require('wpt-driver');26wpt.waitForPageShow(function() {27});28var wpt = require('wpt-driver');29wpt.waitForPageShow(function() {30});31var wpt = require('wpt-driver');32wpt.waitForPageShow(function()

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var wpt = require('webpagetest');3 build();4driver.getTitle().then(function(title) {5 console.log(title);6});7driver.quit();8var webdriver = require('selenium-webdriver');9var wpt = require('webpagetest');10 build();11driver.getTitle().then(function(title) {12 console.log(title);13});14driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3c9d0f1b1b9b9b9b9b9b9b9b9b9b9b9b');3var testId;4wpt.runTest(url, {runs: 1, location: 'Dulles:Chrome'}, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 testId = data.data.testId;9 wpt.waitForTestStart(testId, function(err, data) {10 if (err) {11 console.log(err);12 } else {13 wpt.waitForTestComplete(testId, function(err, data) {14 if (err) {15 console.log(err);16 } else {17 wpt.getTestResults(testId, function(err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log(data.data.median.firstView.SpeedIndex);22 }23 });24 }25 });26 }27 });28 }29});

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