Bug 1242643 - Fix and re-enable js/xpconnect/tests/browser_dead_object.js by triggering onunload from new/added test page. r=jimm

This commit is contained in:
Tracy Walker 2016-03-08 12:38:19 -06:00
Родитель c30875f1e9
Коммит 6a7dad9d56
1 изменённых файлов: 124 добавлений и 160 удалений

Просмотреть файл

@ -1,193 +1,157 @@
/*
* This test checks that keyboard navigation for tabs isn't blocked by content
*/
function test() {
waitForExplicitFinish();
add_task(function* test() {
let testPage1 = "data:text/html,<html id='tab1'><body><button id='button1'>Tab 1</button></body></html>";
let testPage2 = "data:text/html,<html id='tab2'><body><button id='button2'>Tab 2</button><script>function preventDefault(event) { event.preventDefault(); event.stopImmediatePropagation(); } window.addEventListener('keydown', preventDefault, true); window.addEventListener('keypress', preventDefault, true);</script></body></html>";
let testPage3 = "data:text/html,<html id='tab3'><body><button id='button3'>Tab 3</button></body></html>";
let tab1 = gBrowser.addTab();
let tab1 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage1);
let browser1 = gBrowser.getBrowserForTab(tab1);
let tab2 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage2);
let tab3 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage3);
let tab2 = gBrowser.addTab();
let browser2 = gBrowser.getBrowserForTab(tab2);
// Kill the animation for simpler test.
Services.prefs.setBoolPref("browser.tabs.animate", false);
let tab3 = gBrowser.addTab();
let browser3 = gBrowser.getBrowserForTab(tab3);
gBrowser.selectedTab = tab1;
browser1.focus();
let loadCount = 0;
function check()
{
// wait for all tabs to load
if (++loadCount != 3) {
return;
}
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+Tab on Tab1");
browser1.removeEventListener("load", check, true);
browser2.removeEventListener("load", check, true);
browser3.removeEventListener("load", check, true);
executeSoon(_run_tab_keyboard_navigation_tests);
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+Tab on Tab2");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+Shift+Tab on Tab3");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+Shift+Tab on Tab2");
gBrowser.selectedTab = tab1;
browser1.focus();
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+PageDown on Tab1");
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+PageDown on Tab2");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+PageUp on Tab3");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+PageUp on Tab2");
if (gBrowser.mTabBox._handleMetaAltArrows) {
gBrowser.selectedTab = tab1;
browser1.focus();
let ltr = window.getComputedStyle(gBrowser.mTabBox, "").direction == "ltr";
let advanceKey = ltr ? "VK_RIGHT" : "VK_LEFT";
let reverseKey = ltr ? "VK_LEFT" : "VK_RIGHT";
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey(advanceKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + advanceKey + " on Tab1");
EventUtils.synthesizeKey(advanceKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+" + advanceKey + " on Tab2");
EventUtils.synthesizeKey(reverseKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + reverseKey + " on Tab3");
EventUtils.synthesizeKey(reverseKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2");
}
function _run_tab_keyboard_navigation_tests()
{
// Kill the animation for simpler test.
Services.prefs.setBoolPref("browser.tabs.animate", false);
gBrowser.selectedTab = tab2;
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated");
is(gBrowser.tabContainer.selectedIndex, 2,
"Tab2 index should be 2");
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated after Ctrl+Shift+PageDown");
is(gBrowser.tabContainer.selectedIndex, 3,
"Tab2 index should be 1 after Ctrl+Shift+PageDown");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated after Ctrl+Shift+PageUp");
is(gBrowser.tabContainer.selectedIndex, 2,
"Tab2 index should be 2 after Ctrl+Shift+PageUp");
if (navigator.platform.indexOf("Mac") == 0) {
gBrowser.selectedTab = tab1;
browser1.contentWindow.focus();
browser1.focus();
// XXX Currently, Command + "{" and "}" don't work if keydown event is
// consumed because following keypress event isn't fired.
let ltr = window.getComputedStyle(gBrowser.mTabBox, "").direction == "ltr";
let advanceKey = ltr ? "}" : "{";
let reverseKey = ltr ? "{" : "}";
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+Tab on Tab1");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
EventUtils.synthesizeKey(advanceKey, { metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + advanceKey + " on Tab1");
EventUtils.synthesizeKey(advanceKey, { metaKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+Tab on Tab2");
"Tab3 should be activated by pressing Ctrl+" + advanceKey + " on Tab2");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: true });
EventUtils.synthesizeKey(reverseKey, { metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+Shift+Tab on Tab3");
"Tab2 should be activated by pressing Ctrl+" + reverseKey + " on Tab3");
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: true });
EventUtils.synthesizeKey(reverseKey, { metaKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+Shift+Tab on Tab2");
gBrowser.selectedTab = tab1;
browser1.contentWindow.focus();
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+PageDown on Tab1");
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+PageDown on Tab2");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+PageUp on Tab3");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+PageUp on Tab2");
if (gBrowser.mTabBox._handleMetaAltArrows) {
gBrowser.selectedTab = tab1;
browser1.contentWindow.focus();
let ltr =
window.getComputedStyle(gBrowser.mTabBox, "").direction == "ltr";
let advanceKey = ltr ? "VK_RIGHT" : "VK_LEFT";
let reverseKey = ltr ? "VK_LEFT" : "VK_RIGHT";
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey(advanceKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + advanceKey + " on Tab1");
EventUtils.synthesizeKey(advanceKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+" + advanceKey + " on Tab2");
EventUtils.synthesizeKey(reverseKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + reverseKey + " on Tab3");
EventUtils.synthesizeKey(reverseKey, { altKey: true, metaKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2");
}
"Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2");
} else {
gBrowser.selectedTab = tab2;
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated");
is(gBrowser.tabContainer.selectedIndex, 2,
"Tab2 index should be 2");
EventUtils.synthesizeKey("VK_F4", { type: "keydown", ctrlKey: true });
EventUtils.synthesizeKey("VK_PAGE_DOWN", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated after Ctrl+Shift+PageDown");
is(gBrowser.tabContainer.selectedIndex, 3,
"Tab2 index should be 1 after Ctrl+Shift+PageDown");
isnot(gBrowser.selectedTab, tab2,
"Tab2 should be closed by pressing Ctrl+F4 on Tab2");
is(gBrowser.tabs.length, 3,
"The count of tabs should be 3 since tab2 should be closed");
EventUtils.synthesizeKey("VK_PAGE_UP", { ctrlKey: true, shiftKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated after Ctrl+Shift+PageUp");
is(gBrowser.tabContainer.selectedIndex, 2,
"Tab2 index should be 2 after Ctrl+Shift+PageUp");
if (navigator.platform.indexOf("Mac") == 0) {
gBrowser.selectedTab = tab1;
browser1.contentWindow.focus();
// XXX Currently, Command + "{" and "}" don't work if keydown event is
// consumed because following keypress event isn't fired.
let ltr =
window.getComputedStyle(gBrowser.mTabBox, "").direction == "ltr";
let advanceKey = ltr ? "}" : "{";
let reverseKey = ltr ? "{" : "}";
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated");
EventUtils.synthesizeKey(advanceKey, { metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + advanceKey + " on Tab1");
EventUtils.synthesizeKey(advanceKey, { metaKey: true });
is(gBrowser.selectedTab, tab3,
"Tab3 should be activated by pressing Ctrl+" + advanceKey + " on Tab2");
EventUtils.synthesizeKey(reverseKey, { metaKey: true });
is(gBrowser.selectedTab, tab2,
"Tab2 should be activated by pressing Ctrl+" + reverseKey + " on Tab3");
EventUtils.synthesizeKey(reverseKey, { metaKey: true });
is(gBrowser.selectedTab, tab1,
"Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2");
} else {
gBrowser.selectedTab = tab2;
EventUtils.synthesizeKey("VK_F4", { type: "keydown", ctrlKey: true });
isnot(gBrowser.selectedTab, tab2,
"Tab2 should be closed by pressing Ctrl+F4 on Tab2");
let activeWindow = gBrowser.getBrowserForTab(gBrowser.selectedTab).contentWindow;
// NOTE: keypress event shouldn't be fired since the keydown event should
// be consumed by tab2.
EventUtils.synthesizeKey("VK_F4", { type: "keyup", ctrlKey: true });
is(gBrowser.tabs.length, 3,
"The count of tabs should be 3 since tab2 should be closed");
"The count of tabs should be 3 since renaming key events shouldn't close other tabs");
}
let activeWindow =
gBrowser.getBrowserForTab(gBrowser.selectedTab).contentWindow;
// NOTE: keypress event shouldn't be fired since the keydown event should
// be consumed by tab2.
EventUtils.synthesizeKey("VK_F4", { type: "keyup", ctrlKey: true });
is(gBrowser.tabs.length, 3,
"The count of tabs should be 3 since renaming key events shouldn't close other tabs");
}
gBrowser.selectedTab = tab3;
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
gBrowser.selectedTab = tab3;
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
Services.prefs.clearUserPref("browser.tabs.animate");
finish();
}
browser1.addEventListener("load", check, true);
browser2.addEventListener("load", check, true);
browser3.addEventListener("load", check, true);
browser1.contentWindow.location = testPage1;
browser2.contentWindow.location = testPage2;
browser3.contentWindow.location = testPage3;
}
});