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 | function test() |
michael@0 | 2 | { |
michael@0 | 3 | var embed = '<embed type="application/x-test" allowscriptaccess="always" allowfullscreen="true" wmode="window" width="640" height="480"></embed>' |
michael@0 | 4 | |
michael@0 | 5 | waitForExplicitFinish(); |
michael@0 | 6 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED); |
michael@0 | 7 | |
michael@0 | 8 | // create a few tabs |
michael@0 | 9 | var tabs = [ |
michael@0 | 10 | gBrowser.tabs[0], |
michael@0 | 11 | gBrowser.addTab("about:blank", {skipAnimation: true}), |
michael@0 | 12 | gBrowser.addTab("about:blank", {skipAnimation: true}), |
michael@0 | 13 | gBrowser.addTab("about:blank", {skipAnimation: true}), |
michael@0 | 14 | gBrowser.addTab("about:blank", {skipAnimation: true}) |
michael@0 | 15 | ]; |
michael@0 | 16 | |
michael@0 | 17 | function setLocation(i, url) { |
michael@0 | 18 | gBrowser.getBrowserForTab(tabs[i]).contentWindow.location = url; |
michael@0 | 19 | } |
michael@0 | 20 | function moveTabTo(a, b) { |
michael@0 | 21 | gBrowser.swapBrowsersAndCloseOther(gBrowser.tabs[b], gBrowser.tabs[a]); |
michael@0 | 22 | } |
michael@0 | 23 | function clickTest(doc, win) { |
michael@0 | 24 | var clicks = doc.defaultView.clicks; |
michael@0 | 25 | EventUtils.synthesizeMouseAtCenter(doc.body, {}, win); |
michael@0 | 26 | is(doc.defaultView.clicks, clicks+1, "adding 1 more click on BODY"); |
michael@0 | 27 | } |
michael@0 | 28 | function test1() { |
michael@0 | 29 | moveTabTo(2, 3); // now: 0 1 2 4 |
michael@0 | 30 | is(gBrowser.tabs[1], tabs[1], "tab1"); |
michael@0 | 31 | is(gBrowser.tabs[2], tabs[3], "tab3"); |
michael@0 | 32 | |
michael@0 | 33 | var plugin = gBrowser.getBrowserForTab(tabs[4]).docShell.contentViewer.DOMDocument.wrappedJSObject.body.firstChild; |
michael@0 | 34 | var tab4_plugin_object = plugin.getObjectValue(); |
michael@0 | 35 | |
michael@0 | 36 | gBrowser.selectedTab = gBrowser.tabs[2]; |
michael@0 | 37 | moveTabTo(3, 2); // now: 0 1 4 |
michael@0 | 38 | gBrowser.selectedTab = tabs[4]; |
michael@0 | 39 | var doc = gBrowser.getBrowserForTab(gBrowser.tabs[2]).docShell.contentViewer.DOMDocument.wrappedJSObject; |
michael@0 | 40 | plugin = doc.body.firstChild; |
michael@0 | 41 | ok(plugin && plugin.checkObjectValue(tab4_plugin_object), "same plugin instance"); |
michael@0 | 42 | is(gBrowser.tabs[1], tabs[1], "tab1"); |
michael@0 | 43 | is(gBrowser.tabs[2], tabs[3], "tab4"); |
michael@0 | 44 | is(doc.defaultView.clicks, 0, "no click on BODY so far"); |
michael@0 | 45 | clickTest(doc, window); |
michael@0 | 46 | |
michael@0 | 47 | moveTabTo(2, 1); // now: 0 4 |
michael@0 | 48 | is(gBrowser.tabs[1], tabs[1], "tab1"); |
michael@0 | 49 | doc = gBrowser.getBrowserForTab(gBrowser.tabs[1]).docShell.contentViewer.DOMDocument.wrappedJSObject; |
michael@0 | 50 | plugin = doc.body.firstChild; |
michael@0 | 51 | ok(plugin && plugin.checkObjectValue(tab4_plugin_object), "same plugin instance"); |
michael@0 | 52 | clickTest(doc, window); |
michael@0 | 53 | |
michael@0 | 54 | // Load a new document (about:blank) in tab4, then detach that tab into a new window. |
michael@0 | 55 | // In the new window, navigate back to the original document and click on its <body>, |
michael@0 | 56 | // verify that its onclick was called. |
michael@0 | 57 | var t = tabs[1]; |
michael@0 | 58 | var b = gBrowser.getBrowserForTab(t); |
michael@0 | 59 | gBrowser.selectedTab = t; |
michael@0 | 60 | b.addEventListener("load", function() { |
michael@0 | 61 | b.removeEventListener("load", arguments.callee, true); |
michael@0 | 62 | |
michael@0 | 63 | executeSoon(function () { |
michael@0 | 64 | var win = gBrowser.replaceTabWithWindow(t); |
michael@0 | 65 | whenDelayedStartupFinished(win, function () { |
michael@0 | 66 | // Verify that the original window now only has the initial tab left in it. |
michael@0 | 67 | is(gBrowser.tabs[0], tabs[0], "tab0"); |
michael@0 | 68 | is(gBrowser.getBrowserForTab(gBrowser.tabs[0]).contentWindow.location, "about:blank", "tab0 uri"); |
michael@0 | 69 | |
michael@0 | 70 | executeSoon(function () { |
michael@0 | 71 | win.gBrowser.addEventListener("pageshow", function () { |
michael@0 | 72 | win.gBrowser.removeEventListener("pageshow", arguments.callee, false); |
michael@0 | 73 | executeSoon(function () { |
michael@0 | 74 | t = win.gBrowser.tabs[0]; |
michael@0 | 75 | b = win.gBrowser.getBrowserForTab(t); |
michael@0 | 76 | var doc = b.docShell.contentViewer.DOMDocument.wrappedJSObject; |
michael@0 | 77 | clickTest(doc, win); |
michael@0 | 78 | win.close(); |
michael@0 | 79 | finish(); |
michael@0 | 80 | }); |
michael@0 | 81 | }, false); |
michael@0 | 82 | win.gBrowser.goBack(); |
michael@0 | 83 | }); |
michael@0 | 84 | }); |
michael@0 | 85 | }); |
michael@0 | 86 | }, true); |
michael@0 | 87 | b.loadURI("about:blank"); |
michael@0 | 88 | |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | var loads = 0; |
michael@0 | 92 | function waitForLoad(event, tab, listenerContainer) { |
michael@0 | 93 | var b = gBrowser.getBrowserForTab(gBrowser.tabs[tab]); |
michael@0 | 94 | if (b.contentDocument != event.target) { |
michael@0 | 95 | return; |
michael@0 | 96 | } |
michael@0 | 97 | gBrowser.getBrowserForTab(gBrowser.tabs[tab]).removeEventListener("load", listenerContainer.listener, true); |
michael@0 | 98 | ++loads; |
michael@0 | 99 | if (loads == tabs.length - 1) { |
michael@0 | 100 | executeSoon(test1); |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function fn(f, arg) { |
michael@0 | 105 | var listenerContainer = { listener: null } |
michael@0 | 106 | listenerContainer.listener = function (event) { return f(event, arg, listenerContainer); }; |
michael@0 | 107 | return listenerContainer.listener; |
michael@0 | 108 | } |
michael@0 | 109 | for (var i = 1; i < tabs.length; ++i) { |
michael@0 | 110 | gBrowser.getBrowserForTab(tabs[i]).addEventListener("load", fn(waitForLoad,i), true); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | setLocation(1, "data:text/html;charset=utf-8,<title>tab1</title><body>tab1<iframe>"); |
michael@0 | 114 | setLocation(2, "data:text/plain;charset=utf-8,tab2"); |
michael@0 | 115 | setLocation(3, "data:text/html;charset=utf-8,<title>tab3</title><body>tab3<iframe>"); |
michael@0 | 116 | setLocation(4, "data:text/html;charset=utf-8,<body onload='clicks=0' onclick='++clicks'>"+embed); |
michael@0 | 117 | gBrowser.selectedTab = tabs[3]; |
michael@0 | 118 | |
michael@0 | 119 | } |