| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/CSSTestHelper.h" | 5 #include "core/css/CSSTestHelper.h" |
| 6 #include "core/css/RuleSet.h" | 6 #include "core/css/RuleSet.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 ".a.b .c {}"; | 48 ".a.b .c {}"; |
| 49 | 49 |
| 50 helper.addCSSRules(cssRules); | 50 helper.addCSSRules(cssRules); |
| 51 EXPECT_EQ(30u, helper.ruleSet().ruleCount()); // .a, .b counts as two rules. | 51 EXPECT_EQ(30u, helper.ruleSet().ruleCount()); // .a, .b counts as two rules. |
| 52 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| 53 helper.ruleSet().show(); | 53 helper.ruleSet().show(); |
| 54 #endif | 54 #endif |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST(CSSSelector, OverflowRareDataMatchNth) |
| 58 { |
| 59 int maxInt = std::numeric_limits<int>::max(); |
| 60 int minInt = std::numeric_limits<int>::min(); |
| 61 CSSSelector selector; |
| 62 |
| 63 // Overflow count - b (maxInt - -1 = maxInt + 1) |
| 64 selector.setNth(1, -1); |
| 65 EXPECT_FALSE(selector.matchNth(maxInt)); |
| 66 // 0 - (minInt) = maxInt + 1 |
| 67 selector.setNth(1, minInt); |
| 68 EXPECT_FALSE(selector.matchNth(0)); |
| 69 // minInt - 1 |
| 70 selector.setNth(1, 1); |
| 71 EXPECT_FALSE(selector.matchNth(minInt)); |
| 72 |
| 73 // Overflow b - count (0 - minInt = maxInt + 1) |
| 74 selector.setNth(-1, 0); |
| 75 EXPECT_FALSE(selector.matchNth(minInt)); |
| 76 // maxInt - -1 = maxInt + 1 |
| 77 selector.setNth(-1, maxInt); |
| 78 EXPECT_FALSE(selector.matchNth(-1)); |
| 79 // minInt - 1 |
| 80 selector.setNth(-1, minInt); |
| 81 EXPECT_FALSE(selector.matchNth(1)); |
| 82 |
| 83 // a shouldn't negate to itself (and minInt negates to itself). |
| 84 // Note: This test can only fail when using ubsan. |
| 85 selector.setNth(minInt, 10); |
| 86 EXPECT_FALSE(selector.matchNth(2)); |
| 87 } |
| 88 |
| 57 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |