Bug 1641598 - Added gtest test cases for ToLocaleAwareKey. r=ttung, a=RyanVM
authorSimon Giesecke <sgiesecke@mozilla.com>
Mon, 29 Jun 2020 10:55:07 +0000
changeset 601894 a24cfb80b10eafb3c5d534f5a85be792c19d8afe
parent 601893 5007d36153abdbfce831be777885fa083c66de3e
child 601895 54b80be511d33c81c2601db1b0ad779433b93511
push id13342
push userryanvm@gmail.com
push dateThu, 02 Jul 2020 16:51:46 +0000
treeherdermozilla-beta@54b80be511d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttung, RyanVM
bugs1641598
milestone79.0
Bug 1641598 - Added gtest test cases for ToLocaleAwareKey. r=ttung, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D78697
dom/indexedDB/test/gtest/TestKey.cpp
--- a/dom/indexedDB/test/gtest/TestKey.cpp
+++ b/dom/indexedDB/test/gtest/TestKey.cpp
@@ -4,16 +4,18 @@
  * 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/dom/SimpleGlobalObject.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/indexedDB/Key.h"
+#include "mozilla/IntegerRange.h"
+#include "mozilla/Unused.h"
 
 #include "jsapi.h"
 #include "js/Array.h"  // JS::GetArrayLength, JS::IsArrayObject, JS::NewArrayObject
 #include "js/ArrayBuffer.h"
 
 // TODO: This PrintTo overload is defined in dom/media/gtest/TestGroupId.cpp.
 // However, it is not used, probably because of
 // https://stackoverflow.com/a/36941270
@@ -415,8 +417,51 @@ TEST(DOM_IndexedDB_Key, CompareKeys_NonZ
   Rooted<JS::Value> arrayBuffer2(
       context, CreateArrayBufferValue(context, sizeof buf, strdup(buf)));
   const auto result2 = second.SetFromJSVal(context, arrayBuffer2, rv2);
   EXPECT_FALSE(rv2.Failed());
   EXPECT_TRUE(result2.Is(mozilla::dom::indexedDB::Ok, rv2));
 
   EXPECT_EQ(0, Key::CompareKeys(first, second));
 }
+
+constexpr auto kTestLocale = NS_LITERAL_CSTRING("e");
+
+TEST(DOM_IndexedDB_Key, ToLocaleAwareKey_Empty)
+{
+  const auto input = Key{};
+
+  auto rv1 = mozilla::ErrorResult{};
+  auto rv2 = mozilla::ErrorResult{};
+  auto output = Key{};
+
+  auto res = input.ToLocaleAwareKey(output, kTestLocale, rv1);
+  EXPECT_FALSE(rv1.Failed());
+  EXPECT_TRUE(res.Is(mozilla::dom::indexedDB::Ok, rv2));
+
+  EXPECT_TRUE(output.IsUnset());
+}
+
+TEST(DOM_IndexedDB_Key, ToLocaleAwareKey_Bug_1641598)
+{
+  const auto buffer = [] {
+    nsCString res;
+    // This is the encoded representation produced by the test case from bug
+    // 1641598.
+    res.AppendLiteral("\x90\x01\x01\x01\x01\x00\x40");
+    for (const size_t unused : IntegerRange<size_t>(256)) {
+      Unused << unused;
+      res.AppendLiteral("\x01\x01\x80\x03\x43");
+    }
+    return res;
+  }();
+  const auto input = Key{buffer};
+
+  auto rv1 = mozilla::ErrorResult{};
+  auto rv2 = mozilla::ErrorResult{};
+  auto output = Key{};
+
+  auto res = input.ToLocaleAwareKey(output, kTestLocale, rv1);
+  EXPECT_FALSE(rv1.Failed());
+  EXPECT_TRUE(res.Is(mozilla::dom::indexedDB::Ok, rv2));
+
+  EXPECT_EQ(input, output);
+}