1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/taskbar_previews.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="Taskbar Previews Test" 1.9 + xmlns:html="http://www.w3.org/1999/xhtml" 1.10 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.11 + onload="loaded();"> 1.12 + 1.13 + <title>Previews - yeah!</title> 1.14 + <script type="application/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.16 + <script class="testbody" type="application/javascript"> 1.17 + <![CDATA[ 1.18 + let Cc = Components.classes; 1.19 + let Ci = Components.interfaces; 1.20 + let Cu = Components.utils; 1.21 + Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.22 + 1.23 + let taskbar = Cc["@mozilla.org/windows-taskbar;1"].getService(Ci.nsIWinTaskbar); 1.24 + 1.25 + function IsWin7OrHigher() { 1.26 + try { 1.27 + var sysInfo = Cc["@mozilla.org/system-info;1"]. 1.28 + getService(Ci.nsIPropertyBag2); 1.29 + var ver = parseFloat(sysInfo.getProperty("version")); 1.30 + if (ver >= 6.1) 1.31 + return true; 1.32 + } catch (ex) { } 1.33 + return false; 1.34 + } 1.35 + isnot(taskbar, null, "Taskbar service is defined"); 1.36 + is(taskbar.available, IsWin7OrHigher(), "Expected availability of taskbar"); 1.37 + 1.38 + SimpleTest.waitForExplicitFinish(); 1.39 + 1.40 + function stdPreviewSuite(p) { 1.41 + p.visible = !p.visible; 1.42 + p.visible = !p.visible; 1.43 + p.visible = true; 1.44 + p.invalidate(); 1.45 + p.visible = false; 1.46 + } 1.47 + 1.48 + function loaded() 1.49 + { 1.50 + if (!taskbar.available) 1.51 + SimpleTest.finish(); 1.52 + let controller = { 1.53 + width: 400, 1.54 + height: 400, 1.55 + thumbnailAspectRatio: 1.0, 1.56 + drawThumbnail: function () { return false; }, 1.57 + drawPreview: function () { return false; }, 1.58 + get wrappedJSObject() { return this; } 1.59 + } 1.60 + // HACK from mconnor: 1.61 + var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); 1.62 + let win = wm.getMostRecentWindow("navigator:browser"); 1.63 + let docShell = win.gBrowser.docShell; 1.64 + 1.65 + let winPreview = taskbar.getTaskbarWindowPreview(docShell); 1.66 + isnot(winPreview, null, "Window preview is not null"); 1.67 + winPreview.controller = controller; 1.68 + let button = winPreview.getButton(0); 1.69 + isnot(button, null, "Could get button at valid index"); 1.70 + try { 1.71 + winPreview.getButton(-1); 1.72 + ok(false, "Got button at negative index"); 1.73 + } catch (ex) {} 1.74 + try { 1.75 + winPreview.getButton(Ci.nsITaskbarWindowPreview.NUM_TOOLBAR_BUTTONS); 1.76 + ok(false, "Got button at index that is too large"); 1.77 + } catch (ex) {} 1.78 + button.image = null; 1.79 + stdPreviewSuite(winPreview); 1.80 + // Let's not perma-hide this window from the taskbar 1.81 + winPreview.visible = true; 1.82 + 1.83 + let tabP = taskbar.createTaskbarTabPreview(docShell, controller); 1.84 + isnot(tabP, null, "Tab preview is not null"); 1.85 + is(tabP.controller.wrappedJSObject, controller, "Controllers match"); 1.86 + is(tabP.icon, null, "Default icon is null (windows default)"); 1.87 + tabP.icon = null; 1.88 + tabP.move(null); 1.89 + try { 1.90 + tabP.move(tabP); 1.91 + ok(false, "Moved a preview next to itself!"); 1.92 + } catch (ex) {} 1.93 + stdPreviewSuite(tabP); 1.94 + 1.95 + let tabP2 = taskbar.createTaskbarTabPreview(docShell, controller); 1.96 + tabP.visible = true; 1.97 + tabP2.visible = true; 1.98 + 1.99 + isnot(tabP2, null, "2nd Tab preview is not null"); 1.100 + isnot(tabP,tabP2, "Tab previews are different"); 1.101 + tabP.active = true; 1.102 + ok(tabP.active && !tabP2.active, "Only one tab is active (part 1)"); 1.103 + tabP2.active = true; 1.104 + ok(!tabP.active && tabP2.active, "Only one tab is active (part 2)"); 1.105 + tabP.active = true; 1.106 + ok(tabP.active && !tabP2.active, "Only one tab is active (part 3)"); 1.107 + tabP.active = false; 1.108 + ok(!tabP.active && !tabP2.active, "Neither tab is active"); 1.109 + is(winPreview.active, false, "Window preview is not active"); 1.110 + tabP.active = true; 1.111 + winPreview.active = true; 1.112 + ok(winPreview.active && !tabP.active, "Tab preview takes activation from window"); 1.113 + tabP.active = true; 1.114 + ok(tabP.active && !winPreview.active, "Tab preview takes activation from window"); 1.115 + 1.116 + tabP.visible = false; 1.117 + tabP2.visible = false; 1.118 + 1.119 + SimpleTest.finish(); 1.120 + } 1.121 + ]]> 1.122 + </script> 1.123 + 1.124 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.125 + <p id="display"></p> 1.126 + <div id="content" style="display: none"></div> 1.127 + <pre id="test"></pre> 1.128 + </body> 1.129 + 1.130 +</window>