| 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/geometry/IntRect.h" | 11 #include "platform/geometry/IntRect.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 struct TestParam { | 18 struct TestParam { |
| 18 String description; | 19 String description; |
| 19 IntRect targetRect; | 20 IntRect targetRect; |
| 20 bool expectedResult; | 21 bool expectedResult; |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 } // anonymous namespace | 24 } // anonymous namespace |
| 24 | 25 |
| 25 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { | 26 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { |
| 26 protected: | 27 protected: |
| 27 void SetUp() override { | 28 void SetUp() override { |
| 29 m_originalVideoFullscreenDetectionEnabled = |
| 30 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled(); |
| 31 |
| 32 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true); |
| 33 |
| 28 m_pageHolder = DummyPageHolder::create(); | 34 m_pageHolder = DummyPageHolder::create(); |
| 29 m_newPageHolder = DummyPageHolder::create(); | 35 m_newPageHolder = DummyPageHolder::create(); |
| 30 | 36 |
| 31 m_video = HTMLVideoElement::create(m_pageHolder->document()); | 37 m_video = HTMLVideoElement::create(m_pageHolder->document()); |
| 32 document().body()->appendChild(&videoElement()); | 38 document().body()->appendChild(&videoElement()); |
| 33 } | 39 } |
| 34 | 40 |
| 41 void TearDown() override { |
| 42 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled( |
| 43 m_originalVideoFullscreenDetectionEnabled); |
| 44 } |
| 45 |
| 35 HTMLVideoElement& videoElement() const { return *m_video; } | 46 HTMLVideoElement& videoElement() const { return *m_video; } |
| 36 MediaCustomControlsFullscreenDetector& fullscreenDetector() const { | 47 MediaCustomControlsFullscreenDetector& fullscreenDetector() const { |
| 37 return *videoElement().m_customControlsFullscreenDetector; | 48 return *videoElement().m_customControlsFullscreenDetector; |
| 38 } | 49 } |
| 39 | 50 |
| 40 Document& document() const { return m_pageHolder->document(); } | 51 Document& document() const { return m_pageHolder->document(); } |
| 41 Document& newDocument() const { return m_newPageHolder->document(); } | 52 Document& newDocument() const { return m_newPageHolder->document(); } |
| 42 | 53 |
| 43 bool checkEventListenerRegistered(EventTarget& target, | 54 bool checkEventListenerRegistered(EventTarget& target, |
| 44 const AtomicString& eventType, | 55 const AtomicString& eventType, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 const IntRect& rootRect, | 69 const IntRect& rootRect, |
| 59 const IntRect& intersectionRect) { | 70 const IntRect& intersectionRect) { |
| 60 return MediaCustomControlsFullscreenDetector:: | 71 return MediaCustomControlsFullscreenDetector:: |
| 61 computeIsDominantVideoForTests(targetRect, rootRect, intersectionRect); | 72 computeIsDominantVideoForTests(targetRect, rootRect, intersectionRect); |
| 62 } | 73 } |
| 63 | 74 |
| 64 private: | 75 private: |
| 65 std::unique_ptr<DummyPageHolder> m_pageHolder; | 76 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 66 std::unique_ptr<DummyPageHolder> m_newPageHolder; | 77 std::unique_ptr<DummyPageHolder> m_newPageHolder; |
| 67 Persistent<HTMLVideoElement> m_video; | 78 Persistent<HTMLVideoElement> m_video; |
| 79 |
| 80 bool m_originalVideoFullscreenDetectionEnabled; |
| 68 }; | 81 }; |
| 69 | 82 |
| 70 TEST_F(MediaCustomControlsFullscreenDetectorTest, computeIsDominantVideo) { | 83 TEST_F(MediaCustomControlsFullscreenDetectorTest, computeIsDominantVideo) { |
| 71 // TestWithParam cannot be applied here as IntRect needs the memory allocator | 84 // TestWithParam cannot be applied here as IntRect needs the memory allocator |
| 72 // to be initialized, but the array of parameters is statically initialized, | 85 // to be initialized, but the array of parameters is statically initialized, |
| 73 // which is before the memory allocation initialization. | 86 // which is before the memory allocation initialization. |
| 74 TestParam testParams[] = { | 87 TestParam testParams[] = { |
| 75 {"xCompleteFill", {0, 0, 100, 50}, true}, | 88 {"xCompleteFill", {0, 0, 100, 50}, true}, |
| 76 {"yCompleteFill", {0, 0, 50, 100}, true}, | 89 {"yCompleteFill", {0, 0, 50, 100}, true}, |
| 77 {"xyCompleteFill", {0, 0, 100, 100}, true}, | 90 {"xyCompleteFill", {0, 0, 100, 100}, true}, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 document(), EventTypeNames::webkitfullscreenchange, | 129 document(), EventTypeNames::webkitfullscreenchange, |
| 117 &fullscreenDetector())); | 130 &fullscreenDetector())); |
| 118 EXPECT_TRUE(checkEventListenerRegistered( | 131 EXPECT_TRUE(checkEventListenerRegistered( |
| 119 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); | 132 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); |
| 120 EXPECT_TRUE(checkEventListenerRegistered( | 133 EXPECT_TRUE(checkEventListenerRegistered( |
| 121 newDocument(), EventTypeNames::webkitfullscreenchange, | 134 newDocument(), EventTypeNames::webkitfullscreenchange, |
| 122 &fullscreenDetector())); | 135 &fullscreenDetector())); |
| 123 } | 136 } |
| 124 | 137 |
| 125 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |