Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the public domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Bug 690168 - Support Allow-From notation for X-Frame-Options header. |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 8 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 9 | browserElementTestHelpers.addPermission(); |
michael@0 | 10 | |
michael@0 | 11 | var initialScreenshotArrayBuffer = null; |
michael@0 | 12 | |
michael@0 | 13 | function arrayBuffersEqual(a, b) { |
michael@0 | 14 | var x = new Int8Array(a); |
michael@0 | 15 | var y = new Int8Array(b); |
michael@0 | 16 | if (x.length != y.length) { |
michael@0 | 17 | return false; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | for (var i = 0; i < x.length; i++) { |
michael@0 | 21 | if (x[i] != y[i]) { |
michael@0 | 22 | return false; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | return true; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function runTest() { |
michael@0 | 30 | var count = 0; |
michael@0 | 31 | |
michael@0 | 32 | var iframe = document.createElement('iframe'); |
michael@0 | 33 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 34 | iframe.height = '1000px'; |
michael@0 | 35 | |
michael@0 | 36 | // The innermost page we load will fire an alert when it successfully loads. |
michael@0 | 37 | iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { |
michael@0 | 38 | switch (e.detail.message) { |
michael@0 | 39 | case 'step 1': |
michael@0 | 40 | // Make the page wait for us to unblock it (which we do after we finish |
michael@0 | 41 | // taking the screenshot). |
michael@0 | 42 | e.preventDefault(); |
michael@0 | 43 | |
michael@0 | 44 | iframe.getScreenshot(1000, 1000).onsuccess = function(sshot) { |
michael@0 | 45 | var fr = new FileReader(); |
michael@0 | 46 | fr.onloadend = function() { |
michael@0 | 47 | if (initialScreenshotArrayBuffer == null) |
michael@0 | 48 | initialScreenshotArrayBuffer = fr.result; |
michael@0 | 49 | e.detail.unblock(); |
michael@0 | 50 | }; |
michael@0 | 51 | fr.readAsArrayBuffer(sshot.target.result); |
michael@0 | 52 | }; |
michael@0 | 53 | break; |
michael@0 | 54 | case 'step 2': |
michael@0 | 55 | ok(false, 'cross origin page loaded'); |
michael@0 | 56 | break; |
michael@0 | 57 | case 'finish': |
michael@0 | 58 | // The page has now attempted to load the X-Frame-Options page; take |
michael@0 | 59 | // another screenshot. |
michael@0 | 60 | iframe.getScreenshot(1000, 1000).onsuccess = function(sshot) { |
michael@0 | 61 | var fr = new FileReader(); |
michael@0 | 62 | fr.onloadend = function() { |
michael@0 | 63 | ok(arrayBuffersEqual(fr.result, initialScreenshotArrayBuffer), |
michael@0 | 64 | "Screenshots should be identical"); |
michael@0 | 65 | SimpleTest.finish(); |
michael@0 | 66 | }; |
michael@0 | 67 | fr.readAsArrayBuffer(sshot.target.result); |
michael@0 | 68 | }; |
michael@0 | 69 | break; |
michael@0 | 70 | } |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | document.body.appendChild(iframe); |
michael@0 | 74 | |
michael@0 | 75 | iframe.src = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_XFrameOptionsAllowFrom.html'; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | addEventListener('testready', runTest); |