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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | let tabs = []; |
michael@0 | 6 | |
michael@0 | 7 | function addTab(aURL) { |
michael@0 | 8 | tabs.push(gBrowser.addTab(aURL, {skipAnimation: true})); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function testAttrib(elem, attrib, attribValue, msg) { |
michael@0 | 12 | is(elem.hasAttribute(attrib), attribValue, msg); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | waitForExplicitFinish(); |
michael@0 | 17 | is(gBrowser.tabs.length, 1, "one tab is open initially"); |
michael@0 | 18 | |
michael@0 | 19 | // Add several new tabs in sequence, hiding some, to ensure that the |
michael@0 | 20 | // correct attributes get set |
michael@0 | 21 | |
michael@0 | 22 | addTab("http://mochi.test:8888/#0"); |
michael@0 | 23 | addTab("http://mochi.test:8888/#1"); |
michael@0 | 24 | addTab("http://mochi.test:8888/#2"); |
michael@0 | 25 | addTab("http://mochi.test:8888/#3"); |
michael@0 | 26 | |
michael@0 | 27 | gBrowser.selectedTab = gBrowser.tabs[0]; |
michael@0 | 28 | testAttrib(gBrowser.tabs[0], "first-visible-tab", true, |
michael@0 | 29 | "First tab marked first-visible-tab!"); |
michael@0 | 30 | testAttrib(gBrowser.tabs[4], "last-visible-tab", true, |
michael@0 | 31 | "Fifth tab marked last-visible-tab!"); |
michael@0 | 32 | testAttrib(gBrowser.tabs[0], "selected", true, "First tab marked selected!"); |
michael@0 | 33 | testAttrib(gBrowser.tabs[0], "afterselected-visible", false, |
michael@0 | 34 | "First tab not marked afterselected-visible!"); |
michael@0 | 35 | testAttrib(gBrowser.tabs[1], "afterselected-visible", true, |
michael@0 | 36 | "Second tab marked afterselected-visible!"); |
michael@0 | 37 | gBrowser.hideTab(gBrowser.tabs[1]); |
michael@0 | 38 | executeSoon(test_hideSecond); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function test_hideSecond() { |
michael@0 | 42 | testAttrib(gBrowser.tabs[2], "afterselected-visible", true, |
michael@0 | 43 | "Third tab marked afterselected-visible!"); |
michael@0 | 44 | gBrowser.showTab(gBrowser.tabs[1]) |
michael@0 | 45 | executeSoon(test_showSecond); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function test_showSecond() { |
michael@0 | 49 | testAttrib(gBrowser.tabs[1], "afterselected-visible", true, |
michael@0 | 50 | "Second tab marked afterselected-visible!"); |
michael@0 | 51 | testAttrib(gBrowser.tabs[2], "afterselected-visible", false, |
michael@0 | 52 | "Third tab not marked as afterselected-visible!"); |
michael@0 | 53 | gBrowser.selectedTab = gBrowser.tabs[1]; |
michael@0 | 54 | gBrowser.hideTab(gBrowser.tabs[0]); |
michael@0 | 55 | executeSoon(test_hideFirst); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function test_hideFirst() { |
michael@0 | 59 | testAttrib(gBrowser.tabs[0], "first-visible-tab", false, |
michael@0 | 60 | "Hidden first tab not marked first-visible-tab!"); |
michael@0 | 61 | testAttrib(gBrowser.tabs[1], "first-visible-tab", true, |
michael@0 | 62 | "Second tab marked first-visible-tab!"); |
michael@0 | 63 | gBrowser.showTab(gBrowser.tabs[0]); |
michael@0 | 64 | executeSoon(test_showFirst); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function test_showFirst() { |
michael@0 | 68 | testAttrib(gBrowser.tabs[0], "first-visible-tab", true, |
michael@0 | 69 | "First tab marked first-visible-tab!"); |
michael@0 | 70 | gBrowser.selectedTab = gBrowser.tabs[2]; |
michael@0 | 71 | testAttrib(gBrowser.tabs[3], "afterselected-visible", true, |
michael@0 | 72 | "Fourth tab marked afterselected-visible!"); |
michael@0 | 73 | |
michael@0 | 74 | gBrowser.moveTabTo(gBrowser.selectedTab, 1); |
michael@0 | 75 | executeSoon(test_movedLower); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function test_movedLower() { |
michael@0 | 79 | testAttrib(gBrowser.tabs[2], "afterselected-visible", true, |
michael@0 | 80 | "Third tab marked afterselected-visible!"); |
michael@0 | 81 | test_hoverOne(); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function test_hoverOne() { |
michael@0 | 85 | EventUtils.synthesizeMouseAtCenter(gBrowser.tabs[4], { type: "mousemove" }); |
michael@0 | 86 | testAttrib(gBrowser.tabs[3], "beforehovered", true, "Fourth tab marked beforehovered"); |
michael@0 | 87 | EventUtils.synthesizeMouseAtCenter(gBrowser.tabs[3], { type: "mousemove" }); |
michael@0 | 88 | testAttrib(gBrowser.tabs[2], "beforehovered", true, "Third tab marked beforehovered!"); |
michael@0 | 89 | testAttrib(gBrowser.tabs[2], "afterhovered", false, "Third tab not marked afterhovered!"); |
michael@0 | 90 | testAttrib(gBrowser.tabs[4], "afterhovered", true, "Fifth tab marked afterhovered!"); |
michael@0 | 91 | testAttrib(gBrowser.tabs[4], "beforehovered", false, "Fifth tab not marked beforehovered!"); |
michael@0 | 92 | testAttrib(gBrowser.tabs[0], "beforehovered", false, "First tab not marked beforehovered!"); |
michael@0 | 93 | testAttrib(gBrowser.tabs[0], "afterhovered", false, "First tab not marked afterhovered!"); |
michael@0 | 94 | testAttrib(gBrowser.tabs[1], "beforehovered", false, "Second tab not marked beforehovered!"); |
michael@0 | 95 | testAttrib(gBrowser.tabs[1], "afterhovered", false, "Second tab not marked afterhovered!"); |
michael@0 | 96 | testAttrib(gBrowser.tabs[3], "beforehovered", false, "Fourth tab not marked beforehovered!"); |
michael@0 | 97 | testAttrib(gBrowser.tabs[3], "afterhovered", false, "Fourth tab not marked afterhovered!"); |
michael@0 | 98 | gBrowser.removeTab(tabs.pop()); |
michael@0 | 99 | executeSoon(test_hoverStatePersistence); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function test_hoverStatePersistence() { |
michael@0 | 103 | // Test that the afterhovered and beforehovered attributes are still there when |
michael@0 | 104 | // a tab is selected and then unselected again. See bug 856107. |
michael@0 | 105 | |
michael@0 | 106 | function assertState() { |
michael@0 | 107 | testAttrib(gBrowser.tabs[0], "beforehovered", true, "First tab still marked beforehovered!"); |
michael@0 | 108 | testAttrib(gBrowser.tabs[0], "afterhovered", false, "First tab not marked afterhovered!"); |
michael@0 | 109 | testAttrib(gBrowser.tabs[2], "afterhovered", true, "Third tab still marked afterhovered!"); |
michael@0 | 110 | testAttrib(gBrowser.tabs[2], "beforehovered", false, "Third tab not marked afterhovered!"); |
michael@0 | 111 | testAttrib(gBrowser.tabs[1], "beforehovered", false, "Second tab not marked beforehovered!"); |
michael@0 | 112 | testAttrib(gBrowser.tabs[1], "afterhovered", false, "Second tab not marked afterhovered!"); |
michael@0 | 113 | testAttrib(gBrowser.tabs[3], "beforehovered", false, "Fourth tab not marked beforehovered!"); |
michael@0 | 114 | testAttrib(gBrowser.tabs[3], "afterhovered", false, "Fourth tab not marked afterhovered!"); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | gBrowser.selectedTab = gBrowser.tabs[3]; |
michael@0 | 118 | EventUtils.synthesizeMouseAtCenter(gBrowser.tabs[1], { type: "mousemove" }); |
michael@0 | 119 | assertState(); |
michael@0 | 120 | gBrowser.selectedTab = gBrowser.tabs[1]; |
michael@0 | 121 | assertState(); |
michael@0 | 122 | gBrowser.selectedTab = gBrowser.tabs[3]; |
michael@0 | 123 | assertState(); |
michael@0 | 124 | executeSoon(test_pinning); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function test_pinning() { |
michael@0 | 128 | gBrowser.selectedTab = gBrowser.tabs[3]; |
michael@0 | 129 | testAttrib(gBrowser.tabs[3], "last-visible-tab", true, |
michael@0 | 130 | "Fourth tab marked last-visible-tab!"); |
michael@0 | 131 | testAttrib(gBrowser.tabs[3], "selected", true, "Fourth tab marked selected!"); |
michael@0 | 132 | testAttrib(gBrowser.tabs[3], "afterselected-visible", false, |
michael@0 | 133 | "Fourth tab not marked afterselected-visible!"); |
michael@0 | 134 | // Causes gBrowser.tabs to change indices |
michael@0 | 135 | gBrowser.pinTab(gBrowser.tabs[3]); |
michael@0 | 136 | testAttrib(gBrowser.tabs[3], "last-visible-tab", true, |
michael@0 | 137 | "Fourth tab marked last-visible-tab!"); |
michael@0 | 138 | testAttrib(gBrowser.tabs[1], "afterselected-visible", true, |
michael@0 | 139 | "Second tab marked afterselected-visible!"); |
michael@0 | 140 | testAttrib(gBrowser.tabs[0], "first-visible-tab", true, |
michael@0 | 141 | "First tab marked first-visible-tab!"); |
michael@0 | 142 | testAttrib(gBrowser.tabs[0], "selected", true, "First tab marked selected!"); |
michael@0 | 143 | gBrowser.selectedTab = gBrowser.tabs[1]; |
michael@0 | 144 | testAttrib(gBrowser.tabs[2], "afterselected-visible", true, |
michael@0 | 145 | "Third tab marked afterselected-visible!"); |
michael@0 | 146 | test_cleanUp(); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | function test_cleanUp() { |
michael@0 | 150 | tabs.forEach(gBrowser.removeTab, gBrowser); |
michael@0 | 151 | finish(); |
michael@0 | 152 | } |