Web Inspector: adopt Object.awaitEvent in LayoutTests/inspector/model
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2016 17:28:51 +0000 (17:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2016 17:28:51 +0000 (17:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162074

Patch by Devin Rousso <dcrousso+webkit@gmail.com> on 2016-09-20
Reviewed by Brian Burg.

Replace instances of singleFireEventListener with awaitEvent and use promise logic to make
tests more readable.

* inspector/model/frame-extra-scripts.html:
* inspector/model/scope-chain-node.html:
* inspector/model/script-resource-relationship-expected.txt:
* inspector/model/script-resource-relationship.html:
* inspector/model/stack-trace.html:

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

LayoutTests/ChangeLog
LayoutTests/inspector/model/frame-extra-scripts.html
LayoutTests/inspector/model/scope-chain-node.html
LayoutTests/inspector/model/script-resource-relationship-expected.txt
LayoutTests/inspector/model/script-resource-relationship.html
LayoutTests/inspector/model/stack-trace.html

index c2b4b01..512b2d8 100644 (file)
@@ -1,3 +1,19 @@
+2016-09-20  Devin Rousso  <dcrousso+webkit@gmail.com>
+
+        Web Inspector: adopt Object.awaitEvent in LayoutTests/inspector/model
+        https://bugs.webkit.org/show_bug.cgi?id=162074
+
+        Reviewed by Brian Burg.
+
+        Replace instances of singleFireEventListener with awaitEvent and use promise logic to make
+        tests more readable.
+
+        * inspector/model/frame-extra-scripts.html:
+        * inspector/model/scope-chain-node.html:
+        * inspector/model/script-resource-relationship-expected.txt:
+        * inspector/model/script-resource-relationship.html:
+        * inspector/model/stack-trace.html:
+
 2016-09-20  Jer Noble  <jer.noble@apple.com>
 
         [media-source] Support MediaSource.setLiveSeekableRanges()
index 353c640..6eb9b7a 100644 (file)
@@ -16,7 +16,7 @@ function test()
     suite.addTestCase({
         name: "FrameHasNoExtraScriptsYet",
         description: "No extra scripts yet.",
-        test: (resolve, reject) => {
+        test(resolve, reject) {
             let mainFrame = WebInspector.frameResourceManager.mainFrame;
             InspectorTest.expectThat(mainFrame.extraScripts.length === 0, "Main frame should have no dynamic scripts.");
             resolve();
@@ -26,17 +26,18 @@ function test()
     suite.addTestCase({
         name: "AddExtraScript",
         description: "Add extra script.",
-        test: (resolve, reject) => {            
-            WebInspector.frameResourceManager.mainFrame.singleFireEventListener(WebInspector.Frame.Event.ExtraScriptAdded, (event) => {
+        test(resolve, reject) {
+            WebInspector.frameResourceManager.mainFrame.awaitEvent(WebInspector.Frame.Event.ExtraScriptAdded)
+            .then((event) => {
                 InspectorTest.pass("ExtraScriptAdded event fired.");
                 InspectorTest.expectThat(event.data.script.dynamicallyAddedScriptElement, "Script should identify as dynamic.");
-            });
 
-            InspectorTest.evaluateInPage("triggerAddScriptElement()", () => {
                 let mainFrame = WebInspector.frameResourceManager.mainFrame;
                 InspectorTest.expectThat(mainFrame.extraScripts.length === 1, "Main frame should have 1 dynamic script.");
-                resolve();
-            });
+            })
+            .then(resolve, reject);
+
+            InspectorTest.evaluateInPage("triggerAddScriptElement()");
         }
     });
 
index f57a5e0..5f6c29a 100644 (file)
@@ -23,7 +23,7 @@ function test()
         return "Unexpected Scope Type";
     }
 
-    function harvestScopeChain(scopeChain) {        
+    function harvestScopeChain(scopeChain) {
         let promises = [];
         for (let scope of scopeChain) {
             promises.push(new Promise((resolve, reject) => {
@@ -40,7 +40,8 @@ function test()
     }
 
     function logScopeChain(scopeChain) {
-        return harvestScopeChain(scopeChain).then((results) => {
+        return harvestScopeChain(scopeChain)
+        .then((results) => {
             InspectorTest.log("SCOPE CHAIN:");
             for (let {scope, propertyDescriptors} of results) {
                 InspectorTest.log(`    ${scopeTypeToString(scope.type)}`);
@@ -59,69 +60,75 @@ function test()
     suite.addTestCase({
         name: "WebInspector.ScopeChainNode.AllTypes",
         description: "Tests for each of the different scope chain node types.",
-        test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("setTimeout(testAllScopes)");
-            WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, (event) => {
+        test(resolve, reject) {
+            WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.CallFramesDidChange)
+            .then((event) => {
                 let scopeChain = WebInspector.debuggerManager.activeCallFrame.scopeChain;
                 InspectorTest.expectThat(scopeChain.length === 13, "ScopeChain should have 13 scopes.");
-                logScopeChain(scopeChain).then((result) => {
-                    WebInspector.debuggerManager.resume();
-                    WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, (event) => {
-                        resolve();
-                    });
-                });
-            });
+                return logScopeChain(scopeChain);
+            })
+            .then((result) => {
+                let promise = WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.Resumed);
+                WebInspector.debuggerManager.resume();
+                return promise;
+            })
+            .then(resolve, reject);
+
+            InspectorTest.evaluateInPage("setTimeout(testAllScopes)");
         }
     });
 
     suite.addTestCase({
         name: "WebInspector.ScopeChainNode.FunctionNameInFunctionExpression",
         description: "Tests that there should be a FunctionName scope inside a function expression.",
-        test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("setTimeout(testFunctionNameScope1)");
-            WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, (event) => {
+        test(resolve, reject) {
+            WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.CallFramesDidChange)
+            .then((event) => {
                 let scopeChain = WebInspector.debuggerManager.activeCallFrame.scopeChain;
-                logScopeChain(scopeChain).then((result) => {
-                    WebInspector.debuggerManager.resume();
-                    WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, (event) => {
-                        resolve();
-                    });
-                });
-            });
+                return logScopeChain(scopeChain);
+            })
+            .then((result) => {
+                let promise = WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.Resumed);
+                WebInspector.debuggerManager.resume();
+                return promise;
+            })
+            .then(resolve, reject);
+
+            InspectorTest.evaluateInPage("setTimeout(testFunctionNameScope1)");
         }
     });
 
     suite.addTestCase({
         name: "WebInspector.ScopeChainNode.FunctionNameInClassMethod",
         description: "Tests that there should be a FunctionName scope inside a class method.",
-        test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("setTimeout(testFunctionNameScope2)");
-            WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, (event) => {
+        test(resolve, reject) {
+            WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.CallFramesDidChange)
+            .then((event) => {
                 let scopeChain = WebInspector.debuggerManager.activeCallFrame.scopeChain;
-                logScopeChain(scopeChain).then((result) => {
-                    WebInspector.debuggerManager.resume();
-                    WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, (event) => {
-                        resolve();
-                    });
-                });
-            });
+                return logScopeChain(scopeChain);
+            })
+            .then((result) => {
+                let promise = WebInspector.debuggerManager.awaitEvent(WebInspector.DebuggerManager.Event.Resumed);
+                WebInspector.debuggerManager.resume();
+                return promise;
+            })
+            .then(resolve, reject);
+
+            InspectorTest.evaluateInPage("setTimeout(testFunctionNameScope2)");
         }
     });
 
     suite.addTestCase({
         name: "WebInspector.ScopeChainNode.BlockScopes",
         description: "Tests for a Block scope inside all the different types of blocks.",
-        test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("setTimeout(testBlockScopes)");
-            WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, callFramesDidChangeListener);
-
+        test(resolve, reject) {
             let pauseCount = 0;
             let pauseEventsExpected = 19;
             function callFramesDidChangeListener(event) {
                 if (!WebInspector.debuggerManager.activeCallFrame)
                     return;
 
-                pauseCount++;                
+                pauseCount++;
                 let scopeChain = WebInspector.debuggerManager.activeCallFrame.scopeChain;
 
                 // First, normal function scope.
@@ -149,10 +156,15 @@ function test()
 
                 // Print out the full scope of the last few where there are nested or buried block scopes.
                 InspectorTest.expectThat(scopeChain.some((scopeChain) => scopeChain.type === WebInspector.ScopeChainNode.Type.Block), `Pause #${pauseCount} - Contains a Block scope.`);
-                logScopeChain(scopeChain).then((result) => {
+
+                logScopeChain(scopeChain)
+                .then((result) => {
                     WebInspector.debuggerManager.resume();
                 });
             }
+
+            WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, callFramesDidChangeListener);
+            InspectorTest.evaluateInPage("setTimeout(testBlockScopes)");
         }
     });
 
index ed62220..850a61c 100644 (file)
@@ -3,8 +3,7 @@ WebInspector.Script and WebInspector.Resource relationship.
 
 == Running test suite: WebInspector.Script and WebInspector.Resource relationship
 -- Running test case: ScriptWithResource
-PASS: Resource was added.
-PASS: Script was added.
+PASS: Only one Script should be added.
 PASS: Resource and Script have the same URL.
 PASS: Resource should be related to one script.
 PASS: Resource should be related to the newly added script.
@@ -12,8 +11,7 @@ PASS: Script should be related to the resource.
 PASS: Script should not have a sourceURL.
 
 -- Running test case: NamedScriptWithResource
-PASS: Resource was added.
-PASS: Script was added.
+PASS: Only one Script should be added.
 PASS: Resource and Script have the same URL.
 PASS: Resource should be related to one script.
 PASS: Resource should be related to the newly added script.
index c3ffa65..cc00705 100644 (file)
@@ -46,24 +46,31 @@ function test()
     suite.addTestCase({
         name: "ScriptWithResource",
         description: "Normal relationship between a script and a resource.",
-        test: (resolve, reject) => {
-            let script = null, resource = null;
+        test(resolve, reject) {
+            let script = null;
+            let resource = null;
             
             WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, scriptListener);
-            WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
-                InspectorTest.pass("Resource was added.");
+            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
+            .then((event) => {
                 resource = event.data.resource;
+                validateRelationship();
             });
             
             function scriptListener(event) {
                 if (!event.data.script.url)
                     return;
-                InspectorTest.pass("Script was added.");
+
+                InspectorTest.expectThat(!script, "Only one Script should be added.");
+
                 script = event.data.script;
                 validateRelationship();
             }
 
             function validateRelationship() {
+                if (!resource || !script)
+                    return;
+
                 validateNormalRelationship(resource, script);
                 InspectorTest.expectThat(!script.sourceURL, "Script should not have a sourceURL.");
 
@@ -78,24 +85,31 @@ function test()
     suite.addTestCase({
         name: "NamedScriptWithResource",
         description: "Normal relationship between a named script and a resource.",
-        test: (resolve, reject) => {
-            let script = null, resource = null;
+        test(resolve, reject) {
+            let script = null;
+            let resource = null;
 
             WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, scriptListener);
-            WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
-                InspectorTest.pass("Resource was added.");
+            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
+            .then((event) => {
                 resource = event.data.resource;
+                validateRelationship();
             });
 
             function scriptListener(event) {
                 if (!event.data.script.url)
                     return;
-                InspectorTest.pass("Script was added.");
+
+                InspectorTest.expectThat(!script, "Only one Script should be added.");
+
                 script = event.data.script;
                 validateRelationship();
             }
 
             function validateRelationship() {
+                if (!resource || !script)
+                    return;
+
                 validateNormalRelationship(resource, script);
                 InspectorTest.expectThat(script.sourceURL === "foo.js", "Script should have a sourceURL.");
                 WebInspector.debuggerManager.removeEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, scriptListener, null);
@@ -109,7 +123,7 @@ function test()
     suite.addTestCase({
         name: "ScriptWithoutResource",
         description: "A named eval does not have a resource.",
-        test: (resolve, reject) => {
+        test(resolve, reject) {
             WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, scriptListener);
             let resourceListener = WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
                 InspectorTest.fail("Resource should not be added.");
@@ -138,7 +152,7 @@ function test()
     suite.addTestCase({
         name: "DynamicallyAddedScriptElementNoResource",
         description: "A dynamically added script element has no resource.",
-        test: (resolve, reject) => {
+        test(resolve, reject) {
             WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, scriptListener);
 
             function scriptListener(event) {
@@ -161,7 +175,7 @@ function test()
     suite.addTestCase({
         name: "DocumentWithInlineScripts",
         description: "A document resource may be associated with multiple inline scripts.",
-        test: (resolve, reject) => {
+        test(resolve, reject) {
             let mainResource = WebInspector.frameResourceManager.mainFrame.mainResource;
             let scripts = mainResource.scripts.slice().sort((a, b) => a.range.startLine - b.range.startLine);
 
index 0bd809f..f29c8ef 100644 (file)
@@ -30,9 +30,9 @@ function test()
     suite.addTestCase({
         name: "WebInspector.ConsoleMessage.StackTrace",
         description: "Test we can create a StackTrace from console messages (Console.StackTrace).",
-        test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("triggerConsoleMessage()");
-            WebInspector.logManager.singleFireEventListener(WebInspector.LogManager.Event.MessageAdded, function addListener(event) {
+        test(resolve, reject) {
+            WebInspector.logManager.awaitEvent(WebInspector.LogManager.Event.MessageAdded)
+            .then((event) => {
                 // Trace message should always have a stack trace.
                 let consoleMessage = event.data.message;
                 let stackTrace = consoleMessage.stackTrace;
@@ -45,8 +45,10 @@ function test()
                 InspectorTest.expectThat(!stackTrace.callFrames[0].scopeChain.length, "CallFrame in StackTrace has no scopeChain.");
 
                 logStackTrace(consoleMessage.stackTrace);
-                resolve();
-            });
+            })
+            .then(resolve, reject);
+
+            InspectorTest.evaluateInPage("triggerConsoleMessage()");
         }
     });