summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_reload_tab.js
blob: ba44ba1e3478a3d26487a58207adcba558151dc4 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";

/**
 * Check that customize mode doesn't break when its tab is reloaded.
 */
add_task(async function reload_tab() {
  let initialTab = gBrowser.selectedTab;
  let customizeTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
  gCustomizeMode.setTab(customizeTab);
  let customizationContainer = document.getElementById(
    "customization-container"
  );

  is(
    customizationContainer.clientWidth,
    0,
    "Customization container shouldn't be visible (X)"
  );
  is(
    customizationContainer.clientHeight,
    0,
    "Customization container shouldn't be visible (Y)"
  );

  let customizePromise = BrowserTestUtils.waitForEvent(
    gNavToolbox,
    "customizationready"
  );
  gCustomizeMode.enter();
  await customizePromise;

  let tabReloaded = new Promise(resolve => {
    gBrowser.addTabsProgressListener({
      async onLocationChange(aBrowser) {
        if (customizeTab.linkedBrowser == aBrowser) {
          gBrowser.removeTabsProgressListener(this);
          await Promise.resolve();
          resolve();
        }
      },
    });
  });
  gBrowser.reloadTab(customizeTab);
  await tabReloaded;

  is(
    gBrowser.getIcon(customizeTab),
    "chrome://browser/skin/customize.svg",
    "Tab should have customize icon"
  );
  is(
    customizeTab.getAttribute("customizemode"),
    "true",
    "Tab should be in customize mode"
  );
  Assert.greater(
    customizationContainer.clientWidth,
    0,
    "Customization container should be visible (X)"
  );
  Assert.greater(
    customizationContainer.clientHeight,
    0,
    "Customization container should be visible (Y)"
  );

  customizePromise = BrowserTestUtils.waitForEvent(
    gNavToolbox,
    "aftercustomization"
  );
  await BrowserTestUtils.switchTab(gBrowser, initialTab);
  await customizePromise;

  customizePromise = BrowserTestUtils.waitForEvent(
    gNavToolbox,
    "customizationready"
  );
  await BrowserTestUtils.switchTab(gBrowser, customizeTab);
  await customizePromise;

  is(
    gBrowser.getIcon(customizeTab),
    "chrome://browser/skin/customize.svg",
    "Tab should still have customize icon"
  );
  is(
    customizeTab.getAttribute("customizemode"),
    "true",
    "Tab should still be in customize mode"
  );
  Assert.greater(
    customizationContainer.clientWidth,
    0,
    "Customization container should still be visible (X)"
  );
  Assert.greater(
    customizationContainer.clientHeight,
    0,
    "Customization container should still be visible (Y)"
  );

  await endCustomizing();
});