summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/zoom/browser_default_zoom_multitab.js
blob: d204020889e6d4408bb1e478ce02f1dd6242ce96 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* Any copyright is dedicated to the Public Domain.
 * https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_multidomain_global_zoom() {
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  const TEST_PAGE_URL_1 = "http://example.com/";
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  const TEST_PAGE_URL_2 = "http://example.org/";

  // Prepare the test tabs
  console.log("Creating tab 1");
  let tab1 = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL_1);
  let tabBrowser1 = gBrowser.getBrowserForTab(tab1);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);

  console.log("Creating tab 2");
  let tab2 = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL_2);
  let tabBrowser2 = gBrowser.getBrowserForTab(tab2);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab2);

  // 67% global zoom
  console.log("Changing default zoom");
  await FullZoomHelper.changeDefaultZoom(67);
  let defaultZoom = await FullZoomHelper.getGlobalValue();
  is(defaultZoom, 0.67, "Global zoom is set to 67%");

  // 67% local zoom tab 1
  console.log("Selecting tab 1");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);
  await TestUtils.waitForCondition(() => {
    console.log(
      "Currnet zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser1)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser1) == 0.67;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser1),
    0.67,
    "Setting default zoom causes tab 1 (background) to zoom to default zoom."
  );

  // 67% local zoom tab 2
  console.log("Selecting tab 2");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab2);
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser2)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser2) == 0.67;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser2),
    0.67,
    "Setting default zoom causes tab 2 (foreground) to zoom to default zoom."
  );
  console.log("Enlarging tab");
  await FullZoom.enlarge();
  // 80% local zoom tab 2
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser2)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser2) == 0.8;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser2),
    0.8,
    "Enlarging local zoom of tab 2."
  );

  // 67% local zoom tab 1
  console.log("Selecting tab 1");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser1)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser1) == 0.67;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser1),
    0.67,
    "Tab 1 is unchanged by tab 2's enlarge call."
  );
  console.log("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
  console.log("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
});

add_task(async function test_site_specific_global_zoom() {
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  const TEST_PAGE_URL_1 = "http://example.net/";
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  const TEST_PAGE_URL_2 = "http://example.net/";

  // Prepare the test tabs
  console.log("Adding tab 1");
  let tab1 = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL_1);
  console.log("Getting tab 1 browser");
  let tabBrowser1 = gBrowser.getBrowserForTab(tab1);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);

  console.log("Adding tab 2");
  let tab2 = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL_2);
  console.log("Getting tab 2 browser");
  let tabBrowser2 = gBrowser.getBrowserForTab(tab2);
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab2);

  console.log("checking global zoom");
  // 67% global zoom persists from previous test
  let defaultZoom = await FullZoomHelper.getGlobalValue();
  is(defaultZoom, 0.67, "Default zoom is 67%");

  // 67% local zoom tab 1
  console.log("Selecting tab 1");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);
  console.log("Awaiting condition");
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current tab 1 zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser1)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser1) == 0.67;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser1),
    0.67,
    "Setting default zoom causes tab 1 (background) to zoom to default zoom."
  );

  // 67% local zoom tab 2
  console.log("Selecting tab 2");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab2);
  console.log("Awaiting condition");
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current tab 2 zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser2)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser2) == 0.67;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser2),
    0.67,
    "Setting default zoom causes tab 2 (foreground) to zoom to default zoom."
  );

  // 80% site specific zoom
  console.log("Selecting tab 1");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab1);
  console.log("Enlarging");
  await FullZoom.enlarge();
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current tab 1 zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser1)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser1) == 0.8;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser1),
    0.8,
    "Changed local zoom in tab one."
  );
  console.log("Selecting tab 2");
  await FullZoomHelper.selectTabAndWaitForLocationChange(tab2);
  await TestUtils.waitForCondition(() => {
    console.log(
      "Current tab 2 zoom is: ",
      ZoomManager.getZoomForBrowser(tabBrowser2)
    );
    return ZoomManager.getZoomForBrowser(tabBrowser2) == 0.8;
  });
  is(
    ZoomManager.getZoomForBrowser(tabBrowser2),
    0.8,
    "Second tab respects site specific zoom."
  );
  console.log("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
  console.log("Removing tab");
  await FullZoomHelper.removeTabAndWaitForLocationChange();
});