Bug 1555060 Rewrite webextension tabs.move tests r=kmag

These tests are full of too many problems to catalog here.
This patch just rewrites them to make them less insane.

Differential Revision: https://phabricator.services.mozilla.com/D34647

--HG--
extra : source : c71c45fe3e63c9fb97551654d079344448c49c6e
extra : histedit_source : 7caaeeed52e6937cb55dbd33b0156bc2762a0f16
This commit is contained in:
Andrew Swan 2019-06-03 21:10:14 -07:00
Родитель 9e8f08b278
Коммит c716c93bbf
3 изменённых файлов: 97 добавлений и 79 удалений

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

@ -3,54 +3,78 @@
"use strict";
add_task(async function() {
await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.net/");
let window1 = await BrowserTestUtils.openNewBrowserWindow();
await BrowserTestUtils.openNewForegroundTab(window1.gBrowser, "http://example.com/");
let window2 = await BrowserTestUtils.openNewBrowserWindow({private: true});
await BrowserTestUtils.openNewForegroundTab(window2.gBrowser, "http://example.com/");
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
},
incognitoOverride: "spanning",
async background() {
let tabs = await browser.tabs.query({url: "<all_urls>"});
let destination = tabs[0];
let source = tabs[1]; // skip over about:blank in window1
let privateTab = tabs[2];
browser.test.assertTrue(privateTab.incognito, "have a private tab.");
const URL = "http://example.com/";
let mainWindow = await browser.windows.getCurrent();
let newWindow = await browser.windows.create({
url: [URL, URL],
});
let privateWindow = await browser.windows.create({
incognito: true,
url: [URL, URL],
});
browser.tabs.onUpdated.addListener(() => {
// Bug 1398272: Adding onUpdated listener broke tab IDs across windows.
});
let tab = newWindow.tabs[0].id;
let privateTab = privateWindow.tabs[0].id;
// Assuming that this windowId does not exist.
await browser.test.assertRejects(
browser.tabs.move(source.id, {windowId: 123144576, index: 0}),
browser.tabs.move(tab, {windowId: 123144576, index: 0}),
/Invalid window/,
"Should receive invalid window error");
// Test that a tab cannot be moved to a private window.
let moved = await browser.tabs.move(source.id, {windowId: privateTab.windowId, index: 0});
let moved = await browser.tabs.move(tab, {windowId: privateWindow.id, index: 0});
browser.test.assertEq(moved.length, 0, "tab was not moved to private window");
// Test that a private tab cannot be moved to a non-private window.
moved = await browser.tabs.move(privateTab.id, {windowId: source.windowId, index: 0});
moved = await browser.tabs.move(privateTab,
{windowId: newWindow.id, index: 0});
browser.test.assertEq(moved.length, 0, "tab was not moved from private window");
// Verify tabs did not move between windows via another query.
let tabs2 = await browser.tabs.query({url: "<all_urls>"});
for (let i = 0; i < 3; i++) {
browser.test.assertEq(tabs2[i].windowId, tabs[i].windowId, "tab was not moved to another window");
browser.test.assertEq(tabs2[i].incognito, tabs[i].incognito, "tab privateness matches.");
let windows = await browser.windows.getAll({populate: true});
let newWin2 = windows.find(w => w.id === newWindow.id);
browser.test.assertTrue(newWin2, "Found window");
browser.test.assertEq(newWin2.tabs.length, 2, "Window still has two tabs");
for (let origTab of newWindow.tabs) {
browser.test.assertTrue(newWin2.tabs.find(t => t.id === origTab.id),
`Window still has tab ${origTab.id}`);
}
browser.tabs.move(source.id, {windowId: destination.windowId, index: 0});
let privateWin2 = windows.find(w => w.id === privateWindow.id);
browser.test.assertTrue(privateWin2 !== null, "Found private window");
browser.test.assertEq(privateWin2.incognito, true,
"Private window is still private");
browser.test.assertEq(privateWin2.tabs.length, 2,
"Private window still has two tabs");
for (let origTab of privateWindow.tabs) {
browser.test.assertTrue(privateWin2.tabs.find(t => t.id === origTab.id),
`Private window still has tab ${origTab.id}`);
}
tabs = await browser.tabs.query({url: "<all_urls>"});
browser.test.assertEq(tabs[0].url, "http://example.com/");
browser.test.assertEq(tabs[0].windowId, destination.windowId);
browser.test.assertEq(tabs[0].id, source.id);
// Move a tab from one non-private window to another
await browser.tabs.move(tab, {windowId: mainWindow.id, index: 0});
mainWindow = await browser.windows.get(mainWindow.id, {populate: true});
browser.test.assertTrue(mainWindow.tabs.find(t => t.id === tab),
"Moved tab is in main window");
newWindow = await browser.windows.get(newWindow.id, {populate: true});
browser.test.assertEq(newWindow.tabs.length, 1, "New window has 1 tab left");
browser.test.assertTrue(newWindow.tabs[0].id != tab, "Moved tab is no longer in original window");
await browser.windows.remove(newWindow.id);
await browser.windows.remove(privateWindow.id);
await browser.tabs.remove(tab);
browser.test.notifyPass("tabs.move.window");
},
@ -59,12 +83,6 @@ add_task(async function() {
await extension.startup();
await extension.awaitFinish("tabs.move.window");
await extension.unload();
for (let tab of window.gBrowser.tabs) {
BrowserTestUtils.removeTab(tab);
}
await BrowserTestUtils.closeWindow(window1);
await BrowserTestUtils.closeWindow(window2);
});
add_task(async function test_currentWindowAfterTabMoved() {

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

@ -3,41 +3,46 @@
"use strict";
add_task(async function() {
let window1 = await BrowserTestUtils.openNewBrowserWindow();
await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "http://example.net/");
await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "http://example.com/");
await BrowserTestUtils.openNewForegroundTab(window1.gBrowser, "http://example.net/");
await BrowserTestUtils.openNewForegroundTab(window1.gBrowser, "http://example.com/");
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
},
background: function() {
browser.tabs.query(
{url: "<all_urls>"},
tabs => {
let move1 = tabs[1];
let move3 = tabs[3];
browser.tabs.move([move1.id, move3.id], {index: 0});
browser.tabs.query(
{url: "<all_urls>"},
tabs => {
browser.test.assertEq(tabs[0].url, move1.url);
browser.test.assertEq(tabs[2].url, move3.url);
browser.test.notifyPass("tabs.move.multiple");
});
});
async background() {
const URL = "http://example.com/";
let mainWin = await browser.windows.getCurrent();
let tab1 = await browser.tabs.create({url: URL});
let tab2 = await browser.tabs.create({url: URL});
let newWin = await browser.windows.create({url: [URL, URL]});
browser.test.assertEq(newWin.tabs.length, 2, "New window has 2 tabs");
let [tab3, tab4] = newWin.tabs;
// move tabs in both windows to index 0 in a single call
await browser.tabs.move([tab2.id, tab4.id], {index: 0});
tab1 = await browser.tabs.get(tab1.id);
browser.test.assertEq(tab1.windowId, mainWin.id, "tab 1 is still in main window");
tab2 = await browser.tabs.get(tab2.id);
browser.test.assertEq(tab2.windowId, mainWin.id, "tab 2 is still in main window");
browser.test.assertEq(tab2.index, 0, "tab 2 moved to index 0");
tab3 = await browser.tabs.get(tab3.id);
browser.test.assertEq(tab3.windowId, newWin.id, "tab 3 is still in new window");
tab4 = await browser.tabs.get(tab4.id);
browser.test.assertEq(tab4.windowId, newWin.id, "tab 4 is still in new window");
browser.test.assertEq(tab4.index, 0, "tab 4 moved to index 0");
await browser.tabs.remove([tab1.id, tab2.id]);
await browser.windows.remove(newWin.id);
browser.test.notifyPass("tabs.move.multiple");
},
});
await extension.startup();
await extension.awaitFinish("tabs.move.multiple");
await extension.unload();
for (let tab of window.gBrowser.tabs) {
BrowserTestUtils.removeTab(tab);
}
await BrowserTestUtils.closeWindow(window1);
});

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

