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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=536567 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 536567</title> |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script type="application/javascript"> |
michael@0 | 17 | /** Test for Bug 536567 **/ |
michael@0 | 18 | |
michael@0 | 19 | const Cc = Components.classes; |
michael@0 | 20 | const Ci = Components.interfaces; |
michael@0 | 21 | const Cu = Components.utils; |
michael@0 | 22 | const Cm = Components.manager; |
michael@0 | 23 | |
michael@0 | 24 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 25 | |
michael@0 | 26 | var MockFilePicker = SpecialPowers.MockFilePicker; |
michael@0 | 27 | MockFilePicker.init(window); |
michael@0 | 28 | |
michael@0 | 29 | var tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile); |
michael@0 | 30 | var homeDir = Services.dirsvc.get("Desk", Ci.nsILocalFile); |
michael@0 | 31 | |
michael@0 | 32 | function newDir() { |
michael@0 | 33 | var dir = tmpDir.clone(); |
michael@0 | 34 | dir.append("testdir" + Math.floor(Math.random() * 10000)); |
michael@0 | 35 | dir.QueryInterface(Ci.nsILocalFile); |
michael@0 | 36 | dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700); |
michael@0 | 37 | return dir; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | var dirs = []; |
michael@0 | 41 | for(var i = 0; i < 6; i++) { |
michael@0 | 42 | dirs.push(newDir()); |
michael@0 | 43 | } |
michael@0 | 44 | dirs.push(homeDir); |
michael@0 | 45 | var domains = ['http://mochi.test:8888', 'http://example.org:80', 'http://example.com:80']; |
michael@0 | 46 | /* |
michael@0 | 47 | * These tests take 3 args each: |
michael@0 | 48 | * - which domain to load |
michael@0 | 49 | * - the filePicker displayDirectory we expect to be set |
michael@0 | 50 | * - the file to pick (in most cases this will show up in the next test, |
michael@0 | 51 | * as indicated by the comments) |
michael@0 | 52 | */ |
michael@0 | 53 | var tests = [ |
michael@0 | 54 | "clear history", |
michael@0 | 55 | [0, 6, 0], // 0 -> 3 |
michael@0 | 56 | [1, 6, 1], // 1 -> 4 |
michael@0 | 57 | [2, 6, 2], // 2 -> 5 |
michael@0 | 58 | [0, 0, 3], // 3 -> 6 |
michael@0 | 59 | [1, 1, 1], // 4 -> 8 |
michael@0 | 60 | [2, 2, 2], // 5 -> 9 |
michael@0 | 61 | [0, 3, 1], // 6 -> 7 |
michael@0 | 62 | [0, 1, 0], // 7 -> x |
michael@0 | 63 | [1, 1, 1], // 8 -> x |
michael@0 | 64 | [2, 2, 2], // 9 -> x |
michael@0 | 65 | "clear history", |
michael@0 | 66 | [0, 6, 0], // 11 -> 15 |
michael@0 | 67 | [1, 6, 1], // 12 -> 16 |
michael@0 | 68 | [2, 6, 2], // 13 -> 17 |
michael@0 | 69 | "pb on", |
michael@0 | 70 | [0, 0, 3], // 15 -> 18 |
michael@0 | 71 | [1, 1, 4], // 16 -> 19 |
michael@0 | 72 | [2, 2, 5], // 17 -> 20 |
michael@0 | 73 | [0, 3, 3], // 18 -> x |
michael@0 | 74 | [1, 4, 4], // 19 -> x |
michael@0 | 75 | [2, 5, 5], // 20 -> x |
michael@0 | 76 | "pb off", |
michael@0 | 77 | [0, 0, 5], // 22 -> 26 |
michael@0 | 78 | [1, 1, 4], // 23 -> 27 |
michael@0 | 79 | [2, 2, 3], // 24 -> 28 |
michael@0 | 80 | "pb on", |
michael@0 | 81 | [0, 3, 5], // 26 -> x |
michael@0 | 82 | [1, 4, 4], // 27 -> x |
michael@0 | 83 | [2, 5, 3], // 28 -> x |
michael@0 | 84 | "clear history", |
michael@0 | 85 | // Not checking after clear history because browser.download.lastDir content |
michael@0 | 86 | // pref is not being clear properly in private windows. |
michael@0 | 87 | //[0, 6, 0], // 30 -> x |
michael@0 | 88 | //[1, 6, 1], // 31 -> x |
michael@0 | 89 | //[2, 6, 2], // 32 -> x |
michael@0 | 90 | "pb off" |
michael@0 | 91 | ]; |
michael@0 | 92 | |
michael@0 | 93 | var testIndex = 0; |
michael@0 | 94 | var content; |
michael@0 | 95 | var normalWindow; |
michael@0 | 96 | var privateWindow; |
michael@0 | 97 | var normalWindowIframe; |
michael@0 | 98 | var privateWindowIframe; |
michael@0 | 99 | |
michael@0 | 100 | function runTest() { |
michael@0 | 101 | var test = tests[testIndex]; |
michael@0 | 102 | if (test == undefined) { |
michael@0 | 103 | endTest(); |
michael@0 | 104 | } else if (test == "pb on") { |
michael@0 | 105 | content = privateWindowIframe; |
michael@0 | 106 | testIndex++; |
michael@0 | 107 | runTest(); |
michael@0 | 108 | } else if (test == "pb off") { |
michael@0 | 109 | content = normalWindowIframe; |
michael@0 | 110 | testIndex++; |
michael@0 | 111 | runTest(); |
michael@0 | 112 | } else if (test == "clear history") { |
michael@0 | 113 | Services.obs.notifyObservers(null, "browser:purge-session-history", ""); |
michael@0 | 114 | testIndex++; |
michael@0 | 115 | runTest(); |
michael@0 | 116 | } else { |
michael@0 | 117 | var file = dirs[test[2]].clone(); |
michael@0 | 118 | file.append("file.file"); |
michael@0 | 119 | MockFilePicker.returnFiles = [file]; |
michael@0 | 120 | content.setAttribute('src', domains[test[0]] + '/chrome/layout/forms/test/bug536567_subframe.html'); |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function endTest() { |
michael@0 | 125 | for(var i = 0; i < dirs.length - 1; i++) { |
michael@0 | 126 | dirs[i].remove(true); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | normalWindow.close(); |
michael@0 | 130 | privateWindow.close(); |
michael@0 | 131 | MockFilePicker.cleanup(); |
michael@0 | 132 | SimpleTest.finish(); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | var mainWindow = |
michael@0 | 136 | window.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 137 | getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem). |
michael@0 | 138 | rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 139 | getInterface(Ci.nsIDOMWindow); |
michael@0 | 140 | var contentPage = "http://mochi.test:8888/chrome/layout/forms/test/bug536567_iframe.html"; |
michael@0 | 141 | |
michael@0 | 142 | function whenDelayedStartupFinished(aWindow, aCallback) { |
michael@0 | 143 | Services.obs.addObserver(function observer(aSubject, aTopic) { |
michael@0 | 144 | if (aWindow == aSubject) { |
michael@0 | 145 | Services.obs.removeObserver(observer, aTopic); |
michael@0 | 146 | setTimeout(aCallback, 0); |
michael@0 | 147 | } |
michael@0 | 148 | }, "browser-delayed-startup-finished", false); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 152 | var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 153 | whenDelayedStartupFinished(win, function() { |
michael@0 | 154 | win.addEventListener("DOMContentLoaded", function onInnerLoad() { |
michael@0 | 155 | if (win.content.location.href != contentPage) { |
michael@0 | 156 | win.gBrowser.loadURI(contentPage); |
michael@0 | 157 | return; |
michael@0 | 158 | } |
michael@0 | 159 | win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |
michael@0 | 160 | win.gBrowser.selectedBrowser.focus(); |
michael@0 | 161 | SimpleTest.info("DOMContentLoaded's window: " + win.location + " vs. " + window.location); |
michael@0 | 162 | win.setTimeout(function() { aCallback(win); }, 0); |
michael@0 | 163 | }, true); |
michael@0 | 164 | SimpleTest.info("load's window: " + win.location + " vs. " + window.location); |
michael@0 | 165 | win.setTimeout(function() { win.gBrowser.loadURI(contentPage); }, 0); |
michael@0 | 166 | }); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | MockFilePicker.showCallback = function(filepicker) { |
michael@0 | 170 | var test = tests[testIndex]; |
michael@0 | 171 | var returned = -1; |
michael@0 | 172 | for (var i = 0; i < dirs.length; i++) { |
michael@0 | 173 | if (dirs[i].path == MockFilePicker.displayDirectory.path) { |
michael@0 | 174 | returned = i; |
michael@0 | 175 | break; |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | if (test[1] == -1) { |
michael@0 | 179 | ok(false, "We should never get an unknown directory back"); |
michael@0 | 180 | } else { |
michael@0 | 181 | is(returned, test[1], 'test ' + testIndex); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | filepicker.window.setTimeout(function() { |
michael@0 | 185 | testIndex++; |
michael@0 | 186 | runTest(); |
michael@0 | 187 | }, 0); |
michael@0 | 188 | }; |
michael@0 | 189 | |
michael@0 | 190 | window.onload = function() { |
michael@0 | 191 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 192 | testOnWindow(false, function(aWin) { |
michael@0 | 193 | var selectedBrowser = aWin.gBrowser.selectedBrowser; |
michael@0 | 194 | |
michael@0 | 195 | normalWindow = aWin; |
michael@0 | 196 | normalWindowIframe = |
michael@0 | 197 | selectedBrowser.contentDocument.getElementById("content"); |
michael@0 | 198 | |
michael@0 | 199 | testOnWindow(true, function(aPrivateWin) { |
michael@0 | 200 | selectedBrowser = aPrivateWin.gBrowser.selectedBrowser; |
michael@0 | 201 | |
michael@0 | 202 | privateWindow = aPrivateWin; |
michael@0 | 203 | privateWindowIframe = |
michael@0 | 204 | selectedBrowser.contentDocument.getElementById("content"); |
michael@0 | 205 | |
michael@0 | 206 | content = normalWindowIframe; |
michael@0 | 207 | selectedBrowser.contentWindow.setTimeout(runTest, 0); |
michael@0 | 208 | }); |
michael@0 | 209 | }); |
michael@0 | 210 | }; |
michael@0 | 211 | |
michael@0 | 212 | </script> |
michael@0 | 213 | </pre> |
michael@0 | 214 | </body> |
michael@0 | 215 | </html> |