Bug 1315170 - gtestify dom/security/test/TestCSPParser.cpp. r=francois.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 04 Nov 2016 17:02:26 +1100
changeset 321323 ad907a673389fb1d6b7b9690d8ed57b77e2c5aa0
parent 321322 db20b5de138f842350bc8305c9a98e2bad8f94e3
child 321324 803d5895353dd7053a80b3fcd702a17aeff7aad2
push id83555
push usernnethercote@mozilla.com
push dateSun, 06 Nov 2016 23:14:13 +0000
treeherdermozilla-inbound@ad907a673389 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1315170
milestone52.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 1315170 - gtestify dom/security/test/TestCSPParser.cpp. r=francois.
dom/security/test/TestCSPParser.cpp
dom/security/test/gtest/TestCSPParser.cpp
dom/security/test/gtest/moz.build
dom/security/test/moz.build
testing/cppunittest.ini
rename from dom/security/test/TestCSPParser.cpp
rename to dom/security/test/gtest/TestCSPParser.cpp
--- a/dom/security/test/TestCSPParser.cpp
+++ b/dom/security/test/gtest/TestCSPParser.cpp
@@ -1,14 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 <string.h>
 #include <stdlib.h>
 
 #ifndef MOZILLA_INTERNAL_API
 // some of the includes make use of internal string types
 #define nsAString_h___
 #define nsString_h___
 #define nsStringFwd_h___
@@ -20,17 +22,16 @@ class nsAFlatCString;
 class nsAdoptingString;
 class nsAdoptingCString;
 class nsXPIDLString;
 template<class T> class nsReadingIterator;
 #endif
 
 #include "nsIContentSecurityPolicy.h"
 #include "nsNetUtil.h"
-#include "TestHarness.h"
 #include "nsIScriptSecurityManager.h"
 #include "mozilla/dom/nsCSPContext.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 
 #ifndef MOZILLA_INTERNAL_API
 #undef nsString_h___
 #undef nsAString_h___
@@ -85,17 +86,17 @@ static const uint32_t kMaxPolicyLength =
 struct PolicyTest
 {
   char policy[kMaxPolicyLength];
   char expectedResult[kMaxPolicyLength];
 };
 
 nsresult runTest(uint32_t aExpectedPolicyCount, // this should be 0 for policies which should fail to parse
                  const char* aPolicy,
-                 const char* aExpextedResult) {
+                 const char* aExpectedResult) {
 
   nsresult rv;
   nsCOMPtr<nsIScriptSecurityManager> secman =
     do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // we init the csp with http://www.selfuri.com
   nsCOMPtr<nsIURI> selfURI;
@@ -130,37 +131,41 @@ nsresult runTest(uint32_t aExpectedPolic
     return NS_OK;
   }
 
   // verify that the expected number of policies exists
   uint32_t actualPolicyCount;
   rv = csp->GetPolicyCount(&actualPolicyCount);
   NS_ENSURE_SUCCESS(rv, rv);
   if (actualPolicyCount != aExpectedPolicyCount) {
-    fail("Actual policy count not equal to expected policy count (%d != %d) for policy: %s",
-          actualPolicyCount, aExpectedPolicyCount, aPolicy);
+    EXPECT_TRUE(false) <<
+      "Actual policy count not equal to expected policy count (" <<
+      actualPolicyCount << " != " << aExpectedPolicyCount <<
+      ") for policy: " << aPolicy;
     return NS_ERROR_UNEXPECTED;
   }
 
   // if the expected policy count is 0, we can return, because
   // we can not compare any output anyway. Used when parsing
   // errornous policies.
   if (aExpectedPolicyCount == 0) {
     return NS_OK;
   }
 
   // compare the parsed policy against the expected result
   nsString parsedPolicyStr;
   // checking policy at index 0, which is the one what we appended.
   rv = csp->GetPolicyString(0, parsedPolicyStr);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!NS_ConvertUTF16toUTF8(parsedPolicyStr).EqualsASCII(aExpextedResult)) {
-    fail("Actual policy does not match expected policy  (%s != %s)",
-          NS_ConvertUTF16toUTF8(parsedPolicyStr).get(), aExpextedResult);
+  if (!NS_ConvertUTF16toUTF8(parsedPolicyStr).EqualsASCII(aExpectedResult)) {
+    EXPECT_TRUE(false) <<
+      "Actual policy does not match expected policy (" <<
+      NS_ConvertUTF16toUTF8(parsedPolicyStr).get() << " != " <<
+      aExpectedResult << ")";
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
 // ============================= run Tests ========================
 
@@ -185,18 +190,18 @@ nsresult runTestSuite(const PolicyTest* 
     prefs->SetBoolPref("security.csp.experimentalEnabled", experimentalEnabledCache);
   }
 
   return NS_OK;
 }
 
 // ============================= TestDirectives ========================
 
-nsresult TestDirectives() {
-
+TEST(CSPParser, Directives)
+{
   static const PolicyTest policies[] =
   {
     { "default-src http://www.example.com",
       "default-src http://www.example.com" },
     { "script-src http://www.example.com",
       "script-src http://www.example.com" },
     { "object-src http://www.example.com",
       "object-src http://www.example.com" },
@@ -220,23 +225,23 @@ nsresult TestDirectives() {
       "script-src 'sha256-siVR8vAcqP06h2ppeNwqgjr0yZ6yned4X2VF84j4GmI='" },
     { "referrer no-referrer",
       "referrer no-referrer" },
     { "require-sri-for script style",
       "require-sri-for script style"}
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestKeywords ========================
 
-nsresult TestKeywords() {
-
+TEST(CSPParser, Keywords)
+{
   static const PolicyTest policies[] =
   {
     { "script-src 'self'",
       "script-src http://www.selfuri.com" },
     { "script-src 'unsafe-inline'",
       "script-src 'unsafe-inline'" },
     { "script-src 'unsafe-eval'",
       "script-src 'unsafe-eval'" },
@@ -244,23 +249,23 @@ nsresult TestKeywords() {
       "script-src 'unsafe-inline' 'unsafe-eval'" },
     { "script-src 'none'",
       "script-src 'none'" },
     { "img-src 'none'; script-src 'unsafe-eval' 'unsafe-inline'; default-src 'self'",
       "img-src 'none'; script-src 'unsafe-eval' 'unsafe-inline'; default-src http://www.selfuri.com" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestIgnoreUpperLowerCasePolicies ========================
 
-nsresult TestIgnoreUpperLowerCasePolicies() {
-
+TEST(CSPParser, IgnoreUpperLowerCasePolicies)
+{
   static const PolicyTest policies[] =
   {
     { "script-src 'SELF'",
       "script-src http://www.selfuri.com" },
     { "sCriPt-src 'Unsafe-Inline'",
       "script-src 'unsafe-inline'" },
     { "SCRIPT-src 'unsafe-eval'",
       "script-src 'unsafe-eval'" },
@@ -290,23 +295,23 @@ nsresult TestIgnoreUpperLowerCasePolicie
       "upgrade-insecure-requests" },
     { "sanDBox alloW-foRMs",
       "sandbox allow-forms"},
     { "require-SRI-for sCript stYle",
       "require-sri-for script style"},
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestPaths ========================
 
-nsresult TestPaths() {
-
+TEST(CSPParser, Paths)
+{
   static const PolicyTest policies[] =
   {
     { "script-src http://www.example.com",
       "script-src http://www.example.com" },
     { "script-src http://www.example.com/",
       "script-src http://www.example.com/" },
     { "script-src http://www.example.com/path-1",
       "script-src http://www.example.com/path-1" },
@@ -388,23 +393,23 @@ nsresult TestPaths() {
       "connect-src http://test.com/pathIncludingAz19-._~!$&'()*+=:@" },
     { "script-src http://www.example.com:88/.js",
       "script-src http://www.example.com:88/.js" },
     { "script-src https://foo.com/_abc/abc_/_/_a_b_c_",
       "script-src https://foo.com/_abc/abc_/_/_a_b_c_" }
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestSimplePolicies ========================
 
-nsresult TestSimplePolicies() {
-
+TEST(CSPParser, SimplePolicies)
+{
   static const PolicyTest policies[] =
   {
     { "default-src *",
       "default-src *" },
     { "default-src https:",
       "default-src https:" },
     { "default-src https://*",
       "default-src https://*" },
@@ -466,23 +471,23 @@ nsresult TestSimplePolicies() {
       "upgrade-insecure-requests" },
     { "upgrade-insecure-requests https:",
       "upgrade-insecure-requests" },
     { "sandbox allow-scripts allow-forms  ",
       "sandbox allow-scripts allow-forms" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestPoliciesWithInvalidSrc ========================
 
-nsresult TestPoliciesWithInvalidSrc() {
-
+TEST(CSPParser, PoliciesWithInvalidSrc)
+{
   static const PolicyTest policies[] =
   {
     { "script-src 'self'; SCRIPT-SRC http://www.example.com",
       "script-src http://www.selfuri.com" },
     { "script-src 'none' test.com; script-src example.com",
       "script-src http://test.com" },
     { "default-src **",
       "default-src 'none'" },
@@ -533,23 +538,23 @@ nsresult TestPoliciesWithInvalidSrc() {
     { "require-SRI-for script elephants",
       "require-sri-for script"},
     { "sandbox    foo",
       "sandbox"},
   };
 
   // amount of tests - 1, because the latest should be ignored.
   uint32_t policyCount = (sizeof(policies) / sizeof(PolicyTest)) -1;
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestBadPolicies ========================
 
-nsresult TestBadPolicies() {
-
+TEST(CSPParser, BadPolicies)
+{
   static const PolicyTest policies[] =
   {
     { "script-sr 'self", "" },
     { "", "" },
     { "; ; ; ; ; ; ;", "" },
     { "defaut-src asdf", "" },
     { "default-src: aaa", "" },
     { "asdf http://test.com", ""},
@@ -557,23 +562,23 @@ nsresult TestBadPolicies() {
     { "referrer foo", ""},
     { "require-sri-for", ""},
     { "require-sri-for foo", ""},
     { "report-uri", ""},
     { "report-uri http://:foo", ""},
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 0);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 0)));
 }
 
 // ============================= TestGoodGeneratedPolicies ========================
 
-nsresult TestGoodGeneratedPolicies() {
-
+TEST(CSPParser, GoodGeneratedPolicies)
+{
   static const PolicyTest policies[] =
   {
     { "default-src 'self'; img-src *",
       "default-src http://www.selfuri.com; img-src *" },
     { "report-uri /policy",
       "report-uri http://www.selfuri.com/policy"},
     { "img-src *",
       "img-src *" },
@@ -791,23 +796,23 @@ nsresult TestGoodGeneratedPolicies() {
       "frame-ancestors http://self.com/bar" },
     { "default-src 'self'; frame-ancestors 'self'",
       "default-src http://www.selfuri.com; frame-ancestors http://www.selfuri.com" },
     { "frame-ancestors http://bar.com/foo.png",
       "frame-ancestors http://bar.com/foo.png" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestBadGeneratedPolicies ========================
 
-nsresult TestBadGeneratedPolicies() {
-
+TEST(CSPParser, BadGeneratedPolicies)
+{
   static const PolicyTest policies[] =
   {
     { "foo.*.bar", ""},
     { "foo!bar.com", ""},
     { "x.*.a.com", ""},
     { "a#2-c.com", ""},
     { "http://foo.com:bar.com:23", ""},
     { "f!oo.bar", ""},
@@ -817,22 +822,23 @@ nsresult TestBadGeneratedPolicies() {
     { "*a", ""},
     { "http://username:password@self.com/foo", ""},
     { "http://other:pass1@self.com/foo", ""},
     { "http://user1:pass1@self.com/foo", ""},
     { "http://username:password@self.com/bar", ""},
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 0);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 0)));
 }
 
 // ============ TestGoodGeneratedPoliciesForPathHandling ============
 
-nsresult TestGoodGeneratedPoliciesForPathHandling() {
+TEST(CSPParser, GoodGeneratedPoliciesForPathHandling)
+{
   // Once bug 808292 (Implement path-level host-source matching to CSP)
   // lands we have to update the expected output to include the parsed path
 
   static const PolicyTest policies[] =
   {
     { "img-src http://test1.example.com",
       "img-src http://test1.example.com" },
     { "img-src http://test1.example.com/",
@@ -939,23 +945,23 @@ nsresult TestGoodGeneratedPoliciesForPat
       "img-src https://test1.example.com:80/abc/def/ghi//" },
     { "img-src https://test1.example.com/abc////////////def/",
       "img-src https://test1.example.com/abc////////////def/" },
     { "img-src https://test1.example.com/abc////////////",
       "img-src https://test1.example.com/abc////////////" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============ TestBadGeneratedPoliciesForPathHandling ============
 
-nsresult TestBadGeneratedPoliciesForPathHandling() {
-
+TEST(CSPParser, BadGeneratedPoliciesForPathHandling)
+{
   static const PolicyTest policies[] =
   {
     { "img-src test1.example.com:88path-1/",
       "img-src 'none'" },
     { "img-src test1.example.com:80.js",
       "img-src 'none'" },
     { "img-src test1.example.com:*.js",
       "img-src 'none'" },
@@ -965,94 +971,90 @@ nsresult TestBadGeneratedPoliciesForPath
       "img-src 'none'" },
     { "img-src http://test1.example.com:80//",
       "img-src 'none'" },
     { "img-src http://test1.example.com:80abc",
       "img-src 'none'" },
   };
 
   uint32_t policyCount = sizeof(policies) / sizeof(PolicyTest);
-  return runTestSuite(policies, policyCount, 1);
+  ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(policies, policyCount, 1)));
 }
 
 // ============================= TestFuzzyPolicies ========================
 
 // Use a policy, eliminate one character at a time,
 // and feed it as input to the parser.
 
-nsresult TestShorteningPolicies() {
-
+TEST(CSPParser, ShorteningPolicies)
+{
   char pol[] = "default-src http://www.sub1.sub2.example.com:88/path1/path2/ 'unsafe-inline' 'none'";
   uint32_t len = static_cast<uint32_t>(sizeof(pol));
 
   PolicyTest testPol[1];
   memset(&testPol[0].policy, '\0', kMaxPolicyLength * sizeof(char));
-  nsresult rv = NS_OK;
 
   while (--len) {
     memset(&testPol[0].policy, '\0', kMaxPolicyLength * sizeof(char));
     memcpy(&testPol[0].policy, &pol, len * sizeof(char));
-    rv = runTestSuite(testPol, 1, kFuzzyExpectedPolicyCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(testPol, 1,
+                                          kFuzzyExpectedPolicyCount)));
   }
-  return NS_OK;
 }
 
 // ============================= TestFuzzyPolicies ========================
 
 // We generate kFuzzyRuns inputs by (pseudo) randomly picking from the 128
 // ASCII characters; feed them to the parser and verfy that the parser
 // handles the input gracefully.
 //
 // Please note, that by using srand(0) we get deterministic results!
 
 #if RUN_OFFLINE_TESTS
 
-nsresult TestFuzzyPolicies() {
-
+TEST(CSPParser, FuzzyPolicies)
+{
   // init srand with 0 so we get same results
   srand(0);
 
   PolicyTest testPol[1];
   memset(&testPol[0].policy, '\0', kMaxPolicyLength);
-  nsresult rv = NS_OK;
 
   for (uint32_t index = 0; index < kFuzzyRuns; index++) {
     // randomly select the length of the next policy
     uint32_t polLength = rand() % kMaxPolicyLength;
     // reset memory of the policy string
     memset(&testPol[0].policy, '\0', kMaxPolicyLength * sizeof(char));
 
     for (uint32_t i = 0; i < polLength; i++) {
       // fill the policy array with random ASCII chars
       testPol[0].policy[i] = static_cast<char>(rand() % 128);
     }
-    rv = runTestSuite(testPol, 1, kFuzzyExpectedPolicyCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(testPol, 1,
+                                          kFuzzyExpectedPolicyCount)));
   }
-  return NS_OK;
 }
 
 #endif
+
 // ============================= TestFuzzyPoliciesIncDir ========================
 
 // In a similar fashion as in TestFuzzyPolicies, we again (pseudo) randomly
 // generate input for the parser, but this time also include a valid directive
 // followed by the random input.
 
 #if RUN_OFFLINE_TESTS
 
-nsresult TestFuzzyPoliciesIncDir() {
-
+TEST(CSPParser, FuzzyPoliciesIncDir)
+{
   // init srand with 0 so we get same results
   srand(0);
 
   PolicyTest testPol[1];
   memset(&testPol[0].policy, '\0', kMaxPolicyLength);
-  nsresult rv = NS_OK;
 
   char defaultSrc[] = "default-src ";
   int defaultSrcLen = sizeof(defaultSrc) - 1;
   // copy default-src into the policy array
   memcpy(&testPol[0].policy, &defaultSrc, (defaultSrcLen * sizeof(char)));
 
   for (uint32_t index = 0; index < kFuzzyRuns; index++) {
     // randomly select the length of the next policy
@@ -1061,44 +1063,42 @@ nsresult TestFuzzyPoliciesIncDir() {
     memset((&(testPol[0].policy) + (defaultSrcLen * sizeof(char))),
            '\0', (kMaxPolicyLength - defaultSrcLen) * sizeof(char));
 
     // do not start at index 0 so we do not overwrite 'default-src'
     for (uint32_t i = defaultSrcLen; i < polLength; i++) {
       // fill the policy array with random ASCII chars
       testPol[0].policy[i] = static_cast<char>(rand() % 128);
     }
-    rv = runTestSuite(testPol, 1, kFuzzyExpectedPolicyCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(testPol, 1,
+                                          kFuzzyExpectedPolicyCount)));
   }
-  return NS_OK;
 }
 
 #endif
 
 // ============================= TestFuzzyPoliciesIncDirLimASCII ==============
 
 // Same as TestFuzzyPoliciesIncDir() but using limited ASCII,
 // which represents more likely input.
 
 #if RUN_OFFLINE_TESTS
 
-nsresult TestFuzzyPoliciesIncDirLimASCII() {
-
+TEST(CSPParser, FuzzyPoliciesIncDirLimASCII)
+{
   char input[] = "1234567890" \
                  "abcdefghijklmnopqrstuvwxyz" \
                  "ABCDEFGHIJKLMNOPQRSTUVWZYZ" \
                  "!@#^&*()-+_=";
 
   // init srand with 0 so we get same results
   srand(0);
 
   PolicyTest testPol[1];
   memset(&testPol[0].policy, '\0', kMaxPolicyLength);
-  nsresult rv = NS_OK;
 
   char defaultSrc[] = "default-src ";
   int defaultSrcLen = sizeof(defaultSrc) - 1;
   // copy default-src into the policy array
   memcpy(&testPol[0].policy, &defaultSrc, (defaultSrcLen * sizeof(char)));
 
   for (uint32_t index = 0; index < kFuzzyRuns; index++) {
     // randomly select the length of the next policy
@@ -1108,45 +1108,14 @@ nsresult TestFuzzyPoliciesIncDirLimASCII
            '\0', (kMaxPolicyLength - defaultSrcLen) * sizeof(char));
 
     // do not start at index 0 so we do not overwrite 'default-src'
     for (uint32_t i = defaultSrcLen; i < polLength; i++) {
       // fill the policy array with chars from the pre-defined input
       uint32_t inputIndex = rand() % sizeof(input);
       testPol[0].policy[i] = input[inputIndex];
     }
-    rv = runTestSuite(testPol, 1, kFuzzyExpectedPolicyCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    ASSERT_TRUE(NS_SUCCEEDED(runTestSuite(testPol, 1,
+                                          kFuzzyExpectedPolicyCount)));
   }
-  return NS_OK;
 }
 #endif
 
-// ============================= Run the tests ========================
-
-int main(int argc, char** argv) {
-
-  ScopedXPCOM xpcom("ContentSecurityPolicyParser");
-  if (xpcom.failed()) {
-    return 1;
-  }
-
-  if (NS_FAILED(TestDirectives()))                           { return 1; }
-  if (NS_FAILED(TestKeywords()))                             { return 1; }
-  if (NS_FAILED(TestIgnoreUpperLowerCasePolicies()))         { return 1; }
-  if (NS_FAILED(TestPaths()))                                { return 1; }
-  if (NS_FAILED(TestSimplePolicies()))                       { return 1; }
-  if (NS_FAILED(TestPoliciesWithInvalidSrc()))               { return 1; }
-  if (NS_FAILED(TestBadPolicies()))                          { return 1; }
-  if (NS_FAILED(TestGoodGeneratedPolicies()))                { return 1; }
-  if (NS_FAILED(TestBadGeneratedPolicies()))                 { return 1; }
-  if (NS_FAILED(TestGoodGeneratedPoliciesForPathHandling())) { return 1; }
-  if (NS_FAILED(TestBadGeneratedPoliciesForPathHandling()))  { return 1; }
-  if (NS_FAILED(TestShorteningPolicies()))                   { return 1; }
-
-#if RUN_OFFLINE_TESTS
-  if (NS_FAILED(TestFuzzyPolicies()))                        { return 1; }
-  if (NS_FAILED(TestFuzzyPoliciesIncDir()))                  { return 1; }
-  if (NS_FAILED(TestFuzzyPoliciesIncDirLimASCII()))          { return 1; }
-#endif
-
-  return 0;
-}
new file mode 100644
--- /dev/null
+++ b/dom/security/test/gtest/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+UNIFIED_SOURCES += [
+     'TestCSPParser.cpp',
+]
+
+FINAL_LIBRARY = 'xul-gtest'
--- a/dom/security/test/moz.build
+++ b/dom/security/test/moz.build
@@ -3,19 +3,19 @@
 # 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/.
 
 XPCSHELL_TESTS_MANIFESTS += [
     'unit/xpcshell.ini',
 ]
 
-GeckoCppUnitTests([
-     'TestCSPParser',
-])
+TEST_DIRS += [
+    'gtest',
+]
 
 MOCHITEST_MANIFESTS += [
     'cors/mochitest.ini',
     'csp/mochitest.ini',
     'general/mochitest.ini',
     'mixedcontentblocker/mochitest.ini',
     'sri/mochitest.ini',
 ]
--- a/testing/cppunittest.ini
+++ b/testing/cppunittest.ini
@@ -6,18 +6,16 @@
 [TestAudioBuffers]
 skip-if = os == 'b2g'  # Bug 1062937
 [TestAudioMixer]
 [TestBinarySearch]
 [TestBind]
 [TestBloomFilter]
 [TestCOM]
 skip-if = os != 'win'
-[TestCSPParser]
-skip-if = os == 'b2g' || (os == 'android' && debug) # Bug 1054246
 [TestCasting]
 [TestCeilingFloor]
 [TestCertDB]
 [TestCheckedInt]
 [TestCookie]
 [TestCountPopulation]
 [TestCountZeroes]
 [TestDeadlockDetector]