Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/test/gtest/TestContentUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "gtest/gtest.h"
8
9
#include "jsapi.h"
10
#include "nsContentUtils.h"
11
#include "mozilla/CycleCollectedJSContext.h"
12
#include "mozilla/dom/SimpleGlobalObject.h"
13
14
TEST(DOM_Base_ContentUtils, StringifyJSON_EmptyValue)
15
0
{
16
0
  JSObject* globalObject =
17
0
    mozilla::dom::SimpleGlobalObject::Create(mozilla::dom::SimpleGlobalObject::GlobalType::BindingDetail);
18
0
  mozilla::dom::AutoJSAPI jsAPI;
19
0
  ASSERT_TRUE(jsAPI.Init(globalObject));
20
0
  JSContext* cx = jsAPI.cx();
21
0
  nsAutoString serializedValue;
22
0
23
0
  JS::RootedValue jsValue(cx);
24
0
  ASSERT_TRUE(nsContentUtils::StringifyJSON(cx, &jsValue, serializedValue));
25
0
26
0
  ASSERT_TRUE(serializedValue.EqualsLiteral("null"));
27
0
}
28
29
TEST(DOM_Base_ContentUtils, StringifyJSON_Object)
30
0
{
31
0
  JSObject* globalObject =
32
0
    mozilla::dom::SimpleGlobalObject::Create(mozilla::dom::SimpleGlobalObject::GlobalType::BindingDetail);
33
0
  mozilla::dom::AutoJSAPI jsAPI;
34
0
  ASSERT_TRUE(jsAPI.Init(globalObject));
35
0
  JSContext* cx = jsAPI.cx();
36
0
  nsAutoString serializedValue;
37
0
38
0
  JS::RootedObject jsObj(cx, JS_NewPlainObject(cx));
39
0
  JS::RootedString valueStr(cx, JS_NewStringCopyZ(cx, "Hello World!"));
40
0
  ASSERT_TRUE(JS_DefineProperty(cx, jsObj, "key1", valueStr, JSPROP_ENUMERATE));
41
0
  JS::RootedValue jsValue(cx, JS::ObjectValue(*jsObj));
42
0
43
0
  ASSERT_TRUE(nsContentUtils::StringifyJSON(cx, &jsValue, serializedValue));
44
0
45
0
  ASSERT_TRUE(serializedValue.EqualsLiteral("{\"key1\":\"Hello World!\"}"));
46
0
}