Bug 1041571 - Add some basic leak testing for nsSystemStatusBarCocoa. r=smichaud
authorMarkus Stange <mstange@themasta.com>
Thu, 07 Aug 2014 13:23:08 +0200
changeset 198296 cf6966a86753254270df552d9c5bc7b0a26d8f06
parent 198295 c5132b91b9ba502770d1ac6f25ce814093bde548
child 198297 ebfcfbeba792ca13ae447926c1fa8917c4b21d34
push id47355
push usermstange@themasta.com
push dateThu, 07 Aug 2014 11:25:07 +0000
treeherdermozilla-inbound@62002e19868a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud
bugs1041571
milestone34.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 1041571 - Add some basic leak testing for nsSystemStatusBarCocoa. r=smichaud
widget/cocoa/nsSystemStatusBarCocoa.mm
widget/tests/chrome.ini
widget/tests/test_system_status_bar.xul
--- a/widget/cocoa/nsSystemStatusBarCocoa.mm
+++ b/widget/cocoa/nsSystemStatusBarCocoa.mm
@@ -42,16 +42,18 @@ nsSystemStatusBarCocoa::RemoveItem(nsIDO
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 nsSystemStatusBarCocoa::StatusItem::StatusItem(nsStandaloneNativeMenu* aMenu)
   : mMenu(aMenu)
 {
+  MOZ_COUNT_CTOR(nsSystemStatusBarCocoa::StatusItem);
+
   NSMenu* nativeMenu = nil;
   mMenu->GetNativeMenu(reinterpret_cast<void**>(&nativeMenu));
 
   mStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
   [mStatusItem setMenu:nativeMenu];
   [mStatusItem setHighlightMode:YES];
 
   // We want the status item to get its image from menu item that mMenu was
@@ -62,9 +64,11 @@ nsSystemStatusBarCocoa::StatusItem::Stat
 }
 
 nsSystemStatusBarCocoa::StatusItem::~StatusItem()
 {
   mMenu->SetContainerStatusBarItem(nil);
   [[NSStatusBar systemStatusBar] removeStatusItem:mStatusItem];
   [mStatusItem release];
   mStatusItem = nil;
+
+  MOZ_COUNT_DTOR(nsSystemStatusBarCocoa::StatusItem);
 }
--- a/widget/tests/chrome.ini
+++ b/widget/tests/chrome.ini
@@ -62,16 +62,18 @@ skip-if = toolkit != "cocoa"
 [test_bug673301.xul]
 skip-if = toolkit != "cocoa"
 [test_taskbar_progress.xul]
 skip-if = toolkit != "cocoa"
 [test_secure_input.html]
 skip-if = toolkit != "cocoa"
 [test_native_key_bindings_mac.html]
 skip-if = toolkit != "cocoa"
+[test_system_status_bar.xul]
+skip-if = toolkit != "cocoa"
 
 # Windows
 # taskbar_previews.xul
 # window_state_windows.xul
 [test_chrome_context_menus_win.xul]
 skip-if = toolkit != "windows"
 support-files = chrome_context_menus_win.xul
 [test_plugin_input_event.html]
new file mode 100644
--- /dev/null
+++ b/widget/tests/test_system_status_bar.xul
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+<window title="Testing composition, text and query content events"
+  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
+
+<body  xmlns="http://www.w3.org/1999/xhtml">
+
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+</pre>
+</body>
+
+<menupopup id="menuContainer">
+  <menu id="menu1" image="data:image/svg+xml,&lt;svg%20xmlns=&quot;http://www.w3.org/2000/svg&quot;%20width=&quot;32&quot;%20height=&quot;32&quot;>&lt;circle%20cx=&quot;16&quot;%20cy=&quot;16&quot;%20r=&quot;16&quot;/>&lt;/svg>">
+    <menupopup>
+      <menuitem label="Item 1 in menu 1"/>
+      <menuitem label="Item 2 in menu 1"/>
+    </menupopup>
+  </menu>
+  <menu id="menu2" image="data:image/svg+xml,&lt;svg%20xmlns=&quot;http://www.w3.org/2000/svg&quot;%20width=&quot;32&quot;%20height=&quot;32&quot;>&lt;path%20d=&quot;M0 16 L 16 0 L 32 16 L 16 32 Z&quot;/>&lt;/svg>">
+    <menupopup>
+      <menuitem label="Item 1 in menu 2"/>
+      <menuitem label="Item 2 in menu 2"/>
+    </menupopup>
+  </menu>
+</menupopup>
+
+<script class="testbody" type="application/javascript">
+<![CDATA[
+  let Cc = Components.classes;
+  let Ci = Components.interfaces;
+
+  let systemStatusBar = Cc["@mozilla.org/widget/macsystemstatusbar;1"].getService(Ci.nsISystemStatusBar);
+  ok(systemStatusBar, "should have got an nsISystemStatusBar instance");
+
+  let menu1 = document.getElementById("menu1");
+  let menu2 = document.getElementById("menu2");
+
+  // Add and remove the item, just to get basic leak testing coverage.
+  systemStatusBar.addItem(menu1);
+  systemStatusBar.removeItem(menu1);
+
+  // Make sure that calling addItem twice with the same element doesn't leak.
+  systemStatusBar.addItem(menu2);
+  systemStatusBar.addItem(menu2);
+  systemStatusBar.removeItem(menu2);
+
+]]>
+</script>
+</window>