1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_tab_dragdrop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +function test() 1.5 +{ 1.6 + var embed = '<embed type="application/x-test" allowscriptaccess="always" allowfullscreen="true" wmode="window" width="640" height="480"></embed>' 1.7 + 1.8 + waitForExplicitFinish(); 1.9 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED); 1.10 + 1.11 + // create a few tabs 1.12 + var tabs = [ 1.13 + gBrowser.tabs[0], 1.14 + gBrowser.addTab("about:blank", {skipAnimation: true}), 1.15 + gBrowser.addTab("about:blank", {skipAnimation: true}), 1.16 + gBrowser.addTab("about:blank", {skipAnimation: true}), 1.17 + gBrowser.addTab("about:blank", {skipAnimation: true}) 1.18 + ]; 1.19 + 1.20 + function setLocation(i, url) { 1.21 + gBrowser.getBrowserForTab(tabs[i]).contentWindow.location = url; 1.22 + } 1.23 + function moveTabTo(a, b) { 1.24 + gBrowser.swapBrowsersAndCloseOther(gBrowser.tabs[b], gBrowser.tabs[a]); 1.25 + } 1.26 + function clickTest(doc, win) { 1.27 + var clicks = doc.defaultView.clicks; 1.28 + EventUtils.synthesizeMouseAtCenter(doc.body, {}, win); 1.29 + is(doc.defaultView.clicks, clicks+1, "adding 1 more click on BODY"); 1.30 + } 1.31 + function test1() { 1.32 + moveTabTo(2, 3); // now: 0 1 2 4 1.33 + is(gBrowser.tabs[1], tabs[1], "tab1"); 1.34 + is(gBrowser.tabs[2], tabs[3], "tab3"); 1.35 + 1.36 + var plugin = gBrowser.getBrowserForTab(tabs[4]).docShell.contentViewer.DOMDocument.wrappedJSObject.body.firstChild; 1.37 + var tab4_plugin_object = plugin.getObjectValue(); 1.38 + 1.39 + gBrowser.selectedTab = gBrowser.tabs[2]; 1.40 + moveTabTo(3, 2); // now: 0 1 4 1.41 + gBrowser.selectedTab = tabs[4]; 1.42 + var doc = gBrowser.getBrowserForTab(gBrowser.tabs[2]).docShell.contentViewer.DOMDocument.wrappedJSObject; 1.43 + plugin = doc.body.firstChild; 1.44 + ok(plugin && plugin.checkObjectValue(tab4_plugin_object), "same plugin instance"); 1.45 + is(gBrowser.tabs[1], tabs[1], "tab1"); 1.46 + is(gBrowser.tabs[2], tabs[3], "tab4"); 1.47 + is(doc.defaultView.clicks, 0, "no click on BODY so far"); 1.48 + clickTest(doc, window); 1.49 + 1.50 + moveTabTo(2, 1); // now: 0 4 1.51 + is(gBrowser.tabs[1], tabs[1], "tab1"); 1.52 + doc = gBrowser.getBrowserForTab(gBrowser.tabs[1]).docShell.contentViewer.DOMDocument.wrappedJSObject; 1.53 + plugin = doc.body.firstChild; 1.54 + ok(plugin && plugin.checkObjectValue(tab4_plugin_object), "same plugin instance"); 1.55 + clickTest(doc, window); 1.56 + 1.57 + // Load a new document (about:blank) in tab4, then detach that tab into a new window. 1.58 + // In the new window, navigate back to the original document and click on its <body>, 1.59 + // verify that its onclick was called. 1.60 + var t = tabs[1]; 1.61 + var b = gBrowser.getBrowserForTab(t); 1.62 + gBrowser.selectedTab = t; 1.63 + b.addEventListener("load", function() { 1.64 + b.removeEventListener("load", arguments.callee, true); 1.65 + 1.66 + executeSoon(function () { 1.67 + var win = gBrowser.replaceTabWithWindow(t); 1.68 + whenDelayedStartupFinished(win, function () { 1.69 + // Verify that the original window now only has the initial tab left in it. 1.70 + is(gBrowser.tabs[0], tabs[0], "tab0"); 1.71 + is(gBrowser.getBrowserForTab(gBrowser.tabs[0]).contentWindow.location, "about:blank", "tab0 uri"); 1.72 + 1.73 + executeSoon(function () { 1.74 + win.gBrowser.addEventListener("pageshow", function () { 1.75 + win.gBrowser.removeEventListener("pageshow", arguments.callee, false); 1.76 + executeSoon(function () { 1.77 + t = win.gBrowser.tabs[0]; 1.78 + b = win.gBrowser.getBrowserForTab(t); 1.79 + var doc = b.docShell.contentViewer.DOMDocument.wrappedJSObject; 1.80 + clickTest(doc, win); 1.81 + win.close(); 1.82 + finish(); 1.83 + }); 1.84 + }, false); 1.85 + win.gBrowser.goBack(); 1.86 + }); 1.87 + }); 1.88 + }); 1.89 + }, true); 1.90 + b.loadURI("about:blank"); 1.91 + 1.92 + } 1.93 + 1.94 + var loads = 0; 1.95 + function waitForLoad(event, tab, listenerContainer) { 1.96 + var b = gBrowser.getBrowserForTab(gBrowser.tabs[tab]); 1.97 + if (b.contentDocument != event.target) { 1.98 + return; 1.99 + } 1.100 + gBrowser.getBrowserForTab(gBrowser.tabs[tab]).removeEventListener("load", listenerContainer.listener, true); 1.101 + ++loads; 1.102 + if (loads == tabs.length - 1) { 1.103 + executeSoon(test1); 1.104 + } 1.105 + } 1.106 + 1.107 + function fn(f, arg) { 1.108 + var listenerContainer = { listener: null } 1.109 + listenerContainer.listener = function (event) { return f(event, arg, listenerContainer); }; 1.110 + return listenerContainer.listener; 1.111 + } 1.112 + for (var i = 1; i < tabs.length; ++i) { 1.113 + gBrowser.getBrowserForTab(tabs[i]).addEventListener("load", fn(waitForLoad,i), true); 1.114 + } 1.115 + 1.116 + setLocation(1, "data:text/html;charset=utf-8,<title>tab1</title><body>tab1<iframe>"); 1.117 + setLocation(2, "data:text/plain;charset=utf-8,tab2"); 1.118 + setLocation(3, "data:text/html;charset=utf-8,<title>tab3</title><body>tab3<iframe>"); 1.119 + setLocation(4, "data:text/html;charset=utf-8,<body onload='clicks=0' onclick='++clicks'>"+embed); 1.120 + gBrowser.selectedTab = tabs[3]; 1.121 + 1.122 +}