@ -3,40 +3,35 @@
"use strict";
add_task(async function() {
await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.net/");
let window1 = await BrowserTestUtils.openNewBrowserWindow();
let tab1 = await BrowserTestUtils.openNewForegroundTab(window1.gBrowser, "http://example.com/");
window1.gBrowser.pinTab(tab1);
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
},
background: function() {
browser.tabs.query(
{url: "<all_urls>"},
tabs => {
let destination = tabs[0];
let source = tabs[1]; // remember, pinning moves it to the left.
browser.tabs.move(source.id, {windowId: destination.windowId, index: 0});
async background() {
const URL = "http://example.com/";
browser.tabs.query(
{url: "<all_urls>"},
tabs => {
browser.test.assertEq(true, tabs[0].pinned);
browser.test.notifyPass("tabs.move.pin");
});
});
let mainWin = await browser.windows.getCurrent();
let tab = await browser.tabs.create({url: URL});
let newWin = await browser.windows.create({url: URL});
let tab2 = newWin.tabs[0];
await browser.tabs.update(tab2.id, {pinned: true});
// Try to move a tab before the pinned tab. The move should be ignored.
let moved = await browser.tabs.move(tab.id, {windowId: newWin.id, index: 0});
browser.test.assertEq(moved.length, 0, "move() returned no moved tab");
tab = await browser.tabs.get(tab.id);
browser.test.assertEq(tab.windowId, mainWin.id, "Tab stayed in its original window");
await browser.tabs.remove(tab.id);
await browser.windows.remove(newWin.id);
browser.test.notifyPass("tabs.move.pin");
},
});
await extension.startup();
await extension.awaitFinish("tabs.move.pin");
await extension.unload();
for (let tab of window.gBrowser.tabs) {
BrowserTestUtils.removeTab(tab);
}
await BrowserTestUtils.closeWindow(window1);
});