Commit 758f138b authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Fixes a bug in the manifest type converters

Previously, this code path was never executed, which is how the bug
wasn't discovered.

Bug: 829689
Change-Id: I636536914ca24ba4872c275d705c8f75f2f9b9bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1597934
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657609}
parent a70a2ade
...@@ -310,6 +310,7 @@ jumbo_source_set("unit_tests") { ...@@ -310,6 +310,7 @@ jumbo_source_set("unit_tests") {
"manifest/image_resource_type_converters_test.cc", "manifest/image_resource_type_converters_test.cc",
"manifest/manifest_manager_unittest.cc", "manifest/manifest_manager_unittest.cc",
"manifest/manifest_parser_unittest.cc", "manifest/manifest_parser_unittest.cc",
"manifest/manifest_type_converters_unittest.cc",
"media_controls/elements/media_control_animated_arrow_container_element_test.cc", "media_controls/elements/media_control_animated_arrow_container_element_test.cc",
"media_controls/elements/media_control_display_cutout_fullscreen_button_element_test.cc", "media_controls/elements/media_control_display_cutout_fullscreen_button_element_test.cc",
"media_controls/elements/media_control_input_element_test.cc", "media_controls/elements/media_control_input_element_test.cc",
......
...@@ -57,6 +57,7 @@ TypeConverter<blink::mojom::blink::ManifestPtr, ...@@ -57,6 +57,7 @@ TypeConverter<blink::mojom::blink::ManifestPtr,
file_filters.push_back( file_filters.push_back(
blink::mojom::blink::ManifestFileFilter::From(&file_handler)); blink::mojom::blink::ManifestFileFilter::From(&file_handler));
} }
output->file_handler = blink::mojom::blink::ManifestFileHandler::New();
output->file_handler->action = blink::KURL(input->file_handler->action); output->file_handler->action = blink::KURL(input->file_handler->action);
output->file_handler->files = std::move(file_filters); output->file_handler->files = std::move(file_filters);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink.h" #include "third_party/blink/public/mojom/manifest/manifest.mojom-blink.h"
#include "third_party/blink/renderer/modules/modules_export.h"
namespace blink { namespace blink {
struct Manifest; struct Manifest;
...@@ -19,7 +20,8 @@ namespace mojo { ...@@ -19,7 +20,8 @@ namespace mojo {
// directly. // directly.
template <> template <>
struct TypeConverter<blink::mojom::blink::ManifestPtr, const blink::Manifest*> { struct MODULES_EXPORT
TypeConverter<blink::mojom::blink::ManifestPtr, const blink::Manifest*> {
static blink::mojom::blink::ManifestPtr Convert(const blink::Manifest* input); static blink::mojom::blink::ManifestPtr Convert(const blink::Manifest* input);
}; };
......
// 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/string_piece_forward.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 {}
blink::Manifest Load(const base::StringPiece& 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();
}
private:
DISALLOW_COPY_AND_ASSIGN(ManifestTypeConvertersTest);
};
TEST_F(ManifestTypeConvertersTest, NoFileHandlerDoesNotConvert) {
const base::StringPiece json = "{\"start_url\": \"/\"}";
const blink::Manifest& manifest = Load(json);
auto mojo_manifest = mojom::blink::Manifest::From(&manifest);
EXPECT_FALSE(mojo_manifest->file_handler);
}
TEST_F(ManifestTypeConvertersTest, BasicFileHandlerIsCorrectlyConverted) {
const blink::Manifest& manifest = Load(
"{"
" \"file_handler\": {"
" \"files\": ["
" {"
" \"name\": \"name\", "
" \"accept\": \"image/png\""
" }"
" ], "
" \"action\": \"/files\""
" }"
"}");
auto mojo_manifest = mojom::blink::Manifest::From(&manifest);
ASSERT_TRUE(mojo_manifest->file_handler);
EXPECT_EQ(mojo_manifest->file_handler->action, "http://example.com/files");
ASSERT_EQ(mojo_manifest->file_handler->files.size(), 1u);
EXPECT_EQ(mojo_manifest->file_handler->files[0]->name, "name");
ASSERT_EQ(mojo_manifest->file_handler->files[0]->accept.size(), 1u);
EXPECT_EQ(mojo_manifest->file_handler->files[0]->accept[0], "image/png");
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment