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 /* vim: set ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 "use strict";
7 // Test that markup-containers in the markup-view do flash when their
8 // corresponding DOM nodes mutate
10 const TEST_URL = TEST_URL_ROOT + "doc_markup_flashing.html";
11 // The test data contains a list of mutations to test.
12 // Each item is an object:
13 // - desc: a description of the test step, for better logging
14 // - mutate: a function that should make changes to the content DOM
15 // - shouldFlash: a function that returns the element that should be the one flashing
16 const TEST_DATA = [{
17 desc: "Adding a new node should flash the new node",
18 mutate: (doc, rootNode) => {
19 let newLi = doc.createElement("LI");
20 newLi.textContent = "new list item";
21 rootNode.appendChild(newLi);
22 },
23 shouldFlash: rootNode => rootNode.lastElementChild
24 }, {
25 desc: "Removing a node should flash its parent",
26 mutate: (doc, rootNode) => {
27 rootNode.removeChild(rootNode.lastElementChild);
28 },
29 shouldFlash: rootNode => rootNode
30 }, {
31 desc: "Re-appending an existing node should only flash this node",
32 mutate: (doc, rootNode) => {
33 rootNode.appendChild(rootNode.firstElementChild);
34 },
35 shouldFlash: rootNode => rootNode.lastElementChild
36 }, {
37 desc: "Adding an attribute should flash the node",
38 mutate: (doc, rootNode) => {
39 rootNode.setAttribute("name-" + Date.now(), "value-" + Date.now());
40 },
41 shouldFlash: rootNode => rootNode
42 }, {
43 desc: "Editing an attribute should flash the node",
44 mutate: (doc, rootNode) => {
45 rootNode.setAttribute("class", "list value-" + Date.now());
46 },
47 shouldFlash: rootNode => rootNode
48 }, {
49 desc: "Removing an attribute should flash the node",
50 mutate: (doc, rootNode) => {
51 rootNode.removeAttribute("class");
52 },
53 shouldFlash: rootNode => rootNode
54 }];
56 let test = asyncTest(function*() {
57 let {inspector} = yield addTab(TEST_URL).then(openInspector);
59 info("Getting the <ul.list> root node to test mutations on");
60 let rootNode = getNode(".list");
62 info("Selecting the last element of the root node before starting");
63 yield selectNode(rootNode.lastElementChild, inspector);
65 for (let {mutate, shouldFlash, desc} of TEST_DATA) {
66 info("Starting test: " + desc);
68 info("Mutating the DOM and listening for markupmutation event");
69 let mutated = inspector.once("markupmutation");
70 let updated = inspector.once("inspector-updated");
71 mutate(content.document, rootNode);
72 yield mutated;
74 info("Asserting that the correct markup-container is flashing");
75 assertNodeFlashing(shouldFlash(rootNode), inspector);
77 // Making sure the inspector has finished updating before moving on
78 yield updated;
79 }
80 });
82 function assertNodeFlashing(node, inspector) {
83 let container = getContainerForRawNode(node, inspector);
85 if (!container) {
86 ok(false, "Node not found");
87 } else {
88 ok(container.tagState.classList.contains("theme-bg-contrast"),
89 "Node is flashing");
90 }
91 }