browser_bug386835.js
Go to the documentation of this file.
1 var gTestPage = "http://example.org/browser/browser/base/content/test/dummy_page.html";
2 var gTestImage = "http://example.org/browser/browser/base/content/test/moz.png";
4 var gLevel;
5 const kBack = 0;
6 const kForward = 1;
7 
8 function test() {
10 
11  gTab1 = gBrowser.addTab(gTestPage);
12  gTab2 = gBrowser.addTab();
13  gTab3 = gBrowser.addTab();
14  gBrowser.selectedTab = gTab1;
15 
16  load(gTab1, gTestPage, function () {
18  });
19 }
20 
21 function secondPageLoaded() {
22  zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1");
23  zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
24  zoomTest(gTab3, 1, "Initial zoom of tab 3 should be 1");
25 
26  // Now have three tabs, two with the test page, one blank. Tab 1 is selected
27  // Zoom tab 1
28  FullZoom.enlarge();
29  gLevel = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1));
30 
31  ok(gLevel > 1, "New zoom for tab 1 should be greater than 1");
32  zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2");
33  zoomTest(gTab3, 1, "Zooming tab 1 should not affect tab 3");
34 
36 }
37 
38 function thirdPageLoaded() {
39  zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
40  zoomTest(gTab2, 1, "Tab 2 should still not be affected");
41  zoomTest(gTab3, gLevel, "Tab 3 should have zoomed as it was loading in the background");
42 
43  // Switching to tab 2 should update its zoom setting.
44  gBrowser.selectedTab = gTab2;
45 
46  zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
47  zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now");
48  zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed");
49 
51 }
52 
53 function imageLoaded() {
54  zoomTest(gTab1, 1, "Zoom should be 1 when image was loaded in the background");
55  gBrowser.selectedTab = gTab1;
56  zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
57 
58  executeSoon(imageZoomSwitch);
59 }
60 
61 function imageZoomSwitch() {
62  navigate(kBack, function() {
63  navigate(kForward, function() {
64  zoomTest(gTab1, 1, "Tab 1 should not be zoomed when an image loads");
65  gBrowser.selectedTab = gTab2;
66  zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected");
67 
68  // Mac OS X does not support print preview, so skip those tests
69  let isOSX = ("nsILocalFileMac" in Components.interfaces);
70  if (isOSX)
71  finishTest();
72  else
74  });
75  });
76 }
77 
79  // test print preview on image document
80  testPrintPreview(gTab1, function() {
81  // test print preview on HTML document
82  testPrintPreview(gTab2, function() {
83  // test print preview on image document with siteSpecific set to false
84  gPrefService.setBoolPref("browser.zoom.siteSpecific", false);
85  testPrintPreview(gTab1, function() {
86  // test print preview of HTML document with siteSpecific set to false
87  testPrintPreview(gTab2, function() {
88  if (gPrefService.prefHasUserValue("browser.zoom.siteSpecific"))
89  gPrefService.clearUserPref("browser.zoom.siteSpecific");
90  finishTest();
91  });
92  });
93  });
94  });
95 }
96 
97 function testPrintPreview(aTab, aCallback) {
98  gBrowser.selectedTab = aTab;
99  FullZoom.enlarge();
100  let level = ZoomManager.zoom;
101 
102  function onEnterPP() {
103  toggleAffectedChromeOrig.apply(null, arguments);
104 
105  function onExitPP() {
106  toggleAffectedChromeOrig.apply(null, arguments);
107  toggleAffectedChrome = toggleAffectedChromeOrig;
108 
109  zoomTest(aTab, level, "Toggling print preview mode should not affect zoom level");
110 
111  FullZoom.reset();
112  aCallback();
113  }
114  toggleAffectedChrome = onExitPP;
115  PrintUtils.exitPrintPreview();
116  }
117  let toggleAffectedChromeOrig = toggleAffectedChrome;
118  toggleAffectedChrome = onEnterPP;
119 
120  let printPreview = new Function(document.getElementById("cmd_printPreview")
121  .getAttribute("oncommand"));
122  executeSoon(printPreview);
123 }
124 
125 function finishTest() {
126  gBrowser.selectedTab = gTab1;
127  FullZoom.reset();
128  gBrowser.removeTab(gTab1);
129  FullZoom.reset();
130  gBrowser.removeTab(gTab2);
131  FullZoom.reset();
132  gBrowser.removeTab(gTab3);
133  finish();
134 }
135 
136 function zoomTest(tab, val, msg) {
137  is(ZoomManager.getZoomForBrowser(tab.linkedBrowser), val, msg);
138 }
139 
140 function load(tab, url, cb) {
141  tab.linkedBrowser.addEventListener("load", function (event) {
142  event.currentTarget.removeEventListener("load", arguments.callee, true);
143  cb();
144  }, true);
145  tab.linkedBrowser.loadURI(url);
146 }
147 
148 function navigate(direction, cb) {
149  gBrowser.addEventListener("pageshow", function(event) {
150  gBrowser.removeEventListener("pageshow", arguments.callee, true);
151  setTimeout(cb, 0);
152  }, true);
153  if (direction == kBack)
154  gBrowser.goBack();
155  else if (direction == kForward)
156  gBrowser.goForward();
157 }
var gTestPage
function finishTest()
const kBack
var FullZoom
function navigate(direction, cb)
function thirdPageLoaded()
var event
function imageZoomSwitch()
function runPrintPreviewTests()
var gTab1
var tab
function load(tab, url, cb)
var gLevel
var gTab3
var gTab2
waitForExplicitFinish()
this _dialogInput val(dateText)
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
return null
Definition: FeedWriter.js:1143
return!aWindow arguments!aWindow arguments[0]
var gPrefService
Definition: overlay.js:34
function secondPageLoaded()
function url(spec)
function test()
const kForward
var gTestImage
function testPrintPreview(aTab, aCallback)
_replaceLoadingTitle aTab
function msg
function toggleAffectedChrome(aHide)
Definition: browser.js:2560
function imageLoaded()
function zoomTest(tab, val, msg)