Bug 1405245 - enable test-csp-violation.html for new webconsole;r=nchevobbe
MozReview-Commit-ID: IgONHkE3Pjk
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -6,17 +6,16 @@ support-files =
code_bundle_invalidmap.js.map
code_bundle_nosource.js
code_bundle_nosource.js.map
head.js
sjs_slow-response-test-server.sjs
source-mapped.css
source-mapped.css.map
source-mapped.scss
- test_bug_1247459_violation.html
test_bug_770099_violation.html
test_bug_770099_violation.html^headers^
test_console_csp_ignore_reflected_xss_message.html
test_console_csp_ignore_reflected_xss_message.html^headers^
test_hpkp-invalid-headers.sjs
test_hsts-invalid-headers.sjs
test-autocomplete-in-stackframe.html
test-batching.html
@@ -41,16 +40,17 @@ support-files =
test-bug-782653-css-errors-2.css
test-bug-782653-css-errors.html
test-bug-837351-security-errors.html
test-bug-859170-longstring-hang.html
test-bug-952277-highlight-nodes-in-vview.html
test-cd-iframe-child.html
test-cd-iframe-parent.html
test-console-api-iframe.html
+ test-csp-violation.html
test-cspro.html
test-cspro.html^headers^
test-iframe-child.html
test-iframe-parent.html
test-certificate-messages.html
test-click-function-to-source.html
test-click-function-to-source.js
test-closure-optimized-out.html
@@ -261,16 +261,17 @@ subsuite = clipboard
skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
[browser_webconsole_context_menu_copy_object.js]
subsuite = clipboard
[browser_webconsole_context_menu_object_in_sidebar.js]
[browser_webconsole_context_menu_open_url.js]
[browser_webconsole_context_menu_store_as_global.js]
[browser_webconsole_csp_ignore_reflected_xss_message.js]
skip-if = (e10s && debug) || (e10s && os == 'win') # Bug 1221499 enabled these on windows
+[browser_webconsole_csp_violation.js]
[browser_webconsole_cspro.js]
[browser_webconsole_document_focus.js]
[browser_webconsole_duplicate_errors.js]
[browser_webconsole_errors_after_page_reload.js]
[browser_webconsole_eval_in_debugger_stackframe.js]
[browser_webconsole_eval_in_debugger_stackframe2.js]
[browser_webconsole_execution_scope.js]
[browser_webconsole_external_script_errors.js]
@@ -379,14 +380,11 @@ skip-if = true # Bug 1405650
# old console skip-if = (os == 'win' && bits == 64) # Bug 1390001
[browser_webconsole_variables_view_dont_sort_non_sortable_classes_properties.js]
skip-if = true # Bug 1403196
[browser_webconsole_variables_view_while_debugging.js]
skip-if = true # Bug 1403200
[browser_webconsole_variables_view_while_debugging_and_inspecting.js]
skip-if = true # Bug 1403205
[browser_webconsole_view_source.js]
-[browser_webconsole_violation.js]
-skip-if = true # Bug 1405245
-# old console skip-if = e10s && (os == 'win') # Bug 1264955
[browser_webconsole_visibility_messages.js]
[browser_webconsole_warn_about_replaced_api.js]
[browser_webconsole_websocket.js]
rename from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_violation.js
rename to devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_csp_violation.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_violation.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_csp_violation.js
@@ -4,37 +4,24 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the Web Console CSP messages for two META policies
// are correctly displayed. See Bug 1247459.
"use strict";
const TEST_URI = "data:text/html;charset=utf8,Web Console CSP violation test";
-const TEST_VIOLATION = "https://example.com/browser/devtools/client/" +
- "webconsole/test/test_bug_1247459_violation.html";
+const TEST_VIOLATION = "https://example.com/browser/devtools/client/webconsole/" +
+ "new-console-output/test/mochitest/test-csp-violation.html";
const CSP_VIOLATION_MSG = "Content Security Policy: The page\u2019s settings " +
"blocked the loading of a resource at " +
- "http://some.example.com/test.png (\u201cimg-src " +
- "https://example.com\u201d).";
+ "http://some.example.com/test.png (\u201cimg-src\u201d).";
-add_task(function* () {
- let { browser } = yield loadTab(TEST_URI);
-
- let hud = yield openConsole();
-
+add_task(async function () {
+ let hud = await openNewTabAndConsole(TEST_URI);
hud.jsterm.clearOutput();
- let loaded = loadBrowser(browser);
- BrowserTestUtils.loadURI(browser, TEST_VIOLATION);
- yield loaded;
+ let onRepeatedMessage = waitForRepeatedMessage(hud, CSP_VIOLATION_MSG, 2);
+ await loadDocument(TEST_VIOLATION);
+ await onRepeatedMessage;
- yield waitForMessages({
- webconsole: hud,
- messages: [
- {
- name: "CSP policy URI warning displayed successfully",
- text: CSP_VIOLATION_MSG,
- repeats: 2
- }
- ]
- });
+ ok(true, "Received expected messages");
});
--- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js
@@ -134,16 +134,41 @@ function waitForMessages({ hud, messages
return;
}
}
});
});
}
/**
+ * Wait for a message with the provided text and showing the provided repeat count.
+ *
+ * @param {Object} hud : the webconsole
+ * @param {String} text : text included in .message-body
+ * @param {Number} repeat : expected repeat count in .message-repeats
+ */
+function waitForRepeatedMessage(hud, text, repeat) {
+ return waitFor(() => {
+ // Wait for a message matching the provided text.
+ let node = findMessage(hud, text);
+ if (!node) {
+ return false;
+ }
+
+ // Check if there is a repeat node with the expected count.
+ let repeatNode = node.querySelector(".message-repeats");
+ if (repeatNode && parseInt(repeatNode.textContent, 10) === repeat) {
+ return node;
+ }
+
+ return false;
+ });
+}
+
+/**
* Wait for a single message in the web console output, resolving once it is received.
*
* @param {Object} hud : the webconsole
* @param {String} text : text included in .message-body
*/
async function waitForMessage(hud, text) {
const messages = await waitForMessages({hud, messages: [{text}]});
return messages[0];
@@ -172,16 +197,17 @@ async function waitFor(condition, messag
* Find a message in the output.
*
* @param object hud
* The web console.
* @param string text
* A substring that can be found in the message.
* @param selector [optional]
* The selector to use in finding the message.
+ * @return {Node} the node corresponding the found message
*/
function findMessage(hud, text, selector = ".message") {
const elements = findMessages(hud, text, selector);
return elements.pop();
}
/**
* Find multiple messages in the output.
rename from devtools/client/webconsole/new-console-output/test/mochitest/test_bug_1247459_violation.html
rename to devtools/client/webconsole/new-console-output/test/mochitest/test-csp-violation.html