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

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: nits 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.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 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 default:
88 NOTREACHED();
89 }
90 return emptyString();
91 }
92
93 TEST_P(HTMLMediaElementTest, preloadType) {
94 struct TestData {
95 bool dataSaverEnabled;
96 bool forcePreloadNoneForMediaElements;
97 bool isCellular;
98 TestURLScheme srcScheme;
99 AtomicString preloadToSet;
100 AtomicString preloadExpected;
101 } testData[] = {
102 // Tests for conditions in which preload type should be overriden to
103 // "none".
104 {false, true, false, TestURLScheme::kHttp, "auto", "none"},
105 {true, true, false, TestURLScheme::kHttps, "auto", "none"},
106 {true, true, false, TestURLScheme::kFtp, "metadata", "none"},
107 {false, false, false, TestURLScheme::kHttps, "auto", "auto"},
108 {false, true, false, TestURLScheme::kFile, "auto", "auto"},
109 {false, true, false, TestURLScheme::kData, "metadata", "metadata"},
110 {false, true, false, TestURLScheme::kBlob, "auto", "auto"},
111 {false, true, false, TestURLScheme::kFile, "none", "none"},
112 // Tests for conditions in which preload type should be overriden to
113 // "metadata".
114 {false, false, true, TestURLScheme::kHttp, "auto", "metadata"},
115 {false, false, true, TestURLScheme::kHttp, "scheme", "metadata"},
116 {false, false, true, TestURLScheme::kHttp, "none", "none"},
117 // Tests that the preload is overriden to "auto"
118 {false, false, false, TestURLScheme::kHttp, "foo", "auto"},
119 };
120
121 int index = 0;
122 for (const auto& data : testData) {
123 media()->document().settings()->setDataSaverEnabled(data.dataSaverEnabled);
124 media()->document().settings()->setForcePreloadNoneForMediaElements(
125 data.forcePreloadNoneForMediaElements);
126 if (data.isCellular) {
127 networkStateNotifier().setOverride(
128 true, WebConnectionType::WebConnectionTypeCellular3G, 2.0);
129 } else {
130 networkStateNotifier().clearOverride();
131 }
132 setCurrentSrc(srcSchemeToURL(data.srcScheme));
133 media()->setPreload(data.preloadToSet);
134
135 EXPECT_EQ(data.preloadExpected, media()->preload())
136 << "preload type differs at index" << index;
137 ++index;
138 }
139 }
140
58 } // namespace blink 141 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698