Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /**
6 * Run a series of edit-outer-html tests.
7 * This function will iterate over the provided tests array and run each test.
8 * Each test's goal is to provide a node (a selector) and a new outer-HTML to be
9 * inserted in place of the current one for that node.
10 * This test runner will wait for the mutation event to be fired and will check
11 * a few things. Each test may also provide its own validate function to perform
12 * assertions and verify that the new outer html is correct.
13 * @param {Array} tests See runEditOuterHTMLTest for the structure
14 * @param {InspectorPanel} inspector The instance of InspectorPanel currently
15 * opened
16 * @return a promise that resolves when the tests have run
17 */
18 function runEditOuterHTMLTests(tests, inspector) {
19 info("Running " + tests.length + " edit-outer-html tests");
20 return Task.spawn(function* () {
21 for (let step of TEST_DATA) {
22 yield runEditOuterHTMLTest(step, inspector);
23 }
24 });
25 }
27 /**
28 * Run a single edit-outer-html test.
29 * See runEditOuterHTMLTests for a description.
30 * @param {Object} test A test object should contain the following properties:
31 * - selector {String} a css selector targeting the node to edit
32 * - oldHTML {String}
33 * - newHTML {String}
34 * - validate {Function} will be executed when the edition test is done,
35 * after the new outer-html has been inserted. Should be used to verify
36 * the actual DOM, see if it corresponds to the newHTML string provided
37 * @param {InspectorPanel} inspector The instance of InspectorPanel currently
38 * opened
39 */
40 function* runEditOuterHTMLTest(test, inspector) {
41 info("Running an edit outerHTML test on '" + test.selector + "'");
42 yield selectNode(test.selector, inspector);
43 let oldNodeFront = inspector.selection.nodeFront;
45 info("Listening for the markupmutation event");
46 // This event fires once the outerHTML is set, with a target as the parent node and a type of "childList".
47 let mutated = inspector.once("markupmutation");
48 info("Editing the outerHTML");
49 inspector.markup.updateNodeOuterHTML(inspector.selection.nodeFront, test.newHTML, test.oldHTML);
50 let mutations = yield mutated;
51 ok(true, "The markupmutation event has fired, mutation done");
53 info("Check to make the sure the correct mutation event was fired, and that the parent is selected");
54 let nodeFront = inspector.selection.nodeFront;
55 let mutation = mutations[0];
56 let isFromOuterHTML = mutation.removed.some(n => n === oldNodeFront);
58 ok(isFromOuterHTML, "The node is in the 'removed' list of the mutation");
59 is(mutation.type, "childList", "Mutation is a childList after updating outerHTML");
60 is(mutation.target, nodeFront, "Parent node is selected immediately after setting outerHTML");
62 // Wait for node to be reselected after outerHTML has been set
63 yield inspector.selection.once("new-node");
65 // Typically selectedNode will === pageNode, but if a new element has been injected in front
66 // of it, this will not be the case. If this happens.
67 let selectedNode = inspector.selection.node;
68 let nodeFront = inspector.selection.nodeFront;
69 let pageNode = getNode(test.selector);
71 if (test.validate) {
72 test.validate(pageNode, selectedNode);
73 } else {
74 is(pageNode, selectedNode, "Original node (grabbed by selector) is selected");
75 is(pageNode.outerHTML, test.newHTML, "Outer HTML has been updated");
76 }
78 // Wait for the inspector to be fully updated to avoid causing errors by
79 // abruptly closing hanging requests when the test ends
80 yield inspector.once("inspector-updated");
81 }