| 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/WebRemotePlaybackClient.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include <memory> | 22 #include <memory> |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 class MockVideoWebMediaPlayer : public WebMediaPlayer { | 28 class MockVideoWebMediaPlayer : public WebMediaPlayer { |
| 28 public: | 29 public: |
| 29 void load(LoadType, const WebMediaPlayerSource&, CORSMode) override{}; | 30 void load(LoadType, const WebMediaPlayerSource&, CORSMode) override{}; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 double mediaTimeForTimeValue(double timeValue) const override { | 55 double mediaTimeForTimeValue(double timeValue) const override { |
| 55 return timeValue; | 56 return timeValue; |
| 56 }; | 57 }; |
| 57 unsigned decodedFrameCount() const override { return 0; }; | 58 unsigned decodedFrameCount() const override { return 0; }; |
| 58 unsigned droppedFrameCount() const override { return 0; }; | 59 unsigned droppedFrameCount() const override { return 0; }; |
| 59 size_t audioDecodedByteCount() const override { return 0; }; | 60 size_t audioDecodedByteCount() const override { return 0; }; |
| 60 size_t videoDecodedByteCount() const override { return 0; }; | 61 size_t videoDecodedByteCount() const override { return 0; }; |
| 61 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; | 62 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; |
| 62 }; | 63 }; |
| 63 | 64 |
| 65 class MockWebRemotePlaybackClient : public WebRemotePlaybackClient { |
| 66 public: |
| 67 void stateChanged(WebRemotePlaybackState) override {} |
| 68 void availabilityChanged(bool isRouteAvailable, |
| 69 bool isSourceCompatible) override { |
| 70 m_availability = isRouteAvailable && isSourceCompatible; |
| 71 } |
| 72 void promptCancelled() override {} |
| 73 bool remotePlaybackAvailable() const override { return m_availability; } |
| 74 |
| 75 private: |
| 76 bool m_availability = false; |
| 77 }; |
| 78 |
| 64 class StubFrameLoaderClient : public EmptyFrameLoaderClient { | 79 class StubFrameLoaderClient : public EmptyFrameLoaderClient { |
| 65 public: | 80 public: |
| 66 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } | 81 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } |
| 67 | 82 |
| 68 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( | 83 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( |
| 69 HTMLMediaElement&, | 84 HTMLMediaElement&, |
| 70 const WebMediaPlayerSource&, | 85 const WebMediaPlayerSource&, |
| 71 WebMediaPlayerClient*) override { | 86 WebMediaPlayerClient*) override { |
| 72 return wrapUnique(new MockVideoWebMediaPlayer); | 87 return wrapUnique(new MockVideoWebMediaPlayer); |
| 73 } | 88 } |
| 89 |
| 90 WebRemotePlaybackClient* createWebRemotePlaybackClient( |
| 91 HTMLMediaElement&, |
| 92 ScriptState*) override { |
| 93 return new MockWebRemotePlaybackClient; |
| 94 } |
| 74 }; | 95 }; |
| 75 | 96 |
| 76 Element* getElementByShadowPseudoId(Node& rootNode, | 97 Element* getElementByShadowPseudoId(Node& rootNode, |
| 77 const char* shadowPseudoId) { | 98 const char* shadowPseudoId) { |
| 78 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { | 99 for (Element& element : ElementTraversal::descendantsOf(rootNode)) { |
| 79 if (element.shadowPseudoId() == shadowPseudoId) | 100 if (element.shadowPseudoId() == shadowPseudoId) |
| 80 return &element; | 101 return &element; |
| 81 } | 102 } |
| 82 return nullptr; | 103 return nullptr; |
| 83 } | 104 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 document.write("<video>"); | 138 document.write("<video>"); |
| 118 HTMLVideoElement& video = | 139 HTMLVideoElement& video = |
| 119 toHTMLVideoElement(*document.querySelector("video")); | 140 toHTMLVideoElement(*document.querySelector("video")); |
| 120 m_mediaControls = video.mediaControls(); | 141 m_mediaControls = video.mediaControls(); |
| 121 | 142 |
| 122 // If scripts are not enabled, controls will always be shown. | 143 // If scripts are not enabled, controls will always be shown. |
| 123 m_pageHolder->frame().settings()->setScriptEnabled(true); | 144 m_pageHolder->frame().settings()->setScriptEnabled(true); |
| 124 } | 145 } |
| 125 | 146 |
| 126 void simulateRouteAvailabe() { | 147 void simulateRouteAvailabe() { |
| 127 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged(true); | 148 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged(true, true); |
| 128 } | 149 } |
| 129 | 150 |
| 130 void ensureLayout() { | 151 void ensureLayout() { |
| 131 // Force a relayout, so that the controls know the width. Otherwise, | 152 // Force a relayout, so that the controls know the width. Otherwise, |
| 132 // they don't know if, for example, the cast button will fit. | 153 // they don't know if, for example, the cast button will fit. |
| 133 m_mediaControls->mediaElement().clientWidth(); | 154 m_mediaControls->mediaElement().clientWidth(); |
| 134 } | 155 } |
| 135 | 156 |
| 136 void simulateHideMediaControlsTimerFired() { | 157 void simulateHideMediaControlsTimerFired() { |
| 137 m_mediaControls->hideMediaControlsTimerFired(nullptr); | 158 m_mediaControls->hideMediaControlsTimerFired(nullptr); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 mediaControls().show(); | 299 mediaControls().show(); |
| 279 mediaControls().toggleOverflowMenu(); | 300 mediaControls().toggleOverflowMenu(); |
| 280 EXPECT_TRUE(isElementVisible(*overflowList)); | 301 EXPECT_TRUE(isElementVisible(*overflowList)); |
| 281 | 302 |
| 282 simulateHideMediaControlsTimerFired(); | 303 simulateHideMediaControlsTimerFired(); |
| 283 EXPECT_TRUE(isElementVisible(*overflowList)); | 304 EXPECT_TRUE(isElementVisible(*overflowList)); |
| 284 EXPECT_TRUE(isElementVisible(*panel)); | 305 EXPECT_TRUE(isElementVisible(*panel)); |
| 285 } | 306 } |
| 286 | 307 |
| 287 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |