diff --git a/content/xul/templates/src/nsXULContentUtils.cpp b/content/xul/templates/src/nsXULContentUtils.cpp index 5123fa81779..df7d367ad4c 100644 --- a/content/xul/templates/src/nsXULContentUtils.cpp +++ b/content/xul/templates/src/nsXULContentUtils.cpp @@ -90,6 +90,7 @@ #include "nsILocale.h" #include "nsILocaleService.h" #include "nsIConsoleService.h" +#include "nsEscape.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -335,6 +336,20 @@ nsXULContentUtils::MakeElementURI(nsIDocument* aDocument, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr mutableURL(do_QueryInterface(docURIClone)); + if (!mutableURL) { + nsCString uri; + rv = docURL->GetSpec(aURI); + NS_ENSURE_SUCCESS(rv, rv); + + nsCAutoString ref; + NS_EscapeURL(NS_ConvertUTF16toUTF8(aElementID), esc_FilePath | esc_AlwaysCopy, ref); + + aURI.Append('#'); + aURI.Append(ref); + + return NS_OK; + } + NS_ENSURE_TRUE(mutableURL, NS_ERROR_NOT_AVAILABLE); rv = mutableURL->SetRef(NS_ConvertUTF16toUTF8(aElementID)); @@ -381,6 +396,19 @@ nsXULContentUtils::MakeElementID(nsIDocument* aDocument, url->GetRef(ref); CopyUTF8toUTF16(ref, aElementID); } else { + const char* start = aURI.BeginReading(); + const char* end = aURI.EndReading(); + const char* chr = end; + + while (--chr >= start) { + if (*chr == '#') { + nsDependentCSubstring ref = Substring(chr + 1, end); + nsCAutoString unescaped; + CopyUTF8toUTF16(NS_UnescapeURL(ref, esc_FilePath, unescaped), aElementID); + return NS_OK; + } + } + aElementID.Truncate(); } diff --git a/toolkit/mozapps/extensions/test/browser/Makefile.in b/toolkit/mozapps/extensions/test/browser/Makefile.in index c8b59628b4b..4feb9a9cafe 100644 --- a/toolkit/mozapps/extensions/test/browser/Makefile.in +++ b/toolkit/mozapps/extensions/test/browser/Makefile.in @@ -50,6 +50,7 @@ _TEST_FILES = \ browser_bug562890.js \ browser_bug562899.js \ browser_bug562992.js \ + browser_bug567137.js \ browser_bug572561.js \ browser_dragdrop.js \ browser_searching.js \ diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug567137.js b/toolkit/mozapps/extensions/test/browser/browser_bug567137.js new file mode 100644 index 00000000000..bb9b9a89456 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_bug567137.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Test that the selected category is persisted across loads of the manager + +function test() { + waitForExplicitFinish(); + + open_manager(null, function(aWindow) { + let utils = new CategoryUtilities(aWindow); + + // Open the plugins category + utils.openType("plugin", function() { + + // Re-open the manager + close_manager(aWindow, function() { + open_manager(null, function(aWindow) { + utils = new CategoryUtilities(aWindow); + + is(utils.selectedCategory, "plugin", "Should have shown the plugins category"); + + // Open the extensions category + utils.openType("extension", function() { + + // Re-open the manager + close_manager(aWindow, function() { + open_manager(null, function(aWindow) { + utils = new CategoryUtilities(aWindow); + + is(utils.selectedCategory, "extension", "Should have shown the extensions category"); + close_manager(aWindow, finish); + }); + }); + }); + }); + }); + }); + }); +}