| 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 ".a.b .c {}"; | 47 ".a.b .c {}"; |
| 48 | 48 |
| 49 helper.AddCSSRules(css_rules); | 49 helper.AddCSSRules(css_rules); |
| 50 EXPECT_EQ(30u, | 50 EXPECT_EQ(30u, |
| 51 helper.GetRuleSet().RuleCount()); // .a, .b counts as two rules. | 51 helper.GetRuleSet().RuleCount()); // .a, .b counts as two rules. |
| 52 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| 53 helper.GetRuleSet().Show(); | 53 helper.GetRuleSet().Show(); |
| 54 #endif | 54 #endif |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST(CSSSelector, OverflowRareDataMatchNth) { |
| 58 int max_int = std::numeric_limits<int>::max(); |
| 59 int min_int = std::numeric_limits<int>::min(); |
| 60 CSSSelector selector; |
| 61 |
| 62 // Overflow count - b (max_int - -1 = max_int + 1) |
| 63 selector.SetNth(1, -1); |
| 64 EXPECT_FALSE(selector.MatchNth(max_int)); |
| 65 // 0 - (min_int) = max_int + 1 |
| 66 selector.SetNth(1, min_int); |
| 67 EXPECT_FALSE(selector.MatchNth(0)); |
| 68 |
| 69 // min_int - 1 |
| 70 selector.SetNth(-1, min_int); |
| 71 EXPECT_FALSE(selector.MatchNth(1)); |
| 72 |
| 73 // a shouldn't negate to itself (and min_int negates to itself). |
| 74 // Note: This test can only fail when using ubsan. |
| 75 selector.SetNth(min_int, 10); |
| 76 EXPECT_FALSE(selector.MatchNth(2)); |
| 77 } |
| 78 |
| 57 } // namespace blink | 79 } // namespace blink |
| OLD | NEW |