зеркало из https://github.com/mozilla/gecko-dev.git
Bug 734280 - [New Tab Page] clean up newtab test suite; r=dietrich
This commit is contained in:
Родитель
885df8ebbc
Коммит
613928238c
|
@ -44,9 +44,8 @@ let gDrop = {
|
|||
* Handles the 'drop' event.
|
||||
* @param aCell The drop target cell.
|
||||
* @param aEvent The 'dragexit' event.
|
||||
* @param aCallback The callback to call when the drop is finished.
|
||||
*/
|
||||
drop: function Drop_drop(aCell, aEvent, aCallback) {
|
||||
drop: function Drop_drop(aCell, aEvent) {
|
||||
// The cell that is the drop target could contain a pinned site. We need
|
||||
// to find out where that site has gone and re-pin it there.
|
||||
if (aCell.containsPinnedSite())
|
||||
|
@ -58,7 +57,7 @@ let gDrop = {
|
|||
this._cancelDelayedArrange();
|
||||
|
||||
// Update the grid and move all sites to their new places.
|
||||
gUpdater.updateGrid(aCallback);
|
||||
gUpdater.updateGrid();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,13 +61,12 @@ Site.prototype = {
|
|||
|
||||
/**
|
||||
* Unpins the site and calls the given callback when done.
|
||||
* @param aCallback The callback to be called when finished.
|
||||
*/
|
||||
unpin: function Site_unpin(aCallback) {
|
||||
unpin: function Site_unpin() {
|
||||
if (this.isPinned()) {
|
||||
this._updateAttributes(false);
|
||||
gPinnedLinks.unpin(this._link);
|
||||
gUpdater.updateGrid(aCallback);
|
||||
gUpdater.updateGrid();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -82,15 +81,14 @@ Site.prototype = {
|
|||
/**
|
||||
* Blocks the site (removes it from the grid) and calls the given callback
|
||||
* when done.
|
||||
* @param aCallback The function to be called when finished.
|
||||
*/
|
||||
block: function Site_block(aCallback) {
|
||||
block: function Site_block() {
|
||||
if (gBlockedLinks.isBlocked(this._link)) {
|
||||
if (aCallback)
|
||||
aCallback();
|
||||
} else {
|
||||
gBlockedLinks.block(this._link);
|
||||
gUpdater.updateGrid(aCallback);
|
||||
gUpdater.updateGrid();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
yield blockCell(cells[4]);
|
||||
yield blockCell(4);
|
||||
checkGrid("0,1,2,3,5,6,7,8,9");
|
||||
|
||||
yield blockCell(cells[4]);
|
||||
yield blockCell(4);
|
||||
checkGrid("0,1,2,3,6,7,8,9,");
|
||||
|
||||
yield blockCell(cells[4]);
|
||||
yield blockCell(4);
|
||||
checkGrid("0,1,2,3,7,8,9,,");
|
||||
|
||||
// we removed a pinned site
|
||||
|
@ -32,7 +32,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1p,2,3,4,5,6,7,8");
|
||||
|
||||
yield blockCell(cells[1]);
|
||||
yield blockCell(1);
|
||||
checkGrid("0,2,3,4,5,6,7,8,");
|
||||
|
||||
// we remove the last site on the grid (which is pinned) and expect the gap
|
||||
|
@ -44,7 +44,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8p");
|
||||
|
||||
yield blockCell(cells[8]);
|
||||
yield blockCell(8);
|
||||
checkGrid("0,1,2,3,4,5,6,7,9");
|
||||
|
||||
// we remove the first site on the grid with the last one pinned. all cells
|
||||
|
@ -56,6 +56,6 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8p");
|
||||
|
||||
yield blockCell(cells[0]);
|
||||
yield blockCell(0);
|
||||
checkGrid("1,2,3,4,5,6,7,9,8p");
|
||||
}
|
||||
|
|
|
@ -20,21 +20,12 @@ function runTests() {
|
|||
fillHistory();
|
||||
yield addNewTabPageTab();
|
||||
|
||||
is(cells[0].site.url, URL, "first site is our fake site");
|
||||
is(getCell(0).site.url, URL, "first site is our fake site");
|
||||
|
||||
let page = {
|
||||
update: function () {
|
||||
executeSoon(TestRunner.next);
|
||||
},
|
||||
|
||||
observe: function () {}
|
||||
};
|
||||
|
||||
NewTabUtils.allPages.register(page);
|
||||
whenPagesUpdated();
|
||||
yield clearHistory();
|
||||
|
||||
NewTabUtils.allPages.unregister(page);
|
||||
ok(!cells[0].site, "the fake site is gone");
|
||||
ok(!getCell(0).site, "the fake site is gone");
|
||||
}
|
||||
|
||||
function fillHistory() {
|
||||
|
|
|
@ -14,5 +14,5 @@ function runTests() {
|
|||
|
||||
ok(NewTabUtils.allPages.enabled, true, "page is enabled");
|
||||
NewTabUtils.allPages.enabled = false;
|
||||
ok(cw.gGrid.node.hasAttribute("page-disabled"), "page is disabled");
|
||||
ok(getGrid().node.hasAttribute("page-disabled"), "page is disabled");
|
||||
}
|
||||
|
|
|
@ -8,41 +8,23 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGridLocked(false, "grid is unlocked");
|
||||
|
||||
let cell = cells[0].node;
|
||||
let site = cells[0].site.node;
|
||||
let cell = getCell(0).node;
|
||||
let site = getCell(0).site.node;
|
||||
let link = site.querySelector(".newtab-link");
|
||||
|
||||
sendDragEvent(link, "dragstart");
|
||||
sendDragEvent("dragstart", link);
|
||||
checkGridLocked(true, "grid is now locked");
|
||||
|
||||
sendDragEvent(link, "dragend");
|
||||
sendDragEvent("dragend", link);
|
||||
checkGridLocked(false, "grid isn't locked anymore");
|
||||
|
||||
sendDragEvent(cell, "dragstart");
|
||||
sendDragEvent("dragstart", cell);
|
||||
checkGridLocked(false, "grid isn't locked - dragstart was ignored");
|
||||
|
||||
sendDragEvent(site, "dragstart");
|
||||
sendDragEvent("dragstart", site);
|
||||
checkGridLocked(false, "grid isn't locked - dragstart was ignored");
|
||||
}
|
||||
|
||||
function checkGridLocked(aLocked, aMessage) {
|
||||
is(cw.gGrid.node.hasAttribute("locked"), aLocked, aMessage);
|
||||
}
|
||||
|
||||
function sendDragEvent(aNode, aType) {
|
||||
let ifaceReq = cw.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
let windowUtils = ifaceReq.getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
||||
let dataTransfer = {
|
||||
mozUserCancelled: false,
|
||||
setData: function () null,
|
||||
setDragImage: function () null,
|
||||
getData: function () "about:blank"
|
||||
};
|
||||
|
||||
let event = cw.document.createEvent("DragEvents");
|
||||
event.initDragEvent(aType, true, true, cw, 0, 0, 0, 0, 0,
|
||||
false, false, false, false, 0, null, dataTransfer);
|
||||
|
||||
windowUtils.dispatchDOMEventViaPresShell(aNode, event, true);
|
||||
is(getGrid().node.hasAttribute("locked"), aLocked, aMessage);
|
||||
}
|
||||
|
|
|
@ -8,45 +8,16 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
let cell = cells[0].node;
|
||||
let cell = getCell(0).node;
|
||||
|
||||
sendDropEvent(cell, "about:blank#99\nblank");
|
||||
sendDragEvent("drop", cell, "about:blank#99\nblank");
|
||||
is(NewTabUtils.pinnedLinks.links[0].url, "about:blank#99",
|
||||
"first cell is pinned and contains the dropped site");
|
||||
|
||||
yield whenPagesUpdated();
|
||||
checkGrid("99p,0,1,2,3,4,5,6,7");
|
||||
|
||||
sendDropEvent(cell, "");
|
||||
sendDragEvent("drop", cell, "");
|
||||
is(NewTabUtils.pinnedLinks.links[0].url, "about:blank#99",
|
||||
"first cell is still pinned with the site we dropped before");
|
||||
}
|
||||
|
||||
function sendDropEvent(aNode, aData) {
|
||||
let ifaceReq = cw.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
let windowUtils = ifaceReq.getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
||||
let dataTransfer = {
|
||||
mozUserCancelled: false,
|
||||
setData: function () null,
|
||||
setDragImage: function () null,
|
||||
getData: function () aData,
|
||||
|
||||
types: {
|
||||
contains: function (aType) aType == "text/x-moz-url"
|
||||
},
|
||||
|
||||
mozGetDataAt: function (aType, aIndex) {
|
||||
if (aIndex || aType != "text/x-moz-url")
|
||||
return null;
|
||||
|
||||
return aData;
|
||||
},
|
||||
};
|
||||
|
||||
let event = cw.document.createEvent("DragEvents");
|
||||
event.initDragEvent("drop", true, true, cw, 0, 0, 0, 0, 0,
|
||||
false, false, false, false, 0, null, dataTransfer);
|
||||
|
||||
windowUtils.dispatchDOMEventViaPresShell(aNode, event, true);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,13 @@ function runTests() {
|
|||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
let receivedError = false;
|
||||
let block = cw.document.querySelector(".newtab-control-block");
|
||||
let block = getContentDocument().querySelector(".newtab-control-block");
|
||||
|
||||
function onError() {
|
||||
receivedError = true;
|
||||
}
|
||||
|
||||
let cw = getContentWindow();
|
||||
cw.addEventListener("error", onError);
|
||||
|
||||
for (let i = 0; i < 3; i++)
|
||||
|
|
|
@ -8,15 +8,15 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[1]);
|
||||
yield simulateDrop(1);
|
||||
checkGrid("0,99p,1,2,3,4,5,6,7");
|
||||
|
||||
yield blockCell(cells[1]);
|
||||
yield blockCell(1);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[1]);
|
||||
yield simulateDrop(1);
|
||||
checkGrid("0,99p,1,2,3,4,5,6,7");
|
||||
|
||||
yield blockCell(cells[1]);
|
||||
yield blockCell(1);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ function runTests() {
|
|||
setPinnedLinks("");
|
||||
|
||||
yield addNewTabPageTab();
|
||||
let gridNode = cw.gGrid.node;
|
||||
let gridNode = getGrid().node;
|
||||
|
||||
ok(!gridNode.hasAttribute("page-disabled"), "page is not disabled");
|
||||
|
||||
NewTabUtils.allPages.enabled = false;
|
||||
ok(gridNode.hasAttribute("page-disabled"), "page is disabled");
|
||||
|
||||
let oldGridNode = cw.gGrid.node;
|
||||
let oldGridNode = gridNode;
|
||||
|
||||
// create a second new tage page and make sure it's disabled. enable it
|
||||
// again and check if the former page gets enabled as well.
|
||||
|
@ -26,7 +26,7 @@ function runTests() {
|
|||
ok(gridNode.hasAttribute("page-disabled"), "page is disabled");
|
||||
|
||||
// check that no sites have been rendered
|
||||
is(0, cw.document.querySelectorAll(".site").length, "no sites have been rendered");
|
||||
is(0, getContentDocument().querySelectorAll(".site").length, "no sites have been rendered");
|
||||
|
||||
NewTabUtils.allPages.enabled = true;
|
||||
ok(!gridNode.hasAttribute("page-disabled"), "page is not disabled");
|
||||
|
|
|
@ -15,7 +15,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[1], cells[0]);
|
||||
yield simulateDrop(1, 0);
|
||||
checkGrid("1,0p,2,3,4,5,6,7,8");
|
||||
|
||||
// drag a cell to its current cell and make sure it's not pinned afterwards
|
||||
|
@ -25,7 +25,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[0], cells[0]);
|
||||
yield simulateDrop(0, 0);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
// ensure that pinned pages aren't moved if that's not necessary
|
||||
|
@ -35,7 +35,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1p,2p,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[3], cells[0]);
|
||||
yield simulateDrop(3, 0);
|
||||
checkGrid("3,1p,2p,0p,4,5,6,7,8");
|
||||
|
||||
// pinned sites should always be moved around as blocks. if a pinned site is
|
||||
|
@ -46,7 +46,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0p,1p,2,3,4,5,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[0], cells[2]);
|
||||
yield simulateDrop(0, 2);
|
||||
checkGrid("2p,0p,1p,3,4,5,6,7,8");
|
||||
|
||||
// pinned sites should not be pushed out of the grid (unless there are only
|
||||
|
@ -57,7 +57,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7p,8p");
|
||||
|
||||
yield simulateDrop(cells[8], cells[2]);
|
||||
yield simulateDrop(8, 2);
|
||||
checkGrid("0,1,3,4,5,6,7p,8p,2p");
|
||||
|
||||
// make sure that pinned sites are re-positioned correctly
|
||||
|
@ -67,7 +67,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0p,1p,2p,3,4,5p,6,7,8");
|
||||
|
||||
yield simulateDrop(cells[4], cells[0]);
|
||||
yield simulateDrop(4, 0);
|
||||
checkGrid("3,1p,2p,4,0p,5p,6,7,8");
|
||||
|
||||
// drag a new site onto the very first cell
|
||||
|
@ -77,7 +77,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7p,8p");
|
||||
|
||||
yield simulateDrop(cells[0]);
|
||||
yield simulateDrop(0);
|
||||
checkGrid("99p,0,1,2,3,4,5,7p,8p");
|
||||
|
||||
// drag a new site onto the grid and make sure that pinned cells don't get
|
||||
|
@ -88,7 +88,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7p,8p");
|
||||
|
||||
yield simulateDrop(cells[7]);
|
||||
yield simulateDrop(7);
|
||||
checkGrid("0,1,2,3,4,5,7p,99p,8p");
|
||||
|
||||
// drag a new site beneath a pinned cell and make sure the pinned cell is
|
||||
|
@ -99,7 +99,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1,2,3,4,5,6,7,8p");
|
||||
|
||||
yield simulateDrop(cells[7]);
|
||||
yield simulateDrop(7);
|
||||
checkGrid("0,1,2,3,4,5,6,99p,8p");
|
||||
|
||||
// drag a new site onto a block of pinned sites and make sure they're shifted
|
||||
|
@ -110,6 +110,6 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0p,1p,2p");
|
||||
|
||||
yield simulateDrop(cells[1]);
|
||||
yield simulateDrop(1);
|
||||
checkGrid("0p,99p,1p,2p,3,4,5,6,7");
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0p,1p,2p,3,4,5p,6,7,8");
|
||||
|
||||
cw.gDrag._draggedSite = cells[0].site;
|
||||
let sites = cw.gDropPreview.rearrange(cells[4]);
|
||||
let cw = getContentWindow();
|
||||
cw.gDrag._draggedSite = getCell(0).site;
|
||||
let sites = cw.gDropPreview.rearrange(getCell(4));
|
||||
cw.gDrag._draggedSite = null;
|
||||
|
||||
checkGrid("3,1p,2p,4,0p,5p,6,7,8", sites);
|
||||
|
|
|
@ -16,7 +16,7 @@ function runTests() {
|
|||
ok(!pb.privateBrowsingEnabled, "private browsing is disabled");
|
||||
|
||||
yield addNewTabPageTab();
|
||||
pinCell(cells[0]);
|
||||
pinCell(0);
|
||||
checkGrid("0p,1,2,3,4,5,6,7,8");
|
||||
|
||||
// enter private browsing mode
|
||||
|
@ -27,10 +27,10 @@ function runTests() {
|
|||
checkGrid("0p,1,2,3,4,5,6,7,8");
|
||||
|
||||
// modify the grid while we're in pb mode
|
||||
yield blockCell(cells[1]);
|
||||
yield blockCell(1);
|
||||
checkGrid("0p,2,3,4,5,6,7,8");
|
||||
|
||||
yield unpinCell(cells[0]);
|
||||
yield unpinCell(0);
|
||||
checkGrid("0,2,3,4,5,6,7,8");
|
||||
|
||||
// exit private browsing mode
|
||||
|
|
|
@ -13,16 +13,16 @@ function runTests() {
|
|||
setPinnedLinks("");
|
||||
|
||||
yield addNewTabPageTab();
|
||||
let resetButton = cw.document.getElementById("toolbar-button-reset");
|
||||
let resetButton = getContentDocument().getElementById("toolbar-button-reset");
|
||||
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
ok(!resetButton.hasAttribute("modified"), "page is not modified");
|
||||
|
||||
yield blockCell(cells[4]);
|
||||
yield blockCell(4);
|
||||
checkGrid("0,1,2,3,5,6,7,8,");
|
||||
ok(resetButton.hasAttribute("modified"), "page is modified");
|
||||
|
||||
yield cw.gToolbar.reset(TestRunner.next);
|
||||
yield getContentWindow().gToolbar.reset(TestRunner.next);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
ok(!resetButton.hasAttribute("modified"), "page is not modified");
|
||||
}
|
||||
|
|
|
@ -17,45 +17,45 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1p,2,3,4,5,6,7,8");
|
||||
|
||||
let resetButton = cw.document.getElementById("toolbar-button-reset");
|
||||
let resetButton = getContentDocument().getElementById("toolbar-button-reset");
|
||||
ok(!resetButton.hasAttribute("modified"), "page is not modified");
|
||||
|
||||
let oldCw = cw;
|
||||
let oldSites = getGrid().sites;
|
||||
let oldResetButton = resetButton;
|
||||
|
||||
// create the new tab page
|
||||
yield addNewTabPageTab();
|
||||
checkGrid("0,1p,2,3,4,5,6,7,8");
|
||||
|
||||
resetButton = cw.document.getElementById("toolbar-button-reset");
|
||||
resetButton = getContentDocument().getElementById("toolbar-button-reset");
|
||||
ok(!resetButton.hasAttribute("modified"), "page is not modified");
|
||||
|
||||
// unpin a cell
|
||||
yield unpinCell(cells[1]);
|
||||
yield unpinCell(1);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
checkGrid("0,1,2,3,4,5,6,7,8", oldCw.gGrid.sites);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8", oldSites);
|
||||
|
||||
// remove a cell
|
||||
yield blockCell(cells[1]);
|
||||
yield blockCell(1);
|
||||
checkGrid("0,2,3,4,5,6,7,8,9");
|
||||
checkGrid("0,2,3,4,5,6,7,8,9", oldCw.gGrid.sites);
|
||||
checkGrid("0,2,3,4,5,6,7,8,9", oldSites);
|
||||
ok(resetButton.hasAttribute("modified"), "page is modified");
|
||||
ok(oldResetButton.hasAttribute("modified"), "page is modified");
|
||||
|
||||
// insert a new cell by dragging
|
||||
yield simulateDrop(cells[1]);
|
||||
yield simulateDrop(1);
|
||||
checkGrid("0,99p,2,3,4,5,6,7,8");
|
||||
checkGrid("0,99p,2,3,4,5,6,7,8", oldCw.gGrid.sites);
|
||||
checkGrid("0,99p,2,3,4,5,6,7,8", oldSites);
|
||||
|
||||
// drag a cell around
|
||||
yield simulateDrop(cells[1], cells[2]);
|
||||
yield simulateDrop(1, 2);
|
||||
checkGrid("0,2p,99p,3,4,5,6,7,8");
|
||||
checkGrid("0,2p,99p,3,4,5,6,7,8", oldCw.gGrid.sites);
|
||||
checkGrid("0,2p,99p,3,4,5,6,7,8", oldSites);
|
||||
|
||||
// reset the new tab page
|
||||
yield cw.gToolbar.reset(TestRunner.next);
|
||||
yield getContentWindow().gToolbar.reset(TestRunner.next);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
checkGrid("0,1,2,3,4,5,6,7,8", oldCw.gGrid.sites);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8", oldSites);
|
||||
ok(!resetButton.hasAttribute("modified"), "page is not modified");
|
||||
ok(!oldResetButton.hasAttribute("modified"), "page is not modified");
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,1p,2,3,4,5,6,7,8");
|
||||
|
||||
yield unpinCell(cells[1]);
|
||||
yield unpinCell(1);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
// we have a pinned link that is not anymore in the list of the most-visited
|
||||
|
@ -26,7 +26,7 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("0,99p,1,2,3,4,5,6,7");
|
||||
|
||||
yield unpinCell(cells[1]);
|
||||
yield unpinCell(1);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
|
||||
// we have a pinned link that changed its position since it was pinned. it
|
||||
|
@ -37,10 +37,10 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("2,1p,3,4,5,6,7,,0p");
|
||||
|
||||
yield unpinCell(cells[1]);
|
||||
yield unpinCell(1);
|
||||
checkGrid("1,2,3,4,5,6,7,,0p");
|
||||
|
||||
yield unpinCell(cells[8]);
|
||||
yield unpinCell(8);
|
||||
checkGrid("0,1,2,3,4,5,6,7,");
|
||||
|
||||
// we have pinned link that changed its position since it was pinned. the
|
||||
|
@ -51,6 +51,6 @@ function runTests() {
|
|||
yield addNewTabPageTab();
|
||||
checkGrid("9p,0,1,2,3,4,5,6,7");
|
||||
|
||||
yield unpinCell(cells[0]);
|
||||
yield unpinCell(0);
|
||||
checkGrid("0,1,2,3,4,5,6,7,8");
|
||||
}
|
||||
|
|
|
@ -16,12 +16,6 @@ registerCleanupFunction(function () {
|
|||
Services.prefs.clearUserPref(PREF_NEWTAB_ENABLED);
|
||||
});
|
||||
|
||||
/**
|
||||
* Global variables that are accessed by tests.
|
||||
*/
|
||||
let cw;
|
||||
let cells;
|
||||
|
||||
/**
|
||||
* We'll want to restore the original links provider later.
|
||||
*/
|
||||
|
@ -81,6 +75,39 @@ let TestRunner = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the selected tab's content window.
|
||||
* @return The content window.
|
||||
*/
|
||||
function getContentWindow() {
|
||||
return gBrowser.selectedBrowser.contentWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selected tab's content document.
|
||||
* @return The content document.
|
||||
*/
|
||||
function getContentDocument() {
|
||||
return gBrowser.selectedBrowser.contentDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the newtab grid of the selected tab.
|
||||
* @return The newtab grid.
|
||||
*/
|
||||
function getGrid() {
|
||||
return getContentWindow().gGrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cell at the given index of the selected tab's newtab grid.
|
||||
* @param aIndex The cell index.
|
||||
* @return The newtab cell.
|
||||
*/
|
||||
function getCell(aIndex) {
|
||||
return getGrid().cells[aIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to provide a list of links that is used to construct the grid.
|
||||
* @param aLinksPattern the pattern (see below)
|
||||
|
@ -143,18 +170,14 @@ function addNewTabPageTab() {
|
|||
browser.addEventListener("load", function onLoad() {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
|
||||
cw = browser.contentWindow;
|
||||
|
||||
if (NewTabUtils.allPages.enabled) {
|
||||
// Continue when the link cache has been populated.
|
||||
NewTabUtils.links.populateCache(function () {
|
||||
cells = cw.gGrid.cells;
|
||||
executeSoon(TestRunner.next);
|
||||
});
|
||||
} else {
|
||||
TestRunner.next();
|
||||
}
|
||||
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
@ -169,118 +192,118 @@ function addNewTabPageTab() {
|
|||
* The fourth cell contains the pinned site 'about:blank#4'.
|
||||
*/
|
||||
function checkGrid(aSitesPattern, aSites) {
|
||||
let valid = true;
|
||||
let length = aSitesPattern.split(",").length;
|
||||
let sites = (aSites || getGrid().sites).slice(0, length);
|
||||
let expected = sites.map(function (aSite) {
|
||||
if (!aSite)
|
||||
return "";
|
||||
|
||||
aSites = aSites || cw.gGrid.sites;
|
||||
let pinned = aSite.isPinned();
|
||||
let pinButton = aSite.node.querySelector(".newtab-control-pin");
|
||||
let hasPinnedAttr = pinButton.hasAttribute("pinned");
|
||||
|
||||
aSitesPattern.split(/\s*,\s*/).forEach(function (id, index) {
|
||||
let site = aSites[index];
|
||||
let match = id.match(/^\d+/);
|
||||
if (pinned != hasPinnedAttr)
|
||||
ok(false, "invalid state (site.isPinned() != site[pinned])");
|
||||
|
||||
// We expect the cell to be empty.
|
||||
if (!match) {
|
||||
if (site) {
|
||||
valid = false;
|
||||
ok(false, "expected cell#" + index + " to be empty");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// We expect the cell to contain a site.
|
||||
if (!site) {
|
||||
valid = false;
|
||||
ok(false, "didn't expect cell#" + index + " to be empty");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let num = match[0];
|
||||
|
||||
// Check the site's url.
|
||||
if (site.url != "about:blank#" + num) {
|
||||
valid = false;
|
||||
is(site.url, "about:blank#" + num, "cell#" + index + " has the wrong url");
|
||||
}
|
||||
|
||||
let shouldBePinned = /p$/.test(id);
|
||||
let cellContainsPinned = site.isPinned();
|
||||
let cssClassPinned = site.node && site.node.querySelector(".newtab-control-pin").hasAttribute("pinned");
|
||||
|
||||
// Check if the site should be and is pinned.
|
||||
if (shouldBePinned) {
|
||||
if (!cellContainsPinned) {
|
||||
valid = false;
|
||||
ok(false, "expected cell#" + index + " to be pinned");
|
||||
} else if (!cssClassPinned) {
|
||||
valid = false;
|
||||
ok(false, "expected cell#" + index + " to have css class 'pinned'");
|
||||
}
|
||||
} else {
|
||||
if (cellContainsPinned) {
|
||||
valid = false;
|
||||
ok(false, "didn't expect cell#" + index + " to be pinned");
|
||||
} else if (cssClassPinned) {
|
||||
valid = false;
|
||||
ok(false, "didn't expect cell#" + index + " to have css class 'pinned'");
|
||||
}
|
||||
}
|
||||
return aSite.url.replace(/^about:blank#(\d+)$/, "$1") + (pinned ? "p" : "");
|
||||
});
|
||||
|
||||
// If every test passed, say so.
|
||||
if (valid)
|
||||
ok(true, "grid status = " + aSitesPattern);
|
||||
is(aSitesPattern, expected, "grid status = " + aSitesPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks the given cell's site from the grid.
|
||||
* @param aCell the cell that contains the site to block
|
||||
* Blocks a site from the grid.
|
||||
* @param aIndex The cell index.
|
||||
*/
|
||||
function blockCell(aCell) {
|
||||
aCell.site.block(function () executeSoon(TestRunner.next));
|
||||
function blockCell(aIndex) {
|
||||
whenPagesUpdated();
|
||||
getCell(aIndex).site.block();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pins a given cell's site on a given position.
|
||||
* @param aCell the cell that contains the site to pin
|
||||
* @param aIndex the index the defines where the site should be pinned
|
||||
* Pins a site on a given position.
|
||||
* @param aIndex The cell index.
|
||||
* @param aPinIndex The index the defines where the site should be pinned.
|
||||
*/
|
||||
function pinCell(aCell, aIndex) {
|
||||
aCell.site.pin(aIndex);
|
||||
function pinCell(aIndex, aPinIndex) {
|
||||
getCell(aIndex).site.pin(aPinIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpins the given cell's site.
|
||||
* @param aCell the cell that contains the site to unpin
|
||||
* @param aIndex The cell index.
|
||||
*/
|
||||
function unpinCell(aCell) {
|
||||
aCell.site.unpin(function () executeSoon(TestRunner.next));
|
||||
function unpinCell(aIndex) {
|
||||
whenPagesUpdated();
|
||||
getCell(aIndex).site.unpin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates a drop and drop operation.
|
||||
* @param aDropTarget the cell that is the drop target
|
||||
* @param aDragSource the cell that contains the dragged site (optional)
|
||||
* @param aDropIndex The cell index of the drop target.
|
||||
* @param aDragIndex The cell index containing the dragged site (optional).
|
||||
*/
|
||||
function simulateDrop(aDropTarget, aDragSource) {
|
||||
let event = {
|
||||
clientX: 0,
|
||||
clientY: 0,
|
||||
dataTransfer: {
|
||||
mozUserCancelled: false,
|
||||
setData: function () null,
|
||||
setDragImage: function () null,
|
||||
getData: function () "about:blank#99\nblank"
|
||||
function simulateDrop(aDropIndex, aDragIndex) {
|
||||
let draggedSite;
|
||||
let {gDrag: drag, gDrop: drop} = getContentWindow();
|
||||
let event = createDragEvent("drop", "about:blank#99\nblank");
|
||||
|
||||
if (typeof aDragIndex != "undefined")
|
||||
draggedSite = getCell(aDragIndex).site;
|
||||
|
||||
if (draggedSite)
|
||||
drag.start(draggedSite, event);
|
||||
|
||||
whenPagesUpdated();
|
||||
drop.drop(getCell(aDropIndex), event);
|
||||
|
||||
if (draggedSite)
|
||||
drag.end(draggedSite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a custom drag event to a given DOM element.
|
||||
* @param aEventType The drag event's type.
|
||||
* @param aTarget The DOM element that the event is dispatched to.
|
||||
* @param aData The event's drag data (optional).
|
||||
*/
|
||||
function sendDragEvent(aEventType, aTarget, aData) {
|
||||
let event = createDragEvent(aEventType, aData);
|
||||
let ifaceReq = getContentWindow().QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
let windowUtils = ifaceReq.getInterface(Ci.nsIDOMWindowUtils);
|
||||
windowUtils.dispatchDOMEventViaPresShell(aTarget, event, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom drag event.
|
||||
* @param aEventType The drag event's type.
|
||||
* @param aData The event's drag data (optional).
|
||||
* @return The drag event.
|
||||
*/
|
||||
function createDragEvent(aEventType, aData) {
|
||||
let dataTransfer = {
|
||||
mozUserCancelled: false,
|
||||
setData: function () null,
|
||||
setDragImage: function () null,
|
||||
getData: function () aData,
|
||||
|
||||
types: {
|
||||
contains: function (aType) aType == "text/x-moz-url"
|
||||
},
|
||||
|
||||
mozGetDataAt: function (aType, aIndex) {
|
||||
if (aIndex || aType != "text/x-moz-url")
|
||||
return null;
|
||||
|
||||
return aData;
|
||||
}
|
||||
};
|
||||
|
||||
if (aDragSource)
|
||||
cw.gDrag.start(aDragSource.site, event);
|
||||
let event = getContentDocument().createEvent("DragEvents");
|
||||
event.initDragEvent(aEventType, true, true, getContentWindow(), 0, 0, 0, 0, 0,
|
||||
false, false, false, false, 0, null, dataTransfer);
|
||||
|
||||
cw.gDrop.drop(aDropTarget, event, function () executeSoon(TestRunner.next));
|
||||
|
||||
if (aDragSource)
|
||||
cw.gDrag.end(aDragSource.site);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче