blob: eb75919be1267f70801a888f55e547e9e18e1e8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/manifest/manifest_parser.h"
#include "base/strings/string_util.h"
#include "content/public/common/manifest.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
TEST(ManifestParserTest, EmptyStringNull) {
Manifest manifest = ManifestParser::Parse("");
// A parsing error is equivalent to an empty manifest.
ASSERT_TRUE(manifest.IsEmpty());
ASSERT_TRUE(manifest.name.is_null());
ASSERT_TRUE(manifest.short_name.is_null());
}
TEST(ManifestParserTest, ValidNoContentParses) {
Manifest manifest = ManifestParser::Parse("{}");
// Check that all the fields are null in that case.
ASSERT_TRUE(manifest.IsEmpty());
ASSERT_TRUE(manifest.name.is_null());
ASSERT_TRUE(manifest.short_name.is_null());
}
TEST(ManifestParserTest, NameParseRules) {
// Smoke test.
{
Manifest manifest = ManifestParser::Parse("{ \"name\": \"foo\" }");
ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo"));
}
// Trim whitespaces.
{
Manifest manifest = ManifestParser::Parse("{ \"name\": \" foo \" }");
ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo"));
}
// Don't parse if name isn't a string.
{
Manifest manifest = ManifestParser::Parse("{ \"name\": {} }");
ASSERT_TRUE(manifest.name.is_null());
}
// Don't parse if name isn't a string.
{
Manifest manifest = ManifestParser::Parse("{ \"name\": 42 }");
ASSERT_TRUE(manifest.name.is_null());
}
}
TEST(ManifestParserTest, ShortNameParseRules) {
// Smoke test.
{
Manifest manifest = ManifestParser::Parse("{ \"short_name\": \"foo\" }");
ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo"));
}
// Trim whitespaces.
{
Manifest manifest =
ManifestParser::Parse("{ \"short_name\": \" foo \" }");
ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo"));
}
// Don't parse if name isn't a string.
{
Manifest manifest = ManifestParser::Parse("{ \"short_name\": {} }");
ASSERT_TRUE(manifest.short_name.is_null());
}
// Don't parse if name isn't a string.
{
Manifest manifest = ManifestParser::Parse("{ \"short_name\": 42 }");
ASSERT_TRUE(manifest.short_name.is_null());
}
}
} // namespace content
|