Bug 865902 - Port old gfx unit tests. r=milan
authorBenoit Girard <b56girard@gmail.com>
Thu, 25 Apr 2013 19:02:13 -0400
changeset 153418 58aed54902a539f23033a205382c05e582311661
parent 153417 7130c6699b743bcbe6b13975d2f792f84aabb78c
child 153419 d6d7900215918382ff6e0d59605142e93ebf148d
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmilan
bugs865902
milestone25.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 865902 - Port old gfx unit tests. r=milan
gfx/tests/Makefile.in
gfx/tests/TestColorNames.cpp
gfx/tests/TestRect.cpp
gfx/tests/TestRegion.cpp
gfx/tests/gfxColorManagementTest.cmtest
gfx/tests/gfxColorManagementTest.cpp
gfx/tests/gfxFontSelectionTest.cpp
gfx/tests/gfxFontSelectionTests.h
gfx/tests/gfxSurfaceRefCountTest.cpp
gfx/tests/gfxTextRunPerfTest.cpp
gfx/tests/gfxWordCacheTest.cpp
gfx/tests/gtest/Makefile.in
gfx/tests/gtest/TestColorNames.cpp
gfx/tests/gtest/TestRect.cpp
gfx/tests/gtest/TestRegion.cpp
gfx/tests/gtest/gfxFontSelectionTest.cpp
gfx/tests/gtest/gfxFontSelectionTests.h
gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
gfx/tests/gtest/gfxTextRunPerfTest.cpp
gfx/tests/gtest/gfxWordCacheTest.cpp
gfx/tests/gtest/moz.build
gfx/tests/gtest/per-word-runs.h
gfx/tests/per-word-runs.h
gfx/tests/testprofiles/DELL2407WFP-2B283C91.icc
gfx/tests/testprofiles/G22LWk-2489A79.icc
gfx/tests/testprofiles/MBP20080419-1.icc
gfx/tests/testprofiles/PhLCD17a.icm
gfx/tests/testprofiles/identity.icc
gfx/tests/testprofiles/murphy.icc
gfx/tests/testprofiles/sRGB_IEC61966-2-1_noBPC.icc
gfx/tests/testprofiles/sRGB_IEC61966-2-1_withBPC.icc
gfx/tests/testprofiles/sRGB_v4_ICC_preference.icc
gfx/thebes/gfxFontTest.h
--- a/gfx/tests/Makefile.in
+++ b/gfx/tests/Makefile.in
@@ -14,61 +14,10 @@ include $(DEPTH)/config/autoconf.mk
 MOZILLA_INTERNAL_API = 1
 
 MOCHITEST_FILES = $(addprefix mochitest/, \
 	test_bug509244.html \
 	test_bug513439.html \
 	test_acceleration.html \
 )
 
-# CPP_UNIT_TESTS disabled for now because they dont work in libxul builds.
-#ifndef BUILD_STATIC_LIBS
-#
-#CPP_UNIT_TESTS	= \
-#		TestColorNames.cpp \
-#		TestRect.cpp \
-#		TestRegion.cpp \
-#		$(NULL)
-#
-## These are built but not run.  gfxColorManagementTest.cpp can't even
-## be built, because it has not been updated for qcms.
-#CPP_DISABLED_UNIT_TESTS = \
-#		gfxFontSelectionTest.cpp \
-#		gfxSurfaceRefCountTest.cpp \
-#		gfxTextRunPerfTest.cpp \
-#		gfxWordCacheTest.cpp \
-#		$(NULL)
-##		gfxColorManagementTest.cpp \
-#
-#
-## rules.mk will put the CPP_UNIT_TESTS into SIMPLE_PROGRAMS twice if we
-## define SIMPLE_PROGRAMS based on CPPSRCS directly.
-#CPPSRCS		= $(CPP_DISABLED_UNIT_TESTS)
-#SIMPLE_PROGRAMS	= $(CPP_DISABLED_UNIT_TESTS:.cpp=$(BIN_SUFFIX))
-#
-#LIBS		= \
-#		$(HELPER_OBJS) \
-#		$(call EXPAND_LIBNAME_PATH,thebes,../thebes) \
-#		$(call EXPAND_LIBNAME_PATH,gkgfx,../src) \
-#		$(MOZ_UNICHARUTIL_LIBS) \
-#		$(XPCOM_LIBS) \
-#		$(MOZ_JS_LIBS) \
-#		$(TK_LIBS) \
-#		$(NULL)
-#
-#endif
-
 include $(topsrcdir)/config/rules.mk
 
