Commit 69f2da3c authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Renaming unit_test class MockCanvas to not collide.

PageOverlayTest and PrintContextTest both use a local mock
test class named MockCanvas for testing. That is normally
no big deal but in jumbo builds they can be compiled
in the same translation unit and then the classes
will collide. This patch gives the classes unique names.

R=fs@opera.com

Change-Id: Icfcb2b4b553e50e08cb6ac56712e4e9aa5f2b69e
Reviewed-on: https://chromium-review.googlesource.com/574349Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#487065}
parent 39e972e8
...@@ -109,9 +109,9 @@ class RuntimeFeatureChange { ...@@ -109,9 +109,9 @@ class RuntimeFeatureChange {
bool old_value_; bool old_value_;
}; };
class MockCanvas : public SkCanvas { class MockPageOverlayCanvas : public SkCanvas {
public: public:
MockCanvas(int width, int height) : SkCanvas(width, height) {} MockPageOverlayCanvas(int width, int height) : SkCanvas(width, height) {}
MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&));
}; };
...@@ -128,7 +128,7 @@ TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) { ...@@ -128,7 +128,7 @@ TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) {
// page overlay actually winds up getting drawn on top of the rest. // page overlay actually winds up getting drawn on top of the rest.
// For now, we just check that the GraphicsLayer will draw the right thing. // For now, we just check that the GraphicsLayer will draw the right thing.
MockCanvas canvas(kViewportWidth, kViewportHeight); MockPageOverlayCanvas canvas(kViewportWidth, kViewportHeight);
EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0));
EXPECT_CALL(canvas, EXPECT_CALL(canvas,
onDrawRect(SkRect::MakeWH(kViewportWidth, kViewportHeight), onDrawRect(SkRect::MakeWH(kViewportWidth, kViewportHeight),
......
...@@ -27,7 +27,7 @@ namespace blink { ...@@ -27,7 +27,7 @@ namespace blink {
const int kPageWidth = 800; const int kPageWidth = 800;
const int kPageHeight = 600; const int kPageHeight = 600;
class MockCanvas : public SkCanvas { class MockPageContextCanvas : public SkCanvas {
public: public:
enum OperationType { kDrawRect, kDrawPoint }; enum OperationType { kDrawRect, kDrawPoint };
...@@ -36,8 +36,8 @@ class MockCanvas : public SkCanvas { ...@@ -36,8 +36,8 @@ class MockCanvas : public SkCanvas {
SkRect rect; SkRect rect;
}; };
MockCanvas() : SkCanvas(kPageWidth, kPageHeight) {} MockPageContextCanvas() : SkCanvas(kPageWidth, kPageHeight) {}
~MockCanvas() override {} ~MockPageContextCanvas() override {}
void onDrawAnnotation(const SkRect& rect, void onDrawAnnotation(const SkRect& rect,
const char key[], const char key[],
...@@ -80,7 +80,7 @@ class PrintContextTest : public RenderingTest { ...@@ -80,7 +80,7 @@ class PrintContextTest : public RenderingTest {
GetDocument().body()->setInnerHTML(body_content); GetDocument().body()->setInnerHTML(body_content);
} }
void PrintSinglePage(MockCanvas& canvas) { void PrintSinglePage(MockPageContextCanvas& canvas) {
IntRect page_rect(0, 0, kPageWidth, kPageHeight); IntRect page_rect(0, 0, kPageWidth, kPageHeight);
GetPrintContext().BeginPrintMode(page_rect.Width(), page_rect.Height()); GetPrintContext().BeginPrintMode(page_rect.Width(), page_rect.Height());
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
...@@ -148,23 +148,24 @@ class PrintContextFrameTest : public PrintContextTest { ...@@ -148,23 +148,24 @@ class PrintContextFrameTest : public PrintContextTest {
EXPECT_EQ(expectedHeight, actualRect.height()); EXPECT_EQ(expectedHeight, actualRect.height());
TEST_F(PrintContextTest, LinkTarget) { TEST_F(PrintContextTest, LinkTarget) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
AbsoluteBlockHtmlForLink(50, 60, 70, 80, "http://www.google.com") + AbsoluteBlockHtmlForLink(50, 60, 70, 80, "http://www.google.com") +
AbsoluteBlockHtmlForLink(150, 160, 170, 180, AbsoluteBlockHtmlForLink(150, 160, 170, 180,
"http://www.google.com#fragment")); "http://www.google.com#fragment"));
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawRect, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[1].type);
EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect);
} }
TEST_F(PrintContextTest, LinkTargetUnderAnonymousBlockBeforeBlock) { TEST_F(PrintContextTest, LinkTargetUnderAnonymousBlockBeforeBlock) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML("<div style='padding-top: 50px'>" + SetBodyInnerHTML("<div style='padding-top: 50px'>" +
InlineHtmlForLink("http://www.google.com", InlineHtmlForLink("http://www.google.com",
"<img style='width: 111; height: 10'>") + "<img style='width: 111; height: 10'>") +
...@@ -173,57 +174,61 @@ TEST_F(PrintContextTest, LinkTargetUnderAnonymousBlockBeforeBlock) { ...@@ -173,57 +174,61 @@ TEST_F(PrintContextTest, LinkTargetUnderAnonymousBlockBeforeBlock) {
"<img style='width: 122; height: 20'>") + "<img style='width: 122; height: 20'>") +
"</div>" + "</div>"); "</div>" + "</div>");
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(0, 50, 111, 10, operations[0].rect); EXPECT_SKRECT_EQ(0, 50, 111, 10, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawRect, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[1].type);
EXPECT_SKRECT_EQ(0, 60, 122, 20, operations[1].rect); EXPECT_SKRECT_EQ(0, 60, 122, 20, operations[1].rect);
} }
TEST_F(PrintContextTest, LinkTargetContainingABlock) { TEST_F(PrintContextTest, LinkTargetContainingABlock) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
"<div style='padding-top: 50px'>" + "<div style='padding-top: 50px'>" +
InlineHtmlForLink("http://www.google2.com", InlineHtmlForLink("http://www.google2.com",
"<div style='width:133; height: 30'>BLOCK</div>") + "<div style='width:133; height: 30'>BLOCK</div>") +
"</div>"); "</div>");
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(1u, operations.size()); ASSERT_EQ(1u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(0, 50, 133, 30, operations[0].rect); EXPECT_SKRECT_EQ(0, 50, 133, 30, operations[0].rect);
} }
TEST_F(PrintContextTest, LinkTargetUnderInInlines) { TEST_F(PrintContextTest, LinkTargetUnderInInlines) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
"<span><b><i><img style='width: 40px; height: 40px'><br>" + "<span><b><i><img style='width: 40px; height: 40px'><br>" +
InlineHtmlForLink("http://www.google3.com", InlineHtmlForLink("http://www.google3.com",
"<img style='width: 144px; height: 40px'>") + "<img style='width: 144px; height: 40px'>") +
"</i></b></span>"); "</i></b></span>");
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(1u, operations.size()); ASSERT_EQ(1u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(0, 40, 144, 40, operations[0].rect); EXPECT_SKRECT_EQ(0, 40, 144, 40, operations[0].rect);
} }
TEST_F(PrintContextTest, LinkTargetUnderRelativelyPositionedInline) { TEST_F(PrintContextTest, LinkTargetUnderRelativelyPositionedInline) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
+ "<span style='position: relative; top: 50px; left: 50px'><b><i><img style='width: 1px; height: 40px'><br>" + "<span style='position: relative; top: 50px; left: 50px'><b><i><img style='width: 1px; height: 40px'><br>"
+ InlineHtmlForLink("http://www.google3.com", "<img style='width: 155px; height: 50px'>") + InlineHtmlForLink("http://www.google3.com", "<img style='width: 155px; height: 50px'>")
+ "</i></b></span>"); + "</i></b></span>");
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(1u, operations.size()); ASSERT_EQ(1u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 90, 155, 50, operations[0].rect); EXPECT_SKRECT_EQ(50, 90, 155, 50, operations[0].rect);
} }
TEST_F(PrintContextTest, LinkTargetSvg) { TEST_F(PrintContextTest, LinkTargetSvg) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
"<svg width='100' height='100'>" "<svg width='100' height='100'>"
"<a xlink:href='http://www.w3.org'><rect x='20' y='20' width='50' " "<a xlink:href='http://www.w3.org'><rect x='20' y='20' width='50' "
...@@ -233,17 +238,18 @@ TEST_F(PrintContextTest, LinkTargetSvg) { ...@@ -233,17 +238,18 @@ TEST_F(PrintContextTest, LinkTargetSvg) {
"</svg>"); "</svg>");
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(20, 20, 50, 50, operations[0].rect); EXPECT_SKRECT_EQ(20, 20, 50, 50, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawRect, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[1].type);
EXPECT_EQ(10, operations[1].rect.x()); EXPECT_EQ(10, operations[1].rect.x());
EXPECT_GE(90, operations[1].rect.y()); EXPECT_GE(90, operations[1].rect.y());
} }
TEST_F(PrintContextTest, LinkedTarget) { TEST_F(PrintContextTest, LinkedTarget) {
MockCanvas canvas; MockPageContextCanvas canvas;
GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://a.com/")); GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://a.com/"));
SetBodyInnerHTML( SetBodyInnerHTML(
AbsoluteBlockHtmlForLink( AbsoluteBlockHtmlForLink(
...@@ -258,39 +264,42 @@ TEST_F(PrintContextTest, LinkedTarget) { ...@@ -258,39 +264,42 @@ TEST_F(PrintContextTest, LinkedTarget) {
"fragment-not-used")); // Generates no annotation "fragment-not-used")); // Generates no annotation
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawPoint, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[1].type);
EXPECT_SKRECT_EQ(250, 260, 0, 0, operations[1].rect); EXPECT_SKRECT_EQ(250, 260, 0, 0, operations[1].rect);
} }
TEST_F(PrintContextTest, EmptyLinkedTarget) { TEST_F(PrintContextTest, EmptyLinkedTarget) {
MockCanvas canvas; MockPageContextCanvas canvas;
GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://a.com/")); GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://a.com/"));
SetBodyInnerHTML(AbsoluteBlockHtmlForLink(50, 60, 70, 80, "#fragment") + SetBodyInnerHTML(AbsoluteBlockHtmlForLink(50, 60, 70, 80, "#fragment") +
HtmlForAnchor(250, 260, "fragment", "")); HtmlForAnchor(250, 260, "fragment", ""));
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawPoint, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[1].type);
EXPECT_SKRECT_EQ(250, 260, 0, 0, operations[1].rect); EXPECT_SKRECT_EQ(250, 260, 0, 0, operations[1].rect);
} }
TEST_F(PrintContextTest, LinkTargetBoundingBox) { TEST_F(PrintContextTest, LinkTargetBoundingBox) {
MockCanvas canvas; MockPageContextCanvas canvas;
SetBodyInnerHTML( SetBodyInnerHTML(
AbsoluteBlockHtmlForLink(50, 60, 70, 20, "http://www.google.com", AbsoluteBlockHtmlForLink(50, 60, 70, 20, "http://www.google.com",
"<img style='width: 200px; height: 100px'>")); "<img style='width: 200px; height: 100px'>"));
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(1u, operations.size()); ASSERT_EQ(1u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 60, 200, 100, operations[0].rect); EXPECT_SKRECT_EQ(50, 60, 200, 100, operations[0].rect);
} }
...@@ -307,14 +316,15 @@ TEST_F(PrintContextFrameTest, WithSubframe) { ...@@ -307,14 +316,15 @@ TEST_F(PrintContextFrameTest, WithSubframe) {
AbsoluteBlockHtmlForLink(250, 260, 270, 280, AbsoluteBlockHtmlForLink(250, 260, 270, 280,
"http://www.google.com#fragment")); "http://www.google.com#fragment"));
MockCanvas canvas; MockPageContextCanvas canvas;
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(2u, operations.size()); ASSERT_EQ(2u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(250, 260, 170, 180, operations[0].rect); EXPECT_SKRECT_EQ(250, 260, 170, 180, operations[0].rect);
EXPECT_EQ(MockCanvas::kDrawRect, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[1].type);
EXPECT_SKRECT_EQ(350, 360, 270, 280, operations[1].rect); EXPECT_SKRECT_EQ(350, 360, 270, 280, operations[1].rect);
} }
...@@ -336,17 +346,18 @@ TEST_F(PrintContextFrameTest, WithScrolledSubframe) { ...@@ -336,17 +346,18 @@ TEST_F(PrintContextFrameTest, WithScrolledSubframe) {
ChildDocument().domWindow()->scrollTo(100, 100); ChildDocument().domWindow()->scrollTo(100, 100);
MockCanvas canvas; MockPageContextCanvas canvas;
PrintSinglePage(canvas); PrintSinglePage(canvas);
const Vector<MockCanvas::Operation>& operations = canvas.RecordedOperations(); const Vector<MockPageContextCanvas::Operation>& operations =
canvas.RecordedOperations();
ASSERT_EQ(3u, operations.size()); ASSERT_EQ(3u, operations.size());
EXPECT_EQ(MockCanvas::kDrawRect, operations[0].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[0].type);
EXPECT_SKRECT_EQ(50, 60, 70, 80, EXPECT_SKRECT_EQ(50, 60, 70, 80,
operations[0].rect); // FIXME: the rect should be clipped. operations[0].rect); // FIXME: the rect should be clipped.
EXPECT_EQ(MockCanvas::kDrawRect, operations[1].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[1].type);
EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect);
EXPECT_EQ(MockCanvas::kDrawRect, operations[2].type); EXPECT_EQ(MockPageContextCanvas::kDrawRect, operations[2].type);
EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment