[Pkg-mozext-commits] [compactheader] 248/441: Fixed bug with race condition when closing preferences dialog. Added mozmill test to check fix for race condition.

David Prévot taffit at moszumanska.debian.org
Wed Mar 18 12:29:04 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository compactheader.

commit 16d27a7ffc98a20b453d70f4d6107f47a300ebac
Author: Joachim.Herb at gmx.de <Joachim.Herb at gmx.de>
Date:   Sun Aug 7 14:47:42 2011 +0200

    Fixed bug with race condition when closing preferences dialog.
    Added mozmill test to check fix for race condition.
    
    --HG--
    branch : preferences
---
 .../CompactHeader/content/compactHeaderOverlay.js  |  42 +++-
 chrome/CompactHeader/content/preferences.js        | 100 ---------
 chrome/CompactHeader/content/preferences.xul       |  22 --
 .../test-compactheader-preferences.js              | 239 +++++++++++++++++++++
 test/compactheader/test-compactheader-toolbar.js   |   2 +-
 test/executeTests.pl                               |   4 +-
 6 files changed, 278 insertions(+), 131 deletions(-)

diff --git a/chrome/CompactHeader/content/compactHeaderOverlay.js b/chrome/CompactHeader/content/compactHeaderOverlay.js
index 9519f50..70de3f8 100644
--- a/chrome/CompactHeader/content/compactHeaderOverlay.js
+++ b/chrome/CompactHeader/content/compactHeaderOverlay.js
@@ -94,6 +94,10 @@ org.mozdev.compactHeader.pane = function() {
     .getService(Components.interfaces.nsIPrefService)
     .getBranch("extensions.CompactHeader.");
 
+  var browserPreferences = Components.classes["@mozilla.org/preferences-service;1"]
+    .getService(Components.interfaces.nsIPrefService)
+    .getBranch("browser.preferences.");
+
   var cohe={
     version: -1,
     firstrun: true,
@@ -568,20 +572,46 @@ org.mozdev.compactHeader.pane = function() {
 
     observe: function(aSubject, aTopic, aData)
     {
-      org.mozdev.compactHeader.debug.log("hit prefObserver");
+      org.mozdev.compactHeader.debug.log("prefObserver start");
       if(aTopic != "nsPref:changed") return;
       // aSubject is the nsIPrefBranch we're observing (after appropriate QI)
       // aData is the name of the pref that's been changed (relative to aSubject)
+      org.mozdev.compactHeader.debug.log("prefObserver 1: " + aData);
 
-      var event = document.createEvent('Events');
-      event.initEvent('messagepane-loaded', false, true);
-      var headerViewElement = document.getElementById("msgHeaderView");
-      headerViewElement.dispatchEvent(event);
+      if (  (aData == "addressstyle")
+          ||(aData == "twolineview")
+          ||(aData == "linkify")
+          ) {
+        preferencesUpdate();
+      }
 
-      gDBView.reloadMessage();
+      org.mozdev.compactHeader.debug.log("prefObserver stop");
     }
   }
 
+  var wasHere = false;
+
+  function preferencesUpdate() {
+    org.mozdev.compactHeader.debug.log("preferencesUpdate " + wasHere);
+    if (!browserPreferences.getBoolPref("instantApply")
+        && wasHere)
+      return;
+    org.mozdev.compactHeader.debug.log("preferencesUpdate 2");
+    wasHere = true;
+    ReloadMessage();
+    var event = document.createEvent('Events');
+    event.initEvent('messagepane-loaded', false, true);
+    var headerViewElement = document.getElementById("msgHeaderView");
+    headerViewElement.dispatchEvent(event);
+    setTimeout(clearReloadTimeout, 250);
+    org.mozdev.compactHeader.debug.log("preferencesUpdate stop");
+  }
+
+  function clearReloadTimeout() {
+    wasHere = false;
+    org.mozdev.compactHeader.debug.log("wasHere cleared");
+  }
+
   function coheCheckFirstRun() {
     var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
                                      .getService(Components.interfaces.nsIXULAppInfo);
diff --git a/chrome/CompactHeader/content/preferences.js b/chrome/CompactHeader/content/preferences.js
deleted file mode 100644
index 74f2ade..0000000
--- a/chrome/CompactHeader/content/preferences.js
+++ /dev/null
@@ -1,100 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//
-//  preferences.js
-//
-//  Copyright 2005 by Michael Buschbeck <michael at buschbeck.net>
-//
-//  Preferences dialog box for the Unselect Message extension. Allows users to
-//  customize the behavior of the extension.
-//
-
-
-///////////////////////////////////////////////////////////////////////////////
-//
-//  Variables
-//
-
-
-if(!org) var org={};
-if(!org.mozdev) org.mozdev={};
-if(!org.mozdev.compactHeader) org.mozdev.compactHeader = {};
-
-org.mozdev.compactHeader.preferences = function() {
-  var pub = {};
-  var prefBranch;
-  ///////////////////////////////////////////////////////////////////////////////
-  //
-  //  onLoad
-  //
-  //  Called when the preferences dialog has finished loading. Initializes the
-  //  controls according to current configuration settings.
-  //
-
-  pub.onLoad = function()
-  {
-    prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-      .getService(Components.interfaces.nsIPrefService)
-      .getBranch("extensions.CompactHeader.");
-
-    loadPrefCheckbox("headersize.twolineview", "checkboxCompactTwolineView");
-    loadPrefCheckbox("headersize.linkify", "checkboxLinkify");
-    //loadPrefInt("headersize.addressstyle", "AddressStyle");
-    loadPrefCheckbox("headersize.addressstyle", "checkboxShowOnlyAddress");
-    loadPrefCheckbox("headersize.flatButtons", "checkboxflatButtons");
-  }
-
-  ///////////////////////////////////////////////////////////////////////////////
-  //
-  //  onDialogAccept
-  //
-  //  Called when the preferences dialog is closed by pressing the OK button.
-  //  Saves the configuration settings.
-  //
-
-  pub.onDialogAccept = function ()
-  {
-    savePrefCheckbox("headersize.twolineview", "checkboxCompactTwolineView");
-    savePrefCheckbox("headersize.linkify", "checkboxLinkify");
-    //savePrefInt("headersize.addressstyle", "AddressStyle");
-    savePrefCheckbox("headersize.addressstyle", "checkboxShowOnlyAddress");
-    savePrefCheckbox("headersize.flatButtons", "checkboxflatButtons");
-    return true;
-  }
-
-
-  ///////////////////////////////////////////////////////////////////////////////
-  //
-  //  loadPrefCheckbox
-  //
-  //  Loads the given boolean preference value into the given checkbox element.
-  //
-
-  function loadPrefCheckbox(pref, idCheckbox)
-  {
-    document.getElementById(idCheckbox).checked = prefBranch.getBoolPref(pref);
-  }
-
-
-  function loadPrefInt(pref, idCheckbox)
-  {
-    document.getElementById(idCheckbox).value = prefBranch.getIntPref(pref);
-  }
-
-  ///////////////////////////////////////////////////////////////////////////////
-  //
-  //  savePrefCheckbox
-  //
-  //  Saves the given boolean preference value from the given checkbox element.
-  //
-
-  function savePrefCheckbox(pref, idCheckbox)
-  {
-    prefBranch.setBoolPref(pref, document.getElementById(idCheckbox).checked);
-  }
-
-  function savePrefInt(pref, idCheckbox)
-  {
-    prefBranch.setIntPref(pref, document.getElementById(idCheckbox).value);
-  }
-  return pub;
-}();
diff --git a/chrome/CompactHeader/content/preferences.xul b/chrome/CompactHeader/content/preferences.xul
index a477f5b..b122f5c 100644
--- a/chrome/CompactHeader/content/preferences.xul
+++ b/chrome/CompactHeader/content/preferences.xul
@@ -48,25 +48,3 @@
               label="&menu.flatButtons.caption;"/>
   </prefpane>
 </prefwindow>
-
-
-<!--
-<dialog id="cohePreferences"
-        title="&dialog.title;"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        onload="org.mozdev.compactHeader.preferences.onLoad();"
-        ondialogaccept="return org.mozdev.compactHeader.preferences.onDialogAccept();">
-
-  <script type="application/x-javascript" src="chrome://CompactHeader/content/preferences.js"/>
-
-  <checkbox id="checkboxCompactTwolineView"
-            label="&checkbox.Compact.TwolineView.caption;"/>
-  <checkbox id="checkboxLinkify"
-            label="&menu.Linkify.caption;"/>
-  <checkbox id="checkboxShowOnlyAddress"
-            label="&menu.ShowOnlyAddress.caption;"/>
-  <checkbox id="checkboxflatButtons"
-            label="&menu.flatButtons.caption;"/>
-
-</dialog>
--->
\ No newline at end of file
diff --git a/test/compactheader/test-compactheader-preferences.js b/test/compactheader/test-compactheader-preferences.js
new file mode 100644
index 0000000..f232925
--- /dev/null
+++ b/test/compactheader/test-compactheader-preferences.js
@@ -0,0 +1,239 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Thunderbird Mail Client.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Blake Winton <bwinton at latte.ca>
+ *   Dan Mosedale <dmose at mozillamessaging.com>
+ *   Joachim Herb <Joachim.Herb at gmx.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var MODULE_NAME = 'test-compactheader-preferences';
+
+var RELATIVE_ROOT = '../shared-modules';
+var MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers',
+                       'address-book-helpers', 'mouse-event-helpers'];
+
+var elib = {};
+Cu.import('resource://mozmill/modules/elementslib.js', elib);
+var controller = {};
+Cu.import('resource://mozmill/modules/controller.js', controller);
+
+// The WindowHelper module
+var WindowHelper;
+
+var folder;
+
+const PREF = "browser.preferences.instantApply";
+var prefBranch = Cc["@mozilla.org/preferences-service;1"]
+                    .getService(Ci.nsIPrefService).getBranch(null);
+
+var messageBodyISO8859_1 = "ae: " + String.fromCharCode(228) +
+  ", oe: " + String.fromCharCode(246) +
+  ", ue: " + String.fromCharCode(252) +
+  ", AE: " + String.fromCharCode(196) +
+  ", OE: " + String.fromCharCode(214) +
+  ", UE: " + String.fromCharCode(220) +
+  ", ss: " + String.fromCharCode(223) + "\n";
+
+var messageBodyUTF8 = "ae: ä, oe: ö, ue: ü, AE: Ä, OE: Ö, UE: Ü, ss: ß";
+
+function setupModule(module) {
+  let fdh = collector.getModule('folder-display-helpers');
+  fdh.installInto(module);
+  WindowHelper = collector.getModule('window-helpers');
+  WindowHelper.installInto(module);
+  let abh = collector.getModule('address-book-helpers');
+  abh.installInto(module);
+  let meh = collector.getModule('mouse-event-helpers');
+  meh.installInto(module);
+  let meh = collector.getModule('mouse-event-helpers');
+  meh.installInto(module);
+
+  folder = create_folder("MessageWindowB");
+
+  // create a message that has the interesting headers that commonly
+  // show up in the message header pane for testing
+  let msg = create_message({cc: msgGen.makeNamesAndAddresses(20), // YYY
+                            subject: "This is a really, really, really, really, really, really, really, really, long subject.",
+                            clobberHeaders: {
+                              "Newsgroups": "alt.test",
+                              "Reply-To": "J. Doe <j.doe at momo.invalid>",
+                              "Content-Base": "http://example.com/",
+                              "Bcc": "Richard Roe <richard.roe at momo.invalid>"
+                            }});
+
+  add_message_to_folder(folder, msg);
+
+  // create a message that has
+
+  addToFolder("test encoded ISO-8859-1", messageBodyISO8859_1, folder, "iso-8859-1");
+  addToFolder("test encoded UTF-8", messageBodyUTF8, folder, "utf-8");
+
+  let msg = create_message();
+  add_message_to_folder(folder, msg);
+
+}
+
+
+/**
+ *  Make sure that opening the header toolbar customization dialog
+ *  does not break the get messages button in main toolbar
+ */
+function test_double_preference_change_ISO(){
+  select_message_in_folder(2);
+  assert_browser_text_present(mc.e("messagepane"), messageBodyISO8859_1);
+  open_preferences_dialog(mc, subtest_p1);
+  mc.sleep(10);
+  assert_browser_text_present(mc.e("messagepane"), messageBodyISO8859_1);
+}
+
+function test_double_preference_change_UTF(){
+  select_message_in_folder(3);
+  assert_browser_text_present(mc.e("messagepane"), messageBodyISO8859_1);
+  open_preferences_dialog(mc, subtest_p1);
+  mc.sleep(10);
+  assert_browser_text_present(mc.e("messagepane"), messageBodyISO8859_1);
+}
+
+function subtest_p1(aController) {
+  aController.click(aController.eid("checkboxCompactTwolineView"));
+  aController.click(aController.eid("checkboxLinkify"));
+  close_preferences_dialog(aController);
+}
+
+
+/**
+ *  Helper function to open an extra window, so that the 3pane
+ *  window can be closed and opend again for persistancy checks.
+ *  They are copied from the test-session-store.js.
+ */
+function close3PaneWindow() {
+  let windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].
+    getService(Ci.nsIWindowMediator);
+  let mail3PaneWindow = windowMediator.getMostRecentWindow("mail:3pane");
+  // close the 3pane window
+  mail3PaneWindow.close();
+}
+
+function open3PaneWindow() {
+  let windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+    getService(Ci.nsIWindowWatcher);
+  WindowHelper.plan_for_new_window("mail:3pane");
+  windowWatcher.openWindow(null,
+                           "chrome://messenger/content/messenger.xul", "",
+                           "all,chrome,dialog=no,status,toolbar",
+                           null);
+  return WindowHelper.wait_for_new_window("mail:3pane");
+}
+
+function openAddressBook() {
+  let windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+    getService(Ci.nsIWindowWatcher);
+  WindowHelper.plan_for_new_window("mail:addressbook");
+  windowWatcher.openWindow(
+                      null,
+                      "chrome://messenger/content/addressbook/addressbook.xul", "",
+                      "all,chrome,dialog=no,status,toolbar",
+                      null);
+  return WindowHelper.wait_for_new_window("mail:addressbook");
+}
+
+function open_preferences_dialog(aController, aSubtest) {
+  plan_for_modal_dialog("ext:options", aSubtest);
+  aController.click(aController.eid("hidecohePreferencesButton"));
+  wait_for_modal_dialog("ext:options", 1);
+}
+
+function close_preferences_dialog(aController) {
+  let okButton = aController.window.document.documentElement.getButton('accept');
+  plan_for_window_close(aController);
+  aController.click(new elib.Elem(okButton));
+  wait_for_window_close();
+  //assert_true(aController.window.closed, "The preferences dialog is not closed.");
+}
+
+/**
+ * Select message in current (global) folder.
+ */
+function select_message_in_folder(aMessageNum)
+{
+  be_in_folder(folder);
+
+  // select and open the first message
+  let curMessage = select_click_row(aMessageNum);
+
+  // make sure it loads
+  wait_for_message_display_completion(mc);
+  assert_selected_and_displayed(mc, curMessage);
+
+  return curMessage;
+}
+
+function addToFolder(aSubject, aBody, aFolder, aCharset) {
+
+  let msgId = Components.classes["@mozilla.org/uuid-generator;1"]
+                          .getService(Components.interfaces.nsIUUIDGenerator)
+                          .generateUUID() +"@mozillamessaging.invalid";
+
+  let source = "From - Sat Nov  1 12:39:54 2008\n" +
+               "X-Mozilla-Status: 0001\n" +
+               "X-Mozilla-Status2: 00000000\n" +
+               "Message-ID: <" + msgId + ">\n" +
+               "Date: Wed, 11 Jun 2008 20:32:02 -0400\n" +
+               "From: Tester <tests at mozillamessaging.invalid>\n" +
+               "User-Agent: Thunderbird 3.0a2pre (Macintosh/2008052122)\n" +
+               "MIME-Version: 1.0\n" +
+               "To: recipient at mozillamessaging.invalid\n" +
+               "Subject: " + aSubject + "\n" +
+               "Content-Type: text/html; charset=" + aCharset + "\n" +
+               "Content-Transfer-Encoding: 8bit\n" +
+               "\n" + aBody + "\n";
+
+  aFolder.QueryInterface(Components.interfaces.nsIMsgLocalMailFolder);
+  aFolder.gettingNewMessages = true;
+
+  aFolder.addMessage(source);
+  aFolder.gettingNewMessages = false;
+
+  return aFolder.msgDatabase.getMsgHdrForMessageID(msgId);
+}
+
+/**
+ * Asserts that the given text is present on the message pane.
+ */
+function assert_browser_text_present(aBrowser, aText) {
+  let html = aBrowser.contentDocument.documentElement.innerHTML;
+  if (html.indexOf(aText) == -1) {
+    throw new Error("Unable to find string \"" + escape(aText) + "\" on the message pane");
+  }
+}
\ No newline at end of file
diff --git a/test/compactheader/test-compactheader-toolbar.js b/test/compactheader/test-compactheader-toolbar.js
index 91ff3ee..dcd237d 100644
--- a/test/compactheader/test-compactheader-toolbar.js
+++ b/test/compactheader/test-compactheader-toolbar.js
@@ -37,7 +37,7 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-var MODULE_NAME = 'test-header-toolbar';
+var MODULE_NAME = 'test-compactheader-toolbar';
 
 var RELATIVE_ROOT = '../shared-modules';
 var MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers',
diff --git a/test/executeTests.pl b/test/executeTests.pl
index 29f8748..adb8101 100644
--- a/test/executeTests.pl
+++ b/test/executeTests.pl
@@ -78,8 +78,8 @@ while (my $line = <F>)
 
     chdir "$currentdir";
     my @timeData = localtime(time);
-    my $datestr = sprintf "%04d%02d%02d%02d%02d", 1900+ at timeData[5],
-      1+ at timeData[4], @timeData[3], @timeData[2], @timeData[1]; 
+    my $datestr = sprintf "%04d%02d%02d%02d%02d", 1900+$timeData[5],
+      1+$timeData[4], $timeData[3], $timeData[2], $timeData[1];
     open (LOG, ">log-$version-$ostype-$hosttype-$datestr.txt");
     print LOG "$log";
     close(LOG);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/compactheader.git



More information about the Pkg-mozext-commits mailing list