TEST(MediaConditionParserTest, Basic) { // The first string represents the input string. // The second string represents the output string, if present. // Otherwise, the output string is identical to the first string. TestCase testCases[] = { {"screen", "not all"}, {"screen and (color)", "not all"}, {"all and (min-width:500px)", "not all"}, {"(min-width:500px)", "(min-width: 500px)"}, {"(min-width: -100px)", "not all"}, {"(min-width: 100px) and print", "not all"}, {"(min-width: 100px) and (max-width: 900px)", "(max-width: 900px) and (min-width: 100px)"}, {"(min-width: [100px) and (max-width: 900px)", "not all"}, {"not (min-width: 900px)", "not all and (min-width: 900px)"}, {"not (blabla)", "not all"}, {0, 0} // Do not remove the terminator line. }; // FIXME: We should test comma-seperated media conditions for (unsigned i = 0; testCases[i].input; ++i) { CSSTokenizer::Scope scope(testCases[i].input); MediaQuerySet* mediaConditionQuerySet = MediaQueryParser::parseMediaCondition(scope.tokenRange()); ASSERT_EQ(mediaConditionQuerySet->queryVector().size(), (unsigned)1); String queryText = mediaConditionQuerySet->queryVector()[0]->cssText(); ASSERT_STREQ(testCases[i].output, queryText.ascii().data()); } }
static void testMediaQuery(TestCase test, MediaQuerySet& querySet, bool oldParser) { StringBuilder output; size_t j = 0; while (j < querySet.queryVector().size()) { String queryText = querySet.queryVector()[j]->cssText(); output.append(queryText); ++j; if (j >= querySet.queryVector().size()) break; output.append(", "); } if (!oldParser || test.shouldWorkOnOldParser) { if (test.output) ASSERT_STREQ(test.output, output.toString().ascii().data()); else ASSERT_STREQ(test.input, output.toString().ascii().data()); } }
static void testMediaQuery(const char* expected, MediaQuerySet& querySet) { const Vector<OwnPtr<MediaQuery> >& queryVector = querySet.queryVector(); size_t queryVectorSize = queryVector.size(); StringBuilder output; for (size_t i = 0; i < queryVectorSize; ) { String queryText = queryVector[i]->cssText(); output.append(queryText); ++i; if (i >= queryVectorSize) break; output.appendLiteral(", "); } ASSERT_STREQ(expected, output.toString().ascii().data()); }