summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/localstorage/test_localStorageQuota.html
blob: a26252b31376376cac3f0a4e621d8638ee36104a (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>localStorage and DOM quota test</title>

<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="interOriginTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

<script type="text/javascript">
//Note: this test is currently giving failures when running standalone, see bug 914865

var currentTest = 1;

function doNextTest()
{
  slave = frame;

  switch (currentTest)
  {
    case 1:
      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
        slaveOrigin = "http://test1.example.com";
      } else {
        slaveOrigin = "http://example.com";
      }
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&A&success";
      break;

    // Now set another key with length 500 bytes, i.e. allocate 501 bytes
    case 2:
      slaveOrigin = "http://test1.example.com";
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
      break;

    // Try to set the same key value again to check we don't fail
    // even 1002 bytes has already been exhausted from the quota
    // We just change the value of an existing key.
    case 3:
      slaveOrigin = "http://test1.example.com";
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&B&success";
      break;

    // Try to set the same key to a larger value that would lead to
    // quota reach and check that the value is still the old one
    case 4:
      slaveOrigin = "http://test1.example.com";
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add2&B&failure";
      break;

    // Try to set a new 500 bytes key and check we fail because we are over the
    // quota.
    case 5:
      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
        slaveOrigin = "http://test1.example.com";
      } else if (SpecialPowers.Services.appinfo.fissionAutostart){
        // Fission makes the "https://test2.example.com" run in the different
        // process with the other two and Legacy LS has issues with usage
        // synchronization within processes, see Bug 1683299 for more details.
        slaveOrigin = "http://test2.example.com";
      } else {
        slaveOrigin = "https://test2.example.com";
      }
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&failure";
      break;

    // Remove the second key, it must not fail. This should release the
    // allocated space of the quota assigned to test1.example.com.
    case 6:
      slaveOrigin = "http://test1.example.com";
      slave.location = slaveOrigin + slavePath + "frameQuota.html?remove&B&success";
      break;

    // Now try again to set 500 bytes key, it must succeed.
    case 7:
      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
        slaveOrigin = "http://test1.example.com";
      } else if (SpecialPowers.Services.appinfo.fissionAutostart){
        slaveOrigin = "http://test2.example.com";
      } else {
        slaveOrigin = "https://test2.example.com";
      }
      slave.location = slaveOrigin + slavePath + "frameQuota.html?add&C&success";
      break;

    case 8:
      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
        SimpleTest.executeSoon(doNextTest);
      } else {
        // Do a clean up...
        slaveOrigin = "http://example.com";
        slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
      }
      break;

    case 9:
      // Do a clean up...
      slaveOrigin = "http://test1.example.com";
      slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
      break;

    case 10:
      if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
        SimpleTest.executeSoon(doNextTest);
      } else {
        // Do a clean up...
        slaveOrigin = "https://test2.example.com";
        slave.location = slaveOrigin + slavePath + "frameQuota.html?clear";
      }
      break;

    default: // end
      SimpleTest.finish();
  }

  ++currentTest;
}

function doStep()
{
}

SimpleTest.waitForExplicitFinish();

function startTest() {
  // Initialy setup the quota to testing value of 1024B and
  // set a 500 bytes key with name length 1 (allocate 501 bytes)
  SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["dom.storage.default_site_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
}
</script>

</head>

<body onload="startTest();">
  <iframe src="" name="frame"></iframe>
</body>
</html>