Chromium Code Reviews| Index: Source/core/css/parser/MediaQueryParserTest.cpp |
| diff --git a/Source/core/css/parser/MediaQueryParserTest.cpp b/Source/core/css/parser/MediaQueryParserTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47a14e97a5b5760b86053b02943d5af3417cfa8c |
| --- /dev/null |
| +++ b/Source/core/css/parser/MediaQueryParserTest.cpp |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/css/parser/MediaQueryParser.h" |
| + |
| +#include "core/css/MediaList.h" |
| +#include "core/css/MediaQuery.h" |
| +#include "core/css/parser/CSSToken.h" |
| +#include "wtf/PassOwnPtr.h" |
| + |
| +#include <gtest/gtest.h> |
| + |
| +namespace WebCore { |
| + |
| +TEST(MediaQueryParserTest, Basic) |
| +{ |
| + Vector<pair<String, String> > testCases; |
| + testCases.append(std::make_pair("screen", "")); |
|
eseidel
2014/02/18 23:24:01
I might use a static helper method for this sort o
|
| + testCases.append(std::make_pair("screen and (color)", "")); |
| + testCases.append(std::make_pair("all and (min-width:500px)", "(min-width: 500px)")); |
| + testCases.append(std::make_pair("(min-width:500px)", "(min-width: 500px)")); |
| + testCases.append(std::make_pair("screen and (color), projection and (color)", "")); |
| + testCases.append(std::make_pair("not screen and (color)", "")); |
| + testCases.append(std::make_pair("only screen and (color)", "")); |
| + testCases.append(std::make_pair("screen and (color), projection and (color)", "")); |
| + testCases.append(std::make_pair("aural and (device-aspect-ratio: 16/9)", "")); |
| + testCases.append(std::make_pair("speech and (min-device-width: 800px)", "")); |
| + testCases.append(std::make_pair("example", "")); |
| + testCases.append(std::make_pair("screen and (max-weight: 3kg) and (color), (monochrome)", "not all, (monochrome)")); |
| + testCases.append(std::make_pair("(min-width: -100px)", "not all")); |
| + testCases.append(std::make_pair("(example, all,), speech", "not all, speech")); |
| + testCases.append(std::make_pair("&test, screen", "not all, screen")); |
| + testCases.append(std::make_pair("print and (min-width: 25cm)", "")); |
| + testCases.append(std::make_pair("screen and (min-width: 400px) and (max-width: 700px)", "screen and (max-width: 700px) and (min-width: 400px)")); |
| + testCases.append(std::make_pair("screen and (device-width: 800px)", "")); |
| + testCases.append(std::make_pair("screen and (device-height: 60em)", "")); |
| + testCases.append(std::make_pair("screen and (device-aspect-ratio: 16/9)", "")); |
| + testCases.append(std::make_pair("all and (color)", "(color)")); |
| + testCases.append(std::make_pair("all and (min-color: 1)", "(min-color: 1)")); |
| + testCases.append(std::make_pair("all and (min-color: 2)", "(min-color: 2)")); |
| + testCases.append(std::make_pair("all and (color-index)", "(color-index)")); |
| + testCases.append(std::make_pair("all and (min-color-index: 1)", "(min-color-index: 1)")); |
| + testCases.append(std::make_pair("all and (monochrome)", "(monochrome)")); |
| + testCases.append(std::make_pair("all and (min-monochrome: 1)", "(min-monochrome: 1)")); |
| + testCases.append(std::make_pair("all and (min-monochrome: 2)", "(min-monochrome: 2)")); |
| + testCases.append(std::make_pair("print and (monochrome)", "")); |
| + testCases.append(std::make_pair("handheld and (grid) and (max-width: 15em)", "")); |
| + testCases.append(std::make_pair("handheld and (grid) and (device-max-height: 7em)", "")); |
| + testCases.append(std::make_pair("screen and (max-width: 50%)", "")); |
| + testCases.append(std::make_pair("tv and (scan: progressive)", "")); |
| + testCases.append(std::make_pair("print and (min-resolution: 300dpi)", "")); |
| + testCases.append(std::make_pair("print and (min-resolution: 118dpcm)", "")); |
| + testCases.append(std::make_pair("handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "")); |
| + testCases.append(std::make_pair("all and(color)", "not all")); |
| + testCases.append(std::make_pair("test;,all", "not all")); |
| + testCases.append(std::make_pair("(orientation: portrait)", "")); |
| + testCases.append(std::make_pair("(min-orientation:portrait)", "")); |
| + testCases.append(std::make_pair("all and (orientation:portrait)", "")); |
| + testCases.append(std::make_pair("all and (orientation:landscape)", "")); |
| + testCases.append(std::make_pair("(color:20example)", "")); |
| + |
| + for (size_t i = 0; i < testCases.size(); ++i) { |
| + RefPtr<MediaQuerySet> querySet = MediaQueryParser::parse(testCases[i].first); |
| + String 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 (testCases[i].second != "") |
| + ASSERT_EQ(testCases[i].second, output); |
| + else |
| + ASSERT_EQ(testCases[i].first, output); |
| + } |
| +} |
| + |
| +} // namespace |