summaryrefslogtreecommitdiffstats
path: root/toolkit/components/xulstore/tests/chrome/window_persistence.xhtml
blob: d474891cfc405dec2c2778981a250a5c40134b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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"/>
<button id="button3" label="Button3" value="Normal" persist="hidden" hidden="true"/>

<script>
<![CDATA[

const XULStore = Services.xulStore;
let URI = "chrome://mochitests/content/chrome/toolkit/components/xulstore/tests/chrome/window_persistence.xhtml";

function opened()
{
  runTest();
}

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

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

    button3.removeAttribute("hidden");

    window.close();
    window.arguments[1].windowOpened();
  }
  else {
    is(button1.getAttribute("value"), "Pressed",
       "Attribute set");
    is(button2.hasAttribute("value"), false,
       "Attribute cleared");
    is(button2.hasAttribute("foo"), false,
       "Attribute cleared");

    is(button3.hasAttribute("hidden"), false,
       "Attribute cleared");

    window.close();
    window.arguments[1].testDone();
  }
}

function is(l, r, n) { window.arguments[1].SimpleTest.is(l,r,n); }

]]></script>

</window>