-CXXFLAGS	+= $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-OS_LIBS		+= $(call EXPAND_LIBNAME,usp10)
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-OS_LIBS		+= -framework Cocoa
-endif
-
-ifdef MOZ_WIDGET_GTK
-OS_LIBS		+= $(MOZ_PANGO_LIBS) $(XLIBS)
-CXXFLAGS	+= $(MOZ_PANGO_CFLAGS)
-endif
deleted file mode 100644
--- a/gfx/tests/gfxColorManagementTest.cmtest
+++ /dev/null
@@ -1,21 +0,0 @@
-# Color Management Test Directive File
-#
-# Format:
-# InputProfileFilename OutputProfileFilename <CRC32 For Each Intent>
-#
-sRGB_IEC61966-2-1_noBPC.icc DELL2407WFP-2B283C91.icc 3d68eb2 3371242e
-sRGB_IEC61966-2-1_noBPC.icc G22LWk-2489A79.icc de8c5443 d56a9e64
-sRGB_IEC61966-2-1_noBPC.icc MBP20080419-1.icc 4eab8dbf 5297944c
-sRGB_IEC61966-2-1_noBPC.icc PhLCD17a.icm a703324f 8b92f57e
-sRGB_IEC61966-2-1_noBPC.icc identity.icc 4c90101e ad73cf0c
-sRGB_IEC61966-2-1_noBPC.icc murphy.icc b6d926ed 30c4bdfa
-sRGB_v4_ICC_preference.icc DELL2407WFP-2B283C91.icc 426d8cc3 c77d12ac
-sRGB_v4_ICC_preference.icc G22LWk-2489A79.icc 55006650 384b6fc2
-sRGB_v4_ICC_preference.icc MBP20080419-1.icc f297fdbe eae8670f
-sRGB_v4_ICC_preference.icc PhLCD17a.icm bab9e368 1bbb1b84
-sRGB_v4_ICC_preference.icc identity.icc fd0d9f54 7d1366b8
-sRGB_v4_ICC_preference.icc murphy.icc 96f8808 26a59d30
-sRGB_IEC61966-2-1_noBPC.icc sRGB_v4_ICC_preference.icc 18873ed 6fbaf5db
-sRGB_v4_ICC_preference.icc sRGB_IEC61966-2-1_noBPC.icc 1fb81a8b 931afa97
-DELL2407WFP-2B283C91.icc G22LWk-2489A79.icc fd1ad5d6 3013a7d5
-MBP20080419-1.icc PhLCD17a.icm f7596c76 108012b2
deleted file mode 100644
--- a/gfx/tests/gfxColorManagementTest.cpp
+++ /dev/null
@@ -1,559 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <cctype>
-
-#include "qcms.h"
-
-using std::isspace;
-
-/* Nabbed from the http://www.jonh.net/~jonh/md5/crc32/crc32.c. License is
- * "do anything, no restrictions." */
-unsigned long crc32(const unsigned char *s, unsigned int len);
-
-/*
- * Test Framework Header stuff
- */
-
-#define ASSERT(foo) { \
-    if (!(foo)) { \
-        fprintf(stderr, "%s: Failed Assertion Line %d\n", __FILE__, __LINE__); \
-        exit(-1); \
-    } \
-}
-
-#define CHECK(condition, var, value, message, label) { \
-    if (!(condition)) { \
-        var = value; \
-        fprintf(stderr, message); \
-        goto label; \
-    } \
-}
-
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#define MIN(a,b) ((a) <= (b) ? (a) : (b))
-#define ABS(a) ((a < 0) ? -a : a)
-
-#define BITMAP_PIXEL_COUNT (256 * 256 * 256)
-#define BITMAP_SIZE (BITMAP_PIXEL_COUNT * 3)
-
-/* Relative, Perceptual, and Saturation all take the same code path through
- * LCMS. As such, we just check perceptual and absolute. */
-int testedIntents[] = {INTENT_PERCEPTUAL, INTENT_ABSOLUTE_COLORIMETRIC};
-#define TESTED_INTENT_COUNT (sizeof(testedIntents)/sizeof(int))
-
-const char *profileDir = "testprofiles";
-
-/* Parameters detailing a single test. */
-struct TestParams {
-
-    /* name of the input profile. */
-    char *iProfileName;
-
-    /* name of the output profile. */
-    char *oProfileName;
-
-    /* Golden CRC32s. */
-    unsigned goldenCRCs[TESTED_INTENT_COUNT];
-
-    /* Did we read golden sums? */
-    int hasGolden;
-
-    /* Generated CRC32. */
-    unsigned ourCRCs[TESTED_INTENT_COUNT];
-
-    /* Linked list pointer. */
-    struct TestParams *next;
-
-};
-
-/* Top level context structure for the test run. */
-struct TestContext {
-
-    /* Base path for files. */
-    char *basePath;
-
-    /* Linked list of param structures. */
-    struct TestParams *paramList;
-
-    /* Our GIANT, ~50 meg buffers for every pixel value. */
-    unsigned char *src, *fixedX, *floatX;
-
-};
-
-/* Reads a line from the directive file. Returns 0 on success, 
-   -1 on malformed file. */
-static int 
-ReadTestFileLine(struct TestContext *ctx, FILE *handle) 
-{
-
-    /* Locals. */
-    char buff[4096];
-    int status = 0;
-    char *iter, *base;
-    char *strings[2];
-    char *rv;
-    unsigned i;
-    struct TestParams *params = NULL;
-   
-    /* Check input. */
-    ASSERT(ctx != NULL);
-    ASSERT(handle != NULL);
-
-    /* Null out string pointers. */
-    for (i = 0; i < 2; ++i)
-        strings[i] = NULL;
-
-    /* Read in the line. */
-    rv = fgets(buff, 4096, handle);
-    if (feof(handle))
-        goto done;
-    CHECK(rv != NULL, status, -1, "Bad Test File\n", error);
-
-    /* Allow for comments and blanklines. */
-    if ((buff[0] == '#') || isspace(buff[0]))
-        goto done;
-
-    /* Allocate a param file. */
-    params = (struct TestParams *) calloc(sizeof(struct TestParams), 1);
-    ASSERT(params);
-
-    /* Parse the profile names. */
-    iter = buff;
-    for (i = 0; i < 2; ++i) {
-        for (base = iter; (*iter != '\0') && !isspace(*iter); ++iter);
-        *iter = '\0';
-        CHECK((iter - base) > 0, status, -1, "Bad Test File\n", error);
-        strings[i] = strdup(base);
-        ++iter;
-    }
-
-    /* Fill the param file. */
-    params->iProfileName = strings[0];
-    params->oProfileName = strings[1];
-
-    /* Skip any whitespace. */
-    for (; (*iter != '\0') && isspace(*iter); ++iter);
-
-    /* if we have more to parse, we should have golden CRCs. */
-    if (*iter != '\0') {
-        for (i = 0; i < TESTED_INTENT_COUNT; ++i) {
-            params->goldenCRCs[i] = strtoul(iter, &base, 16);
-            CHECK((errno != EINVAL) && (errno != ERANGE) && (base != iter),
-                  status, -1, "Bad Checksum List\n", error);
-            iter = base;
-        }
-        params->hasGolden = 1;
-    }
-
-    /* Link up our param structure. */
-    params->next = ctx->paramList;
-    ctx->paramList = params;
-
-    done:
-    return status;
-
-    error:
-
-    /* Free the strings. */
-    for (i = 0; i < 2; ++i)
-        free(strings[i]);
-
-    /* Free the param structure. */
-    if (params != NULL)
-        free(params);
-    
-    return status;
-}
-
-/* Initializes the test context. 0 on success, -1 on failure. */
-static int 
-TestInit(struct TestContext *ctx, const char *filePath)
-{
-
-    /* Locals. */
-    FILE *tfHandle = NULL;
-    const char *iter, *last;
-    unsigned n;
-    int status = 0;
-    unsigned i, j, k, l;
-    struct TestParams *curr, *before, *after;
-
-    /* Checks. */
-    ASSERT(ctx != NULL);
-    ASSERT(filePath != NULL);
-
-    /* Allocate our buffers. If it's going to fail, we should know now. */
-    ctx->src = (unsigned char *) malloc(BITMAP_SIZE);
-    CHECK(ctx->src != NULL, status, -1, "Can't allocate enough memory\n", error);
-    ctx->fixedX = (unsigned char *) malloc(BITMAP_SIZE);
-    CHECK(ctx->fixedX != NULL, status, -1, "Can't allocate enough memory\n", error);
-    ctx->floatX = (unsigned char *) malloc(BITMAP_SIZE);
-    CHECK(ctx->floatX != NULL, status, -1, "Can't allocate enough memory\n", error);
-
-    /* Open the test file. */
-    tfHandle = fopen(filePath, "r");
-    CHECK(tfHandle != NULL, status, -1, "Unable to open test file\n", done);
-
-    /* Extract the base. XXX: Do we need to worry about windows separators? */
-    for (last = iter = filePath; *iter != '\0'; ++iter)
-        if (*iter == '/')
-            last = iter;
-    n = last - filePath;
-    ctx->basePath = (char *) malloc(n + 1);
-    ASSERT(ctx->basePath != NULL);
-    memcpy(ctx->basePath, filePath, n);
-    ctx->basePath[n] = '\0';
-
-    /* Read through the directive file. */
-    while (!feof(tfHandle)) {
-        CHECK(!ReadTestFileLine(ctx, tfHandle), status, -1, 
-              "Failed to Read Test File\n", error);
-    }
-
-    /* Reverse the list so that we process things in the order we read them
-       in. */
-    curr = ctx->paramList;
-    before = NULL;
-    while (curr->next != NULL) {
-        after = curr->next;
-        curr->next = before;
-        before = curr;
-        curr = after;
-    }
-    curr->next = before;
-    ctx->paramList = curr;
-
-    /* Generate our source bitmap. */
-    printf("Generating source bitmap...");
-    fflush(stdout);
-    for (i = 0; i < 256; ++i) {
-        for (j = 0; j < 256; ++j)
-            for (k = 0; k < 256; ++k) {
-                l = ((256 * 256 * i) + (256 * j) + k) * 3;
-                ctx->src[l] = (unsigned char) i;
-                ctx->src[l + 1] = (unsigned char) j;
-                ctx->src[l + 2] = (unsigned char) k;
-            }
-    }
-    ASSERT(l == (BITMAP_SIZE - 3));
-    printf("done!\n");
-    
-    goto done;
-
-    error:
-    /* Free up the buffers. */
-    if (ctx->src != NULL)
-        free(ctx->src);
-    if (ctx->fixedX != NULL)
-        free(ctx->fixedX);
-    if (ctx->floatX != NULL)
-        free(ctx->floatX);
-
-    done:
-
-    /* We're done with the test directive file. */
-    if (tfHandle != NULL)
-        fclose(tfHandle);
-
-    return status;
-}
-
-/* Runs a test for the given param structure. Returns 0 on success (even if
- * the test itself fails), -1 on code failure.
- *
- * 'mode' is either "generate" or "check".
- *
- * 'intentIndex' is an index in testedIntents
- */
-static int 
-RunTest(struct TestContext *ctx, struct TestParams *params, 
-        char *mode, unsigned intentIndex) 
-{
-
-    /* Locals. */
-    cmsHPROFILE inProfile = NULL;
-    cmsHPROFILE outProfile = NULL;
-    cmsHTRANSFORM transformFixed = NULL;
-    cmsHTRANSFORM transformFloat = NULL;
-    char *filePath;
-    unsigned i;
-    int difference;
-    int failures;
-    int status = 0;
-
-    /* Allocate a big enough string for either file path. */
-    filePath = (char *)malloc(strlen(ctx->basePath) + 1 +
-                              strlen(profileDir) + 1 +
-                              MAX(strlen(params->iProfileName),
-                                  strlen(params->oProfileName)) + 1);
-    ASSERT(filePath != NULL);
-
-    /* Set up the profile path for the input profile. */
-    strcpy(filePath, ctx->basePath);
-    strcat(filePath, "/");
-    strcat(filePath, profileDir);
-    strcat(filePath, "/");
-    strcat(filePath, params->iProfileName);
-    inProfile = cmsOpenProfileFromFile(filePath, "r");
-    CHECK(inProfile != NULL, status, -1, "unable to open input profile!\n", done);
-
-    /* Set up the profile path for the output profile. */
-    strcpy(filePath, ctx->basePath);
-    strcat(filePath, "/");
-    strcat(filePath, profileDir);
-    strcat(filePath, "/");
-    strcat(filePath, params->oProfileName);
-    outProfile = cmsOpenProfileFromFile(filePath, "r");
-    CHECK(outProfile != NULL, status, -1, "unable to open input profile!\n", done);
-
-    /* Precache. */
-    cmsPrecacheProfile(inProfile, CMS_PRECACHE_LI16W_FORWARD);
-    cmsPrecacheProfile(inProfile, CMS_PRECACHE_LI8F_FORWARD);
-    cmsPrecacheProfile(outProfile, CMS_PRECACHE_LI1616_REVERSE);
-    cmsPrecacheProfile(outProfile, CMS_PRECACHE_LI168_REVERSE);
-
-    /* Create the fixed transform. */
-    transformFixed = cmsCreateTransform(inProfile, TYPE_RGB_8, 
-                                        outProfile, TYPE_RGB_8, 
-                                        testedIntents[intentIndex], 0);
-    CHECK(transformFixed != NULL, status, -1, 
-          "unable to create fixed transform!\n", done);
-
-    /* Do the fixed transform. */
-    cmsDoTransform(transformFixed, ctx->src, ctx->fixedX, BITMAP_PIXEL_COUNT);
-
-    /* Compute the CRC of the fixed transform. */
-    params->ourCRCs[intentIndex] = crc32(ctx->fixedX, BITMAP_SIZE);
-
-    /* If we're just generating, we have everything we need. */
-    if (!strcmp(mode, "generate")) {
-        printf("In: %s, Out: %s, Intent: %u Generated\n",
-               params->iProfileName, params->oProfileName, testedIntents[intentIndex]);
-        goto done;
-    }
-
-    /* Create the float transform. */
-    transformFloat = cmsCreateTransform(inProfile, TYPE_RGB_8, 
-                                        outProfile, TYPE_RGB_8, 
-                                        testedIntents[intentIndex], 
-                                        cmsFLAGS_FLOATSHAPER);
-    CHECK(transformFloat != NULL, status, -1, 
-          "unable to create float transform!\n", done);
-
-    /* Make sure we have golden values. */
-    CHECK(params->hasGolden, status, -1, 
-          "Error: Check mode enabled but no golden values in file\n", done);
-
-    /* Print out header. */
-    printf("In: %s, Out: %s, Intent: %u\n", 
-           params->iProfileName, params->oProfileName, 
-           testedIntents[intentIndex]);
-
-    /* CRC check the fixed point path. */
-    if (params->goldenCRCs[intentIndex] == params->ourCRCs[intentIndex])
-        printf("\tPASSED - CRC Check of Fixed Point Path\n");
-    else
-        printf("\tFAILED - CRC Check of Fixed Point Path - Expected %x, Got %x\n", 
-               params->goldenCRCs[intentIndex], params->ourCRCs[intentIndex]);
-
-    /* Do the floating point transform. */
-    cmsDoTransform(transformFloat, ctx->src, ctx->floatX, BITMAP_PIXEL_COUNT);
-
-    /* Compare fixed with floating. */
-    failures = 0;
-    for (i = 0; i < BITMAP_SIZE; ++i) {
-        difference = (int)ctx->fixedX[i] - (int)ctx->floatX[i];
-        /* Allow off-by-one from fixed point, nothing more. */
-        if (ABS(difference) > 1)
-            ++failures;
-    }
-    if (failures == 0)
-        printf("\tPASSED - floating point path within acceptable parameters\n");
-    else
-        printf("\tWARNING - floating point path off by 2 or more in %d cases!\n",
-               failures);
-
-    done:
-
-    /* Free the temporary string. */
-    free(filePath);
-
-    /* Close the transforms and profiles if non-null. */
-    if (transformFixed != NULL)
-        cmsDeleteTransform(transformFixed);
-    if (transformFloat != NULL)
-        cmsDeleteTransform(transformFloat);
-    if (inProfile != NULL)
-        cmsCloseProfile(inProfile);
-    if (outProfile != NULL)
-        cmsCloseProfile(outProfile);
-
-    return status;
-}
-
-/* Writes the in memory data structures out to the original test directive
- * file, using the generated CRCs as golden CRCs. */
-static int 
-WriteTestFile(struct TestContext *ctx, const char *filename) 
-{
-
-    /* Locals. */
-    FILE *tfHandle = NULL;
-    int status = 0;
-    struct TestParams *iter;
-    unsigned i;
-
-    /* Check Input. */
-    ASSERT(ctx != NULL);
-    ASSERT(filename != NULL);
-
-    /* Open the file in write mode. */
-    tfHandle = fopen(filename, "w");
-    CHECK(tfHandle != NULL, status, -1, "Couldn't Open Test File For Writing",
-          done);
-
-    /* Print Instructional Comment. */
-    fprintf(tfHandle, "# Color Management Test Directive File\n#\n# Format:\n"
-                      "# InputProfileFilename OutputProfileFilename "
-                      "<CRC32 For Each Intent>\n#\n");
-    /* Iterate and Print. */
-    for (iter = ctx->paramList; iter != NULL; iter = iter->next) {
-        fprintf(tfHandle, "%s %s", iter->iProfileName, iter->oProfileName);
-        for (i = 0; i < TESTED_INTENT_COUNT; ++i)
-            fprintf(tfHandle, " %x", iter->ourCRCs[i]);
-        fprintf(tfHandle, "\n");
-    }
-
-    done:
-
-    /* Close the test file. */
-    if (tfHandle != NULL)
-        fclose(tfHandle);
-
-    return status;
-}
-
-
-/* Main Function. */
-int 
-main (int argc, char **argv) 
-{
-
-    /* Locals. */
-    struct TestContext ctx;
-    struct TestParams *iter;
-    unsigned i;
-    int status = 0;
-
-    /* Zero out context. */
-    memset(&ctx, 0, sizeof(ctx));
-
-    if ((argc != 3) || 
-        (strcmp(argv[1], "generate") && strcmp(argv[1], "check"))) {
-        printf("Usage: %s generate|check PATH/FILE.cmtest\n", argv[0]);
-        return -1;
-    }
-
-    /* Initialize the test. */
-    TestInit(&ctx, argv[2]);
-
-    /* Run each individual test. */
-    iter = ctx.paramList;
-    while (iter != NULL) {
-
-        /* For each intent. */
-        for (i = 0; i < TESTED_INTENT_COUNT; ++i)
-            CHECK(!RunTest(&ctx, iter, argv[1], i),
-                  status, -1, "RunTest Failed\n", done);
-        iter = iter->next;
-    }
-
-    /* If we're generating, write back out. */
-    if (!strcmp(argv[1], "generate"))
-        WriteTestFile(&ctx, argv[2]);
-
-    done:
-
-    return status;
-}
-
-
-/*
- * CRC32 Implementation.
- */
-
-static unsigned long crc32_tab[] = {
-      0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
-      0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
-      0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-      0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
-      0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
-      0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
-      0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
-      0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
-      0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
-      0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
-      0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
-      0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
-      0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
-      0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
-      0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
-      0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
-      0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
-      0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
-      0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
-      0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
-      0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
-      0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
-      0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
-      0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
-      0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
-      0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
-      0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
-      0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
-      0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
-      0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
-      0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
-      0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
-      0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
-      0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
-      0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
-      0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
-      0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
-      0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
-      0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
-      0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
-      0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
-      0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
-      0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
-      0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
-      0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
-      0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
-      0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
-      0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
-      0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
-      0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
-      0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
-      0x2d02ef8dL
-   };
-
-/* Return a 32-bit CRC of the contents of the buffer. */
-
-unsigned long 
-crc32(const unsigned char *s, unsigned int len)
-{
-  unsigned int i;
-  unsigned long crc32val;
-  
-  crc32val = 0;
-  for (i = 0;  i < len;  i ++)
-    {
-      crc32val =
-	crc32_tab[(crc32val ^ s[i]) & 0xff] ^
-	  (crc32val >> 8);
-    }
-  return crc32val;
-}
-
--- a/gfx/tests/gtest/Makefile.in
+++ b/gfx/tests/gtest/Makefile.in
@@ -6,16 +6,18 @@
 DEPTH          = @DEPTH@
 topsrcdir      = @top_srcdir@
 srcdir         = @srcdir@
 VPATH          = @srcdir@ $(srcdir)/$(DEPTH)/gfx/2d/unittest
 relativesrcdir = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
+CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS) 
+
 # Create a GTest library
 MODULE_NAME    = gfxtest
 LIBXUL_LIBRARY = 1
 IS_COMPONENT   = 1
 EXPORT_LIBRARY = 1
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/gfx/layers \
rename from gfx/tests/TestColorNames.cpp
rename to gfx/tests/gtest/TestColorNames.cpp
--- a/gfx/tests/TestColorNames.cpp
+++ b/gfx/tests/gtest/TestColorNames.cpp
@@ -1,111 +1,99 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "TestHarness.h"
+#include "gtest/gtest.h"
 
 #include <string.h>
 #include "nsColor.h"
 #include "nsColorNames.h"
 #include "prprf.h"
 #include "nsString.h"
+#include "mozilla/Util.h"
 
 // define an array of all color names
 #define GFX_COLOR(_name, _value) #_name,
 static const char* const kColorNames[] = {
 #include "nsColorNameList.h"
 };
 #undef GFX_COLOR
 
 // define an array of all color name values
 #define GFX_COLOR(_name, _value) _value,
 static const nscolor kColors[] = {
 #include "nsColorNameList.h"
 };
 #undef GFX_COLOR
 
+using namespace mozilla;
+
 static const char* kJunkNames[] = {
   nullptr,
   "",
   "123",
   "backgroundz",
   "zzzzzz",
   "#@$&@#*@*$@$#"
 };
 
-int main(int argc, char** argv)
-{
-  ScopedXPCOM xpcom("TestColorNames");
-  if (xpcom.failed())
-    return 1;
-
+static
+void RunColorTests() {
   nscolor rgb;
-  int rv = 0;
-
   // First make sure we can find all of the tags that are supposed to
   // be in the table. Futz with the case to make sure any case will
   // work
 
   for (uint32_t index = 0 ; index < ArrayLength(kColorNames); index++) {
     // Lookup color by name and make sure it has the right id
     nsCString tagName(kColorNames[index]);
 
     // Check that color lookup by name gets the right rgb value
-    if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) {
-      fail("can't find '%s'", tagName.get());
-      rv = 1;
-    }
-    if (rgb != kColors[index]) {
-      fail("name='%s' ColorNameToRGB=%x kColors[%d]=%08x",
-           tagName.get(), rgb, index, kColors[index]);
-      rv = 1;
-    }
+    ASSERT_TRUE(NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) <<
+      "can't find '" << tagName.get() << "'";
+    ASSERT_TRUE((rgb == kColors[index])) <<
+      "failed at index " << index << " out of " << ArrayLength(kColorNames);
 
     // fiddle with the case to make sure we can still find it
     tagName.SetCharAt(tagName.CharAt(0) - 32, 0);
-    if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) {
-      fail("can't find '%s'", tagName.get());
-      rv = 1;
-    }
-    if (rgb != kColors[index]) {
-      fail("name='%s' ColorNameToRGB=%x kColors[%d]=%08x",
-           tagName.get(), rgb, index, kColors[index]);
-      rv = 1;
-    }
+    ASSERT_TRUE(NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) <<
+      "can't find '" << tagName.get() << "'";
+    ASSERT_TRUE((rgb == kColors[index])) <<
+      "failed at index " << index << " out of " << ArrayLength(kColorNames);
 
     // Check that parsing an RGB value in hex gets the right values
     uint8_t r = NS_GET_R(rgb);
     uint8_t g = NS_GET_G(rgb);
     uint8_t b = NS_GET_B(rgb);
     uint8_t a = NS_GET_A(rgb);
     if (a != UINT8_MAX) {
       // NS_HexToRGB() can not handle a color with alpha channel
       rgb = NS_RGB(r, g, b);
     }
     char cbuf[50];
     PR_snprintf(cbuf, sizeof(cbuf), "%02x%02x%02x", r, g, b);
     nscolor hexrgb;
-    if (!NS_HexToRGB(NS_ConvertASCIItoUTF16(cbuf), &hexrgb)) {
-      fail("hex conversion to color of '%s'", cbuf);
-      rv = 1;
-    }
-    if (hexrgb != rgb) {
-      fail("rgb=%x hexrgb=%x", rgb, hexrgb);
-      rv = 1;
-    }
+    ASSERT_TRUE(NS_HexToRGB(NS_ConvertASCIItoUTF16(cbuf), &hexrgb)) <<
+      "hex conversion to color of '" << cbuf << "'";
+    ASSERT_TRUE(hexrgb == rgb);
   }
+}
 
+static
+void RunJunkColorTests() {
+  nscolor rgb;
   // Now make sure we don't find some garbage
   for (uint32_t i = 0; i < ArrayLength(kJunkNames); i++) {
     nsCString tag(kJunkNames[i]);
-    if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tag), &rgb)) {
-      fail("found '%s'", kJunkNames[i] ? kJunkNames[i] : "(null)");
-      rv = 1;
-    }
+    ASSERT_FALSE(NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tag), &rgb)) <<
+      "Failed at junk color " << kJunkNames[i];
   }
+}
 
-  if (rv == 0)
-    passed("TestColorNames");
-  return rv;
+TEST(Gfx, ColorNames) {
+  RunColorTests();
 }
+
+TEST(Gfx, JunkColorNames) {
+  RunJunkColorTests();
+}
rename from gfx/tests/TestRect.cpp
rename to gfx/tests/gtest/TestRect.cpp
--- a/gfx/tests/TestRect.cpp
+++ b/gfx/tests/gtest/TestRect.cpp
@@ -1,501 +1,367 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "TestHarness.h"
+#include "gtest/gtest.h"
 
 #include "nsRect.h"
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 template <class RectType>
 static bool
 TestConstructors()
 {
   // Create a rectangle
   RectType  rect1(10, 20, 30, 40);
 
   // Make sure the rectangle was properly initialized
-  if ((rect1.x != 10) || (rect1.y != 20) ||
-      (rect1.width != 30) || (rect1.height != 40)) {
-    fail("[1] Make sure the rectangle was properly initialized with constructor");
-    return false;
-  }
+  EXPECT_TRUE(rect1.x == 10 && rect1.y == 20 &&
+      rect1.width == 30 && rect1.height == 40) <<
+    "[1] Make sure the rectangle was properly initialized with constructor";
 
   // Create a second rect using the copy constructor
   RectType  rect2(rect1);
 
   // Make sure the rectangle was properly initialized
-  if ((rect2.x != rect1.x) || (rect2.y != rect1.y) ||
-      (rect2.width != rect1.width) || (rect2.height != rect1.height)) {
-    fail("[2] Make sure the rectangle was properly initialized with copy constructor");
-    return false;
-  }
+  EXPECT_TRUE(rect2.x == rect1.x && rect2.y == rect2.y &&
+      rect2.width == rect2.width && rect2.height == rect2.height) <<
+    "[2] Make sure the rectangle was properly initialized with copy constructor";
 
-  passed("TestConstructors");
   return true;
 }
 
 template <class RectType>
 static bool
 TestEqualityOperator()
 {
   RectType  rect1(10, 20, 30, 40);
   RectType  rect2(rect1);
 
   // Test the equality operator
-  if (!(rect1 == rect2)) {
-    fail("[1] Test the equality operator");
-    return false;
-  }
+  EXPECT_TRUE(rect1 == rect2) <<
+    "[1] Test the equality operator";
 
-  // Test the inequality operator
-  if (rect1 != rect2) {
-    fail("[2] Test the inequality operator");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.IsEqualInterior(rect2)) <<
+    "[2] Test the inequality operator";
 
   // Make sure that two empty rects are equal
-  rect1.Empty();
-  rect2.Empty();
-  if (!(rect1 == rect2)) {
-    fail("[3] Make sure that two empty rects are equal");
-    return false;
-  }
+  rect1.SetEmpty();
+  rect2.SetEmpty();
+  EXPECT_TRUE(rect1 == rect2) <<
+    "[3] Make sure that two empty rects are equal";
 
-  passed("TestEqualityOperator");
   return true;
 }
 
 template <class RectType>
 static bool
 TestContainment()
 {
   RectType  rect1(10, 10, 50, 50);
 
   // Test the point containment methods
   //
 
   // Basic test of a point in the middle of the rect
-  if (!rect1.Contains(rect1.x + rect1.width/2, rect1.y + rect1.height/2)) {
-    fail("[1] Basic test of a point in the middle of the rect");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Contains(rect1.x + rect1.width/2, rect1.y + rect1.height/2)) <<
+    "[1] Basic test of a point in the middle of the rect";
 
   // Test against a point at the left/top edges
-  if (!rect1.Contains(rect1.x, rect1.y)) {
-    fail("[2] Test against a point at the left/top edges");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Contains(rect1.x, rect1.y)) <<
+    "[2] Test against a point at the left/top edges";
 
   // Test against a point at the right/bottom extents
-  if (rect1.Contains(rect1.XMost(), rect1.YMost())) {
-    fail("[3] Test against a point at the right/bottom extents");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Contains(rect1.XMost(), rect1.YMost())) <<
+    "[3] Test against a point at the right/bottom extents";
 
   // Test the rect containment methods
   //
   RectType  rect2(rect1);
 
   // Test against a rect that's the same as rect1
-  if (!rect1.Contains(rect2)) {
-    fail("[4] Test against a rect that's the same as rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Contains(rect2)) <<
+    "[4] Test against a rect that's the same as rect1";
 
   // Test against a rect whose left edge (only) is outside of rect1
   rect2.x--;
-  if (rect1.Contains(rect2)) {
-    fail("[5] Test against a rect whose left edge (only) is outside of rect1");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Contains(rect2)) <<
+    "[5] Test against a rect whose left edge (only) is outside of rect1";
   rect2.x++;
 
   // Test against a rect whose top edge (only) is outside of rect1
   rect2.y--;
-  if (rect1.Contains(rect2)) {
-    fail("[6] Test against a rect whose top edge (only) is outside of rect1");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Contains(rect2)) <<
+    "[6] Test against a rect whose top edge (only) is outside of rect1";
   rect2.y++;
 
   // Test against a rect whose right edge (only) is outside of rect1
   rect2.x++;
-  if (rect1.Contains(rect2)) {
-    fail("[7] Test against a rect whose right edge (only) is outside of rect1");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Contains(rect2)) <<
+    "[7] Test against a rect whose right edge (only) is outside of rect1";
   rect2.x--;
 
   // Test against a rect whose bottom edge (only) is outside of rect1
   rect2.y++;
-  if (rect1.Contains(rect2)) {
-    fail("[8] Test against a rect whose bottom edge (only) is outside of rect1");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Contains(rect2)) <<
+    "[8] Test against a rect whose bottom edge (only) is outside of rect1";
   rect2.y--;
 
-  passed("TestContainment");
   return true;
 }
 
 // Test the method that returns a boolean result but doesn't return a
 // a rectangle
 template <class RectType>
 static bool
 TestIntersects()
 {
   RectType  rect1(10, 10, 50, 50);
   RectType  rect2(rect1);
 
   // Test against a rect that's the same as rect1
-  if (!rect1.Intersects(rect2)) {
-    fail("[1] Test against a rect that's the same as rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Intersects(rect2)) <<
+    "[1] Test against a rect that's the same as rect1";
 
   // Test against a rect that's enclosed by rect1
   rect2.Inflate(-1, -1);
-  if (!rect1.Contains(rect2) || !rect1.Intersects(rect2)) {
-    fail("[2] Test against a rect that's enclosed by rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Contains(rect2) || !rect1.Intersects(rect2)) <<
+    "[2] Test against a rect that's enclosed by rect1";
   rect2.Inflate(1, 1);
 
   // Make sure inflate and deflate worked correctly
-  if (rect1 != rect2) {
-    fail("[3] Make sure inflate and deflate worked correctly");
-    return false;
-  }
+  EXPECT_TRUE(rect1.IsEqualInterior(rect2)) <<
+    "[3] Make sure inflate and deflate worked correctly";
 
   // Test against a rect that overlaps the left edge of rect1
   rect2.x--;
-  if (!rect1.Intersects(rect2)) {
-    fail("[4] Test against a rect that overlaps the left edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Intersects(rect2)) <<
+    "[4] Test against a rect that overlaps the left edge of rect1";
   rect2.x++;
 
   // Test against a rect that's outside of rect1 on the left
   rect2.x -= rect2.width;
-  if (rect1.Intersects(rect2)) {
-    fail("[5] Test against a rect that's outside of rect1 on the left");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Intersects(rect2)) <<
+    "[5] Test against a rect that's outside of rect1 on the left";
   rect2.x += rect2.width;
 
   // Test against a rect that overlaps the top edge of rect1
   rect2.y--;
-  if (!rect1.Intersects(rect2)) {
-    fail("[6] Test against a rect that overlaps the top edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Intersects(rect2)) <<
+    "[6] Test against a rect that overlaps the top edge of rect1";
   rect2.y++;
 
   // Test against a rect that's outside of rect1 on the top
   rect2.y -= rect2.height;
-  if (rect1.Intersects(rect2)) {
-    fail("[7] Test against a rect that's outside of rect1 on the top");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Intersects(rect2)) <<
+    "[7] Test against a rect that's outside of rect1 on the top";
   rect2.y += rect2.height;
 
   // Test against a rect that overlaps the right edge of rect1
   rect2.x++;
-  if (!rect1.Intersects(rect2)) {
-    fail("[8] Test against a rect that overlaps the right edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Intersects(rect2)) <<
+    "[8] Test against a rect that overlaps the right edge of rect1";
   rect2.x--;
 
   // Test against a rect that's outside of rect1 on the right
   rect2.x += rect2.width;
-  if (rect1.Intersects(rect2)) {
-    fail("[9] Test against a rect that's outside of rect1 on the right");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Intersects(rect2)) <<
+    "[9] Test against a rect that's outside of rect1 on the right";
   rect2.x -= rect2.width;
 
   // Test against a rect that overlaps the bottom edge of rect1
   rect2.y++;
-  if (!rect1.Intersects(rect2)) {
-    fail("[10] Test against a rect that overlaps the bottom edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!rect1.Intersects(rect2)) <<
+    "[10] Test against a rect that overlaps the bottom edge of rect1";
   rect2.y--;
 
   // Test against a rect that's outside of rect1 on the bottom
   rect2.y += rect2.height;
-  if (rect1.Intersects(rect2)) {
-    fail("[11] Test against a rect that's outside of rect1 on the bottom");
-    return false;
-  }
+  EXPECT_FALSE(rect1.Intersects(rect2)) <<
+    "[11] Test against a rect that's outside of rect1 on the bottom";
   rect2.y -= rect2.height;
 
-  passed("TestIntersects");
   return true;
 }
 
 // Test the method that returns a boolean result and an intersection rect
 template <class RectType>
 static bool
 TestIntersection()
 {
   RectType  rect1(10, 10, 50, 50);
   RectType  rect2(rect1);
   RectType  dest;
 
   // Test against a rect that's the same as rect1
-  if (!dest.IntersectRect(rect1, rect2) || (dest != rect1)) {
-    fail("[1] Test against a rect that's the same as rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) || !(dest.IsEqualInterior(rect1))) <<
+    "[1] Test against a rect that's the same as rect1";
 
   // Test against a rect that's enclosed by rect1
   rect2.Inflate(-1, -1);
-  if (!dest.IntersectRect(rect1, rect2) || (dest != rect2)) {
-    fail("[2] Test against a rect that's enclosed by rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) || !(dest.IsEqualInterior(rect2))) <<
+    "[2] Test against a rect that's enclosed by rect1";
   rect2.Inflate(1, 1);
 
   // Test against a rect that overlaps the left edge of rect1
   rect2.x--;
-  if (!dest.IntersectRect(rect1, rect2) ||
-     (dest != RectType(rect1.x, rect1.y, rect1.width - 1, rect1.height))) {
-    fail("[3] Test against a rect that overlaps the left edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) ||
+     !(dest.IsEqualInterior(RectType(rect1.x, rect1.y, rect1.width - 1, rect1.height)))) <<
+    "[3] Test against a rect that overlaps the left edge of rect1";
   rect2.x++;
 
   // Test against a rect that's outside of rect1 on the left
   rect2.x -= rect2.width;
-  if (dest.IntersectRect(rect1, rect2)) {
-    fail("[4] Test against a rect that's outside of rect1 on the left");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2)) <<
+    "[4] Test against a rect that's outside of rect1 on the left";
   // Make sure an empty rect is returned
-  if (!dest.IsEmpty()) {
-    fail("[4] Make sure an empty rect is returned");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IsEmpty()) <<
+    "[4] Make sure an empty rect is returned";
   rect2.x += rect2.width;
 
   // Test against a rect that overlaps the top edge of rect1
   rect2.y--;
-  if (!dest.IntersectRect(rect1, rect2) ||
-     (dest != RectType(rect1.x, rect1.y, rect1.width, rect1.height - 1))) {
-    fail("[5] Test against a rect that overlaps the top edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) ||
+     !(dest.IsEqualInterior(RectType(rect1.x, rect1.y, rect1.width, rect1.height - 1)))) <<
+    "[5] Test against a rect that overlaps the top edge of rect1";
   rect2.y++;
 
   // Test against a rect that's outside of rect1 on the top
   rect2.y -= rect2.height;
-  if (dest.IntersectRect(rect1, rect2)) {
-    fail("[6] Test against a rect that's outside of rect1 on the top");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2)) <<
+    "[6] Test against a rect that's outside of rect1 on the top";
   // Make sure an empty rect is returned
-  if (!dest.IsEmpty()) {
-    fail("[6] Make sure an empty rect is returned");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IsEmpty()) <<
+    "[6] Make sure an empty rect is returned";
   rect2.y += rect2.height;
 
   // Test against a rect that overlaps the right edge of rect1
   rect2.x++;
-  if (!dest.IntersectRect(rect1, rect2) ||
-     (dest != RectType(rect1.x + 1, rect1.y, rect1.width - 1, rect1.height))) {
-    fail("[7] Test against a rect that overlaps the right edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) ||
+     !(dest.IsEqualInterior(RectType(rect1.x + 1, rect1.y, rect1.width - 1, rect1.height)))) <<
+    "[7] Test against a rect that overlaps the right edge of rect1";
   rect2.x--;
 
   // Test against a rect that's outside of rect1 on the right
   rect2.x += rect2.width;
-  if (dest.IntersectRect(rect1, rect2)) {
-    fail("[8] Test against a rect that's outside of rect1 on the right");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2)) <<
+    "[8] Test against a rect that's outside of rect1 on the right";
   // Make sure an empty rect is returned
-  if (!dest.IsEmpty()) {
-    fail("[8] Make sure an empty rect is returned");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IsEmpty()) <<
+    "[8] Make sure an empty rect is returned";
   rect2.x -= rect2.width;
 
   // Test against a rect that overlaps the bottom edge of rect1
   rect2.y++;
-  if (!dest.IntersectRect(rect1, rect2) ||
-     (dest != RectType(rect1.x, rect1.y + 1, rect1.width, rect1.height - 1))) {
-    fail("[9] Test against a rect that overlaps the bottom edge of rect1");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IntersectRect(rect1, rect2) ||
+     !(dest.IsEqualInterior(RectType(rect1.x, rect1.y + 1, rect1.width, rect1.height - 1)))) <<
+    "[9] Test against a rect that overlaps the bottom edge of rect1";
   rect2.y--;
 
   // Test against a rect that's outside of rect1 on the bottom
   rect2.y += rect2.height;
-  if (dest.IntersectRect(rect1, rect2)) {
-    fail("[10] Test against a rect that's outside of rect1 on the bottom");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2)) <<
+    "[10] Test against a rect that's outside of rect1 on the bottom";
   // Make sure an empty rect is returned
-  if (!dest.IsEmpty()) {
-    fail("[10] Make sure an empty rect is returned");
-    return false;
-  }
+  EXPECT_FALSE(!dest.IsEmpty()) <<
+    "[10] Make sure an empty rect is returned";
   rect2.y -= rect2.height;
 
   // Test against a rect with zero width or height
   rect1.SetRect(100, 100, 100, 100);
   rect2.SetRect(150, 100, 0, 100);
-  if (dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) {
-    fail("[11] Intersection of rects with zero width or height should be empty");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) <<
+    "[11] Intersection of rects with zero width or height should be empty";
 
   // Tests against a rect with negative width or height
   //
 
   // Test against a rect with negative width
   rect1.SetRect(100, 100, 100, 100);
   rect2.SetRect(100, 100, -100, 100);
-  if (dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) {
-    fail("[12] Intersection of rects with negative width or height should be empty");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) <<
+    "[12] Intersection of rects with negative width or height should be empty";
 
   // Those two rects exactly overlap in some way...
   // but we still want to return an empty rect
   rect1.SetRect(100, 100, 100, 100);
   rect2.SetRect(200, 200, -100, -100);
-  if (dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) {
-    fail("[13] Intersection of rects with negative width or height should be empty");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) <<
+    "[13] Intersection of rects with negative width or height should be empty";
 
   // Test against two identical rects with negative height
   rect1.SetRect(100, 100, 100, -100);
   rect2.SetRect(100, 100, 100, -100);
-  if (dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) {
-    fail("[14] Intersection of rects with negative width or height should be empty");
-    return false;
-  }
+  EXPECT_FALSE(dest.IntersectRect(rect1, rect2) || !dest.IsEmpty()) <<
+    "[14] Intersection of rects with negative width or height should be empty";
 
-  passed("TestIntersection");
   return true;
 }
 
 template <class RectType>
 static bool
 TestUnion()
 {
   RectType  rect1;
   RectType  rect2(10, 10, 50, 50);
   RectType  dest;
 
   // Check the case where the receiver is an empty rect
-  rect1.Empty();
-  if (!dest.UnionRect(rect1, rect2) || (dest != rect2)) {
-    fail("[1] Check the case where the receiver is an empty rect");
-    return false;
-  }
+  rect1.SetEmpty();
+  dest.UnionRect(rect1, rect2);
+  EXPECT_FALSE(dest.IsEmpty() || !dest.IsEqualInterior(rect2)) <<
+    "[1] Check the case where the receiver is an empty rect";
 
   // Check the case where the source rect is an empty rect
   rect1 = rect2;
-  rect2.Empty();
-  if (!dest.UnionRect(rect1, rect2) || (dest != rect1)) {
-    fail("[2] Check the case where the source rect is an empty rect");
-    return false;
-  }
+  rect2.SetEmpty();
+  dest.UnionRect(rect1, rect2);
+  EXPECT_FALSE(dest.IsEmpty() || !dest.IsEqualInterior(rect1)) <<
+    "[2] Check the case where the source rect is an empty rect";
 
   // Test the case where both rects are empty
-  rect1.Empty();
-  rect2.Empty();
-  if (dest.UnionRect(rect1, rect2)) {
-    fail("[3] Test the case where both rects are empty");
-    return false;
-  }
+  rect1.SetEmpty();
+  rect2.SetEmpty();
+  dest.UnionRect(rect1, rect2);
+  EXPECT_FALSE(!dest.IsEmpty()) <<
+    "[3] Test the case where both rects are empty";
 
   // Test union case where the two rects don't overlap at all
   rect1.SetRect(10, 10, 50, 50);
   rect2.SetRect(100, 100, 50, 50);
-  if (!dest.UnionRect(rect1, rect2) ||
-     (dest != RectType(rect1.x, rect1.y, rect2.XMost() - rect1.x, rect2.YMost() - rect1.y))) {
-    fail("[4] Test union case where the two rects don't overlap at all");
-    return false;
-  }
+  dest.UnionRect(rect1, rect2);
+  EXPECT_FALSE(dest.IsEmpty() ||
+     !(dest.IsEqualInterior(RectType(rect1.x, rect1.y, rect2.XMost() - rect1.x, rect2.YMost() - rect1.y)))) <<
+    "[4] Test union case where the two rects don't overlap at all";
 
   // Test union case where the two rects overlap
   rect1.SetRect(30, 30, 50, 50);
   rect2.SetRect(10, 10, 50, 50);
-  if (!dest.UnionRect(rect1, rect2) ||
-      (dest != RectType(rect2.x, rect2.y, rect1.XMost() - rect2.x, rect1.YMost() - rect2.y))) {
-    fail("[5] Test union case where the two rects overlap");
-    return false;
-  }
+  dest.UnionRect(rect1, rect2);
+  EXPECT_FALSE(dest.IsEmpty() ||
+      !(dest.IsEqualInterior(RectType(rect2.x, rect2.y, rect1.XMost() - rect2.x, rect1.YMost() - rect2.y)))) <<
+    "[5] Test union case where the two rects overlap";
 
-  passed("TestUnion");
   return true;
 }
 
-int main(int argc, char** argv)
-{
-  ScopedXPCOM xpcom("TestRect");
-  if (xpcom.failed())
-    return -1;
-
-  int rv = 0;
-
-  //-----------------------
-  // Test nsRect
-  //
-  printf("===== nsRect tests =====\n");
-
-  if (!TestConstructors<nsRect>())
-    rv = -1;
-
-  if (!TestEqualityOperator<nsRect>())
-    rv = -1;
-
-  if (!TestContainment<nsRect>())
-    rv = -1;
-
-  if (!TestIntersects<nsRect>())
-    rv = -1;
-
-  if (!TestIntersection<nsRect>())
-    rv = -1;
+TEST(Gfx, nsRect) {
+  TestConstructors<nsRect>();
+  TestEqualityOperator<nsRect>();
+  TestContainment<nsRect>();
+  TestIntersects<nsRect>();
+  TestIntersection<nsRect>();
+  TestUnion<nsRect>();
+}
 
-  if (!TestUnion<nsRect>())
-    rv = -1;
-
-  //-----------------------
-  // Test nsIntRect
-  //
-  printf("===== nsIntRect tests =====\n");
- 
-  if (!TestConstructors<nsIntRect>())
-    rv = -1;
-
-  if (!TestEqualityOperator<nsIntRect>())
-    rv = -1;
+TEST(Gfx, nsIntRect) {
+  TestConstructors<nsIntRect>();
+  TestEqualityOperator<nsIntRect>();
+  TestContainment<nsIntRect>();
+  TestIntersects<nsIntRect>();
+  TestIntersection<nsIntRect>();
+  TestUnion<nsIntRect>();
+}
 
-  if (!TestContainment<nsIntRect>())
-    rv = -1;
-
-  if (!TestIntersects<nsIntRect>())
-    rv = -1;
-
-  if (!TestIntersection<nsIntRect>())
-    rv = -1;
-
-  if (!TestUnion<nsIntRect>())
-    rv = -1;
-
-  return rv;
-}
rename from gfx/tests/TestRegion.cpp
rename to gfx/tests/gtest/TestRegion.cpp
--- a/gfx/tests/TestRegion.cpp
+++ b/gfx/tests/gtest/TestRegion.cpp
@@ -1,27 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "TestHarness.h"
+#include "gtest/gtest.h"
 #include "nsRegion.h"
 
 class TestLargestRegion {
-  static bool TestSingleRect(nsRect r) {
+public:
+  static void TestSingleRect(nsRect r) {
     nsRegion region(r);
-    if (!region.GetLargestRectangle().IsEqualInterior(r)) {
-      fail("largest rect of singleton %d %d %d %d", r.x, r.y, r.width, r.height);
-      return false;
-    }
-    return true;
+    EXPECT_TRUE(region.GetLargestRectangle().IsEqualInterior(r));
   }
   // Construct a rectangle, remove part of it, then check the remainder
-  static bool TestNonRectangular() {
+  static void TestNonRectangular() {
     nsRegion r(nsRect(0, 0, 30, 30));
 
     const int nTests = 19;
     struct {
       nsRect rect;
       int64_t expectedArea;
     } tests[nTests] = {
       // Remove a 20x10 chunk from the square
@@ -47,102 +44,83 @@ class TestLargestRegion {
       { nsRect(0, 20, 10, 10), 600 },
       // Remove the corners 20x20
       { nsRect(0, 0, 20, 20), 300 },
       { nsRect(10, 10, 20, 20), 300 },
       { nsRect(10, 0, 20, 20), 300 },
       { nsRect(0, 10, 20, 20), 300 }
     };
 
-    bool success = true;
     for (int32_t i = 0; i < nTests; i++) {
       nsRegion r2;
       r2.Sub(r, tests[i].rect);
 
-      if (!r2.IsComplex())
-        fail("nsRegion code got unexpectedly smarter!");
+      EXPECT_TRUE(r2.IsComplex()) << "nsRegion code got unexpectedly smarter!";
 
       nsRect largest = r2.GetLargestRectangle();
-      if (largest.width * largest.height != tests[i].expectedArea) {
-        fail("Did not successfully find largest rectangle in non-rectangular region on iteration %d", i);
-        success = false;
-      }
+      EXPECT_TRUE(largest.width * largest.height == tests[i].expectedArea) <<
+        "Did not successfully find largest rectangle in non-rectangular region on iteration " << i;
     }
 
-    return success;
   }
-  static bool TwoRectTest() {
+  static void TwoRectTest() {
     nsRegion r(nsRect(0, 0, 100, 100));
     const int nTests = 4;
     struct {
       nsRect rect1, rect2;
       int64_t expectedArea;
     } tests[nTests] = {
       { nsRect(0, 0, 75, 40),  nsRect(0, 60, 75, 40),  2500 },
       { nsRect(25, 0, 75, 40), nsRect(25, 60, 75, 40), 2500 },
       { nsRect(25, 0, 75, 40), nsRect(0, 60, 75, 40),  2000 },
       { nsRect(0, 0, 75, 40),  nsRect(25, 60, 75, 40), 2000 },
     };
-    bool success = true;
     for (int32_t i = 0; i < nTests; i++) {
       nsRegion r2;
 
       r2.Sub(r, tests[i].rect1);
       r2.Sub(r2, tests[i].rect2);
 
-      if (!r2.IsComplex())
-        fail("nsRegion code got unexpectedly smarter!");
+      EXPECT_TRUE(r2.IsComplex()) << "nsRegion code got unexpectedly smarter!";
 
       nsRect largest = r2.GetLargestRectangle();
-      if (largest.width * largest.height != tests[i].expectedArea) {
-        fail("Did not successfully find largest rectangle in two-rect-subtract region on iteration %d", i);
-        success = false;
-      }
+      EXPECT_TRUE(largest.width * largest.height == tests[i].expectedArea) <<
+        "Did not successfully find largest rectangle in two-rect-subtract region on iteration " << i;
     }
-    return success;
   }
-  static bool TestContainsSpecifiedRect() {
-    nsRegion r(nsRect(0, 0, 100, 100));
-    r.Or(r, nsRect(0, 300, 50, 50));
-    if (!r.GetLargestRectangle(nsRect(0, 300, 10, 10)).IsEqualInterior(nsRect(0, 300, 50, 50))) {
-      fail("Chose wrong rectangle");
-      return false;
-    }
-    return true;
-  }
-  static bool TestContainsSpecifiedOverflowingRect() {
+  static void TestContainsSpecifiedRect() {
     nsRegion r(nsRect(0, 0, 100, 100));
     r.Or(r, nsRect(0, 300, 50, 50));
-    if (!r.GetLargestRectangle(nsRect(0, 290, 10, 20)).IsEqualInterior(nsRect(0, 300, 50, 50))) {
-      fail("Chose wrong rectangle");
-      return false;
-    }
-    return true;
+    EXPECT_TRUE(r.GetLargestRectangle(nsRect(0, 300, 10, 10)).IsEqualInterior(nsRect(0, 300, 50, 50))) <<
+      "Chose wrong rectangle";
   }
-public:
-  static bool Test() {
-    if (!TestSingleRect(nsRect(0, 52, 720, 480)) ||
-        !TestSingleRect(nsRect(-20, 40, 50, 20)) ||
-        !TestSingleRect(nsRect(-20, 40, 10, 8)) ||
-        !TestSingleRect(nsRect(-20, -40, 10, 8)) ||
-        !TestSingleRect(nsRect(-10, -10, 20, 20)))
-      return false;
-    if (!TestNonRectangular())
-      return false;
-    if (!TwoRectTest())
-      return false;
-    if (!TestContainsSpecifiedRect())
-      return false;
-    if (!TestContainsSpecifiedOverflowingRect())
-      return false;
-    passed("TestLargestRegion");
-    return true;
+  static void TestContainsSpecifiedOverflowingRect() {
+    nsRegion r(nsRect(0, 0, 100, 100));
+    r.Or(r, nsRect(0, 300, 50, 50));
+    EXPECT_TRUE(r.GetLargestRectangle(nsRect(0, 290, 10, 20)).IsEqualInterior(nsRect(0, 300, 50, 50))) <<
+      "Chose wrong rectangle";
   }
 };
 
-int main(int argc, char** argv) {
-  ScopedXPCOM xpcom("TestRegion");
-  if (xpcom.failed())
-    return -1;
-  if (!TestLargestRegion::Test())
-    return -1;
-  return 0;
+TEST(Gfx, RegionSingleRect) {
+  TestLargestRegion::TestSingleRect(nsRect(0, 52, 720, 480));
+  TestLargestRegion::TestSingleRect(nsRect(-20, 40, 50, 20));
+  TestLargestRegion::TestSingleRect(nsRect(-20, 40, 10, 8));
+  TestLargestRegion::TestSingleRect(nsRect(-20, -40, 10, 8));
+  TestLargestRegion::TestSingleRect(nsRect(-10, -10, 20, 20));
+}
+
+TEST(Gfx, RegionNonRectangular) {
+  TestLargestRegion::TestNonRectangular();
 }
+
+TEST(Gfx, RegionTwoRectTest) {
+  TestLargestRegion::TwoRectTest();
+}
+
+TEST(Gfx, RegionContainsSpecifiedRect) {
+  TestLargestRegion::TestContainsSpecifiedRect();
+}
+
+TEST(Gfx, RegionTestContainsSpecifiedOverflowingRect) {
+  TestLargestRegion::TestContainsSpecifiedOverflowingRect();
+}
+
rename from gfx/tests/gfxFontSelectionTest.cpp
rename to gfx/tests/gtest/gfxFontSelectionTest.cpp
--- a/gfx/tests/gfxFontSelectionTest.cpp
+++ b/gfx/tests/gtest/gfxFontSelectionTest.cpp
@@ -1,34 +1,28 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "gtest/gtest.h"
+
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "mozilla/Preferences.h"
 
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
-#if defined(XP_MACOSX)
-#include "gfxTestCocoaHelper.h"
-#endif
-
-#ifdef MOZ_WIDGET_GTK
-#include "gtk/gtk.h"
-#endif
-
 using namespace mozilla;
 
 enum {
     S_UTF8 = 0,
     S_ASCII = 1
 };
 
 class FrameTextRunCache;
@@ -117,17 +111,17 @@ struct TestEntry {
             }
 
             return true;
         }
 
         nsCString fontName;
         LiteralArray glyphs;
     };
-    
+
     void SetRTL()
     {
         isRTL = true;
     }
 
     // empty/NULL fontName means ignore font name
     void Expect (const char *platform,
                  const char *fontName,
@@ -181,82 +175,80 @@ struct TestEntry {
 
     int stringType;
     const char *string;
     bool isRTL;
 
     nsTArray<ExpectItem> expectItems;
 };
 
-nsTArray<TestEntry> testList;
-
-already_AddRefed<gfxContext>
+static already_AddRefed<gfxContext>
 MakeContext ()
 {
     const int size = 200;
 
     nsRefPtr<gfxASurface> surface;
 
     surface = gfxPlatform::GetPlatform()->
         CreateOffscreenSurface(gfxIntSize(size, size),
                                gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
-    gfxContext *ctx = new gfxContext(surface);
-    NS_IF_ADDREF(ctx);
-    return ctx;
+    nsRefPtr<gfxContext> ctx = new gfxContext(surface);
+    return ctx.forget();
 }
 
 TestEntry*
-AddTest (const char *utf8FamilyString,
+AddTest (nsTArray<TestEntry>& testList,
+         const char *utf8FamilyString,
          const gfxFontStyle& fontStyle,
          int stringType,
          const char *string)
 {
     TestEntry te (utf8FamilyString,
                   fontStyle,
                   stringType,
                   string);
 
     testList.AppendElement(te);
 
     return &(testList[testList.Length()-1]);
 }
 
-void SetupTests();
-
 void
 DumpStore (gfxFontTestStore *store) {
     if (store->items.Length() == 0) {
         printf ("(empty)\n");
     }
 
     for (uint32_t i = 0;
          i < store->items.Length();
          i++)
     {
-        printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(store->items[i].platformFont).get());
+        printf ("Run[% 2d]: '%s' ", i, store->items[i].platformFont.BeginReading());
 
         for (int j = 0; j < store->items[i].num_glyphs; j++)
             printf ("%d ", int(store->items[i].glyphs[j].index));
 
         printf ("\n");
     }
 }
 
 void
 DumpTestExpect (TestEntry *test) {
     for (uint32_t i = 0; i < test->expectItems.Length(); i++) {
-        printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(test->expectItems[i].fontName).get());
+        printf ("Run[% 2d]: '%s' ", i, test->expectItems[i].fontName.BeginReading());
         for (uint32_t j = 0; j < test->expectItems[i].glyphs.data.Length(); j++)
             printf ("%d ", int(test->expectItems[i].glyphs.data[j]));
 
         printf ("\n");
     }
 }
 
-bool
+void SetupTests(nsTArray<TestEntry>& testList);
+
+static bool
 RunTest (TestEntry *test, gfxContext *ctx) {
     nsRefPtr<gfxFontGroup> fontGroup;
 
     fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle, nullptr);
 
     nsAutoPtr<gfxTextRun> textRun;
     gfxTextRunFactory::Parameters params = {
       ctx, nullptr, nullptr, nullptr, 0, 60
@@ -272,83 +264,51 @@ RunTest (TestEntry *test, gfxContext *ct
         textRun = fontGroup->MakeTextRun(reinterpret_cast<const uint8_t*>(test->string), length, &params, flags);
     } else {
         NS_ConvertUTF8toUTF16 str(nsDependentCString(test->string));
         length = str.Length();
         textRun = fontGroup->MakeTextRun(str.get(), length, &params, flags);
     }
 
     gfxFontTestStore::NewStore();
-    textRun->Draw(ctx, gfxPoint(0,0), 0, length, nullptr, nullptr);
+    textRun->Draw(ctx, gfxPoint(0,0), gfxFont::GLYPH_FILL, 0, length, nullptr, nullptr, nullptr);
     gfxFontTestStore *s = gfxFontTestStore::CurrentStore();
 
-    gTextRunCache->RemoveTextRun(textRun);
-
     if (!test->Check(s)) {
         DumpStore(s);
         printf ("  expected:\n");
         DumpTestExpect(test);
+        gfxFontTestStore::DeleteStore();
         return false;
     }
 
+    gfxFontTestStore::DeleteStore();
+
     return true;
 }
 
-int
-main (int argc, char **argv) {
+TEST(Gfx, FontSelection) {
     int passed = 0;
     int failed = 0;
 
-#ifdef MOZ_WIDGET_GTK
-    gtk_init(&argc, &argv); 
-#endif
-#ifdef XP_MACOSX
-    CocoaPoolInit();
-#endif
-
-    // Initialize XPCOM
-    nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv))
-        return -1;
-
-    if (!gfxPlatform::GetPlatform())
-        return -1;
-
-    // let's get all the xpcom goop out of the system
-    fflush (stderr);
-    fflush (stdout);
-
-    // don't need to query, we might need to set up some prefs later
-    if (0) {
-        nsresult rv;
-
-        nsAdoptingCString str = Preferences::GetCString("font.name.sans-serif.x-western");
-        printf ("sans-serif.x-western: %s\n", nsPromiseFlatCString(str).get());
-    }
-
     // set up the tests
-    SetupTests();
+    nsTArray<TestEntry> testList;
+    SetupTests(testList);
 
     nsRefPtr<gfxContext> context = MakeContext();
 
-    for (uint test = 0;
+    for (uint32_t test = 0;
          test < testList.Length();
          test++)
     {
-        printf ("==== Test %d\n", test);
         bool result = RunTest (&testList[test], context);
         if (result) {
-            printf ("Test %d succeeded\n", test);
             passed++;
         } else {
             printf ("Test %d failed\n", test);
             failed++;
         }
     }
-
-    printf ("PASSED: %d FAILED: %d\n", passed, failed);
-    fflush (stderr);
-    fflush (stdout);
 }
 
 // The tests themselves
 
 #include "gfxFontSelectionTests.h"
rename from gfx/tests/gfxFontSelectionTests.h
rename to gfx/tests/gtest/gfxFontSelectionTests.h
--- a/gfx/tests/gfxFontSelectionTests.h
+++ b/gfx/tests/gtest/gfxFontSelectionTests.h
@@ -63,143 +63,148 @@
  *   t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
  *   t->Expect ("win32", "MS UI Gothic", GLYPHS(19401));
  *   t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
  *
  */
 
 
 void
-SetupTests()
+SetupTests(nsTArray<TestEntry>& testList)
 {
     TestEntry *t;
 
     /* some common styles */
-    gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
-                                          NS_FONT_STRETCH_NORMAL,
+    gfxFontStyle style_western_normal_16 (mozilla::gfx::FONT_STYLE_NORMAL,
                                           400,
+                                          0,
                                           16.0,
                                           NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
                                           0.0,
-                                          false, false, false,
+                                          false, false,
                                           NS_LITERAL_STRING(""));
 
-    gfxFontStyle style_western_bold_16 (FONT_STYLE_NORMAL,
-                                        NS_FONT_STRETCH_NORMAL,
+    gfxFontStyle style_western_bold_16 (mozilla::gfx::FONT_STYLE_NORMAL,
                                         700,
+                                        0,
                                         16.0,
                                         NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
                                         0.0,
-                                        false, false, false,
+                                        false, false,
                                         NS_LITERAL_STRING(""));
 
     /* Test 0 */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_ASCII,
                  "ABCD");
 
     t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39));
     t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39));
     t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39));
 
     /* Test 1 */
-    t = AddTest ("verdana,sans-serif",
+    t = AddTest (testList, "verdana,sans-serif",
                  style_western_normal_16,
                  S_UTF8,
                  "foo\xe2\x80\x91""bar");
 
     t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
     t->Expect ("win32", "Arial Unicode MS", GLYPHS(3236));
     t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
 
     t->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82));
     t->Expect ("macosx", "Helvetica", GLYPHS(587));
     t->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85));
 
     /* Test 2 */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_bold_16,
                  S_ASCII,
                  "ABCD");
 
     t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39));
     t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39));
     t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39));
 
     /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_UTF8,
                  " \xd8\xaa\xd9\x85 ");
     t->SetRTL();
     t->Expect ("macosx", "Helvetica", GLYPHS(3));
-    t->Expect ("macosx", "AlBayan", GLYPHS(47));
+    t->Expect ("macosx", "ArialMT", GLYPHS(919, 993));
     t->Expect ("macosx", "Helvetica", GLYPHS(3));
     t->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3));
 
     /* Test 4: LTR Arabic with leading and trailing whitespace */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_UTF8,
                  " \xd9\x85\xd8\xaa ");
     t->Expect ("macosx", "Helvetica", GLYPHS(3));
-    t->Expect ("macosx", "AlBayan", GLYPHS(2, 47));
+    t->Expect ("macosx", "ArialMT", GLYPHS(993, 919));
     t->Expect ("macosx", "Helvetica", GLYPHS(3));
     t->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3));
 
     /* Test 5: RTL ASCII with leading whitespace */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_ASCII,
                  " ab");
     t->SetRTL();
     t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69));
     t->Expect ("win32", "Arial", GLYPHS(3, 68, 69));
     t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69));
 
     /* Test 6: RTL ASCII with trailing whitespace */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_ASCII,
                  "ab ");
     t->SetRTL();
     t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3));
     t->Expect ("win32", "Arial", GLYPHS(68, 69, 3));
     t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3));
 
     /* Test 7: Simple ASCII ligature */
     /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_ASCII,
                  "fi");
     t->Expect ("macosx", "Helvetica", GLYPHS(192));
     t->Expect ("win32", "Arial", GLYPHS(73, 76));
 
     /* Test 8: DEVANAGARI VOWEL I reordering */
     /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */
