Chromium Code Reviews| Index: Source/core/rendering/RenderOverflowTest.cpp |
| diff --git a/Source/core/rendering/RenderOverflowTest.cpp b/Source/core/rendering/RenderOverflowTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..56edeeafe768c4f93ad5986e09dc2d0e37e508db |
| --- /dev/null |
| +++ b/Source/core/rendering/RenderOverflowTest.cpp |
| @@ -0,0 +1,136 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "core/rendering/RenderOverflow.h" |
| + |
| +#include "core/platform/graphics/LayoutRect.h" |
| + |
| +#include <gtest/gtest.h> |
| + |
| +using namespace WebCore; |
| + |
| +namespace WebCore { |
| + |
| +// FIXME: Move this somewhere more generic. |
| +void PrintTo(const LayoutRect& rect, ::std::ostream* os) |
| +{ |
| + *os << "LayoutRect(" |
| + << rect.x().toFloat() << ", " |
| + << rect.y().toFloat() << ", " |
| + << rect.width().toFloat() << ", " |
| + << rect.height().toFloat() << ")"; |
| +} |
| + |
| +} // namespace WebCore |
| + |
| +namespace { |
| + |
| +TEST(RenderOverflowTest, InitialOverflowRects) |
| +{ |
| + RenderOverflow overflow(LayoutRect(10, 10, 80, 80), LayoutRect(0, 0, 100, 100)); |
| + EXPECT_EQ(LayoutRect(10, 10, 80, 80), overflow.layoutOverflowRect()); |
| + EXPECT_EQ(LayoutRect(0, 0, 100, 100), overflow.visualOverflowRect()); |
| + EXPECT_TRUE(overflow.contentsVisualOverflowRect().isEmpty()); |
| +} |
| + |
| +TEST(RenderOverflowTest, AddLayoutOverflow) |
| +{ |
| + RenderOverflow overflow(LayoutRect(10, 10, 80, 80), LayoutRect(0, 0, 100, 100)); |
| + |
| + overflow.addLayoutOverflow(LayoutRect(0, 10, 30, 10)); |
| + EXPECT_EQ(LayoutRect(0, 10, 90, 80), overflow.layoutOverflowRect()); |
| + |
| + overflow.addLayoutOverflow(LayoutRect(50, 50, 10, 20)); |
| + EXPECT_EQ(LayoutRect(0, 10, 90, 80), overflow.layoutOverflowRect()); |
| + |
| + // It's not clear whether any code relies on this behavior (it seems like this |
| + // could probably just use LayoutRect::unite). |
|
Julien - ping for review
2013/08/07 00:17:08
No clue what this comment means.
jbroman
2013/08/08 14:35:39
Removed. It didn't add much value anyhow.
|
| + overflow.addLayoutOverflow(LayoutRect(200, 200, 0, 0)); |
|
Julien - ping for review
2013/08/07 00:17:08
This seems like a dumb case (and arguable in how w
jbroman
2013/08/08 14:35:39
I agree that it's a dumb case, and the previous co
|
| + EXPECT_EQ(LayoutRect(0, 10, 200, 190), overflow.layoutOverflowRect()); |
| + |
| + EXPECT_EQ(LayoutRect(0, 0, 100, 100), overflow.visualOverflowRect()); |
| + EXPECT_TRUE(overflow.contentsVisualOverflowRect().isEmpty()); |
| +} |
| + |
| +TEST(RenderOverflowTest, AddVisualOverflow) |
| +{ |
| + RenderOverflow overflow(LayoutRect(10, 10, 80, 80), LayoutRect(0, 0, 100, 100)); |
| + |
| + overflow.addVisualOverflow(LayoutRect(-10, 0, 30, 30)); |
| + EXPECT_EQ(LayoutRect(-10, 0, 110, 100), overflow.visualOverflowRect()); |
| + |
| + overflow.addVisualOverflow(LayoutRect(50, 50, 10, 20)); |
| + EXPECT_EQ(LayoutRect(-10, 0, 110, 100), overflow.visualOverflowRect()); |
| + |
| + // It's not clear whether any code relies on this behavior (it seems like this |
| + // could probably just use LayoutRect::unite). |
| + overflow.addVisualOverflow(LayoutRect(200, 200, 0, 0)); |
| + EXPECT_EQ(LayoutRect(-10, 0, 210, 200), overflow.visualOverflowRect()); |
| + |
| + EXPECT_EQ(LayoutRect(10, 10, 80, 80), overflow.layoutOverflowRect()); |
| + EXPECT_TRUE(overflow.contentsVisualOverflowRect().isEmpty()); |
| +} |
| + |
| +TEST(RenderOverflowTest, AddContentsVisualOverflow) |
| +{ |
| + RenderOverflow overflow(LayoutRect(10, 10, 80, 80), LayoutRect(0, 0, 100, 100)); |
| + |
| + overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10)); |
| + EXPECT_EQ(LayoutRect(0, 0, 10, 10), overflow.contentsVisualOverflowRect()); |
| + |
| + overflow.addContentsVisualOverflow(LayoutRect(80, 80, 10, 10)); |
| + EXPECT_EQ(LayoutRect(0, 0, 90, 90), overflow.contentsVisualOverflowRect()); |
| + |
| + // Empty contents visual overflow does not affect the overflow rect. |
| + overflow.addContentsVisualOverflow(LayoutRect(200, 200, 0, 0)); |
| + EXPECT_EQ(LayoutRect(0, 0, 90, 90), overflow.contentsVisualOverflowRect()); |
| + |
| + EXPECT_EQ(LayoutRect(0, 0, 100, 100), overflow.visualOverflowRect()); |
| + EXPECT_EQ(LayoutRect(10, 10, 80, 80), overflow.layoutOverflowRect()); |
| +} |
| + |
| +TEST(RenderOverflowTest, Move) |
| +{ |
| + RenderOverflow overflow(LayoutRect(10, 10, 80, 80), LayoutRect(0, 0, 100, 100)); |
| + overflow.addContentsVisualOverflow(LayoutRect(50, 20, 10, 100)); |
| + |
| + overflow.move(500, 0); |
| + EXPECT_EQ(LayoutRect(510, 10, 80, 80), overflow.layoutOverflowRect()); |
| + EXPECT_EQ(LayoutRect(500, 0, 100, 100), overflow.visualOverflowRect()); |
| + EXPECT_EQ(LayoutRect(550, 20, 10, 100), overflow.contentsVisualOverflowRect()); |
| + |
| + overflow.move(-500, 500); |
| + EXPECT_EQ(LayoutRect(10, 510, 80, 80), overflow.layoutOverflowRect()); |
| + EXPECT_EQ(LayoutRect(0, 500, 100, 100), overflow.visualOverflowRect()); |
| + EXPECT_EQ(LayoutRect(50, 520, 10, 100), overflow.contentsVisualOverflowRect()); |
| +} |
| + |
| +} // namespace |