Written on Jul 9, 2018
I’m trying to create tests for this bug https://bugzilla.mozilla.org/show_bug.cgi?id=1419960 and I am not sure how to test that executing window.open(url, "_blank", "noopener")
opens a new tab. Another intern mentioned I could look in browser*
test APIs.
browser*
tests and perhaps they could be helpful./browser/base/content/test
. A lot of tests are located in browser/base/content/test/general
but developers are no longer allowed to place their tests in that directory and instead are instructed to place their tests in other more specific directories.browser/base/content/test/general
and browser/base/content/test/tabs
directories, paying close attention to any tests that have the word ‘tab’ in them.I found the following things useful
function checkTabs(aTabs) {
is(gBrowser.tabs.length, aTabs, "number of open tabs should be " + aTabs);
}
browser/base/content/test/tabs/browser_new_web_tab_in_file_process_pref.js
BrowserTestUtils
API contains useful functions such as ‘open a new tab in the foreground’ or ‘wait for a page load in browser window to complete’ source/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
Somehow, when I use withNewTab
, while opening an html page with the above code, the browser only shows that we have 2 tabs open. Need to figure out another way to open the page.
There is another property getVisibleTabs on browser, so perhaps I could try that.
Realized that withNewTab takes a task and runs it while the tab is loading. I need the task to run after the tab has loaded. Will look into openNewForegroundTab
Using openNewForegroundTab
now. Spent the last hour trying to figure out how to pass a message from the newly opened tab to the ‘noopener test’ tab, only to realize I don’t need to pass a message because I can simply wait on the condition. Things are finally working!