-    t = AddTest ("sans-serif",
+    t = AddTest (testList, "sans-serif",
                  style_western_normal_16,
                  S_UTF8,
                  "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319
     t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60));
     t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102));
 
+    // Disabled Test 9 & 10 because these appear to vary on mac
+
     /* Test 9: NWJ test */
-    t = AddTest ("Kartika",
-                 style_western_normal_16,
-                 S_UTF8,
-                 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
-    t->Expect ("win32", "Kartika", GLYPHS(332));
+    //t = AddTest (testList, "Kartika",
+    //             style_western_normal_16,
+    //             S_UTF8,
+    //             "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
+    //t->Expect ("macosx", "MalayalamMN", GLYPHS(360));
+    //t->Expect ("win32", "Kartika", GLYPHS(332));
 
     /* Test 10: NWJ fallback test */
     /* it isn't clear what we should actually do in this case.  Ideally
        we would have the same results as the previous test, but because
        we use sans-serif (i.e. Arial) CSS says we should should really
        use Arial for U+200D.
     */
-    t = AddTest ("sans-serif",
-                 style_western_normal_16,
-                 S_UTF8,
-                 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
-    t->Expect ("win32", "Kartika", GLYPHS(332));
+    //t = AddTest (testList, "sans-serif",
+    //             style_western_normal_16,
+    //             S_UTF8,
+    //             "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
+    // Disabled because these appear to vary
+    //t->Expect ("macosx", "MalayalamMN", GLYPHS(360));
+    //t->Expect ("win32", "Kartika", GLYPHS(332));
 }
rename from gfx/tests/gfxSurfaceRefCountTest.cpp
rename to gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
--- a/gfx/tests/gfxSurfaceRefCountTest.cpp
+++ b/gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
@@ -1,14 +1,16 @@
 #include <stdio.h>
 
+#include "gtest/gtest.h"
+
 #include "gfxASurface.h"
 #include "gfxImageSurface.h"
 
-#include "cairo.h"
+#include "cairo/cairo.h"
 
 int
 GetASurfaceRefCount(gfxASurface *s) {
     NS_ADDREF(s);
     return s->Release();
 }
 
 int
@@ -133,18 +135,17 @@ TestExistingSurface () {
 
     cairo_surface_destroy(cs);
 
     failures += CheckInt (destroyed, 1);
 
     return failures;
 }
 
-int
-main (int argc, char **argv) {
+TEST(Gfx, SurfaceRefCount) {
     int fail;
 
     fail = TestNewSurface();
-    fprintf (stderr, "TestNewSurface: %d failures\n", fail);
+    EXPECT_TRUE(fail == 0) << "TestNewSurface: " << fail << " failures";
     fail = TestExistingSurface();
-    fprintf (stderr, "TestExistingSurface: %d failures\n", fail);
+    EXPECT_TRUE(fail == 0) << "TestExistingSurface: " << fail << " failures";
 }
 
rename from gfx/tests/gfxTextRunPerfTest.cpp
rename to gfx/tests/gtest/gfxTextRunPerfTest.cpp
--- a/gfx/tests/gfxTextRunPerfTest.cpp
+++ b/gfx/tests/gtest/gfxTextRunPerfTest.cpp
@@ -1,76 +1,69 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "gtest/gtest.h"
+
 #include "mozilla/Util.h"
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "prinrval.h"
 
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
-#if defined(XP_MACOSX)
-#include "gfxTestCocoaHelper.h"
-#endif
-
-#ifdef MOZ_WIDGET_GTK
-#include "gtk/gtk.h"
-#endif
-
 using namespace mozilla;
 
 struct TestEntry {
   const char* mFamilies;
   const char* mString;
 };
 
 TestEntry testList[] = {
 #include "per-word-runs.h"
 { nullptr, nullptr } // terminator
 };
 
-already_AddRefed<gfxContext>
+static already_AddRefed<gfxContext>
 MakeContext ()
 {
     const int size = 200;
 
     nsRefPtr<gfxASurface> surface;
 
     surface = gfxPlatform::GetPlatform()->
         CreateOffscreenSurface(gfxIntSize(size, size),
                                gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
-    gfxContext *ctx = new gfxContext(surface);
-    NS_IF_ADDREF(ctx);
-    return ctx;
+    nsRefPtr<gfxContext> ctx = new gfxContext(surface);
+    return ctx.forget();
 }
 
-nsRefPtr<gfxFontGroup> fontGroup;
 const char* lastFamilies = nullptr;
 
-void
+static void
 RunTest (TestEntry *test, gfxContext *ctx) {
+    nsRefPtr<gfxFontGroup> fontGroup;
     if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
-        gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
-                                              NS_FONT_STRETCH_NORMAL,
+        gfxFontStyle style_western_normal_16 (mozilla::gfx::FONT_STYLE_NORMAL,
                                               400,
+                                              0,
                                               16.0,
                                               NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
                                               0.0,
-                                              false, false, false,
+                                              false, false,
                                               NS_LITERAL_STRING(""));
 
         fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr);
     }
 
     nsAutoPtr<gfxTextRun> textRun;
     uint32_t i;
     bool isASCII = true;
@@ -79,69 +72,49 @@ RunTest (TestEntry *test, gfxContext *ct
             isASCII = false;
         }
     }
     gfxTextRunFactory::Parameters params = {
       ctx, nullptr, nullptr, nullptr, 0, 60
     };
     uint32_t flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
     uint32_t length;
+    gfxFontTestStore::NewStore();
     if (isASCII) {
         flags |= gfxTextRunFactory::TEXT_IS_ASCII |
                  gfxTextRunFactory::TEXT_IS_8BIT;
         length = strlen(test->mString);
         textRun = fontGroup->MakeTextRun(reinterpret_cast<const uint8_t*>(test->mString), length, &params, flags);
     } else {
         NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
         length = str.Length();
         textRun = fontGroup->MakeTextRun(str.get(), length, &params, flags);
     }
 
     // Should we test drawing?
     // textRun->Draw(ctx, gfxPoint(0,0), 0, length, nullptr, nullptr, nullptr);
-    
+
     textRun->GetAdvanceWidth(0, length, nullptr);
+    gfxFontTestStore::DeleteStore();
 }
 
