Bug 865729 - Use XPConnect directly in C++ unit tests. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Apr 2013 11:16:22 -0700
changeset 141199 a6fa01763d9d767dc34913d8b62c115b3b9b6c13
parent 141198 858e4b47cd828bcd63d2642a278760e5899bed0d
child 141200 7247e828e9f5b73dca9a08ff5a4290cece7bd39b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs865729
milestone23.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 865729 - Use XPConnect directly in C++ unit tests. r=gabor
startupcache/test/TestStartupCache.cpp
xpcom/tests/TestSettingsAPI.cpp
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -16,17 +16,17 @@
 #include "nsIStorageStream.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIURI.h"
 #include "nsStringAPI.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsITelemetry.h"
-#include "nsIJSContextStack.h"
+#include "nsIXPConnect.h"
 #include "jsapi.h"
 #include "prio.h"
 
 namespace mozilla {
 namespace scache {
 
 NS_IMPORT nsresult
 NewObjectInputStreamFromBuffer(char* buffer, uint32_t len, 
@@ -500,20 +500,19 @@ int main(int argc, char** argv)
   // we can only have one of per thread. So we need to get a JSContext out of
   // XPConnect here, rather than creating our own runtime. XPConnect rules
   // dictate that we push the context as well, but we're trying to make the
   // pushing/popping APIs accessible only through nsCxPusher, which isn't
   // accessible via the external linkage used by this test. We can get away with
   // using the cx here without triggering a cx stack assert, so just do that
   // for now. Eventually, the whole notion of pushing and popping will just go
   // away.
-  nsCOMPtr<nsIThreadJSContextStack> stack =
-    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
-  if (stack)
-    cx = stack->GetSafeJSContext();
+  nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
+  if (xpc)
+    cx = xpc->GetSafeJSContext();
 
   bool use_js = !!cx;
   JSAutoRequest req(cx);
   static JSClass global_class = {
     "global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE,
     JS_PropertyStub,  JS_DeletePropertyStub,
     JS_PropertyStub,  JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub,
--- a/xpcom/tests/TestSettingsAPI.cpp
+++ b/xpcom/tests/TestSettingsAPI.cpp
@@ -1,14 +1,14 @@
 #include "TestHarness.h"
 
 #include "nsISettingsService.h"
 
 #include "nsCOMPtr.h"
-#include "nsIJSContextStack.h"
+#include "nsIXPConnect.h"
 #include "nsIObserver.h"
 #include "nsIThread.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Services.h"
@@ -148,23 +148,18 @@ TestSettingsObserver::Observe(nsISupport
 
   // Check if receiving the "mozsettings-changed" event.
   if (strcmp(aTopic, MOZSETTINGS_CHANGED) != 0) {
     CHECK_MSG(false, "Got non-mozsettings-changed event");
     return NS_OK;
   }
 
   // Get the safe JS context.
-  nsCOMPtr<nsIThreadJSContextStack> stack =
-    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
-  if (!stack) {
-    CHECK_MSG(false, "Failed to get JSContextStack");
-    return NS_OK;
-  }
-  JSContext *cx = stack->GetSafeJSContext();
+  nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
+  JSContext *cx = xpc->GetSafeJSContext();
   if (!cx) {
     CHECK_MSG(false, "Failed to GetSafeJSContext");
     return NS_OK;
   }
 
   // Parse the JSON data.
   nsDependentString dataStr(aData);
   JS::Value data;