Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 5 | |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | const kTrimPref = "browser.urlbar.trimURLs"; |
michael@0 | 9 | var gTrimPrefValue; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | runTests(); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function setUp() { |
michael@0 | 16 | gTrimPrefValue = SpecialPowers.getBoolPref(kTrimPref); |
michael@0 | 17 | SpecialPowers.setBoolPref(kTrimPref, true); |
michael@0 | 18 | yield addTab("about:blank"); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function tearDown() { |
michael@0 | 22 | SpecialPowers.setBoolPref(kTrimPref, gTrimPrefValue); |
michael@0 | 23 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function testTrim(aOriginal, aTarget) { |
michael@0 | 27 | let urlbar = BrowserUI._edit; |
michael@0 | 28 | urlbar.value = aOriginal; |
michael@0 | 29 | urlbar.valueIsTyped = false; |
michael@0 | 30 | is(urlbar.value, aTarget || aOriginal, "url bar value set"); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | gTests.push({ |
michael@0 | 34 | desc: "URIs - trimming (pref enabled)", |
michael@0 | 35 | setUp: setUp, |
michael@0 | 36 | tearDown: tearDown, |
michael@0 | 37 | run: function () { |
michael@0 | 38 | let testcases = [ |
michael@0 | 39 | ["http://mozilla.org/", "mozilla.org"], |
michael@0 | 40 | ["https://mozilla.org/", "https://mozilla.org"], |
michael@0 | 41 | ["http://mözilla.org/", "mözilla.org"], |
michael@0 | 42 | ["http://mozilla.imaginatory/", "mozilla.imaginatory"], |
michael@0 | 43 | ["http://www.mozilla.org/", "www.mozilla.org"], |
michael@0 | 44 | ["http://sub.mozilla.org/", "sub.mozilla.org"], |
michael@0 | 45 | ["http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org"], |
michael@0 | 46 | ["http://mozilla.org/file.ext", "mozilla.org/file.ext"], |
michael@0 | 47 | ["http://mozilla.org/sub/", "mozilla.org/sub/"], |
michael@0 | 48 | |
michael@0 | 49 | ["http://ftp.mozilla.org/", "http://ftp.mozilla.org"], |
michael@0 | 50 | ["http://ftp1.mozilla.org/", "http://ftp1.mozilla.org"], |
michael@0 | 51 | ["http://ftp42.mozilla.org/", "http://ftp42.mozilla.org"], |
michael@0 | 52 | ["http://ftpx.mozilla.org/", "ftpx.mozilla.org"], |
michael@0 | 53 | ["ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org"], |
michael@0 | 54 | ["ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org"], |
michael@0 | 55 | ["ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org"], |
michael@0 | 56 | ["ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org"], |
michael@0 | 57 | |
michael@0 | 58 | ["https://user:pass@mozilla.org/", "https://user:pass@mozilla.org"], |
michael@0 | 59 | ["http://user:pass@mozilla.org/", "http://user:pass@mozilla.org"], |
michael@0 | 60 | ["http://sub.mozilla.org:666/", "sub.mozilla.org:666"], |
michael@0 | 61 | |
michael@0 | 62 | ["https://[fe80::222:19ff:fe11:8c76]/file.ext"], |
michael@0 | 63 | ["http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]"], |
michael@0 | 64 | ["https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], |
michael@0 | 65 | ["http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"], |
michael@0 | 66 | |
michael@0 | 67 | ["mailto:admin@mozilla.org"], |
michael@0 | 68 | ["gopher://mozilla.org/"], |
michael@0 | 69 | ["about:config"], |
michael@0 | 70 | ["jar:http://mozilla.org/example.jar!/"], |
michael@0 | 71 | ["view-source:http://mozilla.org/"] |
michael@0 | 72 | ]; |
michael@0 | 73 | |
michael@0 | 74 | for (let [original, target] of testcases) |
michael@0 | 75 | testTrim(original, target); |
michael@0 | 76 | } |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | gTests.push({ |
michael@0 | 80 | desc: "URIs - no trimming (pref disabled)", |
michael@0 | 81 | setUp: setUp, |
michael@0 | 82 | tearDown: tearDown, |
michael@0 | 83 | run: function () { |
michael@0 | 84 | SpecialPowers.setBoolPref(kTrimPref, false); |
michael@0 | 85 | testTrim("http://mozilla.org/"); |
michael@0 | 86 | |
michael@0 | 87 | SpecialPowers.setBoolPref(kTrimPref, true); |
michael@0 | 88 | testTrim("http://mozilla.org/", "mozilla.org"); |
michael@0 | 89 | } |
michael@0 | 90 | }); |
michael@0 | 91 | |
michael@0 | 92 | gTests.push({ |
michael@0 | 93 | desc: "Loaded URI - copy/paste behavior", |
michael@0 | 94 | setUp: setUp, |
michael@0 | 95 | tearDown: tearDown, |
michael@0 | 96 | run: function () { |
michael@0 | 97 | let urlbar = BrowserUI._edit; |
michael@0 | 98 | |
michael@0 | 99 | BrowserUI.goToURI("http://example.com/"); |
michael@0 | 100 | let pageLoaded = yield waitForCondition( |
michael@0 | 101 | () => Browser.selectedBrowser.currentURI.spec == "http://example.com/"); |
michael@0 | 102 | |
michael@0 | 103 | ok(pageLoaded, "expected page should have loaded"); |
michael@0 | 104 | is(urlbar.value, "example.com", "trimmed value set"); |
michael@0 | 105 | |
michael@0 | 106 | yield showNavBar(); |
michael@0 | 107 | |
michael@0 | 108 | function clipboardCondition(aExpected) { |
michael@0 | 109 | return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | // Value set by browser -- should copy entire url (w/ scheme) on full select |
michael@0 | 113 | |
michael@0 | 114 | urlbar.focus(); |
michael@0 | 115 | urlbar.select(); |
michael@0 | 116 | CommandUpdater.doCommand("cmd_copy"); |
michael@0 | 117 | |
michael@0 | 118 | let copy = yield waitForCondition(clipboardCondition("http://example.com/")); |
michael@0 | 119 | ok(copy, "should copy entire url (w/ scheme) on full select"); |
michael@0 | 120 | |
michael@0 | 121 | // Value set by browser -- should copy selected text on partial select |
michael@0 | 122 | |
michael@0 | 123 | urlbar.focus(); |
michael@0 | 124 | urlbar.select(); |
michael@0 | 125 | urlbar.selectionStart = 2; |
michael@0 | 126 | CommandUpdater.doCommand("cmd_copy"); |
michael@0 | 127 | |
michael@0 | 128 | copy = yield waitForCondition(clipboardCondition("ample.com")); |
michael@0 | 129 | ok(copy, "should copy selected text on partial select"); |
michael@0 | 130 | |
michael@0 | 131 | // Value set by user -- should not copy full string |
michael@0 | 132 | |
michael@0 | 133 | urlbar.valueIsTyped = true; |
michael@0 | 134 | urlbar.focus(); |
michael@0 | 135 | urlbar.select(); |
michael@0 | 136 | CommandUpdater.doCommand("cmd_copy"); |
michael@0 | 137 | |
michael@0 | 138 | copy = yield waitForCondition(clipboardCondition("example.com")); |
michael@0 | 139 | ok(copy, "should not copy full string"); |
michael@0 | 140 | } |
michael@0 | 141 | }); |