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