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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function test() { |
michael@0 | 6 | waitForExplicitFinish(); |
michael@0 | 7 | |
michael@0 | 8 | let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL; |
michael@0 | 9 | |
michael@0 | 10 | charsToDelete = 5; |
michael@0 | 11 | deletedURLTab = gBrowser.addTab(); |
michael@0 | 12 | fullURLTab = gBrowser.addTab(); |
michael@0 | 13 | partialURLTab = gBrowser.addTab(); |
michael@0 | 14 | testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; |
michael@0 | 15 | |
michael@0 | 16 | function cleanUp() { |
michael@0 | 17 | gBrowser.removeTab(fullURLTab); |
michael@0 | 18 | gBrowser.removeTab(partialURLTab); |
michael@0 | 19 | gBrowser.removeTab(deletedURLTab); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function cycleTabs() { |
michael@0 | 23 | gBrowser.selectedTab = fullURLTab; |
michael@0 | 24 | is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); |
michael@0 | 25 | |
michael@0 | 26 | gBrowser.selectedTab = partialURLTab; |
michael@0 | 27 | is(gURLBar.value, testPartialURL, 'gURLBar.value should be testPartialURL after switching back to partialURLTab'); |
michael@0 | 28 | |
michael@0 | 29 | gBrowser.selectedTab = deletedURLTab; |
michael@0 | 30 | is(gURLBar.value, '', 'gURLBar.value should be "" after switching back to deletedURLTab'); |
michael@0 | 31 | |
michael@0 | 32 | gBrowser.selectedTab = fullURLTab; |
michael@0 | 33 | is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // function borrowed from browser_bug386835.js |
michael@0 | 37 | function load(tab, url, cb) { |
michael@0 | 38 | tab.linkedBrowser.addEventListener("load", function (event) { |
michael@0 | 39 | event.currentTarget.removeEventListener("load", arguments.callee, true); |
michael@0 | 40 | cb(); |
michael@0 | 41 | }, true); |
michael@0 | 42 | tab.linkedBrowser.loadURI(url); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function urlbarBackspace(cb) { |
michael@0 | 46 | gBrowser.selectedBrowser.focus(); |
michael@0 | 47 | gURLBar.addEventListener("focus", function () { |
michael@0 | 48 | gURLBar.removeEventListener("focus", arguments.callee, false); |
michael@0 | 49 | gURLBar.addEventListener("input", function () { |
michael@0 | 50 | gURLBar.removeEventListener("input", arguments.callee, false); |
michael@0 | 51 | cb(); |
michael@0 | 52 | }, false); |
michael@0 | 53 | executeSoon(function () { |
michael@0 | 54 | EventUtils.synthesizeKey("VK_BACK_SPACE", {}); |
michael@0 | 55 | }); |
michael@0 | 56 | }, false); |
michael@0 | 57 | gURLBar.focus(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function prepareDeletedURLTab(cb) { |
michael@0 | 61 | gBrowser.selectedTab = deletedURLTab; |
michael@0 | 62 | is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to deletedURLTab'); |
michael@0 | 63 | |
michael@0 | 64 | // simulate the user removing the whole url from the location bar |
michael@0 | 65 | gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", true); |
michael@0 | 66 | |
michael@0 | 67 | urlbarBackspace(function () { |
michael@0 | 68 | is(gURLBar.value, "", 'gURLBar.value should be "" (just set)'); |
michael@0 | 69 | if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) |
michael@0 | 70 | gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); |
michael@0 | 71 | cb(); |
michael@0 | 72 | }); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function prepareFullURLTab(cb) { |
michael@0 | 76 | gBrowser.selectedTab = fullURLTab; |
michael@0 | 77 | is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to fullURLTab'); |
michael@0 | 78 | cb(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function preparePartialURLTab(cb) { |
michael@0 | 82 | gBrowser.selectedTab = partialURLTab; |
michael@0 | 83 | is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to partialURLTab'); |
michael@0 | 84 | |
michael@0 | 85 | // simulate the user removing part of the url from the location bar |
michael@0 | 86 | gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", false); |
michael@0 | 87 | |
michael@0 | 88 | var deleted = 0; |
michael@0 | 89 | urlbarBackspace(function () { |
michael@0 | 90 | deleted++; |
michael@0 | 91 | if (deleted < charsToDelete) { |
michael@0 | 92 | urlbarBackspace(arguments.callee); |
michael@0 | 93 | } else { |
michael@0 | 94 | is(gURLBar.value, testPartialURL, "gURLBar.value should be testPartialURL (just set)"); |
michael@0 | 95 | if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) |
michael@0 | 96 | gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); |
michael@0 | 97 | cb(); |
michael@0 | 98 | } |
michael@0 | 99 | }); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function runTests() { |
michael@0 | 103 | testURL = gURLBar.trimValue(testURL); |
michael@0 | 104 | testPartialURL = testURL.substr(0, (testURL.length - charsToDelete)); |
michael@0 | 105 | |
michael@0 | 106 | // prepare the three tabs required by this test |
michael@0 | 107 | prepareFullURLTab(function () { |
michael@0 | 108 | preparePartialURLTab(function () { |
michael@0 | 109 | prepareDeletedURLTab(function () { |
michael@0 | 110 | // now cycle the tabs and make sure everything looks good |
michael@0 | 111 | cycleTabs(); |
michael@0 | 112 | cleanUp(); |
michael@0 | 113 | finish(); |
michael@0 | 114 | }); |
michael@0 | 115 | }); |
michael@0 | 116 | }); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | load(deletedURLTab, testURL, function() { |
michael@0 | 120 | load(fullURLTab, testURL, function() { |
michael@0 | 121 | load(partialURLTab, testURL, runTests); |
michael@0 | 122 | }); |
michael@0 | 123 | }); |
michael@0 | 124 | } |
michael@0 | 125 |