OLD | NEW |
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/frame/Settings.h" |
8 #include "core/html/HTMLAudioElement.h" | 8 #include "core/html/HTMLAudioElement.h" |
9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
11 #include "platform/network/NetworkStateNotifier.h" | 11 #include "platform/network/NetworkStateNotifier.h" |
| 12 #include "public/web/WebDataSaverFlag.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 enum class TestParam { kAudio, kVideo }; | 17 enum class TestParam { kAudio, kVideo }; |
17 | 18 |
18 class HTMLMediaElementTest : public ::testing::TestWithParam<TestParam> { | 19 class HTMLMediaElementTest : public ::testing::TestWithParam<TestParam> { |
19 protected: | 20 protected: |
20 void SetUp() { | 21 void SetUp() { |
21 dummy_page_holder_ = DummyPageHolder::Create(); | 22 dummy_page_holder_ = DummyPageHolder::Create(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 case TestURLScheme::kBlob: | 86 case TestURLScheme::kBlob: |
86 return "blob:http://example.com/00000000-0000-0000-0000-000000000000"; | 87 return "blob:http://example.com/00000000-0000-0000-0000-000000000000"; |
87 default: | 88 default: |
88 NOTREACHED(); | 89 NOTREACHED(); |
89 } | 90 } |
90 return g_empty_string; | 91 return g_empty_string; |
91 } | 92 } |
92 | 93 |
93 TEST_P(HTMLMediaElementTest, preloadType) { | 94 TEST_P(HTMLMediaElementTest, preloadType) { |
94 struct TestData { | 95 struct TestData { |
95 bool data_saver_enabled; | 96 WebDataSaverFlag data_saver_flag; |
96 bool force_preload_none_for_media_elements; | 97 bool force_preload_none_for_media_elements; |
97 bool is_cellular; | 98 bool is_cellular; |
98 TestURLScheme src_scheme; | 99 TestURLScheme src_scheme; |
99 AtomicString preload_to_set; | 100 AtomicString preload_to_set; |
100 AtomicString preload_expected; | 101 AtomicString preload_expected; |
101 } test_data[] = { | 102 } test_data[] = { |
102 // Tests for conditions in which preload type should be overriden to | 103 // Tests for conditions in which preload type should be overriden to |
103 // "none". | 104 // "none". |
104 {false, true, false, TestURLScheme::kHttp, "auto", "none"}, | 105 {WebDataSaverFlag::kDisabled, true, false, TestURLScheme::kHttp, "auto", |
105 {true, true, false, TestURLScheme::kHttps, "auto", "none"}, | 106 "none"}, |
106 {true, true, false, TestURLScheme::kFtp, "metadata", "none"}, | 107 {WebDataSaverFlag::kEnabled, true, false, TestURLScheme::kHttps, "auto", |
107 {false, false, false, TestURLScheme::kHttps, "auto", "auto"}, | 108 "none"}, |
108 {false, true, false, TestURLScheme::kFile, "auto", "auto"}, | 109 {WebDataSaverFlag::kEnabled, true, false, TestURLScheme::kFtp, "metadata", |
109 {false, true, false, TestURLScheme::kData, "metadata", "metadata"}, | 110 "none"}, |
110 {false, true, false, TestURLScheme::kBlob, "auto", "auto"}, | 111 {WebDataSaverFlag::kDisabled, false, false, TestURLScheme::kHttps, "auto", |
111 {false, true, false, TestURLScheme::kFile, "none", "none"}, | 112 "auto"}, |
| 113 {WebDataSaverFlag::kDisabled, true, false, TestURLScheme::kFile, "auto", |
| 114 "auto"}, |
| 115 {WebDataSaverFlag::kDisabled, true, false, TestURLScheme::kData, |
| 116 "metadata", "metadata"}, |
| 117 {WebDataSaverFlag::kDisabled, true, false, TestURLScheme::kBlob, "auto", |
| 118 "auto"}, |
| 119 {WebDataSaverFlag::kDisabled, true, false, TestURLScheme::kFile, "none", |
| 120 "none"}, |
112 // Tests for conditions in which preload type should be overriden to | 121 // Tests for conditions in which preload type should be overriden to |
113 // "metadata". | 122 // "metadata". |
114 {false, false, true, TestURLScheme::kHttp, "auto", "metadata"}, | 123 {WebDataSaverFlag::kDisabled, false, true, TestURLScheme::kHttp, "auto", |
115 {false, false, true, TestURLScheme::kHttp, "scheme", "metadata"}, | 124 "metadata"}, |
116 {false, false, true, TestURLScheme::kHttp, "none", "none"}, | 125 {WebDataSaverFlag::kDisabled, false, true, TestURLScheme::kHttp, "scheme", |
| 126 "metadata"}, |
| 127 {WebDataSaverFlag::kDisabled, false, true, TestURLScheme::kHttp, "none", |
| 128 "none"}, |
117 // Tests that the preload is overriden to "auto" | 129 // Tests that the preload is overriden to "auto" |
118 {false, false, false, TestURLScheme::kHttp, "foo", "auto"}, | 130 {WebDataSaverFlag::kDisabled, false, false, TestURLScheme::kHttp, "foo", |
| 131 "auto"}, |
119 }; | 132 }; |
120 | 133 |
121 int index = 0; | 134 int index = 0; |
122 for (const auto& data : test_data) { | 135 for (const auto& data : test_data) { |
123 Media()->GetDocument().GetSettings()->SetDataSaverEnabled( | 136 Media()->GetDocument().GetSettings()->SetDataSaverFlag( |
124 data.data_saver_enabled); | 137 data.data_saver_flag); |
125 Media()->GetDocument().GetSettings()->SetForcePreloadNoneForMediaElements( | 138 Media()->GetDocument().GetSettings()->SetForcePreloadNoneForMediaElements( |
126 data.force_preload_none_for_media_elements); | 139 data.force_preload_none_for_media_elements); |
127 if (data.is_cellular) { | 140 if (data.is_cellular) { |
128 GetNetworkStateNotifier().SetOverride( | 141 GetNetworkStateNotifier().SetOverride( |
129 true, WebConnectionType::kWebConnectionTypeCellular3G, 2.0); | 142 true, WebConnectionType::kWebConnectionTypeCellular3G, 2.0); |
130 } else { | 143 } else { |
131 GetNetworkStateNotifier().ClearOverride(); | 144 GetNetworkStateNotifier().ClearOverride(); |
132 } | 145 } |
133 SetCurrentSrc(SrcSchemeToURL(data.src_scheme)); | 146 SetCurrentSrc(SrcSchemeToURL(data.src_scheme)); |
134 Media()->setPreload(data.preload_to_set); | 147 Media()->setPreload(data.preload_to_set); |
135 | 148 |
136 EXPECT_EQ(data.preload_expected, Media()->preload()) | 149 EXPECT_EQ(data.preload_expected, Media()->preload()) |
137 << "preload type differs at index" << index; | 150 << "preload type differs at index" << index; |
138 ++index; | 151 ++index; |
139 } | 152 } |
140 } | 153 } |
141 | 154 |
142 } // namespace blink | 155 } // namespace blink |
OLD | NEW |