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
|
// Copyright 2019 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 "third_party/blink/renderer/modules/manifest/manifest_type_converters.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/public/cpp/bindings/type_converter.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink.h"
#include "third_party/blink/renderer/modules/manifest/manifest_parser.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
namespace blink {
class ManifestTypeConvertersTest : public testing::Test {
protected:
ManifestTypeConvertersTest() {}
~ManifestTypeConvertersTest() override {}
mojom::blink::ManifestPtr Load(const String& json) {
KURL url("http://example.com");
ManifestParser parser(json, url, url);
parser.Parse();
Vector<mojom::blink::ManifestErrorPtr> errors;
parser.TakeErrors(&errors);
EXPECT_EQ(0u, errors.size());
EXPECT_FALSE(parser.failed());
return parser.manifest().Clone();
}
private:
DISALLOW_COPY_AND_ASSIGN(ManifestTypeConvertersTest);
};
TEST_F(ManifestTypeConvertersTest, NoFileHandlerDoesNotConvert) {
const String json = "{\"start_url\": \"/\"}";
const mojom::blink::ManifestPtr& mojo_manifest = Load(json);
auto manifest = mojo_manifest.To<blink::Manifest>();
EXPECT_EQ(0u, manifest.file_handlers.size());
}
TEST_F(ManifestTypeConvertersTest, BasicFileHandlerIsCorrectlyConverted) {
const mojom::blink::ManifestPtr& mojo_manifest = Load(
"{"
" \"file_handlers\": ["
" {"
" \"name\": \"name\","
" \"action\": \"/files\","
" \"accept\": {"
" \"image/png\": ["
" \".png\""
" ]"
" }"
" }"
" ]"
"}");
auto manifest = mojo_manifest.To<blink::Manifest>();
ASSERT_EQ(manifest.file_handlers.size(), 1u);
EXPECT_EQ(manifest.file_handlers[0].action, "http://example.com/files");
EXPECT_TRUE(base::EqualsASCII(manifest.file_handlers[0].name, "name"));
ASSERT_EQ(manifest.file_handlers[0].accept.size(), 1u);
base::string16 mime = base::UTF8ToUTF16("image/png");
ASSERT_EQ(manifest.file_handlers[0].accept.count(mime), 1u);
EXPECT_EQ(manifest.file_handlers[0].accept[mime].size(), 1u);
EXPECT_TRUE(
base::EqualsASCII(manifest.file_handlers[0].accept[mime][0], ".png"));
}
} // namespace blink
|