tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

image.rs (5509B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 use style::parser::Parse;
      6 use style::values::specified::image::*;
      7 use style_traits::ToCss;
      8 
      9 #[test]
     10 fn test_linear_gradient() {
     11    // Parsing from the right
     12    assert_roundtrip_with_context!(Image::parse, "linear-gradient(to left, red, green)");
     13 
     14    // Parsing from the left
     15    assert_roundtrip_with_context!(Image::parse, "linear-gradient(to right, red, green)");
     16 
     17    // Parsing with two values for <side-or-corner>
     18    assert_roundtrip_with_context!(Image::parse, "linear-gradient(to right top, red, green)");
     19 
     20    // Parsing with <angle>
     21    assert_roundtrip_with_context!(Image::parse, "linear-gradient(45deg, red, green)");
     22 
     23    // Parsing with more than two entries in <color-stop-list>
     24    assert_roundtrip_with_context!(Image::parse, "linear-gradient(red, yellow, green)");
     25 
     26    // Parsing with percentage in the <color-stop-list>
     27    assert_roundtrip_with_context!(Image::parse, "linear-gradient(red, green, yellow 50%)");
     28 
     29    // Parsing without <angle> and <side-or-corner>
     30    assert_roundtrip_with_context!(Image::parse, "linear-gradient(red, green)");
     31 }
     32 
     33 #[test]
     34 fn test_radial_gradient() {
     35    // Parsing with all values
     36    assert_roundtrip_with_context!(
     37        Image::parse,
     38        "radial-gradient(circle closest-side at 20px 30px, red, green)"
     39    );
     40    assert_roundtrip_with_context!(
     41        Image::parse,
     42        "radial-gradient(ellipse closest-side at 20px 30px, red, green)",
     43        "radial-gradient(closest-side at 20px 30px, red, green)"
     44    );
     45    assert_roundtrip_with_context!(
     46        Image::parse,
     47        "radial-gradient(closest-side circle at 20px 30px, red, green)",
     48        "radial-gradient(circle closest-side at 20px 30px, red, green)"
     49    );
     50    assert_roundtrip_with_context!(
     51        Image::parse,
     52        "radial-gradient(closest-side ellipse at 20px 30px, red, green)",
     53        "radial-gradient(closest-side at 20px 30px, red, green)"
     54    );
     55 
     56    // Parsing with <shape-keyword> and <size> reversed
     57    assert_roundtrip_with_context!(
     58        Image::parse,
     59        "radial-gradient(closest-side circle at 20px 30px, red, green)",
     60        "radial-gradient(circle closest-side at 20px 30px, red, green)"
     61    );
     62    assert_roundtrip_with_context!(
     63        Image::parse,
     64        "radial-gradient(closest-corner ellipse at 20px 30px, red, green)",
     65        "radial-gradient(closest-corner at 20px 30px, red, green)"
     66    );
     67    assert_roundtrip_with_context!(
     68        Image::parse,
     69        "radial-gradient(30px circle, red, green)",
     70        "radial-gradient(30px at center center, red, green)"
     71    );
     72    assert_roundtrip_with_context!(
     73        Image::parse,
     74        "radial-gradient(30px 40px ellipse, red, green)",
     75        "radial-gradient(30px 40px at center center, red, green)"
     76    );
     77 
     78    // Parsing without <size>
     79    assert_roundtrip_with_context!(
     80        Image::parse,
     81        "radial-gradient(circle, red, green)",
     82        "radial-gradient(circle at center center, red, green)"
     83    );
     84    assert_roundtrip_with_context!(
     85        Image::parse,
     86        "radial-gradient(ellipse, red, green)",
     87        "radial-gradient(at center center, red, green)"
     88    );
     89    assert_roundtrip_with_context!(
     90        Image::parse,
     91        "radial-gradient(circle at 20px 30px, red, green)"
     92    );
     93    assert_roundtrip_with_context!(
     94        Image::parse,
     95        "radial-gradient(ellipse at 20px 30px, red, green)",
     96        "radial-gradient(at 20px 30px, red, green)"
     97    );
     98 
     99    // Parsing without <shape-keyword>
    100    assert_roundtrip_with_context!(
    101        Image::parse,
    102        "radial-gradient(20px at 20px 30px, red, green)"
    103    );
    104    assert_roundtrip_with_context!(
    105        Image::parse,
    106        "radial-gradient(20px 30px at left center, red, green)"
    107    );
    108    assert_roundtrip_with_context!(
    109        Image::parse,
    110        "radial-gradient(closest-side at center, red, green)",
    111        "radial-gradient(closest-side at center center, red, green)"
    112    );
    113    assert_roundtrip_with_context!(
    114        Image::parse,
    115        "radial-gradient(20px, red, green)",
    116        "radial-gradient(20px at center center, red, green)"
    117    );
    118    assert_roundtrip_with_context!(
    119        Image::parse,
    120        "radial-gradient(20px 30px, red, green)",
    121        "radial-gradient(20px 30px at center center, red, green)"
    122    );
    123    assert_roundtrip_with_context!(
    124        Image::parse,
    125        "radial-gradient(closest-side, red, green)",
    126        "radial-gradient(closest-side at center center, red, green)"
    127    );
    128 
    129    // Parsing without <shape-keyword> and <size>
    130    assert_roundtrip_with_context!(
    131        Image::parse,
    132        "radial-gradient(at center, red, green)",
    133        "radial-gradient(at center center, red, green)"
    134    );
    135    assert_roundtrip_with_context!(
    136        Image::parse,
    137        "radial-gradient(at center bottom, red, green)"
    138    );
    139    assert_roundtrip_with_context!(Image::parse, "radial-gradient(at 40px 50px, red, green)");
    140 
    141    // Parsing with just color stops
    142    assert_roundtrip_with_context!(
    143        Image::parse,
    144        "radial-gradient(red, green)",
    145        "radial-gradient(at center center, red, green)"
    146    );
    147 
    148    // Parsing repeating radial gradient
    149    assert_roundtrip_with_context!(
    150        Image::parse,
    151        "repeating-radial-gradient(red, green)",
    152        "repeating-radial-gradient(at center center, red, green)"
    153    );
    154 }