browser_keybindings_02.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Test that the toolbox keybindings still work after the host is changed.
  6. const URL = "data:text/html;charset=utf8,test page";
  7. var {Toolbox} = require("devtools/client/framework/toolbox");
  8. const {LocalizationHelper} = require("devtools/shared/l10n");
  9. const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
  10. function getZoomValue() {
  11. return parseFloat(Services.prefs.getCharPref("devtools.toolbox.zoomValue"));
  12. }
  13. add_task(function* () {
  14. info("Create a test tab and open the toolbox");
  15. let tab = yield addTab(URL);
  16. let target = TargetFactory.forTab(tab);
  17. let toolbox = yield gDevTools.showToolbox(target, "webconsole");
  18. let {SIDE, BOTTOM} = Toolbox.HostType;
  19. for (let type of [SIDE, BOTTOM, SIDE]) {
  20. info("Switch to host type " + type);
  21. yield toolbox.switchHost(type);
  22. info("Try to use the toolbox shortcuts");
  23. yield checkKeyBindings(toolbox);
  24. }
  25. Services.prefs.clearUserPref("devtools.toolbox.zoomValue");
  26. Services.prefs.setCharPref("devtools.toolbox.host", BOTTOM);
  27. yield toolbox.destroy();
  28. gBrowser.removeCurrentTab();
  29. });
  30. function zoomWithKey(toolbox, key) {
  31. let shortcut = L10N.getStr(key);
  32. if (!shortcut) {
  33. info("Key was empty, skipping zoomWithKey");
  34. return;
  35. }
  36. info("Zooming with key: " + key);
  37. let currentZoom = getZoomValue();
  38. synthesizeKeyShortcut(shortcut, toolbox.win);
  39. isnot(getZoomValue(), currentZoom, "The zoom level was changed in the toolbox");
  40. }
  41. function* checkKeyBindings(toolbox) {
  42. zoomWithKey(toolbox, "toolbox.zoomIn.key");
  43. zoomWithKey(toolbox, "toolbox.zoomIn2.key");
  44. zoomWithKey(toolbox, "toolbox.zoomIn3.key");
  45. zoomWithKey(toolbox, "toolbox.zoomReset.key");
  46. zoomWithKey(toolbox, "toolbox.zoomOut.key");
  47. zoomWithKey(toolbox, "toolbox.zoomOut2.key");
  48. zoomWithKey(toolbox, "toolbox.zoomReset2.key");
  49. }