michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test that markup-containers in the markup-view do flash when their michael@0: // corresponding DOM nodes mutate michael@0: michael@0: const TEST_URL = TEST_URL_ROOT + "doc_markup_flashing.html"; michael@0: // The test data contains a list of mutations to test. michael@0: // Each item is an object: michael@0: // - desc: a description of the test step, for better logging michael@0: // - mutate: a function that should make changes to the content DOM michael@0: // - shouldFlash: a function that returns the element that should be the one flashing michael@0: const TEST_DATA = [{ michael@0: desc: "Adding a new node should flash the new node", michael@0: mutate: (doc, rootNode) => { michael@0: let newLi = doc.createElement("LI"); michael@0: newLi.textContent = "new list item"; michael@0: rootNode.appendChild(newLi); michael@0: }, michael@0: shouldFlash: rootNode => rootNode.lastElementChild michael@0: }, { michael@0: desc: "Removing a node should flash its parent", michael@0: mutate: (doc, rootNode) => { michael@0: rootNode.removeChild(rootNode.lastElementChild); michael@0: }, michael@0: shouldFlash: rootNode => rootNode michael@0: }, { michael@0: desc: "Re-appending an existing node should only flash this node", michael@0: mutate: (doc, rootNode) => { michael@0: rootNode.appendChild(rootNode.firstElementChild); michael@0: }, michael@0: shouldFlash: rootNode => rootNode.lastElementChild michael@0: }, { michael@0: desc: "Adding an attribute should flash the node", michael@0: mutate: (doc, rootNode) => { michael@0: rootNode.setAttribute("name-" + Date.now(), "value-" + Date.now()); michael@0: }, michael@0: shouldFlash: rootNode => rootNode michael@0: }, { michael@0: desc: "Editing an attribute should flash the node", michael@0: mutate: (doc, rootNode) => { michael@0: rootNode.setAttribute("class", "list value-" + Date.now()); michael@0: }, michael@0: shouldFlash: rootNode => rootNode michael@0: }, { michael@0: desc: "Removing an attribute should flash the node", michael@0: mutate: (doc, rootNode) => { michael@0: rootNode.removeAttribute("class"); michael@0: }, michael@0: shouldFlash: rootNode => rootNode michael@0: }]; michael@0: michael@0: let test = asyncTest(function*() { michael@0: let {inspector} = yield addTab(TEST_URL).then(openInspector); michael@0: michael@0: info("Getting the root node to test mutations on"); michael@0: let rootNode = getNode(".list"); michael@0: michael@0: info("Selecting the last element of the root node before starting"); michael@0: yield selectNode(rootNode.lastElementChild, inspector); michael@0: michael@0: for (let {mutate, shouldFlash, desc} of TEST_DATA) { michael@0: info("Starting test: " + desc); michael@0: michael@0: info("Mutating the DOM and listening for markupmutation event"); michael@0: let mutated = inspector.once("markupmutation"); michael@0: let updated = inspector.once("inspector-updated"); michael@0: mutate(content.document, rootNode); michael@0: yield mutated; michael@0: michael@0: info("Asserting that the correct markup-container is flashing"); michael@0: assertNodeFlashing(shouldFlash(rootNode), inspector); michael@0: michael@0: // Making sure the inspector has finished updating before moving on michael@0: yield updated; michael@0: } michael@0: }); michael@0: michael@0: function assertNodeFlashing(node, inspector) { michael@0: let container = getContainerForRawNode(node, inspector); michael@0: michael@0: if (!container) { michael@0: ok(false, "Node not found"); michael@0: } else { michael@0: ok(container.tagState.classList.contains("theme-bg-contrast"), michael@0: "Node is flashing"); michael@0: } michael@0: }