Bug 712767: Send profile shutdown topics to cpp tests requesting a profile.

r=waldo
This commit is contained in:
Marco Bonardo 2012-01-20 14:47:51 +01:00
parent e4cf9c8d53
commit f595b05ddb
4 changed files with 53 additions and 13 deletions

View File

@ -115,6 +115,12 @@ main(PRInt32 argc, char *argv[])
ScopedXPCOM xpcom("STS Parser Tests");
if (xpcom.failed())
return -1;
// Initialize a profile folder to ensure a clean shutdown.
nsCOMPtr<nsIFile> profile = xpcom.GetProfileDirectory();
if (!profile) {
fail("Couldn't get the profile directory.");
return -1;
}
// grab handle to the service
nsCOMPtr<nsIStrictTransportSecurityService> stss;

View File

@ -329,26 +329,41 @@ do_get_lastVisit(PRInt64 placeId, VisitRecord& result)
do_check_success(rv);
}
static const char TOPIC_PROFILE_TEARDOWN[] = "profile-change-teardown";
static const char TOPIC_PROFILE_CHANGE[] = "profile-before-change";
static const char TOPIC_PLACES_CONNECTION_CLOSED[] = "places-connection-closed";
class ProfileScopedXPCOM : public ScopedXPCOM
class WaitForConnectionClosed : public nsIObserver
{
public:
ProfileScopedXPCOM(const char* testName)
: ScopedXPCOM(testName)
{
}
NS_DECL_ISUPPORTS
~ProfileScopedXPCOM() {
nsRefPtr<WaitForTopicSpinner> spinner =
new WaitForTopicSpinner(TOPIC_PLACES_CONNECTION_CLOSED);
WaitForConnectionClosed()
{
nsCOMPtr<nsIObserverService> os =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
(void)os->NotifyObservers(nsnull, TOPIC_PROFILE_TEARDOWN, nsnull);
(void)os->NotifyObservers(nsnull, TOPIC_PROFILE_CHANGE, nsnull);
// Wait for connection close.
MOZ_ASSERT(os);
if (os) {
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(os->AddObserver(this, TOPIC_PROFILE_CHANGE, false)));
}
}
NS_IMETHOD Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
nsCOMPtr<nsIObserverService> os =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
MOZ_ASSERT(os);
if (os) {
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(os->RemoveObserver(this, aTopic)));
}
nsRefPtr<WaitForTopicSpinner> spinner =
new WaitForTopicSpinner(TOPIC_PLACES_CONNECTION_CLOSED);
spinner->Spin();
return NS_OK;
}
};
NS_IMPL_ISUPPORTS1(WaitForConnectionClosed, nsIObserver)

View File

@ -114,8 +114,17 @@ int
main(int aArgc,
char** aArgv)
{
ProfileScopedXPCOM xpcom(TEST_NAME);
ScopedXPCOM xpcom(TEST_NAME);
if (xpcom.failed())
return -1;
// Initialize a profile folder to ensure a clean shutdown.
nsCOMPtr<nsIFile> profile = xpcom.GetProfileDirectory();
if (!profile) {
fail("Couldn't get the profile directory.");
return -1;
}
nsRefPtr<WaitForConnectionClosed> spinClose = new WaitForConnectionClosed();
// Tinderboxes are constantly on idle. Since idle tasks can interact with
// tests, causing random failures, disable the idle service.

View File

@ -65,6 +65,7 @@
#include "nsIDirectoryService.h"
#include "nsIFile.h"
#include "nsIProperties.h"
#include "nsIObserverService.h"
#include "nsXULAppAPI.h"
#include "jsdbgapi.h"
#include <stdio.h>
@ -194,6 +195,15 @@ class ScopedXPCOM : public nsIDirectoryServiceProvider2
{
// If we created a profile directory, we need to remove it.
if (mProfD) {
nsCOMPtr<nsIObserverService> os =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
MOZ_ASSERT(os);
if (os) {
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(os->NotifyObservers(nsnull, "profile-change-net-teardown", nsnull)));
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(os->NotifyObservers(nsnull, "profile-change-teardown", nsnull)));
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(os->NotifyObservers(nsnull, "profile-before-change", nsnull)));
}
if (NS_FAILED(mProfD->Remove(true))) {
NS_WARNING("Problem removing profile directory");
}