Chromium Code Reviews| Index: Source/core/css/MediaQuerySetTest.cpp |
| diff --git a/Source/core/css/MediaQuerySetTest.cpp b/Source/core/css/MediaQuerySetTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f970f4ceaa3387cdb959546b7cbaacad3a10e087 |
| --- /dev/null |
| +++ b/Source/core/css/MediaQuerySetTest.cpp |
| @@ -0,0 +1,145 @@ |
| +// 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/MediaQuery.h" |
| + |
| +#include "core/css/MediaList.h" |
| +#include "wtf/PassOwnPtr.h" |
| + |
| +#include <gtest/gtest.h> |
| + |
| +#define OUTPUT_8BIT_LEN 256 |
| + |
| +namespace WebCore { |
| + |
| +typedef struct { |
| + const char* input; |
| + const char* output; |
| +} TestCase; |
| + |
| +int get8BitString(String str, char* output) |
|
kenneth.r.christiansen
2014/03/04 15:59:30
you write the same way if it is a 16bit string
|
| +{ |
| + if (!str.impl()) { |
| + return 0; |
| + } |
| + |
| + unsigned i; |
| + if (str.is8Bit()) { |
| + for (i = 0; i < str.length(); ++i) |
| + output[i] = str.characters8()[i]; |
| + } else { |
| + for (i = 0; i < str.length(); ++i) |
| + output[i] = str.characters16()[i]; |
| + } |
| + output[i++] = 0; |
| + return i; |
| +} |
| + |
| +TEST(MediaQueryParserTest, Basic) |
| +{ |
| + TestCase testCases[] = { |
| + {"screen", ""}, |
| + {"screen and (color)", ""}, |
| + {"all and (min-width:500px)", "(min-width: 500px)"}, |
| + {"(min-width:500px)", "(min-width: 500px)"}, |
| + {"screen and (color), projection and (color)", ""}, |
| + {"not screen and (color)", ""}, |
| + {"only screen and (color)", ""}, |
| + {"screen and (color), projection and (color)", ""}, |
| + {"aural and (device-aspect-ratio: 16/9)", ""}, |
| + {"speech and (min-device-width: 800px)", ""}, |
| + {"example", ""}, |
| + {"screen and (max-weight: 3kg) and (color), (monochrome)", "not all, (monochrome)"}, |
| + {"(min-width: -100px)", "not all"}, |
| + {"(example, all,), speech", "not all, speech"}, |
| + {"&test, screen", "not all, screen"}, |
| + {"print and (min-width: 25cm)", ""}, |
| + {"screen and (min-width: 400px) and (max-width: 700px)", "screen and (max-width: 700px) and (min-width: 400px)"}, |
| + {"screen and (device-width: 800px)", ""}, |
| + {"screen and (device-height: 60em)", ""}, |
| + {"screen and (device-aspect-ratio: 16/9)", ""}, |
| + {"(device-aspect-ratio: 16.0/9.0)", "not all"}, |
| + {"(device-aspect-ratio: 16/ 9)", "(device-aspect-ratio: 16/9)"}, |
| + {"(device-aspect-ratio: 16/\r9)", "(device-aspect-ratio: 16/9)"}, |
| + {"all and (color)", "(color)"}, |
| + {"all and (min-color: 1)", "(min-color: 1)"}, |
| + {"all and (min-color: 1.0)", "not all"}, |
| + {"all and (min-color: 2)", "(min-color: 2)"}, |
| + {"all and (color-index)", "(color-index)"}, |
| + {"all and (min-color-index: 1)", "(min-color-index: 1)"}, |
| + {"all and (monochrome)", "(monochrome)"}, |
| + {"all and (min-monochrome: 1)", "(min-monochrome: 1)"}, |
| + {"all and (min-monochrome: 2)", "(min-monochrome: 2)"}, |
| + {"print and (monochrome)", ""}, |
| + {"handheld and (grid) and (max-width: 15em)", ""}, |
| + {"handheld and (grid) and (max-device-height: 7em)", ""}, |
| + {"screen and (max-width: 50%)", "not all"}, |
| + {"screen and (max-WIDTH: 500px)", "screen and (max-width: 500px)"}, |
| + {"screen and (max-width: 24.4em)", ""}, |
| + {"screen and (max-width: 24.4EM)", "screen and (max-width: 24.4em)"}, |
| + {"screen and (max-width: blabla)", "not all"}, |
| + {"screen and (max-width: 1)", "not all"}, |
| + {"screen and (max-width: 0)", ""}, |
| + {"screen and (max-width: 1deg)", "not all"}, |
| + {"handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "handheld and (min-width: 20em), screen and (min-width: 20em)"}, |
| + {"print and (min-resolution: 300dpi)", ""}, |
| + {"print and (min-resolution: 118dpcm)", ""}, |
| + {"(resolution: 0.83333333333333333333dppx)", "(resolution: 0.8333333333333334dppx)"}, |
| + {"(resolution: 2.4dppx)", ""}, |
| + {"all and(color)", "not all"}, |
| + {"all and (", "not all"}, |
| + {"test;,all", "not all, all"}, |
| + {"(color:20example)", "not all"}, |
| + {"not braille", ""}, |
| + {",screen", "not all, screen"}, |
| + {",all", "not all, all"}, |
| + {",,all,,", "not all, not all, all, not all, not all"}, |
| + {",,all,, ", "not all, not all, all, not all, not all"}, |
| + {",screen,,&invalid,,", "not all, screen, not all, not all, not all, not all"}, |
| + {",screen,,(invalid,),,", "not all, screen, not all, not all, not all, not all"}, |
| + {",(all,),,", "not all, not all, not all, not all"}, |
| + {",", "not all, not all"}, |
| + {" ", ""}, |
| + {"(color", "(color)"}, |
| + {"(min-color: 2", "(min-color: 2)"}, |
| + {"(orientation: portrait)", ""}, |
| + {"tv and (scan: progressive)", ""}, |
| + {"(pointer: coarse)", ""}, |
| + {"(min-orientation:portrait)", "not all"}, |
| + {"all and (orientation:portrait)", "(orientation: portrait)"}, |
| + {"all and (orientation:landscape)", "(orientation: landscape)"}, |
| + {"NOT braille, tv AND (max-width: 200px) and (min-WIDTH: 100px) and (orientation: landscape), (color)", |
| + "not braille, tv and (max-width: 200px) and (min-width: 100px) and (orientation: landscape), (color)"}, |
| + {"", ""} // That's here as a terminator for the loop. Do not remove! |
|
kenneth.r.christiansen
2014/03/04 15:59:30
why not 0, 0?
|
| + }; |
| + |
| + unsigned i = 0; |
| + while (testCases[i].input[0]) { |
| + RefPtr<MediaQuerySet> querySet = MediaQuerySet::create(testCases[i].input); |
| + String output; |
| + char output8bit[OUTPUT_8BIT_LEN]; |
| + 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(", "); |
| + } |
| + ASSERT(output.length() < OUTPUT_8BIT_LEN); |
| + get8BitString(output, output8bit); |
| + if (testCases[i].output[0]) |
| + ASSERT_STREQ(testCases[i].output, output8bit); |
| + else if (testCases[i].input[0] != ' ') |
| + ASSERT_STREQ(testCases[i].input, output8bit); |
| + else |
| + ASSERT_EQ((unsigned)0, output.length()); |
| + |
| + ++i; |
| + } |
| +} |
| + |
| +} // namespace |