chromium/third_party/blink/web_tests/fast/media/mq-append-delete.html

<!doctype html>
<style type="text/css">@media screen { }</style>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id=log></div>
<script>
var rules = document.styleSheets[0].cssRules;
var mediaList = rules.item(0).media;

// - appendMedium()

test(function () {
    mediaList.mediaText = "screen";
    mediaList.appendMedium("tv, screen");
    assert_equals(mediaList.mediaText, "screen");
    // CSSOM 4.1: Parsing media query returns none as
    // there are more than one; terminate steps.
}, "Add 'tv, screen' to 'screen'");

test(function () {
    mediaList.mediaText = "screen";
    mediaList.appendMedium("tv");
    assert_equals(mediaList.mediaText, "screen, tv");
    // The valid media query is appended.
}, "Add 'tv' to 'screen'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("tv");
    assert_equals(mediaList.mediaText, "screen, tv");
    // CSSOM says to ignore if it exists, terminate steps.
}, "Add 'tv' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("screen");
    assert_equals(mediaList.mediaText, "screen, tv");
    // CSSOM says to ignore if it exists, where as
    // CSS 2.1 says to remove existing and then add
    // it to the end.
    // http://dev.w3.org/csswg/cssom/#dom-medialist-appendmedium
    // http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html
}, "Add 'screen' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium(" ");
    // Ignored; terminate steps.
    assert_equals(mediaList.mediaText, "screen, tv");
}, "Add ' ' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("");
    // Ignored; terminate steps.
    assert_equals(mediaList.mediaText, "screen, tv");
}, "Add '' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium(",");
    assert_equals(mediaList.mediaText, "screen, tv");
    // CSSOM 4.1: Parsing media query returns none as
    // there are more than one; terminate steps.
}, "Add ',' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("&invalid");
    assert_equals(mediaList.mediaText, "screen, tv, not all");
    // Ignored; terminate steps.
}, "Add '&invalid' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("not all");
    assert_equals(mediaList.mediaText, "screen, tv, not all");
}, "Add 'not all' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.appendMedium("#?:/");
    assert_equals(mediaList.mediaText, "screen, tv, not all");
    // Ignored; terminate steps.
}, "Add '#?:/' to 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    assert_throws_js(TypeError,
                     function () { document.appendMedium(); },
                     "Not enough arguments");
}, "Add without argument");

// - deleteMedium()

test(function () {
    mediaList.mediaText = "screen, tv, not all";
    mediaList.deleteMedium("&invalid");
    // Ignored; terminate steps.
    assert_equals(mediaList.mediaText, "screen, tv");
}, "Remove '&invalid' from 'screen, tv, not all'");

test(function () {
    mediaList.mediaText = "screen, tv";
    assert_throws_dom("NOT_FOUND_ERR",
        function () { mediaList.deleteMedium("not all"); }
    );
    // Not found; throw NotFoundError.
}, "Remove 'not all' from 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv";
    assert_throws_dom("NOT_FOUND_ERR",
        function () { mediaList.deleteMedium("cow"); }
    );
    // Not found; throw NotFoundError.
}, "Remove 'cow' from 'screen, tv'");

test(function () {
    mediaList.mediaText = "screen, tv, not all";
    mediaList.deleteMedium("not all");
    assert_equals(mediaList.mediaText, "screen, tv");
    // Remove any media query from the collection of media queries
    // for which comparing the media query returns true.
}, "Remove 'not all' from 'screen, tv, not all'");

test(function () {
    mediaList.mediaText = "screen, tv";
    mediaList.deleteMedium("tv");
    assert_equals(mediaList.mediaText, "screen");
    // Remove any media query from the collection of media queries
    // for which comparing the media query returns true.
}, "Remove 'tv' from 'screen, tv'");

test(function () {
    mediaList.mediaText = "not all, not all, tv, not all";
    mediaList.deleteMedium("not all");
    assert_equals(mediaList.mediaText, "tv");
    // Remove any media query from the collection of media queries
    // for which comparing the media query returns true.
}, "Remove 'not all' from 'not all, not all, tv, not all'");

test(function () {
    mediaList.mediaText = "not all, not all, tv, not all";
    mediaList.deleteMedium("tv");
    assert_equals(mediaList.mediaText, "not all, not all, not all");
    // Remove any media query from the collection of media queries
    // for which comparing the media query returns true.
}, "Remove 'tv' from 'not all, not all, tv, not all'");

test(function () {
    mediaList.mediaText = "tv, print, screen";
    mediaList.deleteMedium("tv, print");
    assert_equals(mediaList.mediaText, "tv, print, screen");
    // CSSOM 4.1: Parsing media query returns none as
    // there are more than one; terminate steps.
}, "Remove 'tv, print' from 'screen, tv, screen'");

test(function () {
    mediaList.mediaText = "screen, tv, not all";
    mediaList.deleteMedium("#?:/");
    // Ignored; terminate steps.
    assert_equals(mediaList.mediaText, "screen, tv");
}, "Remove '#?:/' from 'screen, tv, not all'");

test(function () {
    mediaList.mediaText = "tv, print, screen";
    assert_throws_js(TypeError,
                     function () { document.deleteMedium(); },
                     "Not enough arguments");
}, "Remove without argument");
</script>