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

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

Issue 2546993003: [MediaElement] Allow preloading for non-network scheme src (Closed)
Patch Set: rebased Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/HTMLMediaElement.h" 5 #include "core/html/HTMLMediaElement.h"
6 6
7 #include "core/frame/Settings.h"
7 #include "core/html/HTMLAudioElement.h" 8 #include "core/html/HTMLAudioElement.h"
8 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/page/NetworkStateNotifier.h"
9 #include "core/testing/DummyPageHolder.h" 11 #include "core/testing/DummyPageHolder.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace blink { 14 namespace blink {
13 15
14 enum class TestParam { Audio, Video }; 16 enum class TestParam { Audio, Video };
15 17
16 class HTMLMediaElementTest : public ::testing::TestWithParam<TestParam> { 18 class HTMLMediaElementTest : public ::testing::TestWithParam<TestParam> {
17 protected: 19 protected:
18 void SetUp() { 20 void SetUp() {
19 m_dummyPageHolder = DummyPageHolder::create(); 21 m_dummyPageHolder = DummyPageHolder::create();
20 22
21 if (GetParam() == TestParam::Audio) 23 if (GetParam() == TestParam::Audio)
22 m_media = HTMLAudioElement::create(m_dummyPageHolder->document()); 24 m_media = HTMLAudioElement::create(m_dummyPageHolder->document());
23 else 25 else
24 m_media = HTMLVideoElement::create(m_dummyPageHolder->document()); 26 m_media = HTMLVideoElement::create(m_dummyPageHolder->document());
25 } 27 }
26 28
27 HTMLMediaElement* media() { return m_media.get(); } 29 HTMLMediaElement* media() { return m_media.get(); }
30 void setCurrentSrc(const String& src) {
31 KURL url(ParsedURLString, src);
32 media()->m_currentSrc = url;
33 }
28 34
29 private: 35 private:
30 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 36 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
31 Persistent<HTMLMediaElement> m_media; 37 Persistent<HTMLMediaElement> m_media;
32 }; 38 };
33 39
34 INSTANTIATE_TEST_CASE_P(Audio, 40 INSTANTIATE_TEST_CASE_P(Audio,
35 HTMLMediaElementTest, 41 HTMLMediaElementTest,
36 ::testing::Values(TestParam::Audio)); 42 ::testing::Values(TestParam::Audio));
37 INSTANTIATE_TEST_CASE_P(Video, 43 INSTANTIATE_TEST_CASE_P(Video,
(...skipping 10 matching lines...) Expand all
48 {0.0, true, 0.0}, {0.5, true, 0.0}, {1.0, true, 0.0}, 54 {0.0, true, 0.0}, {0.5, true, 0.0}, {1.0, true, 0.0},
49 }; 55 };
50 56
51 for (const auto& data : test_data) { 57 for (const auto& data : test_data) {
52 media()->setVolume(data.volume); 58 media()->setVolume(data.volume);
53 media()->setMuted(data.muted); 59 media()->setMuted(data.muted);
54 EXPECT_EQ(data.effectiveVolume, media()->effectiveMediaVolume()); 60 EXPECT_EQ(data.effectiveVolume, media()->effectiveMediaVolume());
55 } 61 }
56 } 62 }
57 63
64 enum class TestURLScheme {
65 kHttp,
66 kHttps,
67 kFtp,
68 kFile,
69 kData,
70 kBlob,
71 };
72
73 String srcSchemeToURL(TestURLScheme scheme) {
74 switch (scheme) {
75 case TestURLScheme::kHttp:
76 return "http://example.com/foo.mp4";
77 case TestURLScheme::kHttps:
78 return "https://example.com/foo.mp4";
79 case TestURLScheme::kFtp:
80 return "ftp://example.com/foo.mp4";
81 case TestURLScheme::kFile:
82 return "file:///foo/bar.mp4";
83 case TestURLScheme::kData:
84 return "data:video/mp4;base64,XXXXXXX";
85 case TestURLScheme::kBlob:
86 return "blob:http://example.com/00000000-0000-0000-0000-000000000000";
87 }
88 }
89
90 TEST_P(HTMLMediaElementTest, preloadType) {
91 struct TestData {
92 bool dataSaverEnabled;
93 bool forcePreloadNoneForMediaElements;
94 bool isCellular;
95 TestURLScheme srcScheme;
96 AtomicString preloadToSet;
97 AtomicString preloadExpected;
98 } testData[] = {
99 // Tests for conditions in which preload type should be overriden to
100 // "none".
101 {false, true, false, TestURLScheme::kHttp, "auto", "none"},
102 {true, true, false, TestURLScheme::kHttps, "auto", "none"},
103 {true, true, false, TestURLScheme::kFtp, "metadata", "none"},
104 {false, false, false, TestURLScheme::kHttps, "auto", "auto"},
105 {false, true, false, TestURLScheme::kFile, "auto", "auto"},
106 {false, true, false, TestURLScheme::kData, "metadata", "metadata"},
107 {false, true, false, TestURLScheme::kBlob, "auto", "auto"},
108 {false, true, false, TestURLScheme::kFile, "none", "none"},
109 // Tests for conditions in which preload type should be overriden to
110 // "metadata".
111 {false, false, true, TestURLScheme::kHttp, "auto", "metadata"},
112 {false, false, true, TestURLScheme::kHttp, "scheme", "metadata"},
113 {false, false, true, TestURLScheme::kHttp, "none", "none"},
114 // Tests that the preload is overriden to "auto"
115 {false, false, false, TestURLScheme::kHttp, "foo", "auto"},
116 };
117
118 int index = 0;
119 for (const auto& data : testData) {
120 media()->document().settings()->setDataSaverEnabled(data.dataSaverEnabled);
121 media()->document().settings()->setForcePreloadNoneForMediaElements(
122 data.forcePreloadNoneForMediaElements);
123 if (data.isCellular) {
124 networkStateNotifier().setOverride(
125 true, WebConnectionType::WebConnectionTypeCellular3G, 2.0);
126 } else {
127 networkStateNotifier().clearOverride();
128 }
129 setCurrentSrc(srcSchemeToURL(data.srcScheme));
130 media()->setPreload(data.preloadToSet);
131
132 EXPECT_EQ(data.preloadExpected, media()->preload())
133 << "preload type differs at index" << index;
134 ++index;
135 }
136 }
137
58 } // namespace blink 138 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698