Title: [188019] trunk/LayoutTests
Revision
188019
Author
commit-qu...@webkit.org
Date
2015-08-05 21:36:04 -0700 (Wed, 05 Aug 2015)

Log Message

Web Inspector: rewrite protocol test for console messages from X-Frame-Options
https://bugs.webkit.org/show_bug.cgi?id=147714

Patch by Brian Burg <bb...@apple.com> on 2015-08-05
Reviewed by Joseph Pecoraro.

Rewrite deny-X-FrameOption.html to use AsyncTestSuite, and hopefully address
the flakiness of the test. It is now in the inspector-protocol/console/ directory.

Extract the addConsoleTestCase helper to a shared file. Clean up console test
helpers and use a less awkward namespace for these helpers.

* TestExpectations: Unskip the deleted test, the new test should be less flaky.
* inspector-protocol/console/console-message.html:
* inspector-protocol/console/css-source-locations.html:
* inspector-protocol/console/js-source-locations.html:
* inspector-protocol/console/x-frame-options-message-expected.txt: Added.
* inspector-protocol/console/x-frame-options-message.html: Added.
* inspector-protocol/debugger/setBreakpoint-actions.html:
* inspector-protocol/debugger/setBreakpoint-options-exception.html:
* inspector-protocol/page/deny-X-FrameOption-expected.txt: Removed.
* inspector-protocol/page/deny-X-FrameOption.html: Removed.
* inspector-protocol/resources/console-helper.js: Removed.
* inspector-protocol/resources/console-test.js: Added.
(InspectorTest.Console.sanitizeConsoleMessage):
(InspectorTest.Console.addTestCase):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (188018 => 188019)


--- trunk/LayoutTests/ChangeLog	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/ChangeLog	2015-08-06 04:36:04 UTC (rev 188019)
@@ -1,3 +1,31 @@
+2015-08-05  Brian Burg  <bb...@apple.com>
+
+        Web Inspector: rewrite protocol test for console messages from X-Frame-Options
+        https://bugs.webkit.org/show_bug.cgi?id=147714
+
+        Reviewed by Joseph Pecoraro.
+
+        Rewrite deny-X-FrameOption.html to use AsyncTestSuite, and hopefully address
+        the flakiness of the test. It is now in the inspector-protocol/console/ directory.
+
+        Extract the addConsoleTestCase helper to a shared file. Clean up console test
+        helpers and use a less awkward namespace for these helpers.
+
+        * TestExpectations: Unskip the deleted test, the new test should be less flaky.
+        * inspector-protocol/console/console-message.html:
+        * inspector-protocol/console/css-source-locations.html:
+        * inspector-protocol/console/js-source-locations.html:
+        * inspector-protocol/console/x-frame-options-message-expected.txt: Added.
+        * inspector-protocol/console/x-frame-options-message.html: Added.
+        * inspector-protocol/debugger/setBreakpoint-actions.html:
+        * inspector-protocol/debugger/setBreakpoint-options-exception.html:
+        * inspector-protocol/page/deny-X-FrameOption-expected.txt: Removed.
+        * inspector-protocol/page/deny-X-FrameOption.html: Removed.
+        * inspector-protocol/resources/console-helper.js: Removed.
+        * inspector-protocol/resources/console-test.js: Added.
+        (InspectorTest.Console.sanitizeConsoleMessage):
+        (InspectorTest.Console.addTestCase):
+
 2015-08-05  Ryosuke Niwa  <rn...@webkit.org>
 
         [ES6] Class parser does not allow methods named set and get.

Modified: trunk/LayoutTests/TestExpectations (188018 => 188019)


--- trunk/LayoutTests/TestExpectations	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/TestExpectations	2015-08-06 04:36:04 UTC (rev 188019)
@@ -93,7 +93,6 @@
 
 webkit.org/b/133761 inspector-protocol/debugger/breakpoint-action-detach.html [ Skip ]
 webkit.org/b/129639 inspector-protocol/dom/dom-search-crash.html [ Skip ]
-webkit.org/b/127414 inspector-protocol/page/deny-X-FrameOption.html [ Pass Failure ]
 
 webkit.org/b/147502 inspector/debugger/break-on-uncaught-exception-throw-in-promise-rethrow-in-catch.html [ Skip ]
 webkit.org/b/147502 inspector/debugger/break-on-uncaught-exception-throw-in-promise-then-with-catch.html [ Skip ]

