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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 // If scripts are not enabled, controls will always be shown. | 154 // If scripts are not enabled, controls will always be shown. |
155 m_pageHolder->frame().settings()->setScriptEnabled(true); | 155 m_pageHolder->frame().settings()->setScriptEnabled(true); |
156 } | 156 } |
157 | 157 |
158 void simulateRouteAvailabe() { | 158 void simulateRouteAvailabe() { |
159 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged( | 159 m_mediaControls->mediaElement().remoteRouteAvailabilityChanged( |
160 WebRemotePlaybackAvailability::DeviceAvailable); | 160 WebRemotePlaybackAvailability::DeviceAvailable); |
161 } | 161 } |
162 | 162 |
163 void ensureLayout() { | 163 void ensureSizing() { |
164 // Force a relayout, so that the controls know the width. Otherwise, | 164 // Fire the size-change callback to ensure that the controls have |
165 // they don't know if, for example, the cast button will fit. | 165 // been properly notified of the video size. |
166 m_mediaControls->mediaElement().clientWidth(); | 166 m_mediaControls->notifyElementSizeChanged( |
| 167 m_mediaControls->mediaElement().getBoundingClientRect()); |
167 } | 168 } |
168 | 169 |
169 void simulateHideMediaControlsTimerFired() { | 170 void simulateHideMediaControlsTimerFired() { |
170 m_mediaControls->hideMediaControlsTimerFired(nullptr); | 171 m_mediaControls->hideMediaControlsTimerFired(nullptr); |
171 } | 172 } |
172 | 173 |
173 void simulateLoadedMetadata() { m_mediaControls->onLoadedMetadata(); } | 174 void simulateLoadedMetadata() { m_mediaControls->onLoadedMetadata(); } |
174 | 175 |
175 MediaControls& mediaControls() { return *m_mediaControls; } | 176 MediaControls& mediaControls() { return *m_mediaControls; } |
176 Document& document() { return m_pageHolder->document(); } | 177 Document& document() { return m_pageHolder->document(); } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 Document& document = this->document(); | 228 Document& document = this->document(); |
228 int oldElementCount = document.styleEngine().styleForElementCount(); | 229 int oldElementCount = document.styleEngine().styleForElementCount(); |
229 // Also assert that there are no layouts yet. | 230 // Also assert that there are no layouts yet. |
230 ASSERT_EQ(0, oldElementCount); | 231 ASSERT_EQ(0, oldElementCount); |
231 mediaControls().reset(); | 232 mediaControls().reset(); |
232 int newElementCount = document.styleEngine().styleForElementCount(); | 233 int newElementCount = document.styleEngine().styleForElementCount(); |
233 ASSERT_EQ(oldElementCount, newElementCount); | 234 ASSERT_EQ(oldElementCount, newElementCount); |
234 } | 235 } |
235 | 236 |
236 TEST_F(MediaControlsTest, CastButtonRequiresRoute) { | 237 TEST_F(MediaControlsTest, CastButtonRequiresRoute) { |
237 ensureLayout(); | 238 ensureSizing(); |
238 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, | 239 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, |
239 true); | 240 true); |
240 | 241 |
241 Element* castButton = getElementByShadowPseudoId( | 242 Element* castButton = getElementByShadowPseudoId( |
242 mediaControls(), "-internal-media-controls-cast-button"); | 243 mediaControls(), "-internal-media-controls-cast-button"); |
243 ASSERT_NE(nullptr, castButton); | 244 ASSERT_NE(nullptr, castButton); |
244 | 245 |
245 ASSERT_FALSE(isElementVisible(*castButton)); | 246 ASSERT_FALSE(isElementVisible(*castButton)); |
246 | 247 |
247 simulateRouteAvailabe(); | 248 simulateRouteAvailabe(); |
248 ASSERT_TRUE(isElementVisible(*castButton)); | 249 ASSERT_TRUE(isElementVisible(*castButton)); |
249 } | 250 } |
250 | 251 |
251 TEST_F(MediaControlsTest, CastButtonDisableRemotePlaybackAttr) { | 252 TEST_F(MediaControlsTest, CastButtonDisableRemotePlaybackAttr) { |
252 ensureLayout(); | 253 ensureSizing(); |
253 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, | 254 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, |
254 true); | 255 true); |
255 | 256 |
256 Element* castButton = getElementByShadowPseudoId( | 257 Element* castButton = getElementByShadowPseudoId( |
257 mediaControls(), "-internal-media-controls-cast-button"); | 258 mediaControls(), "-internal-media-controls-cast-button"); |
258 ASSERT_NE(nullptr, castButton); | 259 ASSERT_NE(nullptr, castButton); |
259 | 260 |
260 ASSERT_FALSE(isElementVisible(*castButton)); | 261 ASSERT_FALSE(isElementVisible(*castButton)); |
261 simulateRouteAvailabe(); | 262 simulateRouteAvailabe(); |
262 ASSERT_TRUE(isElementVisible(*castButton)); | 263 ASSERT_TRUE(isElementVisible(*castButton)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 mediaControls().show(); | 330 mediaControls().show(); |
330 mediaControls().toggleOverflowMenu(); | 331 mediaControls().toggleOverflowMenu(); |
331 EXPECT_TRUE(isElementVisible(*overflowList)); | 332 EXPECT_TRUE(isElementVisible(*overflowList)); |
332 | 333 |
333 simulateHideMediaControlsTimerFired(); | 334 simulateHideMediaControlsTimerFired(); |
334 EXPECT_TRUE(isElementVisible(*overflowList)); | 335 EXPECT_TRUE(isElementVisible(*overflowList)); |
335 EXPECT_TRUE(isElementVisible(*panel)); | 336 EXPECT_TRUE(isElementVisible(*panel)); |
336 } | 337 } |
337 | 338 |
338 TEST_F(MediaControlsTest, DownloadButtonDisplayed) { | 339 TEST_F(MediaControlsTest, DownloadButtonDisplayed) { |
339 ensureLayout(); | 340 ensureSizing(); |
340 | 341 |
341 Element* downloadButton = getElementByShadowPseudoId( | 342 Element* downloadButton = getElementByShadowPseudoId( |
342 mediaControls(), "-internal-media-controls-download-button"); | 343 mediaControls(), "-internal-media-controls-download-button"); |
343 ASSERT_NE(nullptr, downloadButton); | 344 ASSERT_NE(nullptr, downloadButton); |
344 | 345 |
345 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); | 346 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); |
346 testing::runPendingTasks(); | 347 testing::runPendingTasks(); |
347 simulateLoadedMetadata(); | 348 simulateLoadedMetadata(); |
348 | 349 |
349 // Download button should normally be displayed. | 350 // Download button should normally be displayed. |
350 EXPECT_TRUE(isElementVisible(*downloadButton)); | 351 EXPECT_TRUE(isElementVisible(*downloadButton)); |
351 } | 352 } |
352 | 353 |
353 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedEmptyUrl) { | 354 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedEmptyUrl) { |
354 ensureLayout(); | 355 ensureSizing(); |
355 | 356 |
356 Element* downloadButton = getElementByShadowPseudoId( | 357 Element* downloadButton = getElementByShadowPseudoId( |
357 mediaControls(), "-internal-media-controls-download-button"); | 358 mediaControls(), "-internal-media-controls-download-button"); |
358 ASSERT_NE(nullptr, downloadButton); | 359 ASSERT_NE(nullptr, downloadButton); |
359 | 360 |
360 // Download button should not be displayed when URL is empty. | 361 // Download button should not be displayed when URL is empty. |
361 mediaControls().mediaElement().setSrc(""); | 362 mediaControls().mediaElement().setSrc(""); |
362 testing::runPendingTasks(); | 363 testing::runPendingTasks(); |
363 simulateLoadedMetadata(); | 364 simulateLoadedMetadata(); |
364 EXPECT_FALSE(isElementVisible(*downloadButton)); | 365 EXPECT_FALSE(isElementVisible(*downloadButton)); |
365 } | 366 } |
366 | 367 |
367 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedInfiniteDuration) { | 368 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedInfiniteDuration) { |
368 ensureLayout(); | 369 ensureSizing(); |
369 | 370 |
370 Element* downloadButton = getElementByShadowPseudoId( | 371 Element* downloadButton = getElementByShadowPseudoId( |
371 mediaControls(), "-internal-media-controls-download-button"); | 372 mediaControls(), "-internal-media-controls-download-button"); |
372 ASSERT_NE(nullptr, downloadButton); | 373 ASSERT_NE(nullptr, downloadButton); |
373 | 374 |
374 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); | 375 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4"); |
375 testing::runPendingTasks(); | 376 testing::runPendingTasks(); |
376 | 377 |
377 // Download button should not be displayed when duration is infinite. | 378 // Download button should not be displayed when duration is infinite. |
378 mediaControls().mediaElement().durationChanged( | 379 mediaControls().mediaElement().durationChanged( |
379 std::numeric_limits<double>::infinity(), false /* requestSeek */); | 380 std::numeric_limits<double>::infinity(), false /* requestSeek */); |
380 simulateLoadedMetadata(); | 381 simulateLoadedMetadata(); |
381 EXPECT_FALSE(isElementVisible(*downloadButton)); | 382 EXPECT_FALSE(isElementVisible(*downloadButton)); |
382 } | 383 } |
383 | 384 |
384 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedHLS) { | 385 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedHLS) { |
385 ensureLayout(); | 386 ensureSizing(); |
386 | 387 |
387 Element* downloadButton = getElementByShadowPseudoId( | 388 Element* downloadButton = getElementByShadowPseudoId( |
388 mediaControls(), "-internal-media-controls-download-button"); | 389 mediaControls(), "-internal-media-controls-download-button"); |
389 ASSERT_NE(nullptr, downloadButton); | 390 ASSERT_NE(nullptr, downloadButton); |
390 | 391 |
391 // Download button should not be displayed for HLS streams. | 392 // Download button should not be displayed for HLS streams. |
392 mediaControls().mediaElement().setSrc("https://example.com/foo.m3u8"); | 393 mediaControls().mediaElement().setSrc("https://example.com/foo.m3u8"); |
393 testing::runPendingTasks(); | 394 testing::runPendingTasks(); |
394 simulateLoadedMetadata(); | 395 simulateLoadedMetadata(); |
395 EXPECT_FALSE(isElementVisible(*downloadButton)); | 396 EXPECT_FALSE(isElementVisible(*downloadButton)); |
396 } | 397 } |
397 | 398 |
398 } // namespace blink | 399 } // namespace blink |
OLD | NEW |