1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug304198.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + waitForExplicitFinish(); 1.10 + 1.11 + let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL; 1.12 + 1.13 + charsToDelete = 5; 1.14 + deletedURLTab = gBrowser.addTab(); 1.15 + fullURLTab = gBrowser.addTab(); 1.16 + partialURLTab = gBrowser.addTab(); 1.17 + testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; 1.18 + 1.19 + function cleanUp() { 1.20 + gBrowser.removeTab(fullURLTab); 1.21 + gBrowser.removeTab(partialURLTab); 1.22 + gBrowser.removeTab(deletedURLTab); 1.23 + } 1.24 + 1.25 + function cycleTabs() { 1.26 + gBrowser.selectedTab = fullURLTab; 1.27 + is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); 1.28 + 1.29 + gBrowser.selectedTab = partialURLTab; 1.30 + is(gURLBar.value, testPartialURL, 'gURLBar.value should be testPartialURL after switching back to partialURLTab'); 1.31 + 1.32 + gBrowser.selectedTab = deletedURLTab; 1.33 + is(gURLBar.value, '', 'gURLBar.value should be "" after switching back to deletedURLTab'); 1.34 + 1.35 + gBrowser.selectedTab = fullURLTab; 1.36 + is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); 1.37 + } 1.38 + 1.39 + // function borrowed from browser_bug386835.js 1.40 + function load(tab, url, cb) { 1.41 + tab.linkedBrowser.addEventListener("load", function (event) { 1.42 + event.currentTarget.removeEventListener("load", arguments.callee, true); 1.43 + cb(); 1.44 + }, true); 1.45 + tab.linkedBrowser.loadURI(url); 1.46 + } 1.47 + 1.48 + function urlbarBackspace(cb) { 1.49 + gBrowser.selectedBrowser.focus(); 1.50 + gURLBar.addEventListener("focus", function () { 1.51 + gURLBar.removeEventListener("focus", arguments.callee, false); 1.52 + gURLBar.addEventListener("input", function () { 1.53 + gURLBar.removeEventListener("input", arguments.callee, false); 1.54 + cb(); 1.55 + }, false); 1.56 + executeSoon(function () { 1.57 + EventUtils.synthesizeKey("VK_BACK_SPACE", {}); 1.58 + }); 1.59 + }, false); 1.60 + gURLBar.focus(); 1.61 + } 1.62 + 1.63 + function prepareDeletedURLTab(cb) { 1.64 + gBrowser.selectedTab = deletedURLTab; 1.65 + is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to deletedURLTab'); 1.66 + 1.67 + // simulate the user removing the whole url from the location bar 1.68 + gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", true); 1.69 + 1.70 + urlbarBackspace(function () { 1.71 + is(gURLBar.value, "", 'gURLBar.value should be "" (just set)'); 1.72 + if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) 1.73 + gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); 1.74 + cb(); 1.75 + }); 1.76 + } 1.77 + 1.78 + function prepareFullURLTab(cb) { 1.79 + gBrowser.selectedTab = fullURLTab; 1.80 + is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to fullURLTab'); 1.81 + cb(); 1.82 + } 1.83 + 1.84 + function preparePartialURLTab(cb) { 1.85 + gBrowser.selectedTab = partialURLTab; 1.86 + is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to partialURLTab'); 1.87 + 1.88 + // simulate the user removing part of the url from the location bar 1.89 + gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", false); 1.90 + 1.91 + var deleted = 0; 1.92 + urlbarBackspace(function () { 1.93 + deleted++; 1.94 + if (deleted < charsToDelete) { 1.95 + urlbarBackspace(arguments.callee); 1.96 + } else { 1.97 + is(gURLBar.value, testPartialURL, "gURLBar.value should be testPartialURL (just set)"); 1.98 + if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) 1.99 + gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); 1.100 + cb(); 1.101 + } 1.102 + }); 1.103 + } 1.104 + 1.105 + function runTests() { 1.106 + testURL = gURLBar.trimValue(testURL); 1.107 + testPartialURL = testURL.substr(0, (testURL.length - charsToDelete)); 1.108 + 1.109 + // prepare the three tabs required by this test 1.110 + prepareFullURLTab(function () { 1.111 + preparePartialURLTab(function () { 1.112 + prepareDeletedURLTab(function () { 1.113 + // now cycle the tabs and make sure everything looks good 1.114 + cycleTabs(); 1.115 + cleanUp(); 1.116 + finish(); 1.117 + }); 1.118 + }); 1.119 + }); 1.120 + } 1.121 + 1.122 + load(deletedURLTab, testURL, function() { 1.123 + load(fullURLTab, testURL, function() { 1.124 + load(partialURLTab, testURL, runTests); 1.125 + }); 1.126 + }); 1.127 +} 1.128 +