browser_scratchpad_tab_switch.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. var tab1;
  4. var tab2;
  5. var sp;
  6. function test()
  7. {
  8. waitForExplicitFinish();
  9. tab1 = gBrowser.addTab();
  10. gBrowser.selectedTab = tab1;
  11. gBrowser.selectedBrowser.addEventListener("load", function onLoad1() {
  12. gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true);
  13. tab2 = gBrowser.addTab();
  14. gBrowser.selectedTab = tab2;
  15. gBrowser.selectedBrowser.addEventListener("load", function onLoad2() {
  16. gBrowser.selectedBrowser.removeEventListener("load", onLoad2, true);
  17. openScratchpad(runTests);
  18. }, true);
  19. content.location = "data:text/html,test context switch in Scratchpad tab 2";
  20. }, true);
  21. content.location = "data:text/html,test context switch in Scratchpad tab 1";
  22. }
  23. function runTests()
  24. {
  25. sp = gScratchpadWindow.Scratchpad;
  26. let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
  27. let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
  28. let notificationBox = sp.notificationBox;
  29. ok(contentMenu, "found #sp-menu-content");
  30. ok(browserMenu, "found #sp-menu-browser");
  31. ok(notificationBox, "found Scratchpad.notificationBox");
  32. sp.setContentContext();
  33. is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT,
  34. "executionContext is content");
  35. is(contentMenu.getAttribute("checked"), "true",
  36. "content menuitem is checked");
  37. isnot(browserMenu.getAttribute("checked"), "true",
  38. "chrome menuitem is not checked");
  39. is(notificationBox.currentNotification, null,
  40. "there is no notification currently shown for content context");
  41. sp.setText("window.foosbug653108 = 'aloha';");
  42. ok(!content.wrappedJSObject.foosbug653108,
  43. "no content.foosbug653108");
  44. sp.run().then(function () {
  45. is(content.wrappedJSObject.foosbug653108, "aloha",
  46. "content.foosbug653108 has been set");
  47. gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true);
  48. gBrowser.selectedTab = tab1;
  49. });
  50. }
  51. function runTests2() {
  52. gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true);
  53. ok(!window.foosbug653108, "no window.foosbug653108");
  54. sp.setText("window.foosbug653108");
  55. sp.run().then(function ([, , result]) {
  56. isnot(result, "aloha", "window.foosbug653108 is not aloha");
  57. sp.setText("window.foosbug653108 = 'ahoyhoy';");
  58. sp.run().then(function () {
  59. is(content.wrappedJSObject.foosbug653108, "ahoyhoy",
  60. "content.foosbug653108 has been set 2");
  61. gBrowser.selectedBrowser.addEventListener("load", runTests3, true);
  62. content.location = "data:text/html,test context switch in Scratchpad location 2";
  63. });
  64. });
  65. }
  66. function runTests3() {
  67. gBrowser.selectedBrowser.removeEventListener("load", runTests3, true);
  68. // Check that the sandbox is not cached.
  69. sp.setText("typeof foosbug653108;");
  70. sp.run().then(function ([, , result]) {
  71. is(result, "undefined", "global variable does not exist");
  72. tab1 = null;
  73. tab2 = null;
  74. sp = null;
  75. finish();
  76. });
  77. }