-uint32_t iterations = 20;
-
-int
-main (int argc, char **argv) {
-#ifdef MOZ_WIDGET_GTK
-    gtk_init(&argc, &argv); 
-#endif
-#ifdef XP_MACOSX
-    CocoaPoolInit();
-#endif
+uint32_t iterations = 1;
 
-    // Initialize XPCOM
-    nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv))
-        return -1; 
-
-    if (!gfxPlatform::GetPlatform())
-        return -1;
-
-    // let's get all the xpcom goop out of the system
-    fflush (stderr);
-    fflush (stdout);
-
+TEST(Gfx, TextRunPref) {
     nsRefPtr<gfxContext> context = MakeContext();
 
     // Start timing
     PRIntervalTime start = PR_IntervalNow();
 
     for (uint32_t i = 0; i < iterations; ++i) {
         for (uint test = 0;
              test < ArrayLength(testList) - 1;
              test++)
         {
             RunTest(&testList[test], context);
         }
     }
 
     PRIntervalTime end = PR_IntervalNow();
-    
+
     printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
 
-    fflush (stderr);
-    fflush (stdout);
 }
rename from gfx/tests/gfxWordCacheTest.cpp
rename to gfx/tests/gtest/gfxWordCacheTest.cpp
--- a/gfx/tests/gfxWordCacheTest.cpp
+++ b/gfx/tests/gtest/gfxWordCacheTest.cpp
@@ -1,35 +1,29 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "gtest/gtest.h"
+
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "prinrval.h"
 
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 #include "mozilla/Attributes.h"
 
-#if defined(XP_MACOSX)
-#include "gfxTestCocoaHelper.h"
-#endif
-
-#ifdef MOZ_WIDGET_GTK
-#include "gtk/gtk.h"
-#endif
-
 class FrameTextRunCache;
 
 static FrameTextRunCache *gTextRuns = nullptr;
 
 /*
  * Cache textruns and expire them after 3*10 seconds of no use.
  */
 class FrameTextRunCache MOZ_FINAL : public nsExpirationTracker<gfxTextRun,3> {
@@ -56,79 +50,60 @@ public:
 
 static gfxTextRun *
 MakeTextRun(const PRUnichar *aText, uint32_t aLength,
            gfxFontGroup *aFontGroup, const gfxFontGroup::Parameters* aParams,
            uint32_t aFlags)
 {
    nsAutoPtr<gfxTextRun> textRun;
    if (aLength == 0) {
-       textRun = aFontGroup->MakeEmptyTextRun(aParams, aFlags);
+       abort();
+       //textRun = aFontGroup->MakeEmptyTextRun(aParams, aFlags);
    } else if (aLength == 1 && aText[0] == ' ') {
-       textRun = aFontGroup->MakeSpaceTextRun(aParams, aFlags);
+       abort();
+       //textRun = aFontGroup->MakeSpaceTextRun(aParams, aFlags);
    } else {
        textRun = aFontGroup->MakeTextRun(aText, aLength, aParams, aFlags);
    }
    if (!textRun)
        return nullptr;
    nsresult rv = gTextRuns->AddObject(textRun);
    if (NS_FAILED(rv)) {
        gTextRuns->RemoveFromCache(textRun);
        return nullptr;
    }
    return textRun.forget();
 }
 
-already_AddRefed<gfxContext>
+static already_AddRefed<gfxContext>
 MakeContext ()
 {
    const int size = 200;
 
    nsRefPtr<gfxASurface> surface;
 
    surface = gfxPlatform::GetPlatform()->
        CreateOffscreenSurface(gfxIntSize(size, size),
                               gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
-   gfxContext *ctx = new gfxContext(surface);
-   NS_IF_ADDREF(ctx);
-   return ctx;
+   nsRefPtr<gfxContext> ctx = new gfxContext(surface);
+   return ctx.forget();
 }
 
-int
-main (int argc, char **argv) {
-#ifdef MOZ_WIDGET_GTK
-   gtk_init(&argc, &argv);
-#endif
-#ifdef XP_MACOSX
-   CocoaPoolInit();
-#endif
-
-   // Initialize XPCOM
-   nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-   if (NS_FAILED(rv))
-       return -1;
-
-   if (!gfxPlatform::GetPlatform())
-       return -1;
-
-   // let's get all the xpcom goop out of the system
-   fflush (stderr);
-   fflush (stdout);
-
+TEST(Gfx, WordCache) {
    gTextRuns = new FrameTextRunCache();
 
    nsRefPtr<gfxContext> ctx = MakeContext();
    {
-       gfxFontStyle style (FONT_STYLE_NORMAL,
-                           NS_FONT_STRETCH_NORMAL,
+       gfxFontStyle style (mozilla::gfx::FONT_STYLE_NORMAL,
                            139,
                            10.0,
+                           0,
                            NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
                            0.0,
-                           false, false, false,
+                           false, false,
                            NS_LITERAL_STRING(""));
 
        nsRefPtr<gfxFontGroup> fontGroup =
            gfxPlatform::GetPlatform()->CreateFontGroup(NS_LITERAL_STRING("Geneva, MS Sans Serif, Helvetica,serif"), &style, nullptr);
 
        gfxTextRunFactory::Parameters params = {
            ctx, nullptr, nullptr, nullptr, 0, 60
        };
@@ -147,11 +122,12 @@ main (int argc, char **argv) {
        // The second word is not in the cache 
        const char cString2[] = "\xd8\xaa\xd9\x85\n\xd8\xaa\xd8\x85 ";
        nsDependentCString cStr2(cString2);
        NS_ConvertUTF8toUTF16 str2(cStr2);
        gfxTextRun *tr2 = MakeTextRun(str2.get(), str2.Length(), fontGroup, &params, flags);
        tr2->GetAdvanceWidth(0, str2.Length(), nullptr);
    }
 
-   fflush (stderr);
-   fflush (stdout);
+   delete gTextRuns;
+   gTextRuns = nullptr;
+
 }
--- a/gfx/tests/gtest/moz.build
+++ b/gfx/tests/gtest/moz.build
@@ -4,22 +4,31 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MODULE = 'gfxtest'
 
 LIBRARY_NAME = 'gfxtest'
 
 GTEST_CPP_SOURCES += [
+    # Hangs on linux in ApplyGdkScreenFontOptions
+    #'gfxFontSelectionTest.cpp',
+    'gfxSurfaceRefCountTest.cpp',
+    # Test works but it doesn't assert anything
+    #'gfxTextRunPerfTest.cpp',
+    'gfxWordCacheTest.cpp',
     'TestAsyncPanZoomController.cpp',
     'TestLayers.cpp',
     'TestTiledLayerBuffer.cpp',
+    'TestRegion.cpp',
+    'TestColorNames.cpp',
 ]
 
 # Because of gkmedia on windows we wont find these
 # symbols in xul.dll.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'windows':
     GTEST_CPP_SOURCES += [
         'TestBase.cpp',
         'TestMoz2D.cpp',
+        'TestRect.cpp',
         'TestPoint.cpp',
         'TestScaling.cpp',
     ]
rename from gfx/tests/per-word-runs.h
rename to gfx/tests/gtest/per-word-runs.h
deleted file mode 100644
index 293721e05330afab5f1f79bc0eec75a2f08b6494..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 7f24a3d7d7d618cd82f252eee1ae50d87383aa65..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 612f4d58dc0ba9929833309a8639ef0501b18f69..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 5cf9667bcc3fcd3c466fcfbdcee6469f45413e86..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 8184276f8daeeeeb920cfd1139f14261a96df25e..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index fef9db4a57f937de8c91d1d534e00d62494f48b4..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index f9a1cf49c4868458efb9f067e10a87807227949b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 5e129fae4ce1cca7d1f9c7d4ccd9b5bbbe6a2c0c..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index cfbd03e1f783ff3e94e08522944718ab32cbd56d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
--- a/gfx/thebes/gfxFontTest.h
+++ b/gfx/thebes/gfxFontTest.h
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_FONT_TEST_H
 #define GFX_FONT_TEST_H
 
 #include "nsString.h"
 #include "nsTArray.h"
 
-#include "cairo.h"
+#include "cairo/cairo.h"
 
 #include "gfxFont.h"
 #include "gfxUserFontSet.h"
 
 struct gfxFontTestItem {
     gfxFontTestItem(const nsCString& fontName,
                     cairo_glyph_t *cglyphs, int nglyphs)
         : platformFont(fontName)