browser_perf-private-browsing.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that the frontend is disabled when in private browsing mode.
  6. */
  7. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  8. const { addWindow } = require("devtools/client/performance/test/helpers/tab-utils");
  9. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  10. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  11. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  12. let gPanelWinTuples = [];
  13. add_task(function* () {
  14. yield testNormalWindow();
  15. yield testPrivateWindow();
  16. yield testRecordingFailingInWindow(0);
  17. yield testRecordingFailingInWindow(1);
  18. yield teardownPerfInWindow(1, { shouldCloseWindow: true, dontWaitForTabClose: true });
  19. yield testRecordingSucceedingInWindow(0);
  20. yield teardownPerfInWindow(0, { shouldCloseWindow: false });
  21. gPanelWinTuples = null;
  22. });
  23. function* createPanelInNewWindow(options) {
  24. let win = yield addWindow(options);
  25. return yield createPanelInWindow(options, win);
  26. }
  27. function* createPanelInWindow(options, win = window) {
  28. let { panel } = yield initPerformanceInNewTab({
  29. url: SIMPLE_URL,
  30. win: win
  31. }, options);
  32. gPanelWinTuples.push({ panel, win });
  33. return { panel, win };
  34. }
  35. function* testNormalWindow() {
  36. let { panel } = yield createPanelInWindow({
  37. private: false
  38. });
  39. let { PerformanceView } = panel.panelWin;
  40. is(PerformanceView.getState(), "empty",
  41. "The initial state of the performance panel view is correct (1).");
  42. }
  43. function* testPrivateWindow() {
  44. let { panel } = yield createPanelInNewWindow({
  45. private: true,
  46. // The add-on SDK can't seem to be able to listen to "ready" or "close"
  47. // events for private tabs. Don't really absolutely need to though.
  48. dontWaitForTabReady: true
  49. });
  50. let { PerformanceView } = panel.panelWin;
  51. is(PerformanceView.getState(), "unavailable",
  52. "The initial state of the performance panel view is correct (2).");
  53. }
  54. function* testRecordingFailingInWindow(index) {
  55. let { panel } = gPanelWinTuples[index];
  56. let { EVENTS, PerformanceController } = panel.panelWin;
  57. let onRecordingStarted = () => {
  58. ok(false, "Recording should not start while a private window is present.");
  59. };
  60. PerformanceController.on(EVENTS.RECORDING_STATE_CHANGE, onRecordingStarted);
  61. let whenFailed = once(PerformanceController,
  62. EVENTS.BACKEND_FAILED_AFTER_RECORDING_START);
  63. PerformanceController.startRecording();
  64. yield whenFailed;
  65. ok(true, "Recording has failed.");
  66. PerformanceController.off(EVENTS.RECORDING_STATE_CHANGE, onRecordingStarted);
  67. }
  68. function* testRecordingSucceedingInWindow(index) {
  69. let { panel } = gPanelWinTuples[index];
  70. let { EVENTS, PerformanceController } = panel.panelWin;
  71. let onRecordingFailed = () => {
  72. ok(false, "Recording should start while now private windows are present.");
  73. };
  74. PerformanceController.on(EVENTS.BACKEND_FAILED_AFTER_RECORDING_START,
  75. onRecordingFailed);
  76. yield startRecording(panel);
  77. yield stopRecording(panel);
  78. ok(true, "Recording has succeeded.");
  79. PerformanceController.off(EVENTS.BACKEND_FAILED_AFTER_RECORDING_START,
  80. onRecordingFailed);
  81. }
  82. function* teardownPerfInWindow(index, options) {
  83. let { panel, win } = gPanelWinTuples[index];
  84. yield teardownToolboxAndRemoveTab(panel, options);
  85. if (options.shouldCloseWindow) {
  86. win.close();
  87. }
  88. }