content/html/content/test/test_iframe_sandbox_plugins.html

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=341604
michael@0 5 Implement HTML5 sandbox attribute for IFRAMEs
michael@0 6 -->
michael@0 7 <head>
michael@0 8 <meta charset="utf-8">
michael@0 9 <title>Test for Bug 341604 - plugins</title>
michael@0 10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12 </head>
michael@0 13 <script type="application/javascript">
michael@0 14 /** Test for Bug 341604 - Implement HTML5 sandbox attribute for IFRAMEs **/
michael@0 15 /** Plugin tests **/
michael@0 16 SimpleTest.waitForExplicitFinish();
michael@0 17
michael@0 18 function doTest() {
michael@0 19 // 1) test that a plugin can't be loaded with <embed> inside a sandboxed <iframe>
michael@0 20 // (done by file_iframe_sandbox_f_if1.html loaded in if1 below)
michael@0 21 // 2) test that a plugin can't be loaded with <object> inside a sandboxed <iframe>
michael@0 22 // (done by file_iframe_sandbox_f_if1.html loaded in if1 below)
michael@0 23 // 3) test that plugin can't be loaded by a sandboxed <iframe> with src pointing to
michael@0 24 // a document that is handled by a plugin (done by if_2 below)
michael@0 25 // 4) test that when a plugin is loaded in an unsandboxed iframe, a sandbox attribute
michael@0 26 // is then added to the iframe and the document containing the plugin is reloaded,
michael@0 27 // the plugin does not load in the sandboxed iframe (done with if_3 below)
michael@0 28 // 5) test that when when a sandboxed iframe's sandbox attribute is removed,
michael@0 29 // and a new document is loaded into the iframe, the plugin loads
michael@0 30 // (done with if_4 below)
michael@0 31
michael@0 32 // these are all handled by checking how many instances of the test plugin are loaded
michael@0 33 // when this script runs as the onload handler - there should be two instances,
michael@0 34 // initially the one loaded directly by this page itself, and the one loaded during
michael@0 35 // test #4 above.
michael@0 36 var p = document.getElementById('plugin1');
michael@0 37 var if_1 = document.getElementById('if_1');
michael@0 38 p.startWatchingInstanceCount();
michael@0 39
michael@0 40 if_1.src = 'file_iframe_sandbox_f_if1.html';
michael@0 41 }
michael@0 42
michael@0 43 function if_1_load() {
michael@0 44 var if_1 = document.getElementById('if_1');
michael@0 45
michael@0 46 if (if_1.src == "about:blank")
michael@0 47 return;
michael@0 48
michael@0 49 // need to wait for plugin to load, if the test fails...
michael@0 50 SimpleTest.executeSoon(if_1_continue);
michael@0 51 }
michael@0 52
michael@0 53 function if_1_continue() {
michael@0 54 // instance count should be 0 (tests #1 and #2 above)
michael@0 55 var p = document.getElementById('plugin1');
michael@0 56 is(p.getInstanceCount(), 0, "plugins should not be loaded via <object> or <embed> by a sandboxed iframe");
michael@0 57
michael@0 58 var if_2 = document.getElementById('if_2');
michael@0 59 if_2.src = 'file_iframe_sandbox_f_if2.html';
michael@0 60
michael@0 61 SimpleTest.executeSoon(if_2_continue);
michael@0 62 }
michael@0 63
michael@0 64 function if_2_continue() {
michael@0 65 // instance count should be 0 (test #3 above)
michael@0 66 var p = document.getElementById('plugin1');
michael@0 67
michael@0 68 is(p.getInstanceCount(), 0, "plugins should not be loaded via a document of a type that requires a plugin embedded in a sandboxed iframe");
michael@0 69
michael@0 70 SimpleTest.executeSoon(if_3_test);
michael@0 71 }
michael@0 72
michael@0 73 function if_3_test() {
michael@0 74 var if_3 = document.getElementById('if_3');
michael@0 75 // add sandbox attribute
michael@0 76 if_3.sandbox = '';
michael@0 77 if_3.src = 'file_iframe_sandbox_f_if1.html';
michael@0 78 }
michael@0 79
michael@0 80 function if_3_load() {
michael@0 81 if (if_3.src == "about:blank")
michael@0 82 return;
michael@0 83
michael@0 84 SimpleTest.executeSoon(if_3_continue);
michael@0 85 }
michael@0 86
michael@0 87 function if_3_continue() {
michael@0 88 var p = document.getElementById('plugin1');
michael@0 89 is(p.getInstanceCount(), 0, "plugins should not be loaded when a sandbox attribute is added" +
michael@0 90 "to an iframe and a document containing a plugin is then loaded into the iframe");
michael@0 91
michael@0 92 SimpleTest.executeSoon(if_4_test);
michael@0 93 }
michael@0 94
michael@0 95 function if_4_test() {
michael@0 96 var if_4 = document.getElementById('if_4');
michael@0 97 // remove sandbox attribute
michael@0 98 if_4.removeAttribute('sandbox');
michael@0 99 if_4.src = 'file_iframe_sandbox_f_if1.html';
michael@0 100 }
michael@0 101
michael@0 102 function if_4_load() {
michael@0 103 if (if_4.src == "about:blank")
michael@0 104 return;
michael@0 105
michael@0 106 SimpleTest.executeSoon(if_4_continue);
michael@0 107 }
michael@0 108
michael@0 109 function if_4_continue() {
michael@0 110 var p = document.getElementById('plugin1');
michael@0 111 // there are 2 plugin instances in file_iframe_sandbox_if1.html loaded by
michael@0 112 // if_1, they should successfully load.
michael@0 113 is(p.getInstanceCount(), 2, "plugins should be loaded when a sandbox attribute is removed " +
michael@0 114 "from an iframe and a document containing a plugin is then loaded into the iframe");
michael@0 115
michael@0 116 p.stopWatchingInstanceCount();
michael@0 117 SimpleTest.executeSoon(finish_test);
michael@0 118 }
michael@0 119
michael@0 120 function finish_test() {
michael@0 121 SimpleTest.finish();
michael@0 122 }
michael@0 123
michael@0 124 addLoadEvent(doTest);
michael@0 125 </script>
michael@0 126 <body>
michael@0 127 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs
michael@0 128 <p id="display"></p>
michael@0 129 <div id="content">
michael@0 130 <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
michael@0 131 <iframe id="if_1" sandbox='allow-same-origin' onLoad='if_1_load()' src="about:blank" height="400" width="400"></iframe>
michael@0 132 <iframe id="if_2" sandbox='allow-same-origin' src="about:blank" height="400" width="400"></iframe>
michael@0 133 <iframe id="if_3" src="about:blank" onload='if_3_load()' height="400" width="400"></iframe>
michael@0 134 <iframe id="if_4" sandbox='allow-same-origin' onload='if_4_load()' src="about:blank" height="400" width="400"></iframe>
michael@0 135 </div>
michael@0 136 </body>
michael@0 137 </html>

mercurial