toolkit/devtools/server/tests/mochitest/test_inspector-mutations-attr.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug </title>
    10   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    11   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    12   <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
    13   <script type="application/javascript;version=1.8">
    14 Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
    15 const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {});
    17 const inspector = devtools.require("devtools/server/actors/inspector");
    19 window.onload = function() {
    20   SimpleTest.waitForExplicitFinish();
    21   runNextTest();
    22 }
    24 var gInspectee = null;
    25 var gWalker = null;
    26 var gClient = null;
    27 var attrNode;
    28 var attrFront;
    30 addTest(function setup() {
    31   let url = document.getElementById("inspectorContent").href;
    32   attachURL(url, function(err, client, tab, doc) {
    33     gInspectee = doc;
    34     let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
    35     let inspector = InspectorFront(client, tab);
    36     promiseDone(inspector.getWalker().then(walker => {
    37       ok(walker, "getWalker() should return an actor.");
    38       gClient = client;
    39       gWalker = walker;
    40     }).then(runNextTest));
    41   });
    42 });
    44 addTest(setupAttrTest);
    45 addTest(testAddAttribute);
    46 addTest(testChangeAttribute);
    47 addTest(testRemoveAttribute);
    48 addTest(setupFrameAttrTest);
    49 addTest(testAddAttribute);
    50 addTest(testChangeAttribute);
    51 addTest(testRemoveAttribute);
    53 function setupAttrTest() {
    54   attrNode = gInspectee.querySelector("#a")
    55   promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(node => {
    56     attrFront = node;
    57   }).then(runNextTest));
    58 }
    60 function setupFrameAttrTest() {
    61   let frame = gInspectee.querySelector('#childFrame');
    62   attrNode = frame.contentDocument.querySelector("#a");
    64   promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
    65     return gWalker.children(childFrame);
    66   }).then(children => {
    67     let nodes = children.nodes;
    68     ok(nodes.length, 1, "There should be only one child of the iframe");
    69     is(nodes[0].nodeType, Node.DOCUMENT_NODE, "iframe child should be a document node");
    70     return gWalker.querySelector(nodes[0], "#a");
    71   }).then(node => {
    72     attrFront = node;
    73   }).then(runNextTest));
    74 }
    76 function testAddAttribute() {
    77   attrNode.setAttribute("data-newattr", "newvalue");
    78   attrNode.setAttribute("data-newattr2", "newvalue");
    79   gWalker.once("mutations", () => {
    80     is(attrFront.attributes.length, 3, "Should have id and two new attributes.");
    81     is(attrFront.getAttribute("data-newattr"), "newvalue", "Node front should have the first new attribute");
    82     is(attrFront.getAttribute("data-newattr2"), "newvalue", "Node front should have the second new attribute.");
    83     runNextTest();
    84   });
    85 }
    87 function testChangeAttribute() {
    88   attrNode.setAttribute("data-newattr", "changedvalue");
    89   gWalker.once("mutations", () => {
    90     is(attrFront.attributes.length, 3, "Should have id and two new attributes.");
    91     is(attrFront.getAttribute("data-newattr"), "changedvalue", "Node front should have the changed first value");
    92     is(attrFront.getAttribute("data-newattr2"), "newvalue", "Second value should remain unchanged.");
    93     runNextTest();
    94   });
    95 }
    97 function testRemoveAttribute() {
    98   attrNode.removeAttribute("data-newattr2");
    99   gWalker.once("mutations", () => {
   100     is(attrFront.attributes.length, 2, "Should have id and one remaining attribute.");
   101     is(attrFront.getAttribute("data-newattr"), "changedvalue", "Node front should still have the first value");
   102     ok(!attrFront.hasAttribute("data-newattr2"), "Second value should be removed.");
   103     runNextTest();
   104   })
   105 }
   107 addTest(function cleanup() {
   108   delete gInspectee;
   109   delete gWalker;
   110   delete gClient;
   111   runNextTest();
   112 });
   115   </script>
   116 </head>
   117 <body>
   118 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
   119 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
   120 <p id="display"></p>
   121 <div id="content" style="display: none">
   123 </div>
   124 <pre id="test">
   125 </pre>
   126 </body>
   127 </html>

mercurial