Web Inspector: Test Debugger.scriptParsed events received after opening inspector...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Oct 2015 04:58:28 +0000 (04:58 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Oct 2015 04:58:28 +0000 (04:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150753

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-10-30
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* parser/Parser.h:
(JSC::Parser<LexerType>::parse):
Only set the directives on the SourceProvider if we were parsing the
entire file (Program or Module), not if we are in function parsing mode.
This was inadvertently clearing the directives stored on the
SourceProvider when the function parse didn't see directives and reset
the values on the source provider.

LayoutTests:

Explicit test for the scriptParsed events we expect to see
when first opening the inspector on an already open page.
We do not expect to see some scripts (built-ins) but do expect
to see all user scripts evaluated on the page.

* inspector/debugger/scriptParsed-expected.txt: Added.
* inspector/debugger/scriptParsed.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/scriptParsed-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/scriptParsed.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/parser/Parser.h

index 5cdfc3eef8a108dd13e36313f1f538235231e60d..278556fe482f7c1348d980be54230377989af850 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-30  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Test Debugger.scriptParsed events received after opening inspector frontend
+        https://bugs.webkit.org/show_bug.cgi?id=150753
+
+        Reviewed by Timothy Hatcher.
+
+        Explicit test for the scriptParsed events we expect to see
+        when first opening the inspector on an already open page.
+        We do not expect to see some scripts (built-ins) but do expect
+        to see all user scripts evaluated on the page.
+
+        * inspector/debugger/scriptParsed-expected.txt: Added.
+        * inspector/debugger/scriptParsed.html: Added.
+
 2015-10-28  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Inner height behavior when the keyboard is shown should match on WKWebView and MobileSafari
diff --git a/LayoutTests/inspector/debugger/scriptParsed-expected.txt b/LayoutTests/inspector/debugger/scriptParsed-expected.txt
new file mode 100644 (file)
index 0000000..5dee95e
--- /dev/null
@@ -0,0 +1,15 @@
+Tests for the Debugger.scriptParsed messages the frontend receives when enabling the Debugger domain.
+
+
+== Running test suite: Debugger.scriptParsed.enable
+-- Running test case: EnableDebuggerDomainAndCheckInitialScripts
+Debugger Enabled - Initial Scripts Received
+PASS: Should have received some scriptParsed messages.
+PASS: Should find External Script.
+PASS: Should find Inline Script Tag Script.
+PASS: Should find Inline Attribute Event Listener Script.
+PASS: Should find Eval Script.
+PASS: Should find Inspector InjectedScriptSource Script.
+PASS: Should find Inspector CommandLineAPISource Script.
+PASS: Should not receive any unexpected scripts.
+
diff --git a/LayoutTests/inspector/debugger/scriptParsed.html b/LayoutTests/inspector/debugger/scriptParsed.html
new file mode 100644 (file)
index 0000000..57ebbca
--- /dev/null
@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
+<script>
+// Create a named eval.
+eval("//# sourceURL=eval.js\nfunction foo() { }");
+
+function test()
+{
+    let suite = ProtocolTest.createAsyncSuite("Debugger.scriptParsed.enable");
+
+    ProtocolTest.dumpActivityToSystemConsole = true;
+    ProtocolTest.dumpInspectorProtocolMessages = true;
+
+    // Because InspectorTest output causes scripts to be parsed
+    // this test only checks the scripts the frontend is notified
+    // of when enabling the Debugger domain.
+    //
+    // Scripts we expect to see (in an undefined order)
+    //   - external <script> protocol-test.js
+    //   - inline <script> (this) starting on line 5
+    //   - inline body onload event listener attribute on <body> line below
+    //   - eval source above on line 7
+    //   - inspector internal scripts InjectedScriptSource.js CommandLineAPIModuleSource.js
+
+    let foundExternalScript = false;
+    let foundInlineScriptTagScript = false;
+    let foundInlineAttributeEventListenerScript = false;
+    let foundEvalScript = false;
+    let foundInjectedScriptSourceScript = false;
+    let foundCommandLineAPISourceScript = false;
+    let foundUnexpectedScript = false;
+
+    function isExternalScript(params) {
+        return /inspector\/resources\/protocol-test\.js/.test(params.url);
+    }
+
+    function isInlineScript(params) {
+        return /inspector\/debugger\/scriptParsed\.html$/.test(params.url);
+    }
+
+    function isInlineScriptTagScript(params) {
+        return isInlineScript(params) && params.startLine === 4;
+    }
+
+    function isInlineAttributeEventListenerScript(params) {
+        return isInlineScript(params) && params.startLine >= 100; // Estimate of <body> below.
+    }
+
+    function isEvalScript(params) {
+        return params.hasSourceURL && params.url === "eval.js";
+    }
+
+    function isInjectedScriptSourceScript(params) {
+        return params.hasSourceURL && params.url === "__WebInspectorInjectedScript__";
+    }
+
+    function isCommandLineAPISourceScript(params) {
+        return params.hasSourceURL && params.url === "__WebInspectorCommandLineAPIModuleSource__";
+    }
+
+    suite.addTestCase({
+        name: "EnableDebuggerDomainAndCheckInitialScripts",
+        test: (resolve, reject) => {
+
+            let initialScriptParsedMessages = [];
+            let receivingInitialScripts = true;
+            InspectorProtocol.sendCommand("Debugger.enable", {}, function() {
+                receivingInitialScripts = false;
+
+                ProtocolTest.log("Debugger Enabled - Initial Scripts Received");
+                ProtocolTest.expectThat(initialScriptParsedMessages.length > 0, "Should have received some scriptParsed messages.");
+
+                for (let messageObject of initialScriptParsedMessages) {
+                    let params = messageObject.params;
+                    if (!foundExternalScript && isExternalScript(params))
+                        foundExternalScript = true;
+                    else if (!foundInlineScriptTagScript && isInlineScriptTagScript(params))
+                        foundInlineScriptTagScript = true;
+                    else if (!foundInlineAttributeEventListenerScript && isInlineAttributeEventListenerScript(params))
+                        foundInlineAttributeEventListenerScript = true;
+                    else if (!foundEvalScript && isEvalScript(params))
+                        foundEvalScript = true;
+                    else if (!foundInjectedScriptSourceScript && isInjectedScriptSourceScript(params))
+                        foundInjectedScriptSourceScript = true;
+                    else if (!foundCommandLineAPISourceScript && isCommandLineAPISourceScript(params))
+                        foundCommandLineAPISourceScript = true;
+                    else {
+                        ProtocolTest.log("UNEXPECTED SCRIPT: " + JSON.stringify(messageObject));
+                        foundUnexpectedScript = true;
+                    }
+                }
+
+                ProtocolTest.expectThat(foundExternalScript, "Should find External Script.");
+                ProtocolTest.expectThat(foundInlineScriptTagScript, "Should find Inline Script Tag Script.");
+                ProtocolTest.expectThat(foundInlineAttributeEventListenerScript, "Should find Inline Attribute Event Listener Script.");
+                ProtocolTest.expectThat(foundEvalScript, "Should find Eval Script.");
+                ProtocolTest.expectThat(foundInjectedScriptSourceScript, "Should find Inspector InjectedScriptSource Script.");
+                ProtocolTest.expectThat(foundCommandLineAPISourceScript, "Should find Inspector CommandLineAPISource Script.");
+                ProtocolTest.expectThat(!foundUnexpectedScript, "Should not receive any unexpected scripts.");
+
+                resolve();
+            });
+
+            InspectorProtocol.eventHandler["Debugger.scriptParsed"] = function(messageObject) {
+                // Ignore non-initial load scripts.
+                if (!receivingInitialScripts)
+                    return;
+
+                initialScriptParsedMessages.push(messageObject);
+            };
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()"> <!-- This line number is important -->
+<p>Tests for the Debugger.scriptParsed messages the frontend receives when enabling the Debugger domain.</p>
+</body>
+</html>
index 995a24baf1c599d9c3dd06ea7edf758d9e659fb6..c4d1535299e321f1ff15c06ddb5b1fb5947f8127 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-30  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Test Debugger.scriptParsed events received after opening inspector frontend
+        https://bugs.webkit.org/show_bug.cgi?id=150753
+
+        Reviewed by Timothy Hatcher.
+
+        * parser/Parser.h:
+        (JSC::Parser<LexerType>::parse):
+        Only set the directives on the SourceProvider if we were parsing the
+        entire file (Program or Module), not if we are in function parsing mode.
+        This was inadvertently clearing the directives stored on the
+        SourceProvider when the function parse didn't see directives and reset
+        the values on the source provider.
+
 2015-10-30  Benjamin Poulain  <bpoulain@apple.com>
 
         [JSC] Add lowering for B3's Sub operation with integers
index 5231c2adfdab23e1789da4dc6394a842e076724e..b9089bc3ea16f328dd14038ebb056ca21400aaf1 100644 (file)
@@ -1330,8 +1330,10 @@ std::unique_ptr<ParsedNode> Parser<LexerType>::parse(ParserError& error, const I
         result->setLoc(m_source->firstLine(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
         result->setEndOffset(m_lexer->currentOffset());
 
-        m_source->provider()->setSourceURLDirective(m_lexer->sourceURL());
-        m_source->provider()->setSourceMappingURLDirective(m_lexer->sourceMappingURL());
+        if (!isFunctionParseMode(parseMode)) {
+            m_source->provider()->setSourceURLDirective(m_lexer->sourceURL());
+            m_source->provider()->setSourceMappingURLDirective(m_lexer->sourceMappingURL());
+        }
     } else {
         // We can never see a syntax error when reparsing a function, since we should have
         // reported the error when parsing the containing program or eval code. So if we're