browser_bug304198.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is bug 491431 test.
15  *
16  * The Initial Developer of the Original Code is
17  * Mozilla Corporation
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Jon Herron <leftturnsolutions@yahoo.com>
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 function test() {
40 
41  let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL;
42 
43  charsToDelete = 5;
44  deletedURLTab = gBrowser.addTab();
45  fullURLTab = gBrowser.addTab();
46  partialURLTab = gBrowser.addTab();
47  testURL = "http://example.org/browser/browser/base/content/test/dummy_page.html";
48 
49  testPartialURL = testURL.substr(0, (testURL.length - charsToDelete));
50 
51  function cleanUp() {
52  gBrowser.removeTab(fullURLTab);
53  gBrowser.removeTab(partialURLTab);
54  gBrowser.removeTab(deletedURLTab);
55  }
56 
57  function cycleTabs() {
58  gBrowser.selectedTab = fullURLTab;
59  is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab');
60 
61  gBrowser.selectedTab = partialURLTab;
62  is(gURLBar.value, testPartialURL, 'gURLBar.value should be testPartialURL after switching back to partialURLTab');
63 
64  gBrowser.selectedTab = deletedURLTab;
65  is(gURLBar.value, '', 'gURLBar.value should be "" after switching back to deletedURLTab');
66 
67  gBrowser.selectedTab = fullURLTab;
68  is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab');
69  }
70 
71  // function borrowed from browser_bug386835.js
72  function load(tab, url, cb) {
73  tab.linkedBrowser.addEventListener("load", function (event) {
74  event.currentTarget.removeEventListener("load", arguments.callee, true);
75  cb();
76  }, true);
77  tab.linkedBrowser.loadURI(url);
78  }
79 
80  function urlbarBackspace(cb) {
81  gBrowser.selectedBrowser.focus();
82  gURLBar.addEventListener("focus", function () {
83  gURLBar.removeEventListener("focus", arguments.callee, false);
84  gURLBar.addEventListener("input", function () {
85  gURLBar.removeEventListener("input", arguments.callee, false);
86  cb();
87  }, false);
88  executeSoon(function () {
89  EventUtils.synthesizeKey("VK_BACK_SPACE", {});
90  });
91  }, false);
92  gURLBar.focus();
93  }
94 
95  function prepareDeletedURLTab(cb) {
96  gBrowser.selectedTab = deletedURLTab;
97  is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to deletedURLTab');
98 
99  // simulate the user removing the whole url from the location bar
100  gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", true);
101 
102  urlbarBackspace(function () {
103  is(gURLBar.value, "", 'gURLBar.value should be "" (just set)');
104  if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll"))
105  gPrefService.clearUserPref("browser.urlbar.clickSelectsAll");
106  cb();
107  });
108  }
109 
110  function prepareFullURLTab(cb) {
111  gBrowser.selectedTab = fullURLTab;
112  is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to fullURLTab');
113  cb();
114  }
115 
116  function preparePartialURLTab(cb) {
117  gBrowser.selectedTab = partialURLTab;
118  is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to partialURLTab');
119 
120  // simulate the user removing part of the url from the location bar
121  gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", false);
122 
123  var deleted = 0;
124  urlbarBackspace(function () {
125  deleted++;
126  if (deleted < charsToDelete) {
127  urlbarBackspace(arguments.callee);
128  } else {
129  is(gURLBar.value, testPartialURL, "gURLBar.value should be testPartialURL (just set)");
130  if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll"))
131  gPrefService.clearUserPref("browser.urlbar.clickSelectsAll");
132  cb();
133  }
134  });
135  }
136 
137  function runTests() {
138  // prepare the three tabs required by this test
139  prepareFullURLTab(function () {
140  preparePartialURLTab(function () {
141  prepareDeletedURLTab(function () {
142  // now cycle the tabs and make sure everything looks good
143  cycleTabs();
144  cleanUp();
145  finish();
146  });
147  });
148  });
149  }
150 
151  load(deletedURLTab, testURL, function() {
152  load(fullURLTab, testURL, function() {
153  load(partialURLTab, testURL, runTests);
154  });
155  });
156 }
157 
var event
var tab
waitForExplicitFinish()
Element Properties load
var testURL
return!aWindow arguments!aWindow arguments[0]
function test()
var gPrefService
Definition: overlay.js:34
function url(spec)
function cleanUp()