Bug 1474179 - Part 3: Updates the mochitest for the "copy" menuitem. r?valentin draft
authorZhang Junzhi <zjz@zjz.name>
Thu, 12 Jul 2018 22:30:12 +0800
changeset 817382 67555daed546460cae7c1eed4745c3652006cc43
parent 817381 263ab29e962de647d2b2779f2a1847e9d2ba705b
child 817383 cecc1939c91537c8434f7e1579e5627d39029f71
push id116050
push userbmo:zjz@zjz.name
push dateThu, 12 Jul 2018 16:06:02 +0000
reviewersvalentin
bugs1474179
milestone63.0a1
Bug 1474179 - Part 3: Updates the mochitest for the "copy" menuitem. r?valentin Because the behaviour of the menuitem has been changed to always copy a Unicode URL, if any. MozReview-Commit-ID: 6xOJkhGekmU
browser/base/content/test/urlbar/browser_urlbarCopying.js
browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
--- a/browser/base/content/test/urlbar/browser_urlbarCopying.js
+++ b/browser/base/content/test/urlbar/browser_urlbarCopying.js
@@ -1,14 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const trimPref = "browser.urlbar.trimURLs";
 const phishyUserPassPref = "network.http.phishy-userpass-length";
-const decodeURLpref = "browser.urlbar.decodeURLsOnCopy";
 
 function toUnicode(input) {
   let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
                     .createInstance(Ci.nsIScriptableUnicodeConverter);
   converter.charset = "UTF-8";
 
   return converter.ConvertToUnicode(input);
 }
@@ -16,17 +15,16 @@ function toUnicode(input) {
 function test() {
 
   let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
 
   registerCleanupFunction(function() {
     gBrowser.removeTab(tab);
     Services.prefs.clearUserPref(trimPref);
     Services.prefs.clearUserPref(phishyUserPassPref);
-    Services.prefs.clearUserPref(decodeURLpref);
     URLBarSetURI();
   });
 
   Services.prefs.setBoolPref(trimPref, true);
   Services.prefs.setIntPref(phishyUserPassPref, 32); // avoid prompting about phishing
 
   waitForExplicitFinish();
 
@@ -60,17 +58,17 @@ var tests = [
     copyVal: "<e><xample.co><m>",
     copyExpected: "example.com"
   },
 
   // pageproxystate="valid" from this point on (due to the load)
   {
     loadURL: "http://example.com/",
     expectedURL: "example.com",
-    copyExpected: "http://example.com/"
+    copyExpected: "http://example.com"
   },
   {
     copyVal: "<example.co>m",
     copyExpected: "example.co"
   },
   {
     copyVal: "e<x>ample.com",
     copyExpected: "x"
@@ -104,97 +102,16 @@ var tests = [
 
   // Test that userPass is stripped out
   {
     loadURL: "http://user:pass@mochi.test:8888/browser/browser/base/content/test/urlbar/authenticate.sjs?user=user&pass=pass",
     expectedURL: "mochi.test:8888/browser/browser/base/content/test/urlbar/authenticate.sjs?user=user&pass=pass",
     copyExpected: "http://mochi.test:8888/browser/browser/base/content/test/urlbar/authenticate.sjs?user=user&pass=pass"
   },
 
-  // Test escaping
-  {
-    loadURL: "http://example.com/()%28%29%C3%A9",
-    expectedURL: "example.com/()()\xe9",
-    copyExpected: "http://example.com/()%28%29%C3%A9"
-  },
-  {
-    copyVal: "<example.com/(>)()\xe9",
-    copyExpected: "http://example.com/("
-  },
-  {
-    copyVal: "e<xample.com/(>)()\xe9",
-    copyExpected: "xample.com/("
-  },
-
-  {
-    loadURL: "http://example.com/%C3%A9%C3%A9",
-    expectedURL: "example.com/\xe9\xe9",
-    copyExpected: "http://example.com/%C3%A9%C3%A9"
-  },
-  {
-    copyVal: "e<xample.com/\xe9>\xe9",
-    copyExpected: "xample.com/\xe9"
-  },
-  {
-    copyVal: "<example.com/\xe9>\xe9",
-    copyExpected: "http://example.com/\xe9"
-  },
-  { // Note: it seems BrowserTestUtils.loadURI fails for unicode domains
-    loadURL: "http://sub2.xn--lt-uia.mochi.test:8888/foo",
-    expectedURL: toUnicode("sub2.ält.mochi.test:8888/foo"),
-    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/foo")
-  },
-  {
-    copyVal: toUnicode("s<ub2.ält.mochi.test:8888/f>oo"),
-    copyExpected: toUnicode("ub2.ält.mochi.test:8888/f")
-  },
-  {
-    copyVal: toUnicode("<sub2.ält.mochi.test:8888/f>oo"),
-    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/f")
-  },
-
-  {
-    loadURL: "http://example.com/?%C3%B7%C3%B7",
-    expectedURL: "example.com/?\xf7\xf7",
-    copyExpected: "http://example.com/?%C3%B7%C3%B7"
-  },
-  {
-    copyVal: "e<xample.com/?\xf7>\xf7",
-    copyExpected: "xample.com/?\xf7"
-  },
-  {
-    copyVal: "<example.com/?\xf7>\xf7",
-    copyExpected: "http://example.com/?\xf7"
-  },
-  {
-    loadURL: "http://example.com/a%20test",
-    expectedURL: "example.com/a test",
-    copyExpected: "http://example.com/a%20test"
-  },
-  {
-    loadURL: "http://example.com/a%E3%80%80test",
-    expectedURL: toUnicode("example.com/a test"),
-    copyExpected: "http://example.com/a%E3%80%80test"
-  },
-  {
-    loadURL: "http://example.com/a%20%C2%A0test",
-    expectedURL: "example.com/a%20%C2%A0test",
-    copyExpected: "http://example.com/a%20%C2%A0test"
-  },
-  {
-    loadURL: "http://example.com/%20%20%20",
-    expectedURL: "example.com/%20%20%20",
-    copyExpected: "http://example.com/%20%20%20"
-  },
-  {
-    loadURL: "http://example.com/%E3%80%80%E3%80%80",
-    expectedURL: "example.com/%E3%80%80%E3%80%80",
-    copyExpected: "http://example.com/%E3%80%80%E3%80%80"
-  },
-
   // data: and javsacript: URIs shouldn't be encoded
   {
     loadURL: "javascript:('%C3%A9%20%25%50')",
     expectedURL: "javascript:('%C3%A9 %25P')",
     copyExpected: "javascript:('%C3%A9 %25P')"
   },
   {
     copyVal: "<javascript:(>'%C3%A9 %25P')",
@@ -209,26 +126,47 @@ var tests = [
   {
     copyVal: "<data:text/html,(>%C3%A9 %25P)",
     copyExpected: "data:text/html,("
   },
   {
     copyVal: "<data:text/html,(%C3%A9 %25P>)",
     copyExpected: "data:text/html,(%C3%A9 %25P",
   },
+  // Unicode URIs should be copied instead of encoded ones.
+  // Note: it seems a bug which leads to failure for BrowserTestUtils.loadURI to
+  // load most Unicode domains defined in build/pgo/server-locations.txt.
+  // Anyway, sub2.xn--lt-uia.mochi.test:8888 gets loaded expectedly.
   {
-    setup() { Services.prefs.setBoolPref(decodeURLpref, true); },
+    loadURL: "http://sub2.xn--lt-uia.mochi.test:8888/foo",
+    expectedURL: toUnicode("sub2.ält.mochi.test:8888/foo"),
+    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/foo")
+  },
+  {
+    copyVal: toUnicode("<sub2.ält.mochi.test:8888/f>oo"),
+    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/f")
+  },
+  {
     loadURL: "http://example.com/%D0%B1%D0%B8%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D1%8F",
     expectedURL: toUnicode("example.com/биография"),
     copyExpected: toUnicode("http://example.com/биография")
   },
   {
     copyVal: toUnicode("<example.com/би>ография"),
     copyExpected: toUnicode("http://example.com/би")
   },
+  {
+    loadURL: "http://sub2.xn--lt-uia.mochi.test:8888/%D0%B1%D0%B8%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D1%8F",
+    expectedURL: toUnicode("sub2.ält.mochi.test:8888/биография"),
+    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/биография")
+  },
+  {
+    copyVal: toUnicode("<sub2.ält.mochi.test:8888/би>ография"),
+    copyExpected: toUnicode("http://sub2.ält.mochi.test:8888/би")
+  },
 ];
 
 function nextTest() {
   let testCase = tests.shift();
   if (tests.length == 0)
     runTest(testCase, finish);
   else
     runTest(testCase, nextTest);
--- a/browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
+++ b/browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
@@ -67,17 +67,17 @@ add_task(async function() {
 
   Services.prefs.setBoolPref(PREF_TRIMURLS, true);
 
   let promiseLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser,
                                                      false, "http://example.com/");
   gBrowser.loadURI("http://example.com/");
   await promiseLoaded;
 
-  await testCopy("example.com", "http://example.com/");
+  await testCopy("example.com", "http://example.com");
 
   SetPageProxyState("invalid");
   gURLBar.valueIsTyped = true;
   await testCopy("example.com", "example.com");
 });
 
 function testVal(originalValue, targetValue) {
   gURLBar.value = originalValue;