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 <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
10 #include "core/css/StylePropertySet.h" | 10 #include "core/css/StylePropertySet.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 MediaControls& mediaControls() { return *m_mediaControls; } | 186 MediaControls& mediaControls() { return *m_mediaControls; } |
187 MockVideoWebMediaPlayer* webMediaPlayer() { | 187 MockVideoWebMediaPlayer* webMediaPlayer() { |
188 return static_cast<MockVideoWebMediaPlayer*>( | 188 return static_cast<MockVideoWebMediaPlayer*>( |
189 mediaControls().mediaElement().webMediaPlayer()); | 189 mediaControls().mediaElement().webMediaPlayer()); |
190 } | 190 } |
191 Document& document() { return m_pageHolder->document(); } | 191 Document& document() { return m_pageHolder->document(); } |
192 | 192 |
193 HistogramTester& histogramTester() { return m_histogramTester; } | 193 HistogramTester& histogramTester() { return m_histogramTester; } |
194 | 194 |
| 195 void loadMediaWithDuration(double duration) { |
| 196 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); |
| 197 testing::runPendingTasks(); |
| 198 WebTimeRange timeRange(0.0, duration); |
| 199 webMediaPlayer()->m_seekable.assign(&timeRange, 1); |
| 200 mediaControls().mediaElement().durationChanged(duration, |
| 201 false /* requestSeek */); |
| 202 simulateLoadedMetadata(); |
| 203 } |
| 204 |
195 private: | 205 private: |
196 std::unique_ptr<DummyPageHolder> m_pageHolder; | 206 std::unique_ptr<DummyPageHolder> m_pageHolder; |
197 Persistent<MediaControls> m_mediaControls; | 207 Persistent<MediaControls> m_mediaControls; |
198 HistogramTester m_histogramTester; | 208 HistogramTester m_histogramTester; |
199 }; | 209 }; |
200 | 210 |
201 TEST_F(MediaControlsTest, HideAndShow) { | 211 TEST_F(MediaControlsTest, HideAndShow) { |
202 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, | 212 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, |
203 true); | 213 true); |
204 | 214 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 484 } |
475 | 485 |
476 TEST_F(MediaControlsTest, TimelineSeekToRoundedEnd) { | 486 TEST_F(MediaControlsTest, TimelineSeekToRoundedEnd) { |
477 ensureLayout(); | 487 ensureLayout(); |
478 | 488 |
479 MediaControlTimelineElement* timeline = | 489 MediaControlTimelineElement* timeline = |
480 static_cast<MediaControlTimelineElement*>(getElementByShadowPseudoId( | 490 static_cast<MediaControlTimelineElement*>(getElementByShadowPseudoId( |
481 mediaControls(), "-webkit-media-controls-timeline")); | 491 mediaControls(), "-webkit-media-controls-timeline")); |
482 ASSERT_NE(nullptr, timeline); | 492 ASSERT_NE(nullptr, timeline); |
483 | 493 |
484 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); | |
485 testing::runPendingTasks(); | |
486 | |
487 // Tests the case where the real length of the video, |exactDuration|, gets | 494 // Tests the case where the real length of the video, |exactDuration|, gets |
488 // rounded up slightly to |roundedUpDuration| when setting the timeline's | 495 // rounded up slightly to |roundedUpDuration| when setting the timeline's |
489 // |max| attribute (crbug.com/695065). | 496 // |max| attribute (crbug.com/695065). |
490 double exactDuration = 596.586667; | 497 double exactDuration = 596.586667; |
491 double roundedUpDuration = 596.587; | 498 double roundedUpDuration = 596.587; |
492 | 499 loadMediaWithDuration(exactDuration); |
493 WebTimeRange timeRange(0.0, exactDuration); | |
494 webMediaPlayer()->m_seekable.assign(&timeRange, 1); | |
495 mediaControls().mediaElement().durationChanged(exactDuration, | |
496 false /* requestSeek */); | |
497 simulateLoadedMetadata(); | |
498 | 500 |
499 // Simulate a click slightly past the end of the track of the timeline's | 501 // Simulate a click slightly past the end of the track of the timeline's |
500 // underlying <input type="range">. This would set the |value| to the |max| | 502 // underlying <input type="range">. This would set the |value| to the |max| |
501 // attribute, which can be slightly rounded relative to the duration. | 503 // attribute, which can be slightly rounded relative to the duration. |
502 timeline->setValueAsNumber(roundedUpDuration, ASSERT_NO_EXCEPTION); | 504 timeline->setValueAsNumber(roundedUpDuration, ASSERT_NO_EXCEPTION); |
503 ASSERT_EQ(roundedUpDuration, timeline->valueAsNumber()); | 505 ASSERT_EQ(roundedUpDuration, timeline->valueAsNumber()); |
504 EXPECT_EQ(0.0, mediaControls().mediaElement().currentTime()); | 506 EXPECT_EQ(0.0, mediaControls().mediaElement().currentTime()); |
505 timeline->dispatchInputEvent(); | 507 timeline->dispatchInputEvent(); |
506 EXPECT_EQ(exactDuration, mediaControls().mediaElement().currentTime()); | 508 EXPECT_EQ(exactDuration, mediaControls().mediaElement().currentTime()); |
507 } | 509 } |
508 | 510 |
| 511 TEST_F(MediaControlsTest, TimelineImmediatelyUpdatesCurrentTime) { |
| 512 ensureLayout(); |
| 513 |
| 514 MediaControlTimelineElement* timeline = |
| 515 static_cast<MediaControlTimelineElement*>(getElementByShadowPseudoId( |
| 516 mediaControls(), "-webkit-media-controls-timeline")); |
| 517 ASSERT_NE(nullptr, timeline); |
| 518 MediaControlCurrentTimeDisplayElement* currentTimeDisplay = |
| 519 static_cast<MediaControlCurrentTimeDisplayElement*>( |
| 520 getElementByShadowPseudoId( |
| 521 mediaControls(), "-webkit-media-controls-current-time-display")); |
| 522 ASSERT_NE(nullptr, currentTimeDisplay); |
| 523 |
| 524 double duration = 600; |
| 525 loadMediaWithDuration(duration); |
| 526 |
| 527 // Simulate seeking the underlying range to 50%. Current time display should |
| 528 // update synchronously (rather than waiting for media to finish seeking). |
| 529 timeline->setValueAsNumber(duration / 2, ASSERT_NO_EXCEPTION); |
| 530 timeline->dispatchInputEvent(); |
| 531 EXPECT_EQ(duration / 2, currentTimeDisplay->currentValue()); |
| 532 } |
| 533 |
509 } // namespace blink | 534 } // namespace blink |
OLD | NEW |