1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/test/test_bug536567_perwindowpb.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,215 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=536567 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 536567</title> 1.11 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a> 1.17 +<p id="display"></p> 1.18 +<pre id="test"> 1.19 +<script type="application/javascript"> 1.20 +/** Test for Bug 536567 **/ 1.21 + 1.22 +const Cc = Components.classes; 1.23 +const Ci = Components.interfaces; 1.24 +const Cu = Components.utils; 1.25 +const Cm = Components.manager; 1.26 + 1.27 +Cu.import("resource://gre/modules/Services.jsm"); 1.28 + 1.29 +var MockFilePicker = SpecialPowers.MockFilePicker; 1.30 +MockFilePicker.init(window); 1.31 + 1.32 +var tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile); 1.33 +var homeDir = Services.dirsvc.get("Desk", Ci.nsILocalFile); 1.34 + 1.35 +function newDir() { 1.36 + var dir = tmpDir.clone(); 1.37 + dir.append("testdir" + Math.floor(Math.random() * 10000)); 1.38 + dir.QueryInterface(Ci.nsILocalFile); 1.39 + dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700); 1.40 + return dir; 1.41 +} 1.42 + 1.43 +var dirs = []; 1.44 +for(var i = 0; i < 6; i++) { 1.45 + dirs.push(newDir()); 1.46 +} 1.47 +dirs.push(homeDir); 1.48 +var domains = ['http://mochi.test:8888', 'http://example.org:80', 'http://example.com:80']; 1.49 +/* 1.50 + * These tests take 3 args each: 1.51 + * - which domain to load 1.52 + * - the filePicker displayDirectory we expect to be set 1.53 + * - the file to pick (in most cases this will show up in the next test, 1.54 + * as indicated by the comments) 1.55 + */ 1.56 +var tests = [ 1.57 + "clear history", 1.58 + [0, 6, 0], // 0 -> 3 1.59 + [1, 6, 1], // 1 -> 4 1.60 + [2, 6, 2], // 2 -> 5 1.61 + [0, 0, 3], // 3 -> 6 1.62 + [1, 1, 1], // 4 -> 8 1.63 + [2, 2, 2], // 5 -> 9 1.64 + [0, 3, 1], // 6 -> 7 1.65 + [0, 1, 0], // 7 -> x 1.66 + [1, 1, 1], // 8 -> x 1.67 + [2, 2, 2], // 9 -> x 1.68 + "clear history", 1.69 + [0, 6, 0], // 11 -> 15 1.70 + [1, 6, 1], // 12 -> 16 1.71 + [2, 6, 2], // 13 -> 17 1.72 + "pb on", 1.73 + [0, 0, 3], // 15 -> 18 1.74 + [1, 1, 4], // 16 -> 19 1.75 + [2, 2, 5], // 17 -> 20 1.76 + [0, 3, 3], // 18 -> x 1.77 + [1, 4, 4], // 19 -> x 1.78 + [2, 5, 5], // 20 -> x 1.79 + "pb off", 1.80 + [0, 0, 5], // 22 -> 26 1.81 + [1, 1, 4], // 23 -> 27 1.82 + [2, 2, 3], // 24 -> 28 1.83 + "pb on", 1.84 + [0, 3, 5], // 26 -> x 1.85 + [1, 4, 4], // 27 -> x 1.86 + [2, 5, 3], // 28 -> x 1.87 + "clear history", 1.88 + // Not checking after clear history because browser.download.lastDir content 1.89 + // pref is not being clear properly in private windows. 1.90 + //[0, 6, 0], // 30 -> x 1.91 + //[1, 6, 1], // 31 -> x 1.92 + //[2, 6, 2], // 32 -> x 1.93 + "pb off" 1.94 +]; 1.95 + 1.96 +var testIndex = 0; 1.97 +var content; 1.98 +var normalWindow; 1.99 +var privateWindow; 1.100 +var normalWindowIframe; 1.101 +var privateWindowIframe; 1.102 + 1.103 +function runTest() { 1.104 + var test = tests[testIndex]; 1.105 + if (test == undefined) { 1.106 + endTest(); 1.107 + } else if (test == "pb on") { 1.108 + content = privateWindowIframe; 1.109 + testIndex++; 1.110 + runTest(); 1.111 + } else if (test == "pb off") { 1.112 + content = normalWindowIframe; 1.113 + testIndex++; 1.114 + runTest(); 1.115 + } else if (test == "clear history") { 1.116 + Services.obs.notifyObservers(null, "browser:purge-session-history", ""); 1.117 + testIndex++; 1.118 + runTest(); 1.119 + } else { 1.120 + var file = dirs[test[2]].clone(); 1.121 + file.append("file.file"); 1.122 + MockFilePicker.returnFiles = [file]; 1.123 + content.setAttribute('src', domains[test[0]] + '/chrome/layout/forms/test/bug536567_subframe.html'); 1.124 + } 1.125 +} 1.126 + 1.127 +function endTest() { 1.128 + for(var i = 0; i < dirs.length - 1; i++) { 1.129 + dirs[i].remove(true); 1.130 + } 1.131 + 1.132 + normalWindow.close(); 1.133 + privateWindow.close(); 1.134 + MockFilePicker.cleanup(); 1.135 + SimpleTest.finish(); 1.136 +} 1.137 + 1.138 +var mainWindow = 1.139 + window.QueryInterface(Ci.nsIInterfaceRequestor). 1.140 + getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem). 1.141 + rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor). 1.142 + getInterface(Ci.nsIDOMWindow); 1.143 +var contentPage = "http://mochi.test:8888/chrome/layout/forms/test/bug536567_iframe.html"; 1.144 + 1.145 +function whenDelayedStartupFinished(aWindow, aCallback) { 1.146 + Services.obs.addObserver(function observer(aSubject, aTopic) { 1.147 + if (aWindow == aSubject) { 1.148 + Services.obs.removeObserver(observer, aTopic); 1.149 + setTimeout(aCallback, 0); 1.150 + } 1.151 + }, "browser-delayed-startup-finished", false); 1.152 +} 1.153 + 1.154 +function testOnWindow(aIsPrivate, aCallback) { 1.155 + var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); 1.156 + whenDelayedStartupFinished(win, function() { 1.157 + win.addEventListener("DOMContentLoaded", function onInnerLoad() { 1.158 + if (win.content.location.href != contentPage) { 1.159 + win.gBrowser.loadURI(contentPage); 1.160 + return; 1.161 + } 1.162 + win.removeEventListener("DOMContentLoaded", onInnerLoad, true); 1.163 + win.gBrowser.selectedBrowser.focus(); 1.164 + SimpleTest.info("DOMContentLoaded's window: " + win.location + " vs. " + window.location); 1.165 + win.setTimeout(function() { aCallback(win); }, 0); 1.166 + }, true); 1.167 + SimpleTest.info("load's window: " + win.location + " vs. " + window.location); 1.168 + win.setTimeout(function() { win.gBrowser.loadURI(contentPage); }, 0); 1.169 + }); 1.170 +} 1.171 + 1.172 +MockFilePicker.showCallback = function(filepicker) { 1.173 + var test = tests[testIndex]; 1.174 + var returned = -1; 1.175 + for (var i = 0; i < dirs.length; i++) { 1.176 + if (dirs[i].path == MockFilePicker.displayDirectory.path) { 1.177 + returned = i; 1.178 + break; 1.179 + } 1.180 + } 1.181 + if (test[1] == -1) { 1.182 + ok(false, "We should never get an unknown directory back"); 1.183 + } else { 1.184 + is(returned, test[1], 'test ' + testIndex); 1.185 + } 1.186 + 1.187 + filepicker.window.setTimeout(function() { 1.188 + testIndex++; 1.189 + runTest(); 1.190 + }, 0); 1.191 +}; 1.192 + 1.193 +window.onload = function() { 1.194 + SimpleTest.waitForExplicitFinish(); 1.195 + testOnWindow(false, function(aWin) { 1.196 + var selectedBrowser = aWin.gBrowser.selectedBrowser; 1.197 + 1.198 + normalWindow = aWin; 1.199 + normalWindowIframe = 1.200 + selectedBrowser.contentDocument.getElementById("content"); 1.201 + 1.202 + testOnWindow(true, function(aPrivateWin) { 1.203 + selectedBrowser = aPrivateWin.gBrowser.selectedBrowser; 1.204 + 1.205 + privateWindow = aPrivateWin; 1.206 + privateWindowIframe = 1.207 + selectedBrowser.contentDocument.getElementById("content"); 1.208 + 1.209 + content = normalWindowIframe; 1.210 + selectedBrowser.contentWindow.setTimeout(runTest, 0); 1.211 + }); 1.212 + }); 1.213 +}; 1.214 + 1.215 +</script> 1.216 +</pre> 1.217 +</body> 1.218 +</html>