browser_scratchpad_help_key.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /* Bug 650760 */
  4. function test()
  5. {
  6. waitForExplicitFinish();
  7. gBrowser.selectedTab = gBrowser.addTab();
  8. content.location = "data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760";
  9. gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
  10. gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
  11. openScratchpad(runTest);
  12. }, true);
  13. }
  14. function runTest()
  15. {
  16. let sp = gScratchpadWindow.Scratchpad;
  17. ok(sp, "Scratchpad object exists in new window");
  18. ok(sp.editor.hasFocus(), "the editor has focus");
  19. let keyid = gScratchpadWindow.document.getElementById("key_openHelp");
  20. let modifiers = keyid.getAttribute("modifiers");
  21. let key = null;
  22. if (keyid.getAttribute("keycode"))
  23. key = keyid.getAttribute("keycode");
  24. else if (keyid.getAttribute("key"))
  25. key = keyid.getAttribute("key");
  26. isnot(key, null, "Successfully retrieved keycode/key");
  27. var aEvent = {
  28. shiftKey: modifiers.match("shift"),
  29. ctrlKey: modifiers.match("ctrl"),
  30. altKey: modifiers.match("alt"),
  31. metaKey: modifiers.match("meta"),
  32. accelKey: modifiers.match("accel")
  33. };
  34. info("check that the MDN page is opened on \"F1\"");
  35. let linkClicked = false;
  36. sp.openDocumentationPage = function (event) { linkClicked = true; };
  37. EventUtils.synthesizeKey(key, aEvent, gScratchpadWindow);
  38. is(linkClicked, true, "MDN page will open");
  39. finishTest();
  40. }
  41. function finishTest()
  42. {
  43. gScratchpadWindow.close();
  44. finish();
  45. }