Modified: trunk/LayoutTests/inspector-protocol/console/console-message.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/console/console-message.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/console/console-message.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -13,9 +13,11 @@
 
 function test()
 {
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
+
     var suite = new InspectorTest.AsyncTestSuite("Console.MessagesFromCommandLineAPI");
 
-    addConsoleTestCase({
+    InspectorTest.Console.addTestCase(suite, {
         name: "ConsoleLogString",
         description: "Test `console.log(\"log\")`",
         _expression_: 'console.log("log");',
@@ -27,7 +29,7 @@
         }
     });
 
-    addConsoleTestCase({
+    InspectorTest.Console.addTestCase(suite, {
         name: "ConsoleInfoString",
         description: "Test `console.info(\"info\")`",
         _expression_: 'console.info("info");',
@@ -39,7 +41,7 @@
         }
     });
 
-    addConsoleTestCase({
+    InspectorTest.Console.addTestCase(suite, {
         name: "ConsoleWarnString",
         description: "Test `console.warn(\"warn\")`",
         _expression_: 'console.warn("warn");',
@@ -51,7 +53,7 @@
         }
     });
 
-    addConsoleTestCase({
+    InspectorTest.Console.addTestCase(suite, {
         name: "ConsoleErrorString",
         description: "Test `console.error(\"error\")`",
         _expression_: 'console.error("error");',
@@ -63,7 +65,7 @@
         }
     });
 
-    addConsoleTestCase({
+    InspectorTest.Console.addTestCase(suite, {
         name: "ConsoleDebugString",
         description: "Test `console.debug(\"debug\")`",
         _expression_: 'console.debug("debug");',
@@ -75,9 +77,6 @@
         }
     });
 
-    // Set up the console prior to running the test suite.
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
-
     InspectorTest.awaitCommand({
         method: "Console.enable",
         params: {}
@@ -91,41 +90,6 @@
         InspectorTest.log("Test failed with fatal error: " + JSON.stringify(e));
         InspectorTest.completeTest();
     }
-
-    function addConsoleTestCase(args) {
-        var {name, description, _expression_, expected} = args;
-        suite.addTestCase({
-            name,
-            description,
-            test: function(resolve, reject) {
-                InspectorTest.awaitEvent({
-                    event: "Console.messageAdded",
-                })
-                .then(function(messageObject) {
-                    var consoleMessage = messageObject.params.message;
-                    var {source, level, text, parameters} = consoleMessage;
-                    InspectorTest.assert(source === expected.source, "ConsoleMessage type should be '" + expected.source + "'.");
-                    InspectorTest.assert(level === expected.level, "ConsoleMessage level should be '" + expected.level + "'.");
-                    InspectorTest.assert(text === expected.text, "ConsoleMessage text should be '" + expected.text + "'.");
-
-                    InspectorTest.assert(parameters.length === expected.parameters.length, "ConsoleMessage parameters.length === " + expected.parameters.length);
-                    for (var i = 0; i < parameters.length; ++i) {
-                        var expectedType = expected.parameters[i];
-                        InspectorTest.assert(parameters[i].type === expectedType, "ConsoleMessage parameter " + i + " should have type '" + expectedType + "'.");
-                    }
-                    resolve();
-                })
-                .catch(reject);
-
-                // Cause a messageAdded event to be generated.
-                InspectorTest.log("Evaluating _expression_: " + _expression_);
-                InspectorTest.sendCommand({
-                    method: "Runtime.evaluate",
-                    params: {_expression_}
-                });
-            }
-        });
-    }
 }
 </script>
 </head>

Modified: trunk/LayoutTests/inspector-protocol/console/css-source-locations.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/console/css-source-locations.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/console/css-source-locations.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -14,7 +14,7 @@
 <script>
 function test()
 {
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
 
     var consoleMessageCount = 0;
     const expectedConsoleMessageCount = 7;
@@ -24,8 +24,8 @@
     InspectorTest.addEventListener({
         event: "Console.messageAdded",
         listener: function(messageObject) {
-            var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
-            InspectorTest.log(JSON.stringify(simplifiedMessage));
+            var message = InspectorTest.Console.sanitizeConsoleMessage(messageObject);
+            InspectorTest.log(JSON.stringify(message));
 
             if (++consoleMessageCount === expectedConsoleMessageCount)
                 InspectorTest.completeTest();

Modified: trunk/LayoutTests/inspector-protocol/console/js-source-locations.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/console/js-source-locations.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/console/js-source-locations.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -10,7 +10,7 @@
 <script>
 function test()
 {
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
 
     var consoleMessageCount = 0;
     const expectedConsoleMessageCount = 8;
@@ -20,8 +20,8 @@
     InspectorTest.addEventListener({
         event: "Console.messageAdded",
         listener: function(messageObject) {
-            var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
-            InspectorTest.log(JSON.stringify(simplifiedMessage));
+            var message = InspectorTest.Console.sanitizeConsoleMessage(messageObject);
+            InspectorTest.log(JSON.stringify(message));
 
             if (++consoleMessageCount === expectedConsoleMessageCount)
                 InspectorTest.completeTest();

Added: trunk/LayoutTests/inspector-protocol/console/x-frame-options-message-expected.txt (0 => 188019)


--- trunk/LayoutTests/inspector-protocol/console/x-frame-options-message-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector-protocol/console/x-frame-options-message-expected.txt	2015-08-06 04:36:04 UTC (rev 188019)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 41: Refused to display 'x-frame-options-message.html' in a frame because it set 'X-Frame-Options' to 'deny'.
+
+
+== Running test suite: Console.XFrameOptionsMessages
+-- Running test case: XFrameOptionsDeny
+Evaluating _expression_: triggerXFrameOptionDeny();
+PASS: ConsoleMessage type should be 'security'.
+PASS: ConsoleMessage level should be 'error'.
+

Added: trunk/LayoutTests/inspector-protocol/console/x-frame-options-message.html (0 => 188019)


--- trunk/LayoutTests/inspector-protocol/console/x-frame-options-message.html	                        (rev 0)
+++ trunk/LayoutTests/inspector-protocol/console/x-frame-options-message.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script type="text/_javascript_" src=""
+<script>
+function test()
+{
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
+
+    let suite = new InspectorTest.AsyncTestSuite("Console.XFrameOptionsMessages");
+
+    InspectorTest.Console.addTestCase(suite, {
+        name: "XFrameOptionsDeny",
+        description: "Ensure that a console message is logged when enforcing an X-Frame-Options policy. In this case, setting X-Frame-Options: 'deny' means the iframe does not want to be embedded in the test page.",
+        _expression_: "triggerXFrameOptionDeny();",
+        expected: {source: 'security', level: 'error'}
+    });
+
+    InspectorTest.awaitCommand({
+        method: "Console.enable",
+        params: {}
+    })
+    .then(function() {
+        suite.runTestCasesAndFinish();
+    })
+    .catch(fatalError);
+
+    function fatalError(e) {
+        InspectorTest.log("Test failed with fatal error: " + JSON.stringify(e));
+        InspectorTest.completeTest();
+    }
+}
+</script>
+</head>
+<body _onload_="runTest()">
+  <iframe id="denied"></iframe>
+  <script>
+  function triggerXFrameOptionDeny()
+  {
+    let deniedFrame = document.getElementById('denied');
+    let deniedDocument = deniedFrame.contentWindow.document;
+    deniedDocument.write('<meta http-equiv="X-Frame-Options" content="deny"/>');
+  }
+  </script>
+</body>
+</html>

Modified: trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-actions.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-actions.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-actions.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -5,7 +5,7 @@
 <script>
 function test()
 {
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
     InspectorTest.importScript("../../../../inspector-protocol/resources/probe-helper.js");
 
     InspectorTest.sendCommand("Console.enable", {});
@@ -111,8 +111,8 @@
             return;
         }
 
-        var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
-        InspectorTest.log("PASS: Console Message: " + JSON.stringify(simplifiedMessage));
+        var message = InspectorTest.Console.sanitizeConsoleMessage(messageObject);
+        InspectorTest.log("PASS: Console Message: " + JSON.stringify(message));
 
         ++logCount;
 

Modified: trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-options-exception.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-options-exception.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/debugger/setBreakpoint-options-exception.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -5,7 +5,7 @@
 <script>
 function test()
 {
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
+    InspectorTest.importScript("../../../../inspector-protocol/resources/console-test.js");
 
     InspectorTest.sendCommand("Console.enable", {});
     InspectorTest.sendCommand("Debugger.enable", {});
@@ -45,8 +45,8 @@
 
     InspectorTest.eventHandler["Console.messageAdded"] = function(messageObject)
     {
-        var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
-        InspectorTest.log("PASS: Console Message: " + JSON.stringify(simplifiedMessage));
+        var message = InspectorTest.Console.sanitizeConsoleMessage(messageObject);
+        InspectorTest.log("PASS: Console Message: " + JSON.stringify(message));
 
         if (++logsSeen === expectedLogs)
             InspectorTest.completeTest();

Deleted: trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption-expected.txt (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption-expected.txt	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption-expected.txt	2015-08-06 04:36:04 UTC (rev 188019)
@@ -1,4 +0,0 @@
-CONSOLE MESSAGE: line 30: Refused to display 'deny-X-FrameOption.html' in a frame because it set 'X-Frame-Options' to 'deny'.
-
-deny-X-FrameOption.html:30:17
-

Deleted: trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption.html (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption.html	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/page/deny-X-FrameOption.html	2015-08-06 04:36:04 UTC (rev 188019)
@@ -1,35 +0,0 @@
-<html>
-<head>
-<script type="text/_javascript_" src=""
-<script>
-function test()
-{
-    InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
-    InspectorTest.sendCommand("Console.enable", {});
-
-    InspectorTest.eventHandler["Console.messageAdded"] = function(messageObject)
-    {
-        var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
-        // FIXME The line and column values will be zeros until this fix:
-        // https://bugs.webkit.org/show_bug.cgi?id=125340
-        // After this probably we should update the expected.txt.
-        InspectorTest.log(simplifiedMessage.location);
-
-        InspectorTest.completeTest();
-    }
-}
-</script>
-</head>
-<body _onload_="startTest()">
-  <iframe id=foo></iframe>
-  <script>
-  function startTest()
-  {
-    var fooFrame = document.getElementById('foo');
-    var fooDoc = fooFrame.contentWindow.document;
-    fooDoc.write('<meta http-equiv="X-Frame-Options" content="deny"/>');
-    runTest();
-  }
-  </script>
-</body>
-</html>

Deleted: trunk/LayoutTests/inspector-protocol/resources/console-helper.js (188018 => 188019)


--- trunk/LayoutTests/inspector-protocol/resources/console-helper.js	2015-08-06 04:01:00 UTC (rev 188018)
+++ trunk/LayoutTests/inspector-protocol/resources/console-helper.js	2015-08-06 04:36:04 UTC (rev 188019)
@@ -1,31 +0,0 @@
-window.ConsoleHelper = {};
-
-ConsoleHelper.simplifiedConsoleMessage = function(messageObject)
-{
-    function basename(url)
-    {
-        return url.substring(url.lastIndexOf("/") + 1) || "???";
-    }
-
-    var message = messageObject.params.message;
-    var obj = {
-        source: message.source,
-        level: message.level,
-        text: message.text,
-        location: basename(message.url) + ":" + message.line + ":" + message.column
-    };
-
-    if (message.parameters) {
-        var params = [];
-        for (var i = 0; i < message.parameters.length; ++i) {
-            var param = message.parameters[i];
-            var o = {type: param.type};
-            if (param.subtype)
-                o.subtype = param.subtype;
-            params.push(o);
-        }
-        obj.parameters = params;
-    }
-
-    return obj;
-}

Added: trunk/LayoutTests/inspector-protocol/resources/console-test.js (0 => 188019)


--- trunk/LayoutTests/inspector-protocol/resources/console-test.js	                        (rev 0)
+++ trunk/LayoutTests/inspector-protocol/resources/console-test.js	2015-08-06 04:36:04 UTC (rev 188019)
@@ -0,0 +1,75 @@
+InspectorTest.Console = {};
+
+InspectorTest.Console.sanitizeConsoleMessage = function(messageObject)
+{
+    function basename(url)
+    {
+        return url.substring(url.lastIndexOf("/") + 1) || "???";
+    }
+
+    var message = messageObject.params.message;
+    var obj = {
+        source: message.source,
+        level: message.level,
+        text: message.text,
+        location: basename(message.url) + ":" + message.line + ":" + message.column
+    };
+
+    if (message.parameters) {
+        var params = [];
+        for (var i = 0; i < message.parameters.length; ++i) {
+            var param = message.parameters[i];
+            var o = {type: param.type};
+            if (param.subtype)
+                o.subtype = param.subtype;
+            params.push(o);
+        }
+        obj.parameters = params;
+    }
+
+    return obj;
+}
+
+InspectorTest.Console.addTestCase = function(suite, args)
+{
+    if (!(suite instanceof InspectorTest.AsyncTestSuite))
+        throw new Error("Console test cases must be added to an async test suite.");
+
+    var {name, description, _expression_, expected} = args;
+    suite.addTestCase({
+        name,
+        description,
+        test: function(resolve, reject) {
+            InspectorTest.awaitEvent({
+                event: "Console.messageAdded",
+            })
+            .then(function(messageObject) {
+                var consoleMessage = messageObject.params.message;
+                var {source, level, text, parameters} = consoleMessage;
+                InspectorTest.assert(source === expected.source, "ConsoleMessage type should be '" + expected.source + "'.");
+                InspectorTest.assert(level === expected.level, "ConsoleMessage level should be '" + expected.level + "'.");
+
+                if (expected.text)
+                    InspectorTest.assert(text === expected.text, "ConsoleMessage text should be '" + expected.text + "'.");
+
+                if (expected.parameters) {
+                    InspectorTest.assert(parameters.length === expected.parameters.length, "ConsoleMessage parameters.length === " + expected.parameters.length);
+                    for (var i = 0; i < parameters.length; ++i) {
+                        var expectedType = expected.parameters[i];
+                        InspectorTest.assert(parameters[i].type === expectedType, "ConsoleMessage parameter " + i + " should have type '" + expectedType + "'.");
+                    }
+                }
+
+                resolve();
+            })
+            .catch(reject);
+
+            // Cause a messageAdded event to be generated.
+            InspectorTest.log("Evaluating _expression_: " + _expression_);
+            InspectorTest.sendCommand({
+                method: "Runtime.evaluate",
+                params: {_expression_}
+            });
+        }
+    });
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to