Bug 456121 - nsApplicationAccessible::GetName does not return a default value when brand.properties does not exist, patch=arno renevier, r=me, marcoz
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 08 Oct 2008 20:58:46 +0800
changeset 20141 05ebcc185813271d7ba40f48138c995718d794b3
parent 20140 32bfbcb0e5ddfbdcc77e1c7d1326f8c6a40635e5
child 20142 785106e4b4cd8c8bdd74050e0edc34c678dc8b27
push idunknown
push userunknown
push dateunknown
reviewersme, marcoz
bugs456121
milestone1.9.1b2pre
Bug 456121 - nsApplicationAccessible::GetName does not return a default value when brand.properties does not exist, patch=arno renevier, r=me, marcoz
accessible/src/base/nsApplicationAccessible.cpp
accessible/tests/mochitest/Makefile.in
accessible/tests/mochitest/test_nsIAccessible_applicationAccessible.html
--- a/accessible/src/base/nsApplicationAccessible.cpp
+++ b/accessible/src/base/nsApplicationAccessible.cpp
@@ -109,26 +109,26 @@ nsApplicationAccessible::GetName(nsAStri
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     do_GetService(NS_STRINGBUNDLE_CONTRACTID);
 
   NS_ASSERTION(bundleService, "String bundle service must be present!");
   NS_ENSURE_STATE(bundleService);
 
   nsCOMPtr<nsIStringBundle> bundle;
-  bundleService->CreateBundle("chrome://branding/locale/brand.properties",
-                              getter_AddRefs(bundle));
+  nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties",
+                                            getter_AddRefs(bundle));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsXPIDLString appName;
-  if (bundle) {
-    bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
-                              getter_Copies(appName));
-  } else {
-    NS_WARNING("brand.properties not present, using default app name");
-    appName.AssignLiteral("Mozilla");
+  rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
+                                 getter_Copies(appName));
+  if (NS_FAILED(rv) || appName.IsEmpty()) {
+    NS_WARNING("brandShortName not found, using default app name");
+    appName.AssignLiteral("Gecko based application");
   }
 
   aName.Assign(appName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsApplicationAccessible::GetRole(PRUint32 *aRole)
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -61,16 +61,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug368835.xul \
 		test_bug420863.html \
 		test_cssattrs.html \
 		test_events_caretmove.html \
 		test_groupattrs.xul \
 	$(warning test_table_indexes.html temporarily disabled) \
 		test_nsIAccessible_actions.html \
 		test_nsIAccessible_actions.xul \
+		test_nsIAccessible_applicationAccessible.html \
 		test_nsIAccessible_editablebody.html \
 		test_nsIAccessible_editabledoc.html \
 		test_nsIAccessible_name.html \
 		test_nsIAccessible_name.xul \
  		test_nsIAccessible_selects.html \
 		test_nsIAccessible_states.html \
 		test_nsIAccessible_focus.html \
 		test_nsIAccessibleDocument.html \
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/test_nsIAccessible_applicationAccessible.html
@@ -0,0 +1,63 @@
+<html>
+
+<head>
+  <title>application accessible name</title>
+  <link rel="stylesheet" type="text/css" 
+         href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+  <script type="application/javascript" 
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript" 
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
+   </script>
+  <script type="application/javascript" 
+          src="chrome://mochikit/content/a11y/accessible/common.js" ></script>
+
+  <script type="application/javascript">
+    function doTest()
+    {
+        var accessible = getAccessible(document);
+        while (accessible && accessible.parent) {
+            accessible = accessible.parent;
+        }
+
+        if (!accessible) {
+            SimpleTest.finish();
+            return;
+        }
+
+        var bundleServ = Components.classes["@mozilla.org/intl/stringbundle;1"]
+                         .getService(Components.interfaces.nsIStringBundleService);
+        var bundle = bundleServ.createBundle("chrome://branding/locale/brand.properties");
+
+        var applicationName = "";
+
+        try {
+            applicationName = bundle.GetStringFromName("brandShortName");
+        }  catch(e) {
+        }
+
+        if (applicationName == "")
+            applicationName = "Gecko based application";
+
+        is (accessible.name, applicationName, "wrong application accessible name");
+
+        SimpleTest.finish();
+    }
+    SimpleTest.waitForExplicitFinish();
+    addLoadEvent(doTest);
+  </script>
+  </head>
+  <body>
+  <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=456121"
+    title="nsApplicationAccessible::GetName does not return a default value when brand.properties does not exist">
+    Mozilla Bug 454211
+  </a>
+
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
+  <pre id="test">
+  </pre>
+
+  </body>
+</html>