| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/shadow/MediaControls.h" | 5 #include "core/html/shadow/MediaControls.h" |
| 6 | 6 |
| 7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
| 8 #include "core/css/StylePropertySet.h" | 8 #include "core/css/StylePropertySet.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
| 11 #include "core/dom/StyleEngine.h" | 11 #include "core/dom/StyleEngine.h" |
| 12 #include "core/frame/Settings.h" | 12 #include "core/frame/Settings.h" |
| 13 #include "core/html/HTMLVideoElement.h" | 13 #include "core/html/HTMLVideoElement.h" |
| 14 #include "core/loader/EmptyClients.h" | 14 #include "core/loader/EmptyClients.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
| 17 #include "platform/testing/UnitTestHelpers.h" | 17 #include "platform/testing/UnitTestHelpers.h" |
| 18 #include "public/platform/WebMediaPlayer.h" | 18 #include "public/platform/WebMediaPlayer.h" |
| 19 #include "public/platform/WebSize.h" | 19 #include "public/platform/WebSize.h" |
| 20 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h
" |
| 20 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" | 21 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include <memory> | 23 #include <memory> |
| 23 | 24 |
| 24 namespace blink { | 25 namespace blink { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class MockVideoWebMediaPlayer : public WebMediaPlayer { | 29 class MockVideoWebMediaPlayer : public WebMediaPlayer { |
| 29 public: | 30 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 55 double mediaTimeForTimeValue(double timeValue) const override { | 56 double mediaTimeForTimeValue(double timeValue) const override { |
| 56 return timeValue; | 57 return timeValue; |
| 57 }; | 58 }; |
| 58 unsigned decodedFrameCount() const override { return 0; }; | 59 unsigned decodedFrameCount() const override { return 0; }; |
| 59 unsigned droppedFrameCount() const override { return 0; }; | 60 unsigned droppedFrameCount() const override { return 0; }; |
| 60 size_t audioDecodedByteCount() const override { return 0; }; | 61 size_t audioDecodedByteCount() const override { return 0; }; |
| 61 size_t videoDecodedByteCount() const override { return 0; }; | 62 size_t videoDecodedByteCount() const override { return 0; }; |
| 62 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; | 63 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; |
| 63 }; | 64 }; |
| 64 | 65 |
| 66 class MockWebRemotePlaybackClient : public WebRemotePlaybackClient { |
| 67 public: |
| 68 void stateChanged(WebRemotePlaybackState) override {} |
| 69 void availabilityChanged( |
| 70 WebRemotePlaybackAvailability availability) override { |
| 71 m_availability = availability; |
| 72 } |
| 73 void promptCancelled() override {} |
| 74 bool remotePlaybackAvailable() const override { |
| 75 return m_availability == WebRemotePlaybackAvailability::DeviceAvailable; |
| 76 } |
| 77 |
| 78 private: |
| 79 WebRemotePlaybackAvailability m_availability = |
| 80 WebRemotePlaybackAvailability::Unknown; |
| 81 }; |
| 82 |
| 65 class StubFrameLoaderClient : public EmptyFrameLoaderClient { | 83 class StubFrameLoaderClient : public EmptyFrameLoaderClient { |
| 66 public: | 84 public: |
| 67 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } | 85 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } |
| 68 | 86 |
| 69 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( | 87 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( |
| 70 HTMLMediaElement&, | 88 HTMLMediaElement&, |
| 71 const WebMediaPlayerSource&, | 89 const WebMediaPlayerSource&, |
| 72 WebMediaPlayerClient*) override { | 90 WebMediaPlayerClient*) override { |
| 73 return wrapUnique(new MockVideoWebMediaPlayer); | 91 return wrapUnique(new MockVideoWebMediaPlayer); |
| 74 } | 92 } |
| 93 |
| 94 WebRemotePlaybackClient* createWebRemotePlaybackClient( |
| 95 HTMLMediaElement&) override { |
| 96 if (!m_remotePlaybackClient) { |
| 97 m_remotePlaybackClient = wrapUnique(new MockWebRemotePlaybackClient); |
| 98 } |
| 99 return m_remotePlaybackClient.get(); |
| 100 } |
| 101 |
| 102 private: |
| 103 std::unique_ptr<MockWebRemotePlaybackClient> m_remotePlaybackClient; |
| 75 }; | 104 }; |
| 76 | 105 |
| 77 Element* getElementByShadowPseudoId(Node& rootNode, | 106 Element* getElementByShadowPseudoId(Node& rootNode, |
| 78 const char* shadowPseudoId) { | 107 const char* shadowPseudoId) { |
| 79 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { | 108 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { |
| 80 if (element.shadowPseudoId() == shadowPseudoId) | 109 if (element.shadowPseudoId() == shadowPseudoId) |
| 81 return &element; | 110 return &element; |
| 82 } | 111 } |
| 83 return nullptr; | 112 return nullptr; |
| 84 } | 113 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 document.write("<video>"); | 147 document.write("<video>"); |
| 119 HTMLVideoElement& video = | 148 HTMLVideoElement& video = |
| 120 toHTMLVideoElement(*document.querySelector("video")); | 149 toHTMLVideoElement(*document.querySelector("video")); |
| 121 m_mediaControls = video.mediaControls(); | 150 m_mediaControls = video.mediaControls(); |
| 122 | 151 |
| 123 // If scripts are not enabled, controls will always be shown. | 152 // If scripts are not enabled, controls will always be shown. |
| 124 m_pageHolder->frame().settings()->setScriptEnabled(true); | 153 m_pageHolder->frame().settings()->setScriptEnabled(true); |
| 125 } | 154 } |
| 126 | 155 |
| 127 void simulateRouteAvailabe() { | 156 void simulateRouteAvailabe() { |
| 128 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged(true); | 157 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged( |
| 158 WebRemotePlaybackAvailability::DeviceAvailable); |
| 129 } | 159 } |
| 130 | 160 |
| 131 void ensureLayout() { | 161 void ensureLayout() { |
| 132 // Force a relayout, so that the controls know the width. Otherwise, | 162 // Force a relayout, so that the controls know the width. Otherwise, |
| 133 // they don't know if, for example, the cast button will fit. | 163 // they don't know if, for example, the cast button will fit. |
| 134 m_mediaControls->mediaElement().clientWidth(); | 164 m_mediaControls->mediaElement().clientWidth(); |
| 135 } | 165 } |
| 136 | 166 |
| 137 void simulateHideMediaControlsTimerFired() { | 167 void simulateHideMediaControlsTimerFired() { |
| 138 m_mediaControls->hideMediaControlsTimerFired(nullptr); | 168 m_mediaControls->hideMediaControlsTimerFired(nullptr); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 mediaControls().show(); | 309 mediaControls().show(); |
| 280 mediaControls().toggleOverflowMenu(); | 310 mediaControls().toggleOverflowMenu(); |
| 281 EXPECT_TRUE(isElementVisible(*overflowList)); | 311 EXPECT_TRUE(isElementVisible(*overflowList)); |
| 282 | 312 |
| 283 simulateHideMediaControlsTimerFired(); | 313 simulateHideMediaControlsTimerFired(); |
| 284 EXPECT_TRUE(isElementVisible(*overflowList)); | 314 EXPECT_TRUE(isElementVisible(*overflowList)); |
| 285 EXPECT_TRUE(isElementVisible(*panel)); | 315 EXPECT_TRUE(isElementVisible(*panel)); |
| 286 } | 316 } |
| 287 | 317 |
| 288 } // namespace blink | 318 } // namespace blink |
| OLD | NEW |