Bug 1211636 - use ToInteger64 in PopulateFromSuffix. r=bholley
authorYoshi Huang <allstars.chh@mozilla.com>
Tue, 06 Oct 2015 15:36:10 +0800
changeset 266572 f60288aebcc7450d7297c77bc63e499c923444f8
parent 266571 e50f1d523996e5529088e502d966dd9dee297671
child 266573 84d1a9cdd3389fc283d388bc194ed4ab22e71ff6
push id29494
push userkwierso@gmail.com
push dateWed, 07 Oct 2015 18:04:30 +0000
treeherdermozilla-central@1e1fa696e2b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1211636, 100644
milestone44.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 1211636 - use ToInteger64 in PopulateFromSuffix. r=bholley From 76c9c3f887d6bce8b15abd37d5921887a187e18d Mon Sep 17 00:00:00 2001 --- caps/BasePrincipal.cpp | 16 ++++++------- caps/moz.build | 3 +++ caps/tests/gtest/TestOriginAttributes.cpp | 37 +++++++++++++++++++++++++++++++ caps/tests/gtest/moz.build | 13 +++++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 caps/tests/gtest/TestOriginAttributes.cpp create mode 100644 caps/tests/gtest/moz.build
caps/BasePrincipal.cpp
caps/moz.build
caps/tests/gtest/TestOriginAttributes.cpp
caps/tests/gtest/moz.build
--- a/caps/BasePrincipal.cpp
+++ b/caps/BasePrincipal.cpp
@@ -115,20 +115,20 @@ public:
     MOZ_ASSERT(aOriginAttributes);
   }
 
   bool URLParamsIterator(const nsString& aName,
                          const nsString& aValue) override
   {
     if (aName.EqualsLiteral("appId")) {
       nsresult rv;
-      mOriginAttributes->mAppId = aValue.ToInteger(&rv);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return false;
-      }
+      int64_t val  = aValue.ToInteger64(&rv);
+      NS_ENSURE_SUCCESS(rv, false);
+      NS_ENSURE_TRUE(val <= UINT32_MAX, false);
+      mOriginAttributes->mAppId = static_cast<uint32_t>(val);
 
       return true;
     }
 
     if (aName.EqualsLiteral("inBrowser")) {
       if (!aValue.EqualsLiteral("1")) {
         return false;
       }
@@ -140,20 +140,20 @@ public:
     if (aName.EqualsLiteral("addonId")) {
       MOZ_RELEASE_ASSERT(mOriginAttributes->mAddonId.IsEmpty());
       mOriginAttributes->mAddonId.Assign(aValue);
       return true;
     }
 
     if (aName.EqualsLiteral("userContextId")) {
       nsresult rv;
-      mOriginAttributes->mUserContextId = aValue.ToInteger(&rv);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return false;
-      }
+      int64_t val  = aValue.ToInteger64(&rv);
+      NS_ENSURE_SUCCESS(rv, false);
+      NS_ENSURE_TRUE(val <= UINT32_MAX, false);
+      mOriginAttributes->mUserContextId  = static_cast<uint32_t>(val);
 
       return true;
     }
 
     if (aName.EqualsLiteral("signedPkg")) {
       MOZ_RELEASE_ASSERT(mOriginAttributes->mSignedPkg.IsEmpty());
       mOriginAttributes->mSignedPkg.Assign(aValue);
       return true;
--- a/caps/moz.build
+++ b/caps/moz.build
@@ -44,11 +44,14 @@ UNIFIED_SOURCES += [
 ]
 
 LOCAL_INCLUDES += [
     '/docshell/base',
     '/dom/base',
     '/js/xpconnect/src',
 ]
 
+if CONFIG['ENABLE_TESTS']:
+    DIRS += ['tests/gtest']
+
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
new file mode 100644
--- /dev/null
+++ b/caps/tests/gtest/TestOriginAttributes.cpp
@@ -0,0 +1,37 @@
+/* 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/BasePrincipal.h"
+
+using mozilla::OriginAttributes;
+
+static void
+TestSuffix(const OriginAttributes& attrs)
+{
+  nsAutoCString suffix;
+  attrs.CreateSuffix(suffix);
+
+  OriginAttributes attrsFromSuffix;
+  attrsFromSuffix.PopulateFromSuffix(suffix);
+
+  EXPECT_EQ(attrs, attrsFromSuffix);
+}
+
+TEST(OriginAttributes, Suffix_default)
+{
+  OriginAttributes attrs;
+  TestSuffix(attrs);
+}
+
+TEST(OriginAttributes, Suffix_appId_inBrowser)
+{
+  OriginAttributes attrs(1, true);
+  TestSuffix(attrs);
+}
+
+TEST(OriginAttributes, Suffix_maxAppId_inBrowser)
+{
+  OriginAttributes attrs(4294967295, true);
+  TestSuffix(attrs);
+}
new file mode 100644
--- /dev/null
+++ b/caps/tests/gtest/moz.build
@@ -0,0 +1,13 @@
+# -*- Mode: python; c-basic-offset: 4; 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 += [
+    'TestOriginAttributes.cpp'
+]
+
+include('/ipc/chromium/chromium-config.mozbuild')
+
+FINAL_LIBRARY = 'xul-gtest'