browser_toolbox_zoom.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. "use strict";
  5. var toolbox;
  6. const {LocalizationHelper} = require("devtools/shared/l10n");
  7. const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
  8. function test() {
  9. addTab("about:blank").then(openToolbox);
  10. }
  11. function openToolbox() {
  12. let target = TargetFactory.forTab(gBrowser.selectedTab);
  13. gDevTools.showToolbox(target).then((aToolbox) => {
  14. toolbox = aToolbox;
  15. toolbox.selectTool("styleeditor").then(testZoom);
  16. });
  17. }
  18. function testZoom() {
  19. info("testing zoom keys");
  20. testZoomLevel("In", 2, 1.2);
  21. testZoomLevel("Out", 3, 0.9);
  22. testZoomLevel("Reset", 1, 1);
  23. tidyUp();
  24. }
  25. function testZoomLevel(type, times, expected) {
  26. sendZoomKey("toolbox.zoom" + type + ".key", times);
  27. let zoom = getCurrentZoom(toolbox);
  28. is(zoom.toFixed(2), expected, "zoom level correct after zoom " + type);
  29. let savedZoom = parseFloat(Services.prefs.getCharPref(
  30. "devtools.toolbox.zoomValue"));
  31. is(savedZoom.toFixed(2), expected,
  32. "saved zoom level is correct after zoom " + type);
  33. }
  34. function sendZoomKey(shortcut, times) {
  35. for (let i = 0; i < times; i++) {
  36. synthesizeKeyShortcut(L10N.getStr(shortcut));
  37. }
  38. }
  39. function getCurrentZoom() {
  40. let windowUtils = toolbox.win.QueryInterface(Ci.nsIInterfaceRequestor)
  41. .getInterface(Ci.nsIDOMWindowUtils);
  42. return windowUtils.fullZoom;
  43. }
  44. function tidyUp() {
  45. toolbox.destroy().then(function () {
  46. gBrowser.removeCurrentTab();
  47. toolbox = null;
  48. finish();
  49. });
  50. }