| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/MediaCustomControlsFullscreenDetector.h" | 5 #include "core/html/MediaCustomControlsFullscreenDetector.h" |
| 6 | 6 |
| 7 #include "core/EventTypeNames.h" | 7 #include "core/EventTypeNames.h" |
| 8 #include "core/html/HTMLVideoElement.h" | 8 #include "core/html/HTMLVideoElement.h" |
| 9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { | 27 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { |
| 28 protected: | 28 protected: |
| 29 void SetUp() override { | 29 void SetUp() override { |
| 30 m_originalVideoFullscreenDetectionEnabled = | 30 m_originalVideoFullscreenDetectionEnabled = |
| 31 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled(); | 31 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled(); |
| 32 | 32 |
| 33 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true); | 33 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true); |
| 34 | 34 |
| 35 m_pageHolder = DummyPageHolder::create(); | 35 m_pageHolder = DummyPageHolder::create(); |
| 36 m_newPageHolder = DummyPageHolder::create(); | 36 m_newPageHolder = DummyPageHolder::create(); |
| 37 | |
| 38 m_video = HTMLVideoElement::create(m_pageHolder->document()); | |
| 39 document().body()->appendChild(&videoElement()); | |
| 40 } | 37 } |
| 41 | 38 |
| 42 void TearDown() override { | 39 void TearDown() override { |
| 43 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled( | 40 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled( |
| 44 m_originalVideoFullscreenDetectionEnabled); | 41 m_originalVideoFullscreenDetectionEnabled); |
| 45 } | 42 } |
| 46 | 43 |
| 47 HTMLVideoElement& videoElement() const { return *m_video; } | 44 HTMLVideoElement* videoElement() const { |
| 48 MediaCustomControlsFullscreenDetector& fullscreenDetector() const { | 45 return toHTMLVideoElement(document().querySelector("video")); |
| 49 return *videoElement().m_customControlsFullscreenDetector; | 46 } |
| 47 |
| 48 static MediaCustomControlsFullscreenDetector* fullscreenDetectorFor( |
| 49 HTMLVideoElement* videoElement) { |
| 50 return videoElement->m_customControlsFullscreenDetector; |
| 51 } |
| 52 |
| 53 MediaCustomControlsFullscreenDetector* fullscreenDetector() const { |
| 54 return fullscreenDetectorFor(videoElement()); |
| 50 } | 55 } |
| 51 | 56 |
| 52 Document& document() const { return m_pageHolder->document(); } | 57 Document& document() const { return m_pageHolder->document(); } |
| 53 Document& newDocument() const { return m_newPageHolder->document(); } | 58 Document& newDocument() const { return m_newPageHolder->document(); } |
| 54 | 59 |
| 55 bool checkEventListenerRegistered(EventTarget& target, | 60 bool checkEventListenerRegistered(EventTarget& target, |
| 56 const AtomicString& eventType, | 61 const AtomicString& eventType, |
| 57 EventListener* listener) { | 62 EventListener* listener) { |
| 58 EventListenerVector* listeners = target.getEventListeners(eventType); | 63 EventListenerVector* listeners = target.getEventListeners(eventType); |
| 59 if (!listeners) | 64 if (!listeners) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 108 |
| 104 for (const TestParam& testParam : testParams) { | 109 for (const TestParam& testParam : testParams) { |
| 105 const IntRect& targetRect = testParam.targetRect; | 110 const IntRect& targetRect = testParam.targetRect; |
| 106 IntRect intersectionRect = intersection(targetRect, rootRect); | 111 IntRect intersectionRect = intersection(targetRect, rootRect); |
| 107 EXPECT_EQ(testParam.expectedResult, | 112 EXPECT_EQ(testParam.expectedResult, |
| 108 computeIsDominantVideo(targetRect, rootRect, intersectionRect)) | 113 computeIsDominantVideo(targetRect, rootRect, intersectionRect)) |
| 109 << testParam.description << " failed"; | 114 << testParam.description << " failed"; |
| 110 } | 115 } |
| 111 } | 116 } |
| 112 | 117 |
| 113 TEST_F(MediaCustomControlsFullscreenDetectorTest, documentMove) { | 118 TEST_F(MediaCustomControlsFullscreenDetectorTest, |
| 119 hasNoListenersBeforeAddingToDocument) { |
| 120 HTMLVideoElement* video = |
| 121 toHTMLVideoElement(document().createElement("video")); |
| 122 |
| 123 EXPECT_FALSE(checkEventListenerRegistered(document(), |
| 124 EventTypeNames::fullscreenchange, |
| 125 fullscreenDetectorFor(video))); |
| 126 EXPECT_FALSE(checkEventListenerRegistered( |
| 127 document(), EventTypeNames::webkitfullscreenchange, |
| 128 fullscreenDetectorFor(video))); |
| 129 EXPECT_FALSE(checkEventListenerRegistered( |
| 130 *video, EventTypeNames::loadedmetadata, fullscreenDetectorFor(video))); |
| 131 } |
| 132 |
| 133 TEST_F(MediaCustomControlsFullscreenDetectorTest, |
| 134 hasListenersAfterAddToDocumentByScript) { |
| 135 HTMLVideoElement* video = |
| 136 toHTMLVideoElement(document().createElement("video")); |
| 137 document().body()->appendChild(video); |
| 138 |
| 114 EXPECT_TRUE(checkEventListenerRegistered( | 139 EXPECT_TRUE(checkEventListenerRegistered( |
| 115 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); | 140 document(), EventTypeNames::fullscreenchange, fullscreenDetector())); |
| 116 EXPECT_TRUE(checkEventListenerRegistered( | 141 EXPECT_TRUE(checkEventListenerRegistered( |
| 117 document(), EventTypeNames::webkitfullscreenchange, | 142 document(), EventTypeNames::webkitfullscreenchange, |
| 118 &fullscreenDetector())); | 143 fullscreenDetector())); |
| 119 EXPECT_FALSE(checkEventListenerRegistered( | 144 EXPECT_TRUE(checkEventListenerRegistered( |
| 120 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); | 145 *videoElement(), EventTypeNames::loadedmetadata, fullscreenDetector())); |
| 121 EXPECT_FALSE(checkEventListenerRegistered( | 146 } |
| 122 newDocument(), EventTypeNames::webkitfullscreenchange, | |
| 123 &fullscreenDetector())); | |
| 124 | 147 |
| 125 newDocument().body()->appendChild(&videoElement()); | 148 TEST_F(MediaCustomControlsFullscreenDetectorTest, |
| 149 hasListenersAfterAddToDocumentByParser) { |
| 150 document().body()->setInnerHTML("<body><video></video></body>"); |
| 126 | 151 |
| 127 EXPECT_FALSE(checkEventListenerRegistered( | 152 EXPECT_TRUE(checkEventListenerRegistered( |
| 128 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); | 153 document(), EventTypeNames::fullscreenchange, fullscreenDetector())); |
| 154 EXPECT_TRUE(checkEventListenerRegistered( |
| 155 document(), EventTypeNames::webkitfullscreenchange, |
| 156 fullscreenDetector())); |
| 157 EXPECT_TRUE(checkEventListenerRegistered( |
| 158 *videoElement(), EventTypeNames::loadedmetadata, fullscreenDetector())); |
| 159 } |
| 160 |
| 161 TEST_F(MediaCustomControlsFullscreenDetectorTest, |
| 162 hasListenersAfterDocumentMove) { |
| 163 HTMLVideoElement* video = |
| 164 toHTMLVideoElement(document().createElement("video")); |
| 165 document().body()->appendChild(video); |
| 166 |
| 167 newDocument().body()->appendChild(videoElement()); |
| 168 |
| 169 EXPECT_FALSE(checkEventListenerRegistered(document(), |
| 170 EventTypeNames::fullscreenchange, |
| 171 fullscreenDetectorFor(video))); |
| 129 EXPECT_FALSE(checkEventListenerRegistered( | 172 EXPECT_FALSE(checkEventListenerRegistered( |
| 130 document(), EventTypeNames::webkitfullscreenchange, | 173 document(), EventTypeNames::webkitfullscreenchange, |
| 131 &fullscreenDetector())); | 174 fullscreenDetectorFor(video))); |
| 132 EXPECT_TRUE(checkEventListenerRegistered( | 175 |
| 133 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); | 176 EXPECT_TRUE(checkEventListenerRegistered(newDocument(), |
| 177 EventTypeNames::fullscreenchange, |
| 178 fullscreenDetectorFor(video))); |
| 134 EXPECT_TRUE(checkEventListenerRegistered( | 179 EXPECT_TRUE(checkEventListenerRegistered( |
| 135 newDocument(), EventTypeNames::webkitfullscreenchange, | 180 newDocument(), EventTypeNames::webkitfullscreenchange, |
| 136 &fullscreenDetector())); | 181 fullscreenDetectorFor(video))); |
| 182 |
| 183 EXPECT_TRUE(checkEventListenerRegistered( |
| 184 *video, EventTypeNames::loadedmetadata, fullscreenDetectorFor(video))); |
| 137 } | 185 } |
| 138 | 186 |
| 139 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |