1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_urlbar_trimURLs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,141 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* Any copyright is dedicated to the Public Domain. 1.7 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.8 + 1.9 +"use strict"; 1.10 + 1.11 +const kTrimPref = "browser.urlbar.trimURLs"; 1.12 +var gTrimPrefValue; 1.13 + 1.14 +function test() { 1.15 + runTests(); 1.16 +} 1.17 + 1.18 +function setUp() { 1.19 + gTrimPrefValue = SpecialPowers.getBoolPref(kTrimPref); 1.20 + SpecialPowers.setBoolPref(kTrimPref, true); 1.21 + yield addTab("about:blank"); 1.22 +} 1.23 + 1.24 +function tearDown() { 1.25 + SpecialPowers.setBoolPref(kTrimPref, gTrimPrefValue); 1.26 + Browser.closeTab(Browser.selectedTab, { forceClose: true }); 1.27 +} 1.28 + 1.29 +function testTrim(aOriginal, aTarget) { 1.30 + let urlbar = BrowserUI._edit; 1.31 + urlbar.value = aOriginal; 1.32 + urlbar.valueIsTyped = false; 1.33 + is(urlbar.value, aTarget || aOriginal, "url bar value set"); 1.34 +} 1.35 + 1.36 +gTests.push({ 1.37 + desc: "URIs - trimming (pref enabled)", 1.38 + setUp: setUp, 1.39 + tearDown: tearDown, 1.40 + run: function () { 1.41 + let testcases = [ 1.42 + ["http://mozilla.org/", "mozilla.org"], 1.43 + ["https://mozilla.org/", "https://mozilla.org"], 1.44 + ["http://mözilla.org/", "mözilla.org"], 1.45 + ["http://mozilla.imaginatory/", "mozilla.imaginatory"], 1.46 + ["http://www.mozilla.org/", "www.mozilla.org"], 1.47 + ["http://sub.mozilla.org/", "sub.mozilla.org"], 1.48 + ["http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org"], 1.49 + ["http://mozilla.org/file.ext", "mozilla.org/file.ext"], 1.50 + ["http://mozilla.org/sub/", "mozilla.org/sub/"], 1.51 + 1.52 + ["http://ftp.mozilla.org/", "http://ftp.mozilla.org"], 1.53 + ["http://ftp1.mozilla.org/", "http://ftp1.mozilla.org"], 1.54 + ["http://ftp42.mozilla.org/", "http://ftp42.mozilla.org"], 1.55 + ["http://ftpx.mozilla.org/", "ftpx.mozilla.org"], 1.56 + ["ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org"], 1.57 + ["ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org"], 1.58 + ["ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org"], 1.59 + ["ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org"], 1.60 + 1.61 + ["https://user:pass@mozilla.org/", "https://user:pass@mozilla.org"], 1.62 + ["http://user:pass@mozilla.org/", "http://user:pass@mozilla.org"], 1.63 + ["http://sub.mozilla.org:666/", "sub.mozilla.org:666"], 1.64 + 1.65 + ["https://[fe80::222:19ff:fe11:8c76]/file.ext"], 1.66 + ["http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]"], 1.67 + ["https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], 1.68 + ["http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], 1.69 + 1.70 + ["mailto:admin@mozilla.org"], 1.71 + ["gopher://mozilla.org/"], 1.72 + ["about:config"], 1.73 + ["jar:http://mozilla.org/example.jar!/"], 1.74 + ["view-source:http://mozilla.org/"] 1.75 + ]; 1.76 + 1.77 + for (let [original, target] of testcases) 1.78 + testTrim(original, target); 1.79 + } 1.80 +}); 1.81 + 1.82 +gTests.push({ 1.83 + desc: "URIs - no trimming (pref disabled)", 1.84 + setUp: setUp, 1.85 + tearDown: tearDown, 1.86 + run: function () { 1.87 + SpecialPowers.setBoolPref(kTrimPref, false); 1.88 + testTrim("http://mozilla.org/"); 1.89 + 1.90 + SpecialPowers.setBoolPref(kTrimPref, true); 1.91 + testTrim("http://mozilla.org/", "mozilla.org"); 1.92 + } 1.93 +}); 1.94 + 1.95 +gTests.push({ 1.96 + desc: "Loaded URI - copy/paste behavior", 1.97 + setUp: setUp, 1.98 + tearDown: tearDown, 1.99 + run: function () { 1.100 + let urlbar = BrowserUI._edit; 1.101 + 1.102 + BrowserUI.goToURI("http://example.com/"); 1.103 + let pageLoaded = yield waitForCondition( 1.104 + () => Browser.selectedBrowser.currentURI.spec == "http://example.com/"); 1.105 + 1.106 + ok(pageLoaded, "expected page should have loaded"); 1.107 + is(urlbar.value, "example.com", "trimmed value set"); 1.108 + 1.109 + yield showNavBar(); 1.110 + 1.111 + function clipboardCondition(aExpected) { 1.112 + return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); 1.113 + } 1.114 + 1.115 + // Value set by browser -- should copy entire url (w/ scheme) on full select 1.116 + 1.117 + urlbar.focus(); 1.118 + urlbar.select(); 1.119 + CommandUpdater.doCommand("cmd_copy"); 1.120 + 1.121 + let copy = yield waitForCondition(clipboardCondition("http://example.com/")); 1.122 + ok(copy, "should copy entire url (w/ scheme) on full select"); 1.123 + 1.124 + // Value set by browser -- should copy selected text on partial select 1.125 + 1.126 + urlbar.focus(); 1.127 + urlbar.select(); 1.128 + urlbar.selectionStart = 2; 1.129 + CommandUpdater.doCommand("cmd_copy"); 1.130 + 1.131 + copy = yield waitForCondition(clipboardCondition("ample.com")); 1.132 + ok(copy, "should copy selected text on partial select"); 1.133 + 1.134 + // Value set by user -- should not copy full string 1.135 + 1.136 + urlbar.valueIsTyped = true; 1.137 + urlbar.focus(); 1.138 + urlbar.select(); 1.139 + CommandUpdater.doCommand("cmd_copy"); 1.140 + 1.141 + copy = yield waitForCondition(clipboardCondition("example.com")); 1.142 + ok(copy, "should not copy full string"); 1.143 + } 1.144 +}); 1.145 \ No newline at end of file