Backed out changeset e1fdd812bd79 (bug 1552141) for Browser-chrome failure in browser/components/urlbar/tests/browser/browser_keywordBookmarklets.js
authorDorel Luca <dluca@mozilla.com>
Tue, 09 Jul 2019 21:46:33 +0300
changeset 481982 dce23f824370db7b0b5a19d675c4ee7ee062aa52
parent 481981 08a4f86a9afa4b2957e0438f9fa8f86778eb3b7f
child 481983 7d105b9c1589153c4fd03d9b2948eb3cf288d2b1
push id113647
push useraciure@mozilla.com
push dateWed, 10 Jul 2019 09:46:39 +0000
treeherdermozilla-inbound@f3a387c13e2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1552141
milestone70.0a1
backs oute1fdd812bd794a6aab446f2b77189b489b31ec4a
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset e1fdd812bd79 (bug 1552141) for Browser-chrome failure in browser/components/urlbar/tests/browser/browser_keywordBookmarklets.js
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
browser/components/urlbar/UrlbarProvidersManager.jsm
browser/components/urlbar/tests/browser/browser_keywordBookmarklets.js
browser/components/urlbar/tests/legacy/browser.ini
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -495,22 +495,16 @@ class UrlbarInput {
       this._loadURL(this.value, where, openParams);
       return;
     }
 
     let { url, postData } = UrlbarUtils.getUrlFromResult(result);
     openParams.postData = postData;
 
     switch (result.type) {
-      case UrlbarUtils.RESULT_TYPE.KEYWORD: {
-        // If this result comes from a bookmark keyword, let it inherit the
-        // current document's principal, otherwise bookmarklets would break.
-        openParams.allowInheritPrincipal = true;
-        break;
-      }
       case UrlbarUtils.RESULT_TYPE.TAB_SWITCH: {
         if (this.hasAttribute("actionoverride")) {
           where = "current";
           break;
         }
 
         this.handleRevert();
         let prevTab = this.window.gBrowser.selectedTab;
--- a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
+++ b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
@@ -281,24 +281,17 @@ function makeUrlbarResult(tokens, info) 
                 !action.params.searchQuery.trim() &&
                 action.params.alias.startsWith("@"),
               false,
             ],
           })
         );
       case "keyword": {
         let title = info.comment;
-        if (!title) {
-          // If the url doesn't have an host (e.g. javascript urls), comment
-          // will be empty, and we can't build the usual title. Thus use the url.
-          title = Services.textToSubURI.unEscapeURIForUI(
-            "UTF-8",
-            action.params.url
-          );
-        } else if (tokens && tokens.length > 1) {
+        if (tokens && tokens.length > 1) {
           title = bundle.formatStringFromName("bookmarkKeywordSearch", [
             info.comment,
             tokens
               .slice(1)
               .map(t => t.value)
               .join(" "),
           ]);
         }
--- a/browser/components/urlbar/UrlbarProvidersManager.jsm
+++ b/browser/components/urlbar/UrlbarProvidersManager.jsm
@@ -352,17 +352,16 @@ class Query {
     // heuristic result though, that is supposed to be added regardless.
     if (!this.acceptableSources.includes(match.source) && !match.heuristic) {
       return;
     }
 
     // Filter out javascript results for safety. The provider is supposed to do
     // it, but we don't want to risk leaking these out.
     if (
-      match.type != UrlbarUtils.RESULT_TYPE.KEYWORD &&
       match.payload.url &&
       match.payload.url.startsWith("javascript:") &&
       !this.context.searchString.startsWith("javascript:") &&
       UrlbarPrefs.get("filter.javascript")
     ) {
       return;
     }
 
--- a/browser/components/urlbar/tests/browser/browser_keywordBookmarklets.js
+++ b/browser/components/urlbar/tests/browser/browser_keywordBookmarklets.js
@@ -1,114 +1,58 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-add_task(async function setup() {
+add_task(async function test_keyword_bookmarklet() {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
   let bm = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmarklet",
-    url: "javascript:'%s'%20",
+    url: "javascript:'1';",
   });
-  await PlacesUtils.keywords.insert({ keyword: "bm", url: bm.url });
+
   registerCleanupFunction(async function() {
+    BrowserTestUtils.removeTab(tab);
     await PlacesUtils.bookmarks.remove(bm);
   });
 
-  let testFns = [
-    function() {
-      info("Type keyword and immediately press enter");
-      gURLBar.value = "bm";
-      gURLBar.focus();
-      EventUtils.synthesizeKey("KEY_Enter");
-      return "javascript:''%20";
-    },
-    function() {
-      info("Type keyword with searchstring and immediately press enter");
-      gURLBar.value = "bm a";
-      gURLBar.focus();
-      EventUtils.synthesizeKey("KEY_Enter");
-      return "javascript:'a'%20";
-    },
-    async function() {
-      info("Search keyword, then press enter");
-      await promiseAutocompleteResultPopup("bm");
-      let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
-      Assert.equal(result.title, "javascript:'' ", "Check title");
-      EventUtils.synthesizeKey("KEY_Enter");
-      return "javascript:''%20";
-    },
-    async function() {
-      info("Search keyword with searchstring, then press enter");
-      await promiseAutocompleteResultPopup("bm a");
-      let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
-      Assert.equal(result.title, "javascript:'a' ", "Check title");
-      EventUtils.synthesizeKey("KEY_Enter");
-      return "javascript:'a'%20";
-    },
-    async function() {
-      await promiseAutocompleteResultPopup("bm");
-      let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
-      Assert.equal(result.title, "javascript:'' ", "Check title");
-      let element = UrlbarTestUtils.getSelectedElement(window);
-      EventUtils.synthesizeMouseAtCenter(element, {});
-      return "javascript:''%20";
-    },
-    async function() {
-      info("Search keyword with searchstring, then click");
-      await promiseAutocompleteResultPopup("bm a");
-      let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
-      Assert.equal(result.title, "javascript:'a' ", "Check title");
-      let element = UrlbarTestUtils.getSelectedElement(window);
-      EventUtils.synthesizeMouseAtCenter(element, {});
-      return "javascript:'a'%20";
-    },
-  ];
-  for (let testFn of testFns) {
-    await do_test(testFn);
+  let originalPrincipal = gBrowser.contentPrincipal;
+  let originalPrincipalURI = await getPrincipalURI(tab.linkedBrowser);
+
+  await PlacesUtils.keywords.insert({ keyword: "bm", url: "javascript:'1';" });
+
+  // Enter bookmarklet keyword in the URL bar
+  gURLBar.value = "bm";
+  gURLBar.focus();
+  EventUtils.synthesizeKey("KEY_Enter");
+
+  await BrowserTestUtils.waitForContentEvent(
+    gBrowser.selectedBrowser,
+    "pageshow"
+  );
+
+  let newPrincipalURI = await getPrincipalURI(tab.linkedBrowser);
+  is(newPrincipalURI, originalPrincipalURI, "content has the same principal");
+
+  // In e10s, null principals don't round-trip so the same null principal sent
+  // from the child will be a new null principal. Verify that this is the
+  // case.
+  if (tab.linkedBrowser.isRemoteBrowser) {
+    ok(
+      originalPrincipal.isNullPrincipal &&
+        gBrowser.contentPrincipal.isNullPrincipal,
+      "both principals should be null principals in the parent"
+    );
+  } else {
+    ok(
+      gBrowser.contentPrincipal.equals(originalPrincipal),
+      "javascript bookmarklet should inherit principal"
+    );
   }
 });
 
-async function do_test(loadFn) {
-  await BrowserTestUtils.withNewTab(
-    {
-      gBrowser,
-    },
-    async browser => {
-      let originalPrincipal = gBrowser.contentPrincipal;
-      let originalPrincipalURI = await getPrincipalURI(browser);
-
-      let expectedUrl = await loadFn();
-      await BrowserTestUtils.waitForContentEvent(browser, "pageshow");
-      Assert.equal(gBrowser.currentURI.spec, expectedUrl);
-
-      let newPrincipalURI = await getPrincipalURI(browser);
-      Assert.equal(
-        newPrincipalURI,
-        originalPrincipalURI,
-        "content has the same principal"
-      );
-
-      // In e10s, null principals don't round-trip so the same null principal sent
-      // from the child will be a new null principal. Verify that this is the
-      // case.
-      if (browser.isRemoteBrowser) {
-        Assert.ok(
-          originalPrincipal.isNullPrincipal &&
-            gBrowser.contentPrincipal.isNullPrincipal,
-          "both principals should be null principals in the parent"
-        );
-      } else {
-        Assert.ok(
-          gBrowser.contentPrincipal.equals(originalPrincipal),
-          "javascript bookmarklet should inherit principal"
-        );
-      }
-    }
-  );
-}
-
 function getPrincipalURI(browser) {
   return ContentTask.spawn(browser, null, function() {
     return content.document.nodePrincipal.URI.spec;
   });
 }
--- a/browser/components/urlbar/tests/legacy/browser.ini
+++ b/browser/components/urlbar/tests/legacy/browser.ini
@@ -54,16 +54,17 @@ skip-if = os != "mac" # Mac only feature
 [../browser/browser_autoFill_typed.js]
 [../browser/browser_autoFill_undo.js]
 [../browser/browser_autocomplete_tag_star_visibility.js]
 [../browser/browser_canonizeURL.js]
 [../browser/browser_dragdropURL.js]
 [../browser/browser_ime_composition.js]
 [../browser/browser_inputHistory.js]
 [../browser/browser_inputHistory_emptystring.js]
+[../browser/browser_keywordBookmarklets.js]
 [../browser/browser_keepStateAcrossTabSwitches.js]
 [../browser/browser_keyword_override.js]
 [../browser/browser_keywordSearch.js]
 [../browser/browser_keywordSearch_postData.js]
 uses-unsafe-cpows = true
 support-files =
   ../browser/POSTSearchEngine.xml
 [../browser/browser_keyword_select_and_type.js]