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 | var isWin7OrHigher = false; |
michael@0 | 3 | try { |
michael@0 | 4 | let version = Cc["@mozilla.org/system-info;1"] |
michael@0 | 5 | .getService(Ci.nsIPropertyBag2) |
michael@0 | 6 | .getProperty("version"); |
michael@0 | 7 | isWin7OrHigher = (parseFloat(version) >= 6.1); |
michael@0 | 8 | } catch (ex) { } |
michael@0 | 9 | |
michael@0 | 10 | is(!!Win7Features, isWin7OrHigher, "Win7Features available when it should be"); |
michael@0 | 11 | if (!isWin7OrHigher) |
michael@0 | 12 | return; |
michael@0 | 13 | |
michael@0 | 14 | const ENABLE_PREF_NAME = "browser.taskbar.previews.enable"; |
michael@0 | 15 | |
michael@0 | 16 | let temp = {}; |
michael@0 | 17 | Cu.import("resource:///modules/WindowsPreviewPerTab.jsm", temp); |
michael@0 | 18 | let AeroPeek = temp.AeroPeek; |
michael@0 | 19 | |
michael@0 | 20 | waitForExplicitFinish(); |
michael@0 | 21 | |
michael@0 | 22 | gPrefService.setBoolPref(ENABLE_PREF_NAME, true); |
michael@0 | 23 | |
michael@0 | 24 | is(1, AeroPeek.windows.length, "Got the expected number of windows"); |
michael@0 | 25 | |
michael@0 | 26 | checkPreviews(1, "Browser starts with one preview"); |
michael@0 | 27 | |
michael@0 | 28 | gBrowser.addTab(); |
michael@0 | 29 | gBrowser.addTab(); |
michael@0 | 30 | gBrowser.addTab(); |
michael@0 | 31 | |
michael@0 | 32 | checkPreviews(4, "Correct number of previews after adding"); |
michael@0 | 33 | |
michael@0 | 34 | for each (let preview in AeroPeek.previews) |
michael@0 | 35 | ok(preview.visible, "Preview is shown as expected"); |
michael@0 | 36 | |
michael@0 | 37 | gPrefService.setBoolPref(ENABLE_PREF_NAME, false); |
michael@0 | 38 | checkPreviews(4, "Previews are unchanged when disabling"); |
michael@0 | 39 | |
michael@0 | 40 | for each (let preview in AeroPeek.previews) |
michael@0 | 41 | ok(!preview.visible, "Preview is not shown as expected after disabling"); |
michael@0 | 42 | |
michael@0 | 43 | gPrefService.setBoolPref(ENABLE_PREF_NAME, true); |
michael@0 | 44 | checkPreviews(4, "Previews are unchanged when re-enabling"); |
michael@0 | 45 | for each (let preview in AeroPeek.previews) |
michael@0 | 46 | ok(preview.visible, "Preview is shown as expected after re-enabling"); |
michael@0 | 47 | |
michael@0 | 48 | [1,2,3,4].forEach(function (idx) { |
michael@0 | 49 | gBrowser.selectedTab = gBrowser.tabs[idx]; |
michael@0 | 50 | ok(checkSelectedTab(), "Current tab is correctly selected"); |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | let currentSelectedTab = gBrowser.selectedTab; |
michael@0 | 54 | for each (let idx in [1,2,3,4]) { |
michael@0 | 55 | let preview = getPreviewForTab(gBrowser.tabs[0]); |
michael@0 | 56 | let canvas = createThumbnailSurface(preview); |
michael@0 | 57 | let ctx = canvas.getContext("2d"); |
michael@0 | 58 | preview.controller.drawThumbnail(ctx, canvas.width, canvas.height); |
michael@0 | 59 | ok(currentSelectedTab.selected, "Drawing thumbnail does not change selection"); |
michael@0 | 60 | canvas = getCanvas(preview.controller.width, preview.controller.height); |
michael@0 | 61 | ctx = canvas.getContext("2d"); |
michael@0 | 62 | preview.controller.drawPreview(ctx); |
michael@0 | 63 | ok(currentSelectedTab.selected, "Drawing preview does not change selection"); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // Close #4 |
michael@0 | 67 | getPreviewForTab(gBrowser.selectedTab).controller.onClose(); |
michael@0 | 68 | checkPreviews(3, "Expected number of previews after closing selected tab via controller"); |
michael@0 | 69 | ok(gBrowser.tabs.length == 3, "Successfully closed a tab"); |
michael@0 | 70 | |
michael@0 | 71 | // Select #1 |
michael@0 | 72 | ok(getPreviewForTab(gBrowser.tabs[0]).controller.onActivate(), "Activation was accepted"); |
michael@0 | 73 | ok(gBrowser.tabs[0].selected, "Correct tab was selected"); |
michael@0 | 74 | checkSelectedTab(); |
michael@0 | 75 | |
michael@0 | 76 | // Remove #3 (non active) |
michael@0 | 77 | gBrowser.removeTab(gBrowser.tabContainer.lastChild); |
michael@0 | 78 | checkPreviews(2, "Expected number of previews after closing unselected via browser"); |
michael@0 | 79 | |
michael@0 | 80 | // Remove #1 (active) |
michael@0 | 81 | gBrowser.removeTab(gBrowser.tabContainer.firstChild); |
michael@0 | 82 | checkPreviews(1, "Expected number of previews after closing selected tab via browser"); |
michael@0 | 83 | |
michael@0 | 84 | // Add a new tab |
michael@0 | 85 | gBrowser.addTab(); |
michael@0 | 86 | checkPreviews(2); |
michael@0 | 87 | // Check default selection |
michael@0 | 88 | checkSelectedTab(); |
michael@0 | 89 | |
michael@0 | 90 | // Change selection |
michael@0 | 91 | gBrowser.selectedTab = gBrowser.tabs[0]; |
michael@0 | 92 | checkSelectedTab(); |
michael@0 | 93 | // Close nonselected tab via controller |
michael@0 | 94 | getPreviewForTab(gBrowser.tabs[1]).controller.onClose(); |
michael@0 | 95 | checkPreviews(1); |
michael@0 | 96 | |
michael@0 | 97 | if (gPrefService.prefHasUserValue(ENABLE_PREF_NAME)) |
michael@0 | 98 | gPrefService.clearUserPref(ENABLE_PREF_NAME); |
michael@0 | 99 | |
michael@0 | 100 | finish(); |
michael@0 | 101 | |
michael@0 | 102 | function checkPreviews(aPreviews, msg) { |
michael@0 | 103 | let nPreviews = AeroPeek.previews.length; |
michael@0 | 104 | is(aPreviews, gBrowser.tabs.length, "Browser has expected number of tabs"); |
michael@0 | 105 | is(nPreviews, gBrowser.tabs.length, "Browser has one preview per tab"); |
michael@0 | 106 | is(nPreviews, aPreviews, msg || "Got expected number of previews"); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function getPreviewForTab(tab) |
michael@0 | 110 | window.gTaskbarTabGroup.previewFromTab(tab); |
michael@0 | 111 | |
michael@0 | 112 | function checkSelectedTab() |
michael@0 | 113 | getPreviewForTab(gBrowser.selectedTab).active; |
michael@0 | 114 | |
michael@0 | 115 | function isTabSelected(idx) |
michael@0 | 116 | gBrowser.tabs[idx].selected; |
michael@0 | 117 | |
michael@0 | 118 | function createThumbnailSurface(p) { |
michael@0 | 119 | let thumbnailWidth = 200, |
michael@0 | 120 | thumbnailHeight = 120; |
michael@0 | 121 | let ratio = p.controller.thumbnailAspectRatio; |
michael@0 | 122 | |
michael@0 | 123 | if (thumbnailWidth/thumbnailHeight > ratio) |
michael@0 | 124 | thumbnailWidth = thumbnailHeight * ratio; |
michael@0 | 125 | else |
michael@0 | 126 | thumbnailHeight = thumbnailWidth / ratio; |
michael@0 | 127 | |
michael@0 | 128 | return getCanvas(thumbnailWidth, thumbnailHeight); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | function getCanvas(width, height) { |
michael@0 | 132 | let win = window.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 133 | let doc = win.document; |
michael@0 | 134 | let canvas = doc.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); |
michael@0 | 135 | canvas.width = width; |
michael@0 | 136 | canvas.height = height; |
michael@0 | 137 | return canvas; |
michael@0 | 138 | } |
michael@0 | 139 | } |