michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const kTrimPref = "browser.urlbar.trimURLs"; michael@0: var gTrimPrefValue; michael@0: michael@0: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: function setUp() { michael@0: gTrimPrefValue = SpecialPowers.getBoolPref(kTrimPref); michael@0: SpecialPowers.setBoolPref(kTrimPref, true); michael@0: yield addTab("about:blank"); michael@0: } michael@0: michael@0: function tearDown() { michael@0: SpecialPowers.setBoolPref(kTrimPref, gTrimPrefValue); michael@0: Browser.closeTab(Browser.selectedTab, { forceClose: true }); michael@0: } michael@0: michael@0: function testTrim(aOriginal, aTarget) { michael@0: let urlbar = BrowserUI._edit; michael@0: urlbar.value = aOriginal; michael@0: urlbar.valueIsTyped = false; michael@0: is(urlbar.value, aTarget || aOriginal, "url bar value set"); michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "URIs - trimming (pref enabled)", michael@0: setUp: setUp, michael@0: tearDown: tearDown, michael@0: run: function () { michael@0: let testcases = [ michael@0: ["http://mozilla.org/", "mozilla.org"], michael@0: ["https://mozilla.org/", "https://mozilla.org"], michael@0: ["http://mözilla.org/", "mözilla.org"], michael@0: ["http://mozilla.imaginatory/", "mozilla.imaginatory"], michael@0: ["http://www.mozilla.org/", "www.mozilla.org"], michael@0: ["http://sub.mozilla.org/", "sub.mozilla.org"], michael@0: ["http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org"], michael@0: ["http://mozilla.org/file.ext", "mozilla.org/file.ext"], michael@0: ["http://mozilla.org/sub/", "mozilla.org/sub/"], michael@0: michael@0: ["http://ftp.mozilla.org/", "http://ftp.mozilla.org"], michael@0: ["http://ftp1.mozilla.org/", "http://ftp1.mozilla.org"], michael@0: ["http://ftp42.mozilla.org/", "http://ftp42.mozilla.org"], michael@0: ["http://ftpx.mozilla.org/", "ftpx.mozilla.org"], michael@0: ["ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org"], michael@0: ["ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org"], michael@0: ["ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org"], michael@0: ["ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org"], michael@0: michael@0: ["https://user:pass@mozilla.org/", "https://user:pass@mozilla.org"], michael@0: ["http://user:pass@mozilla.org/", "http://user:pass@mozilla.org"], michael@0: ["http://sub.mozilla.org:666/", "sub.mozilla.org:666"], michael@0: michael@0: ["https://[fe80::222:19ff:fe11:8c76]/file.ext"], michael@0: ["http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]"], michael@0: ["https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], michael@0: ["http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], michael@0: michael@0: ["mailto:admin@mozilla.org"], michael@0: ["gopher://mozilla.org/"], michael@0: ["about:config"], michael@0: ["jar:http://mozilla.org/example.jar!/"], michael@0: ["view-source:http://mozilla.org/"] michael@0: ]; michael@0: michael@0: for (let [original, target] of testcases) michael@0: testTrim(original, target); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "URIs - no trimming (pref disabled)", michael@0: setUp: setUp, michael@0: tearDown: tearDown, michael@0: run: function () { michael@0: SpecialPowers.setBoolPref(kTrimPref, false); michael@0: testTrim("http://mozilla.org/"); michael@0: michael@0: SpecialPowers.setBoolPref(kTrimPref, true); michael@0: testTrim("http://mozilla.org/", "mozilla.org"); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Loaded URI - copy/paste behavior", michael@0: setUp: setUp, michael@0: tearDown: tearDown, michael@0: run: function () { michael@0: let urlbar = BrowserUI._edit; michael@0: michael@0: BrowserUI.goToURI("http://example.com/"); michael@0: let pageLoaded = yield waitForCondition( michael@0: () => Browser.selectedBrowser.currentURI.spec == "http://example.com/"); michael@0: michael@0: ok(pageLoaded, "expected page should have loaded"); michael@0: is(urlbar.value, "example.com", "trimmed value set"); michael@0: michael@0: yield showNavBar(); michael@0: michael@0: function clipboardCondition(aExpected) { michael@0: return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); michael@0: } michael@0: michael@0: // Value set by browser -- should copy entire url (w/ scheme) on full select michael@0: michael@0: urlbar.focus(); michael@0: urlbar.select(); michael@0: CommandUpdater.doCommand("cmd_copy"); michael@0: michael@0: let copy = yield waitForCondition(clipboardCondition("http://example.com/")); michael@0: ok(copy, "should copy entire url (w/ scheme) on full select"); michael@0: michael@0: // Value set by browser -- should copy selected text on partial select michael@0: michael@0: urlbar.focus(); michael@0: urlbar.select(); michael@0: urlbar.selectionStart = 2; michael@0: CommandUpdater.doCommand("cmd_copy"); michael@0: michael@0: copy = yield waitForCondition(clipboardCondition("ample.com")); michael@0: ok(copy, "should copy selected text on partial select"); michael@0: michael@0: // Value set by user -- should not copy full string michael@0: michael@0: urlbar.valueIsTyped = true; michael@0: urlbar.focus(); michael@0: urlbar.select(); michael@0: CommandUpdater.doCommand("cmd_copy"); michael@0: michael@0: copy = yield waitForCondition(clipboardCondition("example.com")); michael@0: ok(copy, "should not copy full string"); michael@0: } michael@0: });