toolkit/components/xulstore/tests/chrome/window_persistence.xul
author Roberto A. Vitillo <rvitillo@mozilla.com>
Tue, 19 Aug 2014 10:31:00 -0400
changeset 200654 25c918c5f3e118ab9d4edfaa71488300e3134944
parent 200623 143ae44587b25508b39f985aa96f549c88b1f3e1
child 266455 cfc1820361f599c55128b29de4332f8d06511e07
permissions -rw-r--r--
Bug 559505 - Deprecate localstore.rdf and replace it with xulstore. r=enn, sr=bsmedberg CLOSED TREE

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Persistence Tests"
        onload="opened()"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        persist="screenX screenY width height">

<button id="button1" label="Button1" persist="value"/>
<button id="button2" label="Button2" value="Normal" persist="value"/>

<tree id="tree" datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/all-animals" 
       flags="dont-build-content" width="200" height="200">
  <treecols orient="horizontal" id="treecols">
    <treecol id="treecol" primary="true" label="Name" flex="1"/>
  </treecols>
  <template id="template">
    <treechildren>
      <treeitem uri="rdf:*">
        <treerow>
          <treecell label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/>
          <treecell/>
        </treerow>
      </treeitem>
    </treechildren>
  </template>
</tree>

<script>
<![CDATA[

const Cc = Components.classes;
const Ci = Components.interfaces;

let XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
let URI = "chrome://mochitests/content/chrome/toolkit/components/xulstore/tests/chrome/window_persistence.xul";

function opened()
{
  // If the data in the tree has not been loaded yet, wait a bit and try again.
  var treeView = document.getElementById("tree").view;
  if (treeView.rowCount != 6 && treeView.rowCount != 17) {
    setTimeout(opened, 50);
    return;
  }

  runTest(treeView);
}

function runTest(treeView)
{
  var firstRun = window.arguments[0];
  if (firstRun) {
    document.getElementById("button1").setAttribute("value", "Pressed");
    document.getElementById("button2").removeAttribute("value");

    document.getElementById("button2").setAttribute("foo", "bar");
    document.persist("button2", "foo");
    is(XULStore.getValue(URI, "button2", "foo"), "bar", "attribute persisted")
    document.getElementById("button2").removeAttribute("foo");
    document.persist("button2", "foo");
    is(XULStore.hasValue(URI, "button2", "foo"), false, "attribute removed")

    is(treeView.rowCount, 6, "tree rows are closed");
    treeView.toggleOpenState(1);
    treeView.toggleOpenState(7);

    window.close();
    window.opener.windowOpened();
  }
  else {
    is(document.getElementById("button1").getAttribute("value"), "Pressed",
       "Attribute set");
    is(document.getElementById("button2").hasAttribute("value"), true,
       "Attribute cleared");
    is(document.getElementById("button2").getAttribute("value"), "",
       "Attribute cleared");
    is(document.getElementById("button2").hasAttribute("foo"), false,
       "Attribute cleared");
    is(document.getElementById("button2").getAttribute("foo"), "",
       "Attribute cleared");

    is(treeView.rowCount, 17, "tree rows are open");
    is(treeView.isContainerOpen(0), false, "first closed row");
    is(treeView.isContainerOpen(1), true, "first open row");
    is(treeView.isContainerOpen(7), true, "second open row");

    window.close();
    window.opener.testDone();
  }
}

function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }

]]></script>

</window>