Web Inspector: Audit: disable breakpoints when running Audit
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 00:28:57 +0000 (00:28 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 00:28:57 +0000 (00:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193158
<rdar://problem/47057083>

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

* UserInterface/Controllers/DebuggerManager.js:
(WI.DebuggerManager):
(WI.DebuggerManager.prototype._startDisablingBreakpointsTemporarily):
(WI.DebuggerManager.prototype._stopDisablingBreakpointsTemporarily):
(WI.DebuggerManager.prototype._handleAuditManagerTestScheduled): Added.
(WI.DebuggerManager.prototype._handleAuditManagerTestCompleted): Added.

* UserInterface/Views/DebuggerSidebarPanel.js:
(WI.DebuggerSidebarPanel.prototype._timelineCapturingWillStart):
(WI.DebuggerSidebarPanel.prototype._timelineCapturingStopped):
(WI.DebuggerSidebarPanel.prototype._handleAuditManagerTestScheduled): Added.
(WI.DebuggerSidebarPanel.prototype._handleAuditManagerTestCompleted): Added.
(WI.DebuggerSidebarPanel.prototype._updateBreakpointsDisabledBanner):
* UserInterface/Views/DebuggerSidebarPanel.css:
(.sidebar > .panel.navigation.debugger .warning-banner + .warning-banner): Added.

* UserInterface/Base/Main.js:
(WI.loaded):
* UserInterface/Test/Test.js:
(WI.loaded):
Move `WI.auditManager` higher in the managers list so that it can be used in
`WI.DebuggerManager`'s constructor.

* Localizations/en.lproj/localizedStrings.js:

LayoutTests:

* inspector/audit/basic.html:
* inspector/audit/basic-expected.txt:

* inspector/audit/resources/audit-utilities.js:
(TestPage.registerInitializer.InspectorTest.Audit.addTest):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239646 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/audit/basic-expected.txt
LayoutTests/inspector/audit/basic.html
LayoutTests/inspector/audit/resources/audit-utilities.js
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js
Source/WebInspectorUI/UserInterface/Test/Test.js
Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.css
Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js

index 86df3e4..f884bd8 100644 (file)
@@ -1,3 +1,17 @@
+2019-01-04  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Audit: disable breakpoints when running Audit
+        https://bugs.webkit.org/show_bug.cgi?id=193158
+        <rdar://problem/47057083>
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/audit/basic.html:
+        * inspector/audit/basic-expected.txt:
+
+        * inspector/audit/resources/audit-utilities.js:
+        (TestPage.registerInitializer.InspectorTest.Audit.addTest):
+
 2019-01-04  Youenn Fablet  <youenn@apple.com>
 
         [Fetch API] Implement abortable fetch
index b1a0549..79a2965 100644 (file)
@@ -126,3 +126,8 @@ PASS: Result should be "error".
   errors:
    - rejected
 
+-- Running test case: Audit.Basic.Debugger
+Testing `debugger`...
+PASS: Should not pause on the debugger statement.
+PASS: Result should be "pass".
+
index f31ebf4..921a741 100644 (file)
@@ -45,6 +45,43 @@ function test()
     InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Resolved", `setTimeout(resolve, 0)`, WI.AuditTestCaseResult.Level.Error);
     InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Rejected", `setTimeout(reject, 0, "rejected")`, WI.AuditTestCaseResult.Level.Error);
 
+    suite.addTestCase({
+        name: "Audit.Basic.Debugger",
+        description: "Test that a debugger statement doesn't pause when running an audit.",
+        test(resolve, reject) {
+            const level = "pass";
+            let audit = new WI.AuditTestCase("Audit.Basic.Debugger", `function() { debugger; return "${level}"; }`);
+
+            let paused = false;
+            let pausedListener = WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
+                paused = true;
+
+                WI.debuggerManager.resume();
+            });
+
+            WI.auditManager.awaitEvent(WI.AuditManager.Event.TestCompleted).then((event) => {
+                InspectorTest.expectFalse(paused, "Should not pause on the debugger statement.");
+
+                let results = WI.auditManager.results.lastValue;
+                InspectorTest.assert(results.length === 1, "There should be 1 result.");
+
+                let result = results[0];
+                InspectorTest.assert(result instanceof WI.AuditTestCaseResult, "Result should be a WI.AuditTestCaseResult.");
+                if (!result)
+                    return;
+
+                InspectorTest.expectEqual(result.level, level, `Result should be "${level}".`);
+
+                WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
+            });
+
+            InspectorTest.log("Testing `debugger`...");
+
+            WI.auditManager.start([audit])
+            .then(resolve, reject);
+        },
+    });
+
     suite.runTestCasesAndFinish();
 }
 </script>
