Bug 1402399 - Fix browser.windows.update to clear titlePreface if it is passed empty. r=bsilverberg, r=mixedpuppy
authortushararora <tushararora.cs@gmail.com>
Fri, 13 Oct 2017 12:38:19 +0530
changeset 394089 ad69d5466d3c
parent 394088 42fc2739a333
child 394090 1f2a0a7ae4b3
push id32990
push userdluca@mozilla.com
push dateWed, 29 Nov 2017 10:27:31 +0000
treeherdermozilla-central@3f6b9aaed8cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsilverberg, mixedpuppy
bugs1402399
milestone59.0a1
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
Bug 1402399 - Fix browser.windows.update to clear titlePreface if it is passed empty. r=bsilverberg, r=mixedpuppy
browser/components/extensions/ext-windows.js
browser/components/extensions/test/browser/browser_ext_windows.js
--- a/browser/components/extensions/ext-windows.js
+++ b/browser/components/extensions/ext-windows.js
@@ -189,17 +189,17 @@ this.windows = class extends ExtensionAP
             }
             if (allowScriptsToClose) {
               for (let {linkedBrowser} of window.gBrowser.tabs) {
                 onXULFrameLoaderCreated({target: linkedBrowser});
                 linkedBrowser.addEventListener( // eslint-disable-line mozilla/balanced-listeners
                                                "XULFrameLoaderCreated", onXULFrameLoaderCreated);
               }
             }
-            if (createData.titlePreface) {
+            if (createData.titlePreface !== null) {
               win.setTitlePreface(createData.titlePreface);
             }
             return win.convert({populate: true});
           });
         },
 
         update: function(windowId, updateInfo) {
           if (updateInfo.state !== null && updateInfo.state != "normal") {
@@ -220,17 +220,17 @@ this.windows = class extends ExtensionAP
 
           if (updateInfo.drawAttention) {
             // Bug 1257497 - Firefox can't cancel attention actions.
             win.window.getAttention();
           }
 
           win.updateGeometry(updateInfo);
 
-          if (updateInfo.titlePreface) {
+          if (updateInfo.titlePreface !== null) {
             win.setTitlePreface(updateInfo.titlePreface);
             win.window.gBrowser.updateTitlebar();
           }
 
           // TODO: All the other properties, focused=false...
 
           return Promise.resolve(win.convert());
         },
--- a/browser/components/extensions/test/browser/browser_ext_windows.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows.js
@@ -155,16 +155,51 @@ add_task(async function testWindowTitle(
     },
     after: {
       preface: PREFACE2,
       text: NEW_TITLE,
     },
   };
   await updateWindow({titlePreface: PREFACE2}, apiWin, expected);
 
+  // Create a window with a preface.
+  apiWin = await createApiWin({url: START_URL, titlePreface: PREFACE1});
+  realWin = windowTracker.getWindow(apiWin.id);
+
+  // Update the titlePreface of the window with an empty string.
+  expected = {
+    before: {
+      preface: PREFACE1,
+      text: START_TITLE,
+    },
+    after: {
+      preface: "",
+      text: START_TITLE,
+    },
+  };
+  await updateWindow({titlePreface: ""}, apiWin, expected);
+  ok(!realWin.document.title.startsWith(expected.before.preface), "Updated window has the expected empty title preface.");
+
+  // Create a window with a preface.
+  apiWin = await createApiWin({url: START_URL, titlePreface: PREFACE1});
+  realWin = windowTracker.getWindow(apiWin.id);
+
+  // Update the window without a titlePreface.
+  expected = {
+    before: {
+      preface: PREFACE1,
+      text: START_TITLE,
+    },
+    after: {
+      preface: PREFACE1,
+      text: START_TITLE,
+    },
+  };
+  await updateWindow({}, apiWin, expected);
+
   await extension.unload();
 });
 
 // Test that the window title is only available with the correct tab
 // permissions.
 add_task(async function testWindowTitlePermissions() {
   let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "http://example.com/");