Commit 55c25e21 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

[Media Controls] Prevent crash when there is no layout view

This CL adds a check in IsMouseEventOnInternalButton to make sure there
is a layout view before using it. This prevents a crash in
MediaControlOverlayPlayButtonElement.

Bug: 870490
Change-Id: I085333c8ed6704d22b2fe8d33ef9a6e45332288e
Reviewed-on: https://chromium-review.googlesource.com/1182788
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584881}
parent e8305343
...@@ -300,6 +300,10 @@ bool MediaControlOverlayPlayButtonElement::IsMouseEventOnInternalButton( ...@@ -300,6 +300,10 @@ bool MediaControlOverlayPlayButtonElement::IsMouseEventOnInternalButton(
if (!mouse_event.HasPosition()) if (!mouse_event.HasPosition())
return true; return true;
// If there is no layout view, default to yes.
if (!GetDocument().GetLayoutView())
return true;
// Find the zoom-adjusted internal button bounding box. // Find the zoom-adjusted internal button bounding box.
DOMRect* box = internal_button_->getBoundingClientRect(); DOMRect* box = internal_button_->getBoundingClientRect();
float zoom = ComputedStyleRef().EffectiveZoom() / float zoom = ComputedStyleRef().EffectiveZoom() /
......
...@@ -8,7 +8,12 @@ ...@@ -8,7 +8,12 @@
#include "third_party/blink/renderer/core/css/css_property_value_set.h" #include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/event_type_names.h" #include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/events/mouse_event.h"
#include "third_party/blink/renderer/core/html/html_html_element.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/modules/media_controls/media_controls_impl.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
namespace blink { namespace blink {
...@@ -42,6 +47,39 @@ class MediaControlOverlayPlayButtonElementTest : public PageTestBase { ...@@ -42,6 +47,39 @@ class MediaControlOverlayPlayButtonElementTest : public PageTestBase {
GetElementById("arrow-3")->DispatchEvent(*event); GetElementById("arrow-3")->DispatchEvent(*event);
} }
Document& CreateTestDocumentWithBody() {
Document* document = Document::CreateForTest();
HTMLHtmlElement* html = HTMLHtmlElement::Create(*document);
document->AppendChild(html);
document->documentElement()->SetInnerHTMLFromString("<body></body>");
return *document;
}
void CreateTestOverlayPlayButton(Document& test_document) {
// Create a video element so that a MediaControlsImpl is created.
HTMLVideoElement* media_element = HTMLVideoElement::Create(test_document);
media_element->SetBooleanAttribute(HTMLNames::controlsAttr, true);
test_document.body()->AppendChild(media_element);
MediaControlsImpl* media_controls =
static_cast<MediaControlsImpl*>(media_element->GetMediaControls());
ASSERT_NE(nullptr, media_controls);
// Create a MediaControlOverlayPlayButtonElement for testing.
overlay_play_button_ =
new MediaControlOverlayPlayButtonElement(*media_controls);
}
void SimulateKeepEventInNode() {
MouseEventInit mouse_initializer;
mouse_initializer.setView(GetDocument().domWindow());
mouse_initializer.setButton(1);
MouseEvent* mouse_event =
MouseEvent::Create(nullptr, EventTypeNames::click, mouse_initializer);
overlay_play_button_->KeepEventInNode(*mouse_event);
}
private: private:
bool SVGElementHasDisplayValue() { bool SVGElementHasDisplayValue() {
return GetElementById("jump")->InlineStyle()->HasProperty( return GetElementById("jump")->InlineStyle()->HasProperty(
...@@ -54,6 +92,7 @@ class MediaControlOverlayPlayButtonElementTest : public PageTestBase { ...@@ -54,6 +92,7 @@ class MediaControlOverlayPlayButtonElementTest : public PageTestBase {
return GetDocument().body()->getElementById(id); return GetDocument().body()->getElementById(id);
} }
Persistent<MediaControlOverlayPlayButtonElement> overlay_play_button_;
Persistent<MediaControlOverlayPlayButtonElement::AnimatedArrow> Persistent<MediaControlOverlayPlayButtonElement::AnimatedArrow>
arrow_element_; arrow_element_;
}; };
...@@ -79,4 +118,12 @@ TEST_F(MediaControlOverlayPlayButtonElementTest, ShowIncrementsCounter) { ...@@ -79,4 +118,12 @@ TEST_F(MediaControlOverlayPlayButtonElementTest, ShowIncrementsCounter) {
ExpectPresentAndShown(); ExpectPresentAndShown();
} }
TEST_F(MediaControlOverlayPlayButtonElementTest,
KeepEventInNodeWithoutLayoutViewDoesntCrash) {
ScopedModernMediaControlsForTest enable_modern_media_controls(true);
Document& document_without_layout_view = CreateTestDocumentWithBody();
CreateTestOverlayPlayButton(document_without_layout_view);
SimulateKeepEventInNode();
}
} // namespace blink } // 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