summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/zoom/browser_default_zoom.js
blob: bf0533fdad17f923053cbe8600928dd86e75fc04 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Any copyright is dedicated to the Public Domain.
 * https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_init_default_zoom() {
  const TEST_PAGE_URL =
    "data:text/html;charset=utf-8,<body>test_init_default_zoom</body>";

  // Prepare the test tab
  info("Creating tab");
  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
  let tabBrowser = gBrowser.getBrowserForTab(tab);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);

  // 100% global zoom
  info("Getting default zoom");
  let defaultZoom = await FullZoomHelper.getGlobalValue();
  is(defaultZoom, 1, "Global zoom is init at 100%");
  // 100% tab zoom
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1,
    "Current zoom is init at 100%"
  );
  info("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
});

add_task(async function test_set_default_zoom() {
  const TEST_PAGE_URL =
    "data:text/html;charset=utf-8,<body>test_set_default_zoom</body>";

  // Prepare the test tab
  info("Creating tab");
  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
  let tabBrowser = gBrowser.getBrowserForTab(tab);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);

  // 120% global zoom
  info("Changing default zoom");
  await FullZoomHelper.changeDefaultZoom(120);
  let defaultZoom = await FullZoomHelper.getGlobalValue();
  is(defaultZoom, 1.2, "Global zoom is at 120%");

  // 120% tab zoom
  await TestUtils.waitForCondition(() => {
    info("Current zoom is: " + ZoomManager.getZoomForBrowser(tabBrowser));
    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1.2,
    "Current zoom matches changed default zoom"
  );
  info("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
  await FullZoomHelper.changeDefaultZoom(100);
});

add_task(async function test_enlarge_reduce_reset_local_zoom() {
  const TEST_PAGE_URL =
    "data:text/html;charset=utf-8,<body>test_enlarge_reduce_reset_local_zoom</body>";

  // Prepare the test tab
  info("Creating tab");
  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
  let tabBrowser = gBrowser.getBrowserForTab(tab);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);

  // 120% global zoom
  info("Changing default zoom");
  await FullZoomHelper.changeDefaultZoom(120);
  let defaultZoom = await FullZoomHelper.getGlobalValue();
  is(defaultZoom, 1.2, "Global zoom is at 120%");

  await TestUtils.waitForCondition(() => {
    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1.2,
    "Current tab zoom matches default zoom"
  );

  await FullZoom.enlarge();
  info("Enlarged!");
  defaultZoom = await FullZoomHelper.getGlobalValue();
  info("Current global zoom is " + defaultZoom);

  // 133% tab zoom
  await TestUtils.waitForCondition(() => {
    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.33;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1.33,
    "Increasing zoom changes zoom of current tab."
  );
  defaultZoom = await FullZoomHelper.getGlobalValue();
  // 120% global zoom
  is(
    defaultZoom,
    1.2,
    "Increasing zoom of current tab doesn't change default zoom."
  );
  info("Reducing...");
  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
  await FullZoom.reduce(); // 120% tab zoom
  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
  await FullZoom.reduce(); // 110% tab zoom
  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
  await FullZoom.reduce(); // 100% tab zoom
  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));

  await TestUtils.waitForCondition(() => {
    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    return ZoomManager.getZoomForBrowser(tabBrowser) == 1;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1,
    "Decreasing zoom changes zoom of current tab."
  );
  defaultZoom = await FullZoomHelper.getGlobalValue();
  // 120% global zoom
  is(
    defaultZoom,
    1.2,
    "Decreasing zoom of current tab doesn't change default zoom."
  );
  info("Resetting...");
  FullZoom.reset(); // 120% tab zoom
  await TestUtils.waitForCondition(() => {
    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser),
    1.2,
    "Reseting zoom causes current tab to zoom to default zoom."
  );

  // no reset necessary, it was performed as part of the test
  info("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
});