Don't change the media controls visibility in MediaControls::reset()
reset() is called from a number of places with the expectation of
putting the controls into the state they would be if created anew.
One such place is via HTMLMediaElement::preDispatchEventHandler, where
the controls are reset when entering or exiting fullscreen. This has a
very strange side-effect, namely that dispatching a synthetic
webkitfullscreenchange event on a video will cause the media controls to
become visible.
It would be rather messy to write a layout test for this, and it would
be slow to run, so instead add unit tests to test this more directly.
R=fs@opera.com
Review URL: https://codereview.chromium.org/1319433003
git-svn-id: svn://svn.chromium.org/blink/trunk@201126 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/Source/core/core.gypi b/Source/core/core.gypi
index b4ded35..2058d30 100644
--- a/Source/core/core.gypi
+++ b/Source/core/core.gypi
@@ -3819,6 +3819,7 @@
'html/parser/HTMLPreloadScannerTest.cpp',
'html/parser/HTMLResourcePreloaderTest.cpp',
'html/parser/HTMLSrcsetParserTest.cpp',
+ 'html/shadow/MediaControlsTest.cpp',
'html/track/vtt/BufferedLineReaderTest.cpp',
'html/track/vtt/VTTScannerTest.cpp',
'input/EventHandlerTest.cpp',
diff --git a/Source/core/html/shadow/MediaControls.cpp b/Source/core/html/shadow/MediaControls.cpp
index 24e15ed..5c6780b 100644
--- a/Source/core/html/shadow/MediaControls.cpp
+++ b/Source/core/html/shadow/MediaControls.cpp
@@ -261,7 +261,6 @@
m_fullScreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement()));
refreshCastButtonVisibilityWithoutUpdate();
- makeOpaque();
// Set the panel width here, and force a layout, before the controls update.
// This would be harmless for the !useNewUi case too, but it causes
diff --git a/Source/core/html/shadow/MediaControls.h b/Source/core/html/shadow/MediaControls.h
index 4a2b0d1..baa36f9 100644
--- a/Source/core/html/shadow/MediaControls.h
+++ b/Source/core/html/shadow/MediaControls.h
@@ -35,7 +35,7 @@
class Event;
class TextTrackContainer;
-class MediaControls final : public HTMLDivElement {
+class CORE_EXPORT MediaControls final : public HTMLDivElement {
public:
static PassRefPtrWillBeRawPtr<MediaControls> create(HTMLMediaElement&);
diff --git a/Source/core/html/shadow/MediaControlsTest.cpp b/Source/core/html/shadow/MediaControlsTest.cpp
new file mode 100644
index 0000000..31a29ae
--- /dev/null
+++ b/Source/core/html/shadow/MediaControlsTest.cpp
@@ -0,0 +1,106 @@
+// Copyright 2015 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 "config.h"
+#include "core/html/shadow/MediaControls.h"
+
+#include "core/HTMLNames.h"
+#include "core/css/StylePropertySet.h"
+#include "core/dom/Document.h"
+#include "core/dom/ElementTraversal.h"
+#include "core/html/HTMLVideoElement.h"
+#include "core/testing/DummyPageHolder.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+namespace {
+
+Element* getElementByShadowPseudoId(Node& rootNode, const char* shadowPseudoId)
+{
+ for (Element& element : ElementTraversal::descendantsOf(rootNode)) {
+ if (element.fastGetAttribute(HTMLNames::pseudoAttr) == shadowPseudoId)
+ return &element;
+ }
+ return nullptr;
+}
+
+bool isElementVisible(Element& element)
+{
+ const StylePropertySet* inlineStyle = element.inlineStyle();
+
+ if (!inlineStyle)
+ return true;
+
+ if (inlineStyle->getPropertyValue(CSSPropertyDisplay) == "none")
+ return false;
+
+ if (inlineStyle->hasProperty(CSSPropertyOpacity)
+ && inlineStyle->getPropertyValue(CSSPropertyOpacity).toDouble() == 0.0)
+ return false;
+
+ if (inlineStyle->getPropertyValue(CSSPropertyVisibility) == "hidden")
+ return false;
+
+ if (Element* parent = element.parentElement())
+ return isElementVisible(*parent);
+
+ return true;
+}
+
+} // namespace
+
+class MediaControlsTest : public testing::Test {
+protected:
+ virtual void SetUp()
+ {
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
+ Document& document = m_pageHolder->document();
+ document.write("<video controls>");
+ HTMLVideoElement& video = toHTMLVideoElement(*document.querySelector("video", ASSERT_NO_EXCEPTION));
+ m_mediaControls = video.mediaControls();
+ }
+
+ MediaControls& mediaControls() { return *m_mediaControls; }
+
+private:
+ OwnPtr<DummyPageHolder> m_pageHolder;
+ MediaControls* m_mediaControls;
+};
+
+TEST_F(MediaControlsTest, HideAndShow)
+{
+ Element* panel = getElementByShadowPseudoId(mediaControls(), "-webkit-media-controls-panel");
+ ASSERT_NE(nullptr, panel);
+
+ ASSERT_TRUE(isElementVisible(*panel));
+ mediaControls().hide();
+ ASSERT_FALSE(isElementVisible(*panel));
+ mediaControls().show();
+ ASSERT_TRUE(isElementVisible(*panel));
+}
+
+TEST_F(MediaControlsTest, Reset)
+{
+ Element* panel = getElementByShadowPseudoId(mediaControls(), "-webkit-media-controls-panel");
+ ASSERT_NE(nullptr, panel);
+
+ ASSERT_TRUE(isElementVisible(*panel));
+ mediaControls().reset();
+ ASSERT_TRUE(isElementVisible(*panel));
+}
+
+TEST_F(MediaControlsTest, HideAndReset)
+{
+ Element* panel = getElementByShadowPseudoId(mediaControls(), "-webkit-media-controls-panel");
+ ASSERT_NE(nullptr, panel);
+
+ ASSERT_TRUE(isElementVisible(*panel));
+ mediaControls().hide();
+ ASSERT_FALSE(isElementVisible(*panel));
+ mediaControls().reset();
+ ASSERT_FALSE(isElementVisible(*panel));
+}
+
+} // namespace blink