summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/newtab/browser_newtab_drop_preview.js
blob: f9e37f6290af91af80e73fcc7c0198b302adba12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/*
 * These tests ensure that the drop preview correctly arranges sites when
 * dragging them around.
 */
add_task(function* () {
  yield* addNewTabPageTab();

  // the first three sites are pinned - make sure they're re-arranged correctly
  yield setLinks("0,1,2,3,4,5,6,7,8");
  setPinnedLinks("0,1,2,,,5");

  yield* addNewTabPageTab();
  yield* checkGrid("0p,1p,2p,3,4,5p,6,7,8");

  let foundSites = yield ContentTask.spawn(gWindow.gBrowser.selectedBrowser, {}, function*() {
    let cells = content.gGrid.cells;
    content.gDrag._draggedSite = cells[0].site;
    let sites = content.gDropPreview.rearrange(cells[4]);
    content.gDrag._draggedSite = null;

    sites = sites.slice(0, 9);
    return sites.map(function (aSite) {
      if (!aSite)
        return "";

      let pinned = aSite.isPinned();
      if (pinned != aSite.node.hasAttribute("pinned")) {
        Assert.ok(false, "invalid state (site.isPinned() != site[pinned])");
      }

      return aSite.url.replace(/^http:\/\/example(\d+)\.com\/$/, "$1") + (pinned ? "p" : "");
    });
  });

  let expectedSites = "3,1p,2p,4,0p,5p,6,7,8"
  is(foundSites, expectedSites, "grid status = " + expectedSites);
});