| <!doctype html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| class TestRecorder extends WI.DiagnosticEventRecorder { |
| constructor(name, controller, {setup, teardown} = {}) { |
| super(name, controller); |
| |
| this._setupCallback = setup; |
| this._teardownCallback = teardown; |
| } |
| |
| setup() |
| { |
| if (typeof this._setupCallback === "function") |
| this._setupCallback(this); |
| } |
| |
| teardown() |
| { |
| if (typeof this._teardownCallback === "function") |
| this._teardownCallback(this); |
| } |
| |
| sendEvent(name, payload) |
| { |
| this.logDiagnosticEvent(name, payload); |
| } |
| }; |
| |
| let suite = InspectorTest.createSyncSuite("DiagnosticController"); |
| |
| suite.addTestCase({ |
| name: "DiagnosticController.SetupAndTeardown", |
| test() { |
| let diagnosticController = new WI.DiagnosticController; |
| InspectorTest.expectThat(!diagnosticController.diagnosticLoggingAvailable, "Diagnostics should not be available initially."); |
| |
| let recorder = new TestRecorder("Test.1", diagnosticController, { |
| setup: (recorder) => InspectorTest.log("In setup() for recorder: " + recorder.name), |
| teardown: (recorder) => InspectorTest.log("In teardown() for recorder: " + recorder.name), |
| }); |
| |
| InspectorTest.log("Adding recorder..."); |
| diagnosticController.addRecorder(recorder); |
| InspectorTest.expectThat(!recorder.active, "Recorder should be inactive prior to diagnostics becoming available."); |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.0", {"answer": "should NOT be logged"}); |
| |
| |
| InspectorTest.log("Making diagnostics available..."); |
| diagnosticController.diagnosticLoggingAvailable = true; |
| InspectorTest.expectThat(recorder.active, "Recorder should be active after diagnostics are available."); |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.1", {"answer": "should be logged"}); |
| |
| InspectorTest.log("Making diagnostics not available..."); |
| diagnosticController.diagnosticLoggingAvailable = false; |
| |
| InspectorTest.expectThat(!recorder.active, "Recorder should be inactive after diagnostics are not longer available."); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "DiagnosticController.AddRecorderWhileActive", |
| test() { |
| let diagnosticController = new WI.DiagnosticController; |
| |
| InspectorTest.log("Making diagnostics available..."); |
| diagnosticController.diagnosticLoggingAvailable = true; |
| |
| let recorder = new TestRecorder("Test.2", diagnosticController, { |
| setup: (recorder) => InspectorTest.log("In setup() for recorder: " + recorder.name), |
| teardown: (recorder) => InspectorTest.log("In teardown() for recorder: " + recorder.name), |
| }); |
| |
| InspectorTest.log("Adding recorder..."); |
| diagnosticController.addRecorder(recorder); |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.2", {"answer": "should be logged"}); |
| |
| InspectorTest.log("Making diagnostics not available..."); |
| diagnosticController.diagnosticLoggingAvailable = false; |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.3", {"answer": "should NOT be logged"}); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "DiagnosticController.AddRecorderWhileInactive", |
| test() { |
| let diagnosticController = new WI.DiagnosticController; |
| |
| InspectorTest.log("Making diagnostics not available..."); |
| diagnosticController.diagnosticLoggingAvailable = false; |
| |
| let recorder = new TestRecorder("Test.3", diagnosticController, { |
| setup: (recorder) => InspectorTest.log("In setup() for recorder: " + recorder.name), |
| teardown: (recorder) => InspectorTest.log("In teardown() for recorder: " + recorder.name), |
| }); |
| |
| InspectorTest.log("Adding recorder..."); |
| diagnosticController.addRecorder(recorder); |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.4", {"answer": "should NOT be logged"}); |
| |
| InspectorTest.log("Making diagnostics available..."); |
| diagnosticController.diagnosticLoggingAvailable = true; |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.5", {"answer": "should be logged"}); |
| |
| InspectorTest.log("Making diagnostics not available..."); |
| diagnosticController.diagnosticLoggingAvailable = false; |
| |
| InspectorTest.log("Triggering a diagnostic event..."); |
| recorder.sendEvent("TestEvent.6", {"answer": "should NOT be logged"}); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onLoad="runTest()"> |
| </body> |
| </html> |