Beispiel #1
0
/**
 * Verifies that the parser correctly parses a combination of 2 cue settings of
 * different types, delimited by a combination of U+0020 (space) and U+0009
 * (tab)
 *
 * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 *
 * 1. Let settings be the result of splitting input on spaces.
 *
 * From
 * http://dev.w3.org/html5/spec//common-microsyntaxes.html#space-separated-tokens
 * (11/27/2012):
 *
 * 5.1. Collect a sequence of characters that are not space characters.
 *
 * From http://dev.w3.org/html5/spec//common-microsyntaxes.html#space-character
 * (11/27/2012):
 *
 * The space characters, for the purposes of this specification, are U+0020
 * SPACE, "tab" (U+0009), "LF" (U+000A), "FF" (U+000C), and "CR" (U+000D).
 */
TEST_F(CueSetting, MultipleCueSettings2Mixed)
{
    loadVtt( "cue-settings/2-cue-settings-mixed.vtt", 1 );
    EXPECT_EQ( 0, errorCount() ) << "This file should contain no errors.";
    EXPECT_TRUE( getCue( 0 ).isVerticalLeftToRight() );
    EXPECT_EQ( 50, getCue( 0 ).relativeLinePositionPercentage() );
}
Beispiel #2
0
void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
{
    setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
    setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueWebkitPlaintext);
    
    TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue());
    RefPtr<HTMLSpanElement> cueElement = cue->element();

    float size = static_cast<float>(cue->getCSSSize());
    if (cue->useDefaultPosition()) {
        setInlineStyleProperty(CSSPropertyBottom, 0, CSSPrimitiveValue::CSS_PX);
        setInlineStyleProperty(CSSPropertyMarginBottom, 1.0, CSSPrimitiveValue::CSS_PERCENTAGE);
    } else {
        setInlineStyleProperty(CSSPropertyLeft, static_cast<float>(cue->position()), CSSPrimitiveValue::CSS_PERCENTAGE);
        setInlineStyleProperty(CSSPropertyTop, static_cast<float>(cue->line()), CSSPrimitiveValue::CSS_PERCENTAGE);

        if (cue->getWritingDirection() == VTTCue::Horizontal)
            setInlineStyleProperty(CSSPropertyWidth, size, CSSPrimitiveValue::CSS_PERCENTAGE);
        else
            setInlineStyleProperty(CSSPropertyHeight, size,  CSSPrimitiveValue::CSS_PERCENTAGE);
    }

    if (cue->getWritingDirection() == VTTCue::Horizontal)
        setInlineStyleProperty(CSSPropertyMinWidth, "-webkit-min-content");
    else
        setInlineStyleProperty(CSSPropertyMinHeight, "-webkit-min-content");

    if (cue->foregroundColor().isValid())
        cueElement->setInlineStyleProperty(CSSPropertyColor, cue->foregroundColor().serialized());
    if (cue->highlightColor().isValid())
        cueElement->setInlineStyleProperty(CSSPropertyBackgroundColor, cue->highlightColor().serialized());

    if (cue->getWritingDirection() == VTTCue::Horizontal)
        setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
    else
        setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto);

    if (cue->baseFontSizeRelativeToVideoHeight())
        cue->setFontSize(cue->baseFontSizeRelativeToVideoHeight(), videoSize, false);

    if (cue->getAlignment() == VTTCue::Middle)
        setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter);
    else if (cue->getAlignment() == VTTCue::End)
        setInlineStyleProperty(CSSPropertyTextAlign, CSSValueEnd);
    else
        setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart);

    if (cue->backgroundColor().isValid())
        setInlineStyleProperty(CSSPropertyBackgroundColor, cue->backgroundColor().serialized());
    setInlineStyleProperty(CSSPropertyWebkitWritingMode, cue->getCSSWritingMode(), false);
    setInlineStyleProperty(CSSPropertyWhiteSpace, CSSValuePreWrap);
}
Beispiel #3
0
/**
 * Test that the keyword is case-sensitive.
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * 4. Run the appropriate substeps that apply for the value of name, as follows:
 * If name is a case-sensitive match for "vertical" ...
 * If name is a case-sensitive match for "line" ...
 * If name is a case-sensitive match for "position" ...
 * If name is a case-sensitive match for "size" ...
 * If name is a case-sensitive match for "align" ...
 * 5. Next setting: Continue to the next token, if any.
 */
TEST_F(CueSettingAlign, UppercaseKeyword)
{
  loadVtt( "cue-settings/align/uppercase-keyword.vtt", 1 );
  const Error &err = getError( 0 );
  /**
   * Align should be "middle" because the malformed setting should be skipped
     * and "middle" is default.
   */
  ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() );
  /**
   * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the
   * 3rd line
   */
  expectEquals( getError( 0 ), WEBVTT_INVALID_CUESETTING, 3, 25 );
}
Beispiel #4
0
/**
 * Test that the parser requires a colon.
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * 1. If setting does not contain a U+003A COLON character (:), or if the first U+003A COLON character (:) in setting is either the first or last character of setting, then jump to the step labeled next setting.
 * 5. Next setting: Continue to the next token, if any.
 */
TEST_F(CueSettingAlign, NoDelimiter)
{
  loadVtt( "cue-settings/align/no-delimiter.vtt", 1 );
  const Error &err = getError( 0 );
  /**
   * Align should be "middle" because the malformed setting should be skipped
     * and "middle" is default.
   */
  ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() );
  /**
   * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the 3rd line
   */
  ASSERT_EQ( WEBVTT_INVALID_CUESETTING, err.error() );
  ASSERT_EQ( 3, err.line() );
  ASSERT_EQ( 25, err.column() );
}
Beispiel #5
0
/**
 * Test that the parser requires a colon.
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * 1. If setting does not contain a U+003A COLON character (:), or if the first
 *    U+003A COLON character (:) in setting is either the first or last
 *    character of setting, then jump to the step labeled next setting.
 * 5. Next setting: Continue to the next token, if any.
 */
TEST_F(CueSettingAlign, BadDelimiter)
{
  loadVtt( "cue-settings/align/bad-delimiter.vtt", 1 );
  ASSERT_EQ( 1, errorCount() );

  /**
   * Align should be "middle" because the malformed setting should be skipped
   * and "middle" is default.
   */
  ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() );

  /**
   * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the 3rd line
   */
  expectEquals( getError( 0 ), WEBVTT_INVALID_CUESETTING, 3, 25 );
}
Beispiel #6
0
/**
 * Test that the parser does not change align if the keyword matches nothing.
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * 4. Run the appropriate substeps that apply for the value of name, as follows:
 * If name is a case-sensitive match for "vertical" ...
 * If name is a case-sensitive match for "line" ...
 * If name is a case-sensitive match for "position" ...
 * If name is a case-sensitive match for "size" ...
 * If name is a case-sensitive match for "align" ...
 * 5. Next setting: Continue to the next token, if any.
 */
TEST_F(CueSettingAlign, BadKeyword)
{
  loadVtt( "cue-settings/align/bad-keyword.vtt", 1 );
  const Error &err = getError( 0 );
  /**
   * Align should be "middle" because the malformed setting should be skipped
     * and "middle" is default.
   */
  ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() );
  /**
   * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the 3rd line
   * We could return a smarter error, after a little bit of refactoring, perhaps.
   */
  ASSERT_EQ( WEBVTT_INVALID_CUESETTING, err.error() );
  ASSERT_EQ( 3, err.line() );
  ASSERT_EQ( 25, err.column() );
}
Beispiel #7
0
/**
 * Test what happens when there isn't a matching value for the setting align.
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * 4. Run the appropriate substeps that apply for the value of name, as follows:
 * If name is a case-sensitive match for "align"
 * 1. If value is a case-sensitive match for the string "start", ...
 * 2. If value is a case-sensitive match for the string "middle", ...
 * 3. If value is a case-sensitive match for the string "end", ...
 * 4. If value is a case-sensitive match for the string "left", ...
 * 5. If value is a case-sensitive match for the string "right", ...
 * 5. Next setting: Continue to the next token, if any.
 */
TEST_F(CueSettingAlign, BadValue)
{
  loadVtt( "cue-settings/align/bad-value.vtt", 1 );
  ASSERT_LE( 1, errorCount() );
  EXPECT_EQ( 1, errorCount() );

  /**
   * Align should be "middle" because the malformed setting should be skipped
   * and "middle" is default.
   */
  expectDefaultAlignSetting( getCue( 0 ) );

  /**
   * We're expecting a WEBVTT_ALIGN_BAD_VALUE error on the 25th column of the 3rd line
   */
  expectEquals( getError( 0 ), WEBVTT_ALIGN_BAD_VALUE, 3, 25 );
}
Beispiel #8
0
/**
 * Verify the parser accepts duplicate settings.
 *
 * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 *
 * 1. Let settings be the result of splitting input on spaces.
 * 2. For each token setting in the list settings...
 */
TEST_F(CueSetting, SameCueSetting)
{
    loadVtt( "cue-settings/2-same-settings.vtt", 1 );
    ASSERT_LE( 1, errorCount() ) << "This file should contain at least 1 error";
    EXPECT_EQ( 1, errorCount() ) << "This file should contain 1 error";
    /**
     * Parser will successfully parse duplicate settings so there will be no
     * error.  The settings are parsed in order so that the right most (last in
     * the list) one is used.
     */
    ASSERT_TRUE( getCue( 0 ).isVerticalRightToLeft() );
    /**
     * We're expecting a WEBVTT_VERTICAL_ALREADY_SET error on the 37th column of
     * the 3rd line We can probably make this smarter, like
     * WEBVTT_EXPECTED_CUESETTING_DELIMITER or something
     */
    expectEquals( getError( 0 ), WEBVTT_VERTICAL_ALREADY_SET, 3, 37 );
}
Beispiel #9
0
/**
 * Test that the parser takes everything to the right of the first colon in a
 * setting.
 *
 * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 *
 * 1. Let settings be the result of splitting input on spaces.
 * 2. For each token setting in the list settings...
 * 3. Let value be the trailing substring of setting starting from the
 *    character immediately after the first U+003A COLON character (:) in that
 *    string.
 */
TEST_F(CueSetting, BadDelimiter)
{
    loadVtt( "cue-settings/bad-delimiter.vtt", 1 );
    ASSERT_LE( 1, errorCount() ) << "This file should contain at least 1 error";
    EXPECT_EQ( 1, errorCount() ) << "This file should contain 1 error";

    /**
     * The parser should try to use "vertical" as keyword and "lr;line:50%" as
     * value.  Writing direction should "horizontal" because the malformed setting
     * should be skipped and "horizontal" is default.
     */
    expectDefaultVerticalSetting( getCue( 0 ) );

    /**
     * We're expecting a WEBVTT_VERTICAL_BAD_VALUE error on the 34th column of
     * the 3rd line (Beginning of value token)
     */
    expectEquals( getError( 0 ), WEBVTT_VERTICAL_BAD_VALUE, 3, 25 );
}
Beispiel #10
0
/**
 * Verifies that the parser can deal with the U+0020 delimiter
 *
 * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 *
 * 1. Let settings be the result of splitting input on spaces.
 *
 * From
 * http://dev.w3.org/html5/spec//common-microsyntaxes.html#space-separated-tokens
 * (11/27/2012):
 *
 * 4. Skip whitespace
 *
 * From http://dev.w3.org/html5/spec//common-microsyntaxes.html#skip-whitespace
 * (11/27/2012):
 *
 * The step skip whitespace means that the user agent must collect a sequence of
 * characters that are space characters. ...the collected characters are not
 * used.
 *
 * From http://dev.w3.org/html5/spec//common-microsyntaxes.html#space-character
 * (11/27/2012):
 *
 * The space characters, for the purposes of this specification, are U+0020
 * SPACE, "tab" (U+0009), "LF" (U+000A), "FF" (U+000C), and "CR" (U+000D).
 */
TEST_F(CueSetting, DelimiterMixed)
{
    loadVtt( "cue-settings/delimiter-mixed.vtt", 1 );
    EXPECT_EQ( 0, errorCount() ) << "This file should contain no errors.";
    EXPECT_TRUE( getCue( 0 ).isVerticalLeftToRight() );
}
Beispiel #11
0
/**
 * Test properly formatted align end cue setting
 *
 * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012):
 * If name is a case-sensitive match for "align"
 * If value is a case-sensitive match for the string "right", then let cue's text track cue alignment be right alignment.
 */
TEST_F(CueSettingAlign, Right)
{
  loadVtt( "cue-settings/align/right.vtt", 1 );
  ASSERT_EQ( 0, errorCount() ) << "This file should contain no errors.";
  ASSERT_TRUE( getCue( 0 ).isAlignedToRight() );
}
/**
 * Test expecting parser to pass and checks the second component of the time stamp
 *    UNTIL   
 *
 * From http://dev.w3.org/html5/webvtt/#webvtt-timestamp (10/15/2012):
 * A WebVTT timestamp representing hours hours, minutes minutes, seconds seconds,
 * and thousandths of a second seconds-frac, consists of the following components,
 * in the given order:
 * 1. Optionally (required if hour is non-zero):
 *    a. Two or more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
 *       NINE (9), representing the hours as a base ten integer.
 *
 *    b. A U+003A COLON character (:)
 *
 * 2. Two characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), 
 *    representing the minutes as a base ten integer in the range 0 ≤ minutes ≤ 59.
 *
 * 3. A U+003A COLON character (:)
 *
 * 4. Two characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing the 
 *    seconds as a base ten integer in the range 0 ≤ seconds ≤ 59.
 *
 * 5. A U+002E FULL STOP character (.).
 *
 * 6. Three characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), representing the 
 *    thousandths of a second seconds-frac as a base ten integer.
 */
TEST_F(CueTimeTimestampSecond,SecondsCheck)
{
  loadVtt( "cue-times/timestamp/from/second/good.vtt", 1 );
  ASSERT_EQ( 25, getCue(0).startTime().seconds() );
  EXPECT_EQ( 27, getCue(0).endTime().seconds() );
}