Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlsTest.cpp

Issue 2710713003: Media Controls: Remove download button for infinite streams (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 #include <memory>
7 #include "core/HTMLNames.h" 9 #include "core/HTMLNames.h"
8 #include "core/css/StylePropertySet.h" 10 #include "core/css/StylePropertySet.h"
9 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
10 #include "core/dom/ElementTraversal.h" 12 #include "core/dom/ElementTraversal.h"
11 #include "core/dom/StyleEngine.h" 13 #include "core/dom/StyleEngine.h"
12 #include "core/frame/Settings.h" 14 #include "core/frame/Settings.h"
13 #include "core/html/HTMLVideoElement.h" 15 #include "core/html/HTMLVideoElement.h"
14 #include "core/loader/EmptyClients.h" 16 #include "core/loader/EmptyClients.h"
15 #include "core/testing/DummyPageHolder.h" 17 #include "core/testing/DummyPageHolder.h"
16 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
17 #include "platform/testing/UnitTestHelpers.h" 19 #include "platform/testing/UnitTestHelpers.h"
18 #include "public/platform/WebMediaPlayer.h" 20 #include "public/platform/WebMediaPlayer.h"
19 #include "public/platform/WebSize.h" 21 #include "public/platform/WebSize.h"
20 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h " 22 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h "
21 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" 23 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 #include <memory>
24 25
25 namespace blink { 26 namespace blink {
26 27
27 namespace { 28 namespace {
28 29
29 class MockVideoWebMediaPlayer : public WebMediaPlayer { 30 class MockVideoWebMediaPlayer : public WebMediaPlayer {
30 public: 31 public:
32 // WebMediaPlayer overrides:
31 void load(LoadType, const WebMediaPlayerSource&, CORSMode) override{}; 33 void load(LoadType, const WebMediaPlayerSource&, CORSMode) override{};
32 void play() override{}; 34 void play() override{};
33 void pause() override{}; 35 void pause() override{};
34 bool supportsSave() const override { return false; }; 36 bool supportsSave() const override { return false; };
35 void seek(double seconds) override{}; 37 void seek(double seconds) override{};
36 void setRate(double) override{}; 38 void setRate(double) override{};
37 void setVolume(double) override{}; 39 void setVolume(double) override{};
38 WebTimeRanges buffered() const override { return WebTimeRanges(); }; 40 WebTimeRanges buffered() const override { return WebTimeRanges(); };
39 WebTimeRanges seekable() const override { return WebTimeRanges(); }; 41 WebTimeRanges seekable() const override { return WebTimeRanges(); };
40 void setSinkId(const WebString& sinkId, 42 void setSinkId(const WebString& sinkId,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void ensureLayout() { 163 void ensureLayout() {
162 // Force a relayout, so that the controls know the width. Otherwise, 164 // Force a relayout, so that the controls know the width. Otherwise,
163 // they don't know if, for example, the cast button will fit. 165 // they don't know if, for example, the cast button will fit.
164 m_mediaControls->mediaElement().clientWidth(); 166 m_mediaControls->mediaElement().clientWidth();
165 } 167 }
166 168
167 void simulateHideMediaControlsTimerFired() { 169 void simulateHideMediaControlsTimerFired() {
168 m_mediaControls->hideMediaControlsTimerFired(nullptr); 170 m_mediaControls->hideMediaControlsTimerFired(nullptr);
169 } 171 }
170 172
173 void simulateLoadedMetadata() { m_mediaControls->onLoadedMetadata(); }
174
171 MediaControls& mediaControls() { return *m_mediaControls; } 175 MediaControls& mediaControls() { return *m_mediaControls; }
172 Document& document() { return m_pageHolder->document(); } 176 Document& document() { return m_pageHolder->document(); }
173 177
174 private: 178 private:
175 std::unique_ptr<DummyPageHolder> m_pageHolder; 179 std::unique_ptr<DummyPageHolder> m_pageHolder;
176 Persistent<MediaControls> m_mediaControls; 180 Persistent<MediaControls> m_mediaControls;
177 }; 181 };
178 182
179 TEST_F(MediaControlsTest, HideAndShow) { 183 TEST_F(MediaControlsTest, HideAndShow) {
180 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr, 184 mediaControls().mediaElement().setBooleanAttribute(HTMLNames::controlsAttr,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 312
309 mediaControls().show(); 313 mediaControls().show();
310 mediaControls().toggleOverflowMenu(); 314 mediaControls().toggleOverflowMenu();
311 EXPECT_TRUE(isElementVisible(*overflowList)); 315 EXPECT_TRUE(isElementVisible(*overflowList));
312 316
313 simulateHideMediaControlsTimerFired(); 317 simulateHideMediaControlsTimerFired();
314 EXPECT_TRUE(isElementVisible(*overflowList)); 318 EXPECT_TRUE(isElementVisible(*overflowList));
315 EXPECT_TRUE(isElementVisible(*panel)); 319 EXPECT_TRUE(isElementVisible(*panel));
316 } 320 }
317 321
322 TEST_F(MediaControlsTest, DownloadButtonDisplayed) {
323 ensureLayout();
324
325 Element* downloadButton = getElementByShadowPseudoId(
326 mediaControls(), "-internal-media-controls-download-button");
327 ASSERT_NE(nullptr, downloadButton);
328
329 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4");
330 testing::runPendingTasks();
331 simulateLoadedMetadata();
332
333 // Download button should normally be displayed.
334 EXPECT_TRUE(isElementVisible(*downloadButton));
335 }
336
337 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedEmptyUrl) {
338 ensureLayout();
339
340 Element* downloadButton = getElementByShadowPseudoId(
341 mediaControls(), "-internal-media-controls-download-button");
342 ASSERT_NE(nullptr, downloadButton);
343
344 // Download button should not be displayed when URL is empty.
345 mediaControls().mediaElement().setSrc("");
346 testing::runPendingTasks();
347 simulateLoadedMetadata();
348 EXPECT_FALSE(isElementVisible(*downloadButton));
349 }
350
351 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedInfiniteDuration) {
352 ensureLayout();
353
354 Element* downloadButton = getElementByShadowPseudoId(
355 mediaControls(), "-internal-media-controls-download-button");
356 ASSERT_NE(nullptr, downloadButton);
357
358 mediaControls().mediaElement().setSrc("https://example.com/foo.mp4");
359 testing::runPendingTasks();
360
361 // Download button should not be displayed when duration is infinite.
362 mediaControls().mediaElement().durationChanged(
363 std::numeric_limits<double>::infinity(), false /* requestSeek */);
364 simulateLoadedMetadata();
365 EXPECT_FALSE(isElementVisible(*downloadButton));
366 }
367
368 TEST_F(MediaControlsTest, DownloadButtonNotDisplayedHLS) {
369 ensureLayout();
370
371 Element* downloadButton = getElementByShadowPseudoId(
372 mediaControls(), "-internal-media-controls-download-button");
373 ASSERT_NE(nullptr, downloadButton);
374
375 // Download button should not be displayed for HLS streams.
376 mediaControls().mediaElement().setSrc("https://example.com/foo.m3u8");
377 testing::runPendingTasks();
378 simulateLoadedMetadata();
379 EXPECT_FALSE(isElementVisible(*downloadButton));
380 }
381
318 } // namespace blink 382 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698