index 10f114c..8279464 100644 (file)
@@ -58,8 +58,7 @@ TestPage.registerInitializer(() => {
                         logArray("domAttributes", data.domAttributes);
                     if (data.errors)
                         logArray("errors", data.errors);
-                })
-                .then(resolve, reject);
+                });
 
                 InspectorTest.log("Testing" + (logs.beforeStart || "") + "...");
 
index 409dd67..710ce75 100644 (file)
@@ -1,3 +1,36 @@
+2019-01-04  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Audit: disable breakpoints when running Audit
+        https://bugs.webkit.org/show_bug.cgi?id=193158
+        <rdar://problem/47057083>
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WI.DebuggerManager):
+        (WI.DebuggerManager.prototype._startDisablingBreakpointsTemporarily):
+        (WI.DebuggerManager.prototype._stopDisablingBreakpointsTemporarily):
+        (WI.DebuggerManager.prototype._handleAuditManagerTestScheduled): Added.
+        (WI.DebuggerManager.prototype._handleAuditManagerTestCompleted): Added.
+
+        * UserInterface/Views/DebuggerSidebarPanel.js:
+        (WI.DebuggerSidebarPanel.prototype._timelineCapturingWillStart):
+        (WI.DebuggerSidebarPanel.prototype._timelineCapturingStopped):
+        (WI.DebuggerSidebarPanel.prototype._handleAuditManagerTestScheduled): Added.
+        (WI.DebuggerSidebarPanel.prototype._handleAuditManagerTestCompleted): Added.
+        (WI.DebuggerSidebarPanel.prototype._updateBreakpointsDisabledBanner):
+        * UserInterface/Views/DebuggerSidebarPanel.css:
+        (.sidebar > .panel.navigation.debugger .warning-banner + .warning-banner): Added.
+
+        * UserInterface/Base/Main.js:
+        (WI.loaded):
+        * UserInterface/Test/Test.js:
+        (WI.loaded):
+        Move `WI.auditManager` higher in the managers list so that it can be used in
+        `WI.DebuggerManager`'s constructor.
+
+        * Localizations/en.lproj/localizedStrings.js:
+
 2019-01-04  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Add a Setting Toggle for Source Maps
index 0721c09..db4d518 100644 (file)
@@ -276,6 +276,7 @@ localizedStrings["Debug: "] = "Debug: ";
 localizedStrings["Debugger"] = "Debugger";
 localizedStrings["Debugger Paused"] = "Debugger Paused";
 localizedStrings["Debugger Statement"] = "Debugger Statement";
+localizedStrings["Debugger disabled during Audit"] = "Debugger disabled during Audit";
 localizedStrings["Debugger disabled during Timeline recording"] = "Debugger disabled during Timeline recording";
 localizedStrings["Debugger:"] = "Debugger:";
 localizedStrings["Debugs"] = "Debugs";
@@ -896,6 +897,7 @@ localizedStrings["Step out (%s or %s)"] = "Step out (%s or %s)";
 localizedStrings["Step over (%s or %s)"] = "Step over (%s or %s)";
 localizedStrings["Stiffness"] = "Stiffness";
 localizedStrings["Stop"] = "Stop";
+localizedStrings["Stop Audit"] = "Stop Audit";
 localizedStrings["Stop Recording"] = "Stop Recording";
 localizedStrings["Stop element selection (%s)"] = "Stop element selection (%s)";
 localizedStrings["Stop recording"] = "Stop recording";
index 251cef7..81b06dd 100644 (file)
@@ -114,12 +114,12 @@ WI.loaded = function()
         WI.memoryManager = new WI.MemoryManager,
         WI.applicationCacheManager = new WI.ApplicationCacheManager,
         WI.timelineManager = new WI.TimelineManager,
+        WI.auditManager = new WI.AuditManager,
         WI.debuggerManager = new WI.DebuggerManager,
         WI.layerTreeManager = new WI.LayerTreeManager,
         WI.workerManager = new WI.WorkerManager,
         WI.domDebuggerManager = new WI.DOMDebuggerManager,
         WI.canvasManager = new WI.CanvasManager,
-        WI.auditManager = new WI.AuditManager,
     ];
 
     // Register for events.
index e994556..8562816 100644 (file)
@@ -41,6 +41,9 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
         WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingWillStart, this._timelineCapturingWillStart, this);
         WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStopped, this._timelineCapturingStopped, this);
 
+        WI.auditManager.addEventListener(WI.AuditManager.Event.TestScheduled, this._handleAuditManagerTestScheduled, this);
+        WI.auditManager.addEventListener(WI.AuditManager.Event.TestCompleted, this._handleAuditManagerTestCompleted, this);
+
         WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._targetRemoved, this);
 
         WI.settings.pauseForInternalScripts.addEventListener(WI.Setting.Event.Changed, this._pauseForInternalScriptsDidChange, this);
@@ -93,6 +96,7 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
             this._breakpointsEnabledSetting.value = this._temporarilyDisabledBreakpointsRestoreSetting.value;
             this._temporarilyDisabledBreakpointsRestoreSetting.value = null;
         }
+        this._temporarilyDisableBreakpointsRequestCount = 0;
 
         this._ignoreBreakpointDisplayLocationDidChangeEvent = false;
 
@@ -1110,10 +1114,14 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
 
     _startDisablingBreakpointsTemporarily()
     {
+        if (++this._temporarilyDisableBreakpointsRequestCount > 1)
+            return;
+
         console.assert(!this.breakpointsDisabledTemporarily, "Already temporarily disabling breakpoints.");
         if (this.breakpointsDisabledTemporarily)
             return;
 
+
         this._temporarilyDisabledBreakpointsRestoreSetting.value = this._breakpointsEnabledSetting.value;
 
         this.breakpointsEnabled = false;
@@ -1121,6 +1129,10 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
 
     _stopDisablingBreakpointsTemporarily()
     {
+        this._temporarilyDisableBreakpointsRequestCount = Math.max(0, this._temporarilyDisableBreakpointsRequestCount - 1);
+        if (this._temporarilyDisableBreakpointsRequestCount > 0)
+            return;
+
         console.assert(this.breakpointsDisabledTemporarily, "Was not temporarily disabling breakpoints.");
         if (!this.breakpointsDisabledTemporarily)
             return;
@@ -1144,6 +1156,19 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
         this._stopDisablingBreakpointsTemporarily();
     }
 
+    _handleAuditManagerTestScheduled(event)
+    {
+        this._startDisablingBreakpointsTemporarily();
+
+        if (this.paused)
+            this.resume();
+    }
+
+    _handleAuditManagerTestCompleted(event)
+    {
+        this._stopDisablingBreakpointsTemporarily();
+    }
+
     _targetRemoved(event)
     {
         let wasPaused = this.paused;
index f8adde8..195fbc2 100644 (file)
@@ -57,12 +57,12 @@ WI.loaded = function()
         WI.heapManager = new WI.HeapManager,
         WI.memoryManager = new WI.MemoryManager,
         WI.timelineManager = new WI.TimelineManager,
+        WI.auditManager = new WI.AuditManager,
         WI.debuggerManager = new WI.DebuggerManager,
         WI.layerTreeManager = new WI.LayerTreeManager,
         WI.workerManager = new WI.WorkerManager,
         WI.domDebuggerManager = new WI.DOMDebuggerManager,
         WI.canvasManager = new WI.CanvasManager,
-        WI.auditManager = new WI.AuditManager,
     ];
 
     // Register for events.
index f7448e1..48f53ed 100644 (file)
     background-color: hsl(50, 100%, 94%);
 }
 
+.sidebar > .panel.navigation.debugger .warning-banner + .warning-banner {
+    display: none;
+}
+
 .sidebar > .panel.navigation.debugger .tree-outline.single-thread > .item.thread {
     display: none;
 }
index 90ab86d..e7b3db9 100644 (file)
@@ -58,15 +58,25 @@ WI.DebuggerSidebarPanel = class DebuggerSidebarPanel extends WI.NavigationSideba
         WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingWillStart, this._timelineCapturingWillStart, this);
         WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStopped, this._timelineCapturingStopped, this);
 
+        WI.auditManager.addEventListener(WI.AuditManager.Event.TestScheduled, this._handleAuditManagerTestScheduled, this);
+        WI.auditManager.addEventListener(WI.AuditManager.Event.TestCompleted, this._handleAuditManagerTestCompleted, this);
+
         WI.targetManager.addEventListener(WI.TargetManager.Event.TargetAdded, this._targetAdded, this);
         WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._targetRemoved, this);
 
         this._timelineRecordingWarningElement = document.createElement("div");
         this._timelineRecordingWarningElement.classList.add("warning-banner");
-        this._timelineRecordingWarningElement.append(WI.UIString("Debugger disabled during Timeline recording"), " ");
-        let stopRecordingLink = this._timelineRecordingWarningElement.appendChild(document.createElement("a"));
-        stopRecordingLink.textContent = WI.UIString("Stop recording");
-        stopRecordingLink.addEventListener("click", () => { WI.timelineManager.stopCapturing(); });
+        this._timelineRecordingWarningElement.append(WI.UIString("Debugger disabled during Timeline recording"), document.createElement("br"));
+        let timelineStopRecordingLink = this._timelineRecordingWarningElement.appendChild(document.createElement("a"));
+        timelineStopRecordingLink.textContent = WI.UIString("Stop recording");
+        timelineStopRecordingLink.addEventListener("click", () => { WI.timelineManager.stopCapturing(); });
+
+        this._auditTestWarningElement = document.createElement("div");
+        this._auditTestWarningElement.classList.add("warning-banner");
+        this._auditTestWarningElement.append(WI.UIString("Debugger disabled during Audit"), document.createElement("br"));
+        let auditStopRecordingLink = this._auditTestWarningElement.appendChild(document.createElement("a"));
+        auditStopRecordingLink.textContent = WI.UIString("Stop Audit");
+        auditStopRecordingLink.addEventListener("click", () => { WI.auditManager.stop(); });
 
         this._breakpointsDisabledWarningElement = document.createElement("div");
         this._breakpointsDisabledWarningElement.classList.add("warning-banner");
@@ -622,8 +632,7 @@ WI.DebuggerSidebarPanel = class DebuggerSidebarPanel extends WI.NavigationSideba
 
     _timelineCapturingWillStart(event)
     {
-        this._debuggerBreakpointsButtonItem.enabled = false;
-        this._debuggerPauseResumeButtonItem.enabled = false;
+        this._updateTemporarilyDisabledBreakpointsButtons();
 
         this.contentView.element.insertBefore(this._timelineRecordingWarningElement, this.contentView.element.firstChild);
         this._updateBreakpointsDisabledBanner();
@@ -631,19 +640,42 @@ WI.DebuggerSidebarPanel = class DebuggerSidebarPanel extends WI.NavigationSideba
 
     _timelineCapturingStopped(event)
     {
-        this._debuggerBreakpointsButtonItem.enabled = true;
-        this._debuggerPauseResumeButtonItem.enabled = true;
+        this._updateTemporarilyDisabledBreakpointsButtons();
 
         this._timelineRecordingWarningElement.remove();
         this._updateBreakpointsDisabledBanner();
     }
 
+    _handleAuditManagerTestScheduled(event)
+    {
+        this._updateTemporarilyDisabledBreakpointsButtons();
+
+        this.contentView.element.insertBefore(this._auditTestWarningElement, this.contentView.element.firstChild);
+        this._updateBreakpointsDisabledBanner();
+    }
+
+    _handleAuditManagerTestCompleted(event)
+    {
+        this._updateTemporarilyDisabledBreakpointsButtons();
+
+        this._auditTestWarningElement.remove();
+        this._updateBreakpointsDisabledBanner();
+    }
+
+    _updateTemporarilyDisabledBreakpointsButtons()
+    {
+        let breakpointsDisabledTemporarily = WI.debuggerManager.breakpointsDisabledTemporarily;
+        this._debuggerBreakpointsButtonItem.enabled = !breakpointsDisabledTemporarily;
+        this._debuggerPauseResumeButtonItem.enabled = !breakpointsDisabledTemporarily;
+    }
+
     _updateBreakpointsDisabledBanner()
     {
         let breakpointsEnabled = WI.debuggerManager.breakpointsEnabled;
         let timelineWarningShowing = !!this._timelineRecordingWarningElement.parentElement;
+        let auditWarningShowing = !!this._auditTestWarningElement.parentElement;
 
-        if (!breakpointsEnabled && !timelineWarningShowing)
+        if (!breakpointsEnabled && !timelineWarningShowing && !auditWarningShowing)
             this.contentView.element.insertBefore(this._breakpointsDisabledWarningElement, this.contentView.element.firstChild);
         else
             this._breakpointsDisabledWarningElement.remove();