Commit ffdaf8c5 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] WebDialogUI: Add chrome.send() support.

chrome.send() must always be enabled for dialogs, since dialogs rely on
chrome.send() to notify their handlers that the dialog should be closed.

Bug: 824568
Change-Id: I12325c243e2f2cf04d417ea71b03519bcb3d1159
Reviewed-on: https://chromium-review.googlesource.com/1145580Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579989}
parent 40606374
......@@ -2884,6 +2884,7 @@ test("unit_tests") {
"//ui/gfx:test_support",
"//ui/gl",
"//ui/resources",
"//ui/web_dialogs:web_dialogs_unittests",
"//v8",
]
......
......@@ -45,7 +45,11 @@ const base::string16& TestWebUI::GetOverriddenTitle() const {
}
int TestWebUI::GetBindings() const {
return 0;
return bindings_;
}
void TestWebUI::SetBindings(int bindings) {
bindings_ = bindings;
}
void TestWebUI::AddMessageHandler(
......
......@@ -33,7 +33,7 @@ class TestWebUI : public WebUI {
const base::string16& GetOverriddenTitle() const override;
void OverrideTitle(const base::string16& title) override {}
int GetBindings() const override;
void SetBindings(int bindings) override {}
void SetBindings(int bindings) override;
void AddMessageHandler(std::unique_ptr<WebUIMessageHandler> handler) override;
void RegisterMessageCallback(base::StringPiece message,
const MessageCallback& callback) override {}
......@@ -93,6 +93,7 @@ class TestWebUI : public WebUI {
private:
std::vector<std::unique_ptr<CallData>> call_data_;
std::vector<std::unique_ptr<WebUIMessageHandler>> handlers_;
int bindings_ = 0;
base::string16 temp_string_;
WebContents* web_contents_;
std::unique_ptr<WebUIController> controller_;
......
......@@ -52,3 +52,21 @@ static_library("test_support") {
"//url",
]
}
source_set("web_dialogs_unittests") {
testonly = true
sources = [
"web_dialog_ui_unittest.cc",
]
deps = [
":web_dialogs",
"//base",
"//base/test:test_support",
"//content/test:test_support",
"//skia",
"//testing/gtest",
"//third_party/boringssl",
]
}
......@@ -120,8 +120,13 @@ void WebDialogUI::RenderFrameCreated(RenderFrameHost* render_frame_host) {
HandleRenderFrameCreated(render_frame_host);
}
// Note: chrome.send() must always be enabled for dialogs, since dialogs rely on
// chrome.send() to notify their handlers that the dialog should be closed. See
// the "dialogClose" message handler above in
// WebDialogUIBase::HandleRenderFrameCreated().
MojoWebDialogUI::MojoWebDialogUI(content::WebUI* web_ui)
: WebDialogUIBase(web_ui), MojoWebUIController(web_ui) {}
: WebDialogUIBase(web_ui),
MojoWebUIController(web_ui, /*enable_chrome_send=*/true) {}
MojoWebDialogUI::~MojoWebDialogUI() = default;
......
// Copyright 2018 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 "ui/web_dialogs/web_dialog_ui.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/test/test_web_ui.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ui {
TEST(WebDialogUITest, NoBindingsSetForWebDialogUI) {
content::TestWebUI test_web_ui;
EXPECT_EQ(0, test_web_ui.GetBindings());
WebDialogUI web_dialog_ui(&test_web_ui);
EXPECT_EQ(0, test_web_ui.GetBindings());
}
TEST(MojoWebDialogUITest, ChromeSendAndMojoBindingsForMojoWebDialogUI) {
content::TestWebUI test_web_ui;
EXPECT_EQ(0, test_web_ui.GetBindings());
MojoWebDialogUI web_dialog_ui(&test_web_ui);
// MojoWebDialogUIs rely on both Mojo and chrome.send().
EXPECT_EQ(
content::BINDINGS_POLICY_MOJO_WEB_UI | content::BINDINGS_POLICY_WEB_UI,
test_web_ui.GetBindings());
}
} // namespace ui
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