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

Unified Diff: third_party/WebKit/LayoutTests/media/track/track-language-preference.html

Issue 1938533002: Convert track-language* and track-large* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/track/track-language-preference-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/media/track/track-language-preference.html
diff --git a/third_party/WebKit/LayoutTests/media/track/track-language-preference.html b/third_party/WebKit/LayoutTests/media/track/track-language-preference.html
index 02ca7009040c1bffc81b7da4479945786f1a48c9..2ccaf3ccf2271f96e5759c697a578590cc371b67 100644
--- a/third_party/WebKit/LayoutTests/media/track/track-language-preference.html
+++ b/third_party/WebKit/LayoutTests/media/track/track-language-preference.html
@@ -1,121 +1,87 @@
<!DOCTYPE html>
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
- <style>
- video { background-color: yellow; width: 320px; height: 240px;}
- </style>
- <script src=../media-file.js></script>
- <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956
- (Please avoid writing new tests using video-test.js) -->
- <script src=../video-test.js></script>
- <script>
-
- var timer = null;
- var expectedLanguage;
- var testList =
- {
- current : -1,
- tests :
- [
- {
- description: "a track language matches one of the user's preferred languages exactly",
- languages : ['fr', 'en', 'jp'],
- expectedLanguage : "jp",
- },
- {
- description: "a track language without locale exactly matches one of the user's preferred languages",
- languages : ['fr-CH', 'da'],
- expectedLanguage : "fr-CH",
- },
- {
- description: "a track language without locale matches one of the user's preferred languages without locale",
- languages : ['fr', 'es-MX'],
- expectedLanguage : "es-MX",
- },
- {
- description: "no track language matches any of the user's preferred languages",
- languages : ['fa', 'ru', 'no'],
- expectedLanguage : "fa",
- },
- ]
- };
-
- function runNextTest()
- {
- consoleWrite("");
- testList.current++;
- if (testList.current >= testList.tests.length) {
- var tracks = document.querySelectorAll('track');
- testExpected("video.textTracks.length", tracks.length);
- endTest();
- return;
- }
-
- consoleWrite("<b>Test: </b> <em>"+ testList.tests[testList.current].description + ".</em>");
- createTrackElements(testList.tests[testList.current].languages);
- }
-
- function trackLoaded()
- {
- consoleWrite("EVENT(load)");
-
- // Don't log the event name because the order of the two events in not predictable.
- track = event.target;
- testExpected("track.readyState", HTMLTrackElement.LOADED);
- testExpected("track.srclang", testList.tests[testList.current].expectedLanguage);
-
- timer = setTimeout(runNextTest, 200);
- }
-
- function setPreferences()
+<title>Tests that the user's preferred languages are honored.</title>
+<video></video>
+<script src="../media-file.js"></script>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+async_test(function(t) {
+ var video = document.querySelector("video");
+
+ // Set user preferred languages.
+ internals.setUserPreferredLanguages(['jp', 'es-ES', 'en', 'fr']);
+ internals.settings.setTextTrackKindUserPreference('captions');
+
+ var timer;
+ var expectedLanguage;
+ var testList =
+ {
+ currentTestIndex : -1,
+ tests :
+ [
{
- if (!window.internals) {
- consoleWrite("<b>** This test only works in DRT! **<" + "/b>");
- return;
- }
-
- consoleWrite("<i>**Set user preferred languages<" + "/i>");
- run("internals.setUserPreferredLanguages(['jp', 'es-ES', 'en', 'fr'])");
- window.internals.settings.setTextTrackKindUserPreference('captions');
- }
-
- function createTrackElement(language, src)
+ // A track language matches one of the user's preferred languages exactly.
+ languages : ['fr', 'en', 'jp'],
+ expectedLanguage : "jp"
+ },
{
- var track = document.createElement('track');
- track.setAttribute('kind', "captions");
- track.setAttribute('src', src);
- track.setAttribute('srclang', language);
- track.setAttribute('onload', 'trackLoaded()');
- video.appendChild(track);
- }
-
- function createTrackElements(languages)
+ // A track language without locale exactly matches
+ // one of the user's preferred languages.
+ languages : ['fr-CH', 'da'],
+ expectedLanguage : "fr-CH"
+ },
{
- var tracks = document.querySelectorAll('track');
- for (var ndx = 0; ndx < tracks.length; ++ndx)
- video.removeChild(tracks[ndx]);
-
- consoleWrite("<i>- creating tracks for: [" + languages + "].<" + "/i>");
- for (var ndx = 0; ndx < languages.length; ++ndx)
- createTrackElement(languages[ndx], "captions-webvtt/tc004-webvtt-file.vtt");
- }
-
- function setup()
+ // A track language without locale matches one of
+ // the user's preferred languages without locale.
+ languages : ['fr', 'es-MX'],
+ expectedLanguage : "es-MX"
+ },
{
- findMediaElement();
-
- setPreferences();
-
- runNextTest();
+ // No track language matches any of the user's preferred languages.
+ languages : ['fa', 'ru', 'no'],
+ expectedLanguage : "fa"
}
-
- </script>
- </head>
- <body onload="setup()">
- <p>Tests that the user's preferred languages are honored.</p>
- <video>
- </video>
- </body>
-</html>
+ ]
+ };
+
+ runNextTest();
+
+ function runNextTest() {
+ testList.currentTestIndex++;
+ if (testList.currentTestIndex >= testList.tests.length) {
+ var tracks = document.querySelectorAll('track');
+ assert_equals(video.textTracks.length, tracks.length);
+ t.done();
+ return;
+ }
+
+ createTrackElements(testList.tests[testList.currentTestIndex].languages);
+ }
+
+ function createTrackElements(languages) {
+ var tracks = document.querySelectorAll('track');
+ for (var index = 0; index < tracks.length; ++index)
+ video.removeChild(tracks[index]);
+
+ for (var index = 0; index < languages.length; ++index)
+ createTrackElement(languages[index], "captions-webvtt/tc004-webvtt-file.vtt");
+ }
+
+ function createTrackElement(language, src) {
+ var track = document.createElement('track');
+ track.setAttribute('kind', "captions");
+ track.setAttribute('src', src);
+ track.setAttribute('srclang', language);
+ track.onload = t.step_func(trackLoaded);
+ video.appendChild(track);
+ }
+
+ function trackLoaded() {
+ var track = event.target;
+ assert_equals(track.readyState, HTMLTrackElement.LOADED);
+ assert_equals(track.srclang, testList.tests[testList.currentTestIndex].expectedLanguage);
+
+ timer = setTimeout(runNextTest, 200);
+ }
+});
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/track/track-language-preference-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698