| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/html/MediaCustomControlsFullscreenDetector.h" |
| 6 |
| 7 #include "core/EventTypeNames.h" |
| 8 #include "core/html/HTMLVideoElement.h" |
| 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "platform/geometry/IntRect.h" |
| 11 #include "public/platform/WebMediaPlayer.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 namespace { |
| 17 |
| 18 struct TestParam { |
| 19 String description; |
| 20 IntRect targetRect; |
| 21 bool expectedResult; |
| 22 }; |
| 23 |
| 24 } // anonymous namespace |
| 25 |
| 26 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { |
| 27 protected: |
| 28 void SetUp() override { |
| 29 m_pageHolder = DummyPageHolder::create(); |
| 30 m_newPageHolder = DummyPageHolder::create(); |
| 31 |
| 32 m_video = HTMLVideoElement::create(m_pageHolder->document()); |
| 33 document().body()->appendChild(&videoElement()); |
| 34 } |
| 35 |
| 36 HTMLVideoElement& videoElement() const { return *m_video; } |
| 37 MediaCustomControlsFullscreenDetector& fullscreenDetector() const { |
| 38 return *videoElement().m_customControlsFullscreenDetector; |
| 39 } |
| 40 |
| 41 Document& document() const { return m_pageHolder->document(); } |
| 42 Document& newDocument() const { return m_newPageHolder->document(); } |
| 43 |
| 44 bool checkEventListenerRegistered(EventTarget& target, |
| 45 const AtomicString& eventType, |
| 46 EventListener* listener) { |
| 47 EventListenerVector* listeners = target.getEventListeners(eventType); |
| 48 if (!listeners) |
| 49 return false; |
| 50 |
| 51 for (const auto& registeredListener : *listeners) { |
| 52 if (registeredListener.listener() == listener) |
| 53 return true; |
| 54 } |
| 55 return false; |
| 56 } |
| 57 |
| 58 static bool computeIsDominantVideo(const IntRect& targetRect, |
| 59 const IntRect& rootRect, |
| 60 const IntRect& intersectionRect) { |
| 61 return MediaCustomControlsFullscreenDetector:: |
| 62 computeIsDominantVideoForTests(targetRect, rootRect, intersectionRect); |
| 63 } |
| 64 |
| 65 private: |
| 66 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 67 std::unique_ptr<DummyPageHolder> m_newPageHolder; |
| 68 Persistent<HTMLVideoElement> m_video; |
| 69 }; |
| 70 |
| 71 TEST_F(MediaCustomControlsFullscreenDetectorTest, computeIsDominantVideo) { |
| 72 // TestWithParam cannot be applied here as IntRect needs the memory allocator |
| 73 // to be initialized, but the array of parameters is statically initialized, |
| 74 // which is before the memory allocation initialization. |
| 75 TestParam testParams[] = { |
| 76 {"xCompleteFill", {0, 0, 100, 50}, true}, |
| 77 {"yCompleteFill", {0, 0, 50, 100}, true}, |
| 78 {"xyCompleteFill", {0, 0, 100, 100}, true}, |
| 79 {"xIncompleteFillTooSmall", {0, 0, 84, 50}, false}, |
| 80 {"yIncompleteFillTooSmall", {0, 0, 50, 84}, false}, |
| 81 {"xIncompleteFillJustRight", {0, 0, 86, 50}, true}, |
| 82 {"yIncompleteFillJustRight", {0, 0, 50, 86}, true}, |
| 83 {"xVisibleProportionTooSmall", {-26, 0, 100, 100}, false}, |
| 84 {"yVisibleProportionTooSmall", {0, -26, 100, 100}, false}, |
| 85 {"xVisibleProportionJustRight", {-24, 0, 100, 100}, true}, |
| 86 {"yVisibleProportionJustRight", {0, -24, 100, 100}, true}, |
| 87 }; |
| 88 |
| 89 IntRect rootRect(0, 0, 100, 100); |
| 90 |
| 91 for (const TestParam& testParam : testParams) { |
| 92 const IntRect& targetRect = testParam.targetRect; |
| 93 IntRect intersectionRect = intersection(targetRect, rootRect); |
| 94 EXPECT_EQ(testParam.expectedResult, |
| 95 computeIsDominantVideo(targetRect, rootRect, intersectionRect)) |
| 96 << testParam.description << " failed"; |
| 97 } |
| 98 } |
| 99 |
| 100 TEST_F(MediaCustomControlsFullscreenDetectorTest, documentMove) { |
| 101 EXPECT_TRUE(checkEventListenerRegistered( |
| 102 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); |
| 103 EXPECT_TRUE(checkEventListenerRegistered( |
| 104 document(), EventTypeNames::webkitfullscreenchange, |
| 105 &fullscreenDetector())); |
| 106 EXPECT_FALSE(checkEventListenerRegistered( |
| 107 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); |
| 108 EXPECT_FALSE(checkEventListenerRegistered( |
| 109 newDocument(), EventTypeNames::webkitfullscreenchange, |
| 110 &fullscreenDetector())); |
| 111 |
| 112 newDocument().body()->appendChild(&videoElement()); |
| 113 |
| 114 EXPECT_FALSE(checkEventListenerRegistered( |
| 115 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); |
| 116 EXPECT_FALSE(checkEventListenerRegistered( |
| 117 document(), EventTypeNames::webkitfullscreenchange, |
| 118 &fullscreenDetector())); |
| 119 EXPECT_TRUE(checkEventListenerRegistered( |
| 120 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); |
| 121 EXPECT_TRUE(checkEventListenerRegistered( |
| 122 newDocument(), EventTypeNames::webkitfullscreenchange, |
| 123 &fullscreenDetector())); |
| 124 } |
| 125 |
| 126 } // namespace blink |
| OLD | NEW |