2010-09-14 22:41:16 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is browser test code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-10-12 09:32:01 -07:00
|
|
|
* Drew Willcoxon <adw@mozilla.com> (Original Author)
|
2010-09-14 22:41:16 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This tests the "over-link" that appears in the location bar when the user
|
|
|
|
* mouses over a link. See bug 587908.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var gTestIter;
|
|
|
|
|
|
|
|
// TESTS //////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
let gTests = [
|
|
|
|
|
|
|
|
function smokeTestGenerator() {
|
2010-10-12 09:32:01 -07:00
|
|
|
// Make sure the location bar is not focused.
|
|
|
|
gBrowser.contentWindow.focus();
|
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
if (ensureOverLinkHidden())
|
|
|
|
yield;
|
|
|
|
|
|
|
|
setOverLinkWait("http://example.com/");
|
2010-09-18 20:09:17 -07:00
|
|
|
yield;
|
2010-10-12 09:31:44 -07:00
|
|
|
checkURLBar(true);
|
2010-10-12 09:31:44 -07:00
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
setOverLinkWait("");
|
|
|
|
yield;
|
|
|
|
checkURLBar(false);
|
|
|
|
},
|
2010-10-12 09:31:44 -07:00
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
function hostPathLabels() {
|
2010-10-12 09:32:01 -07:00
|
|
|
updateOverLink("http://example.com/");
|
2010-10-12 09:31:44 -07:00
|
|
|
hostLabelIs("http://example.com/");
|
|
|
|
pathLabelIs("");
|
|
|
|
|
2010-10-12 09:32:01 -07:00
|
|
|
updateOverLink("http://example.com/foo");
|
2010-10-12 09:31:44 -07:00
|
|
|
hostLabelIs("http://example.com/");
|
|
|
|
pathLabelIs("foo");
|
|
|
|
|
2010-10-12 09:32:01 -07:00
|
|
|
updateOverLink("javascript:popup('http://example.com/')");
|
2010-10-12 09:31:44 -07:00
|
|
|
hostLabelIs("");
|
|
|
|
pathLabelIs("javascript:popup('http://example.com/')");
|
|
|
|
|
2010-10-12 09:32:01 -07:00
|
|
|
updateOverLink("javascript:popup('http://example.com/foo')");
|
2010-10-12 09:31:44 -07:00
|
|
|
hostLabelIs("");
|
|
|
|
pathLabelIs("javascript:popup('http://example.com/foo')");
|
|
|
|
|
2010-10-12 09:32:01 -07:00
|
|
|
updateOverLink("about:home");
|
2010-10-12 09:31:44 -07:00
|
|
|
hostLabelIs("");
|
|
|
|
pathLabelIs("about:home");
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
2010-09-14 22:41:16 -07:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
2010-10-12 09:31:44 -07:00
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function runNextTest() {
|
|
|
|
let nextTest = gTests.shift();
|
|
|
|
if (nextTest) {
|
|
|
|
dump("Running next test: " + nextTest.name + "\n");
|
|
|
|
gTestIter = nextTest();
|
|
|
|
|
|
|
|
// If the test is a generator, advance it. Otherwise, we just ran the test.
|
|
|
|
if (gTestIter)
|
|
|
|
cont();
|
|
|
|
else
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
finish();
|
2010-09-14 22:41:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// HELPERS ////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances the test iterator. When all iterations have completed, the entire
|
|
|
|
* suite is finish()ed.
|
|
|
|
*/
|
|
|
|
function cont() {
|
|
|
|
try {
|
|
|
|
gTestIter.next();
|
|
|
|
}
|
|
|
|
catch (err if err instanceof StopIteration) {
|
2010-10-12 09:31:44 -07:00
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
// Depending on who calls us, sometimes exceptions are eaten by event
|
|
|
|
// handlers... Make sure we fail.
|
|
|
|
ok(false, "Exception: " + err);
|
|
|
|
throw err;
|
2010-09-14 22:41:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asserts that the location bar looks like it should.
|
|
|
|
*
|
|
|
|
* @param shouldShowOverLink
|
|
|
|
* True if you expect the over-link to be showing and false otherwise.
|
|
|
|
*/
|
|
|
|
function checkURLBar(shouldShowOverLink) {
|
|
|
|
let overLink = window.getComputedStyle(gURLBar._overLinkBox, null);
|
|
|
|
let origin = window.getComputedStyle(gURLBar._originLabel, null);
|
|
|
|
let editLayer = window.getComputedStyle(gURLBar._textboxContainer, null);
|
|
|
|
if (shouldShowOverLink) {
|
|
|
|
isnot(origin.color, "transparent",
|
|
|
|
"Origin color in over-link layer should not be transparent");
|
|
|
|
is(overLink.opacity, 1, "Over-link should be opaque");
|
|
|
|
is(editLayer.color, "transparent",
|
|
|
|
"Edit layer color should be transparent");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(origin.color, "transparent",
|
|
|
|
"Origin color in over-link layer should be transparent");
|
|
|
|
is(overLink.opacity, 0, "Over-link should be transparent");
|
|
|
|
isnot(editLayer.color, "transparent",
|
|
|
|
"Edit layer color should not be transparent");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-12 09:31:44 -07:00
|
|
|
* Sets the over-link. This assumes that str will cause the over-link to fade
|
2010-09-18 20:09:17 -07:00
|
|
|
* in or out. When its transition has finished, the test iterator is
|
|
|
|
* incremented, so you should yield after calling.
|
2010-09-14 22:41:16 -07:00
|
|
|
*
|
2010-10-12 09:31:44 -07:00
|
|
|
* @param str
|
2010-09-18 20:09:17 -07:00
|
|
|
* The over-link will be set to this string or cleared if this is falsey.
|
2010-09-14 22:41:16 -07:00
|
|
|
*/
|
2010-10-12 09:31:44 -07:00
|
|
|
function setOverLinkWait(str) {
|
2010-10-12 09:32:01 -07:00
|
|
|
dump("Setting over-link and waiting: " + str + "\n");
|
|
|
|
|
2010-09-18 20:09:17 -07:00
|
|
|
let overLink = gURLBar._overLinkBox;
|
2010-10-12 09:32:01 -07:00
|
|
|
let opacity = window.getComputedStyle(overLink, null).opacity;
|
|
|
|
dump("Opacity is " + opacity + "\n");
|
|
|
|
|
|
|
|
ok(str || opacity != 0,
|
|
|
|
"Test assumption: either showing or if hiding, not already hidden");
|
|
|
|
ok(!str || opacity != 1,
|
|
|
|
"Test assumption: either hiding or if showing, not already shown");
|
|
|
|
|
2010-09-18 20:09:17 -07:00
|
|
|
overLink.addEventListener("transitionend", function onTrans(event) {
|
2010-10-12 09:32:01 -07:00
|
|
|
dump("transitionend received: " + (event.target == overLink) + " " +
|
|
|
|
event.propertyName + "\n");
|
2010-09-18 20:09:17 -07:00
|
|
|
if (event.target == overLink && event.propertyName == "opacity") {
|
2010-10-12 09:32:01 -07:00
|
|
|
dump("target transitionend received\n");
|
2010-09-18 20:09:17 -07:00
|
|
|
overLink.removeEventListener("transitionend", onTrans, false);
|
2010-09-14 22:41:16 -07:00
|
|
|
cont();
|
|
|
|
}
|
2010-09-18 20:09:17 -07:00
|
|
|
}, false);
|
2010-10-12 09:31:44 -07:00
|
|
|
gURLBar.setOverLink(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the over-link but unlike setOverLinkWait does not assume that a
|
|
|
|
* transition will occur and therefore does not wait.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The over-link will be set to this string or cleared if this is falsey.
|
|
|
|
*/
|
|
|
|
function setOverLink(str) {
|
2010-10-12 09:32:01 -07:00
|
|
|
dump("Setting over-link but not waiting: " + str + "\n");
|
|
|
|
|
|
|
|
let overLink = gURLBar._overLinkBox;
|
|
|
|
let opacity = window.getComputedStyle(overLink, null).opacity;
|
|
|
|
dump("Opacity is " + opacity + "\n");
|
|
|
|
|
|
|
|
ok(str || opacity == 0,
|
|
|
|
"Test assumption: either showing or if hiding, already hidden");
|
|
|
|
ok(!str || opacity == 1,
|
|
|
|
"Test assumption: either hiding or if showing, already shown");
|
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
gURLBar.setOverLink(str);
|
2010-10-12 09:32:01 -07:00
|
|
|
}
|
|
|
|
|
2010-10-12 09:32:01 -07:00
|
|
|
/**
|
|
|
|
* Calls gURLBar._updateOverLink(str), which updates the over-link but does not
|
|
|
|
* change its visibility.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The over-link will be set to this string. Note that setting this to
|
|
|
|
* falsey doesn't make sense for this function.
|
|
|
|
*/
|
|
|
|
function updateOverLink(str) {
|
|
|
|
gURLBar._updateOverLink(str);
|
|
|
|
}
|
|
|
|
|
2010-09-14 22:41:16 -07:00
|
|
|
/**
|
2010-09-18 20:09:17 -07:00
|
|
|
* If the over-link is hidden, returns false. Otherwise, hides the overlink and
|
|
|
|
* returns true. When the overlink is hidden, the test iterator is incremented,
|
|
|
|
* so if this function returns true, you should yield after calling.
|
2010-09-14 22:41:16 -07:00
|
|
|
*
|
2010-09-18 20:09:17 -07:00
|
|
|
* @return True if you should yield and calling and false if not.
|
2010-09-14 22:41:16 -07:00
|
|
|
*/
|
2010-09-18 20:09:17 -07:00
|
|
|
function ensureOverLinkHidden() {
|
2010-10-12 09:32:01 -07:00
|
|
|
dump("Ensuring over-link is hidden" + "\n");
|
|
|
|
|
2010-09-14 22:41:16 -07:00
|
|
|
let overLink = gURLBar._overLinkBox;
|
2010-10-12 09:32:01 -07:00
|
|
|
let opacity = window.getComputedStyle(overLink, null).opacity;
|
|
|
|
dump("Opacity is " + opacity + "\n");
|
|
|
|
|
|
|
|
if (opacity == 0)
|
2010-09-18 20:09:17 -07:00
|
|
|
return false;
|
|
|
|
|
2010-10-12 09:31:44 -07:00
|
|
|
setOverLinkWait("");
|
2010-09-18 20:09:17 -07:00
|
|
|
return true;
|
2010-09-14 22:41:16 -07:00
|
|
|
}
|
2010-10-12 09:31:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Asserts that the over-link host label is a given string.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The host label should be this string.
|
|
|
|
*/
|
|
|
|
function hostLabelIs(str) {
|
|
|
|
let host = gURLBar._overLinkHostLabel;
|
|
|
|
is(host.value, str, "Over-link host label should be correct");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asserts that the over-link path label is a given string.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The path label should be this string.
|
|
|
|
*/
|
|
|
|
function pathLabelIs(str) {
|
|
|
|
let path = gURLBar._overLinkPathLabel;
|
|
|
|
is(path.value, str, "Over-link path label should be correct");
|
|
|
|
}
|