PDF: Switch some unit tests to higher level API.

Also, clean up some headers.

Review URL: https://codereview.chromium.org/968683002
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 5774360..668f7de 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -10,7 +10,6 @@
 #include "SkPDFBitmap.h"
 #include "SkPDFCanon.h"
 #include "SkPDFCatalog.h"
-#include "SkPDFDocument.h"
 #include "SkStream.h"
 #include "SkUnPreMultiply.h"
 
diff --git a/src/pdf/SkPDFCatalog.h b/src/pdf/SkPDFCatalog.h
index 9175f62..1bdac93 100644
--- a/src/pdf/SkPDFCatalog.h
+++ b/src/pdf/SkPDFCatalog.h
@@ -12,9 +12,7 @@
 
 #include <sys/types.h>
 
-#include "SkPDFDocument.h"
 #include "SkPDFTypes.h"
-#include "SkRefCnt.h"
 #include "SkTDArray.h"
 
 /** \class SkPDFCatalog
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index fc762b1..7a1ca97 100644
--- a/tests/AnnotationTest.cpp
+++ b/tests/AnnotationTest.cpp
@@ -8,9 +8,8 @@
 #include "SkAnnotation.h"
 #include "SkCanvas.h"
 #include "SkData.h"
-#include "SkPDFCanon.h"
-#include "SkPDFDevice.h"
-#include "SkPDFDocument.h"
+#include "SkDocument.h"
+#include "SkStream.h"
 #include "Test.h"
 
 /** Returns true if data (may contain null characters) contains needle (null
@@ -41,20 +40,17 @@
 }
 
 DEF_TEST(Annotation_PdfLink, reporter) {
-    SkISize size = SkISize::Make(612, 792);
-    SkPDFCanon canon;
-    SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon));
-    SkCanvas canvas(device.get());
+    SkDynamicMemoryWStream outStream;
+    SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
+    SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
+    REPORTER_ASSERT(reporter, canvas);
 
     SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
                                 SkIntToScalar(288), SkIntToScalar(72));
     SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
-    SkAnnotateRectWithURL(&canvas, r, data.get());
+    SkAnnotateRectWithURL(canvas, r, data.get());
 
-    SkPDFDocument doc;
-    doc.appendPage(device.get());
-    SkDynamicMemoryWStream outStream;
-    doc.emitPDF(&outStream);
+    REPORTER_ASSERT(reporter, doc->close());
     SkAutoDataUnref out(outStream.copyToData());
     const char* rawOutput = (const char*)out->data();
 
@@ -62,19 +58,16 @@
 }
 
 DEF_TEST(Annotation_NamedDestination, reporter) {
-    SkISize size = SkISize::Make(612, 792);
-    SkPDFCanon canon;
-    SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon));
-    SkCanvas canvas(device.get());
+    SkDynamicMemoryWStream outStream;
+    SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
+    SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
+    REPORTER_ASSERT(reporter, canvas);
 
     SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
     SkAutoDataUnref data(SkData::NewWithCString("example"));
-    SkAnnotateNamedDestination(&canvas, p, data.get());
+    SkAnnotateNamedDestination(canvas, p, data.get());
 
-    SkPDFDocument doc;
-    doc.appendPage(device.get());
-    SkDynamicMemoryWStream outStream;
-    doc.emitPDF(&outStream);
+    REPORTER_ASSERT(reporter, doc->close());
     SkAutoDataUnref out(outStream.copyToData());
     const char* rawOutput = (const char*)out->data();
 
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index c405fcd..98cfbc1 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -47,11 +47,9 @@
 #include "SkCanvas.h"
 #include "SkDeferredCanvas.h"
 #include "SkDevice.h"
+#include "SkDocument.h"
 #include "SkMatrix.h"
 #include "SkNWayCanvas.h"
-#include "SkPDFCanon.h"
-#include "SkPDFDevice.h"
-#include "SkPDFDocument.h"
 #include "SkPaint.h"
 #include "SkPath.h"
 #include "SkPicture.h"
@@ -558,17 +556,15 @@
 static void TestPdfDevice(skiatest::Reporter* reporter,
                           const TestData& d,
                           CanvasTestStep* testStep) {
-    SkISize pageSize = SkISize::Make(d.fWidth, d.fHeight);
-    SkPDFCanon canon;
-    SkAutoTUnref<SkPDFDevice> pdfDevice(
-            SkPDFDevice::Create(pageSize, 72.0f, &canon));
-    SkCanvas canvas(pdfDevice.get());
+    SkDynamicMemoryWStream outStream;
+    SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
+    SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth),
+                                      SkIntToScalar(d.fHeight));
+    REPORTER_ASSERT(reporter, canvas);
     testStep->setAssertMessageFormat(kPdfAssertMessageFormat);
-    testStep->draw(&canvas, d, reporter);
-    SkPDFDocument doc;
-    doc.appendPage(pdfDevice.get());
-    SkDynamicMemoryWStream stream;
-    doc.emitPDF(&stream);
+    testStep->draw(canvas, d, reporter);
+
+    REPORTER_ASSERT(reporter, doc->close());
 }
 
 // The following class groups static functions that need to access
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 97ad25e..7861ef0 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -8,6 +8,7 @@
 #include "SkBitmap.h"
 #include "SkCanvas.h"
 #include "SkData.h"
+#include "SkDocument.h"
 #include "SkFlate.h"
 #include "SkImageEncoder.h"
 #include "SkMatrix.h"
@@ -215,21 +216,16 @@
 // SKP files might have invalid glyph ids. This test ensures they are ignored,
 // and there is no assert on input data in Debug mode.
 static void test_issue1083() {
-    SkISize pageSize = SkISize::Make(100, 100);
-    SkPDFCanon canon;
-    SkAutoTUnref<SkPDFDevice> dev(SkPDFDevice::Create(pageSize, 72.0f, &canon));
-    SkCanvas c(dev);
+    SkDynamicMemoryWStream outStream;
+    SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
+    SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
     SkPaint paint;
     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
 
     uint16_t glyphID = 65000;
-    c.drawText(&glyphID, 2, 0, 0, paint);
+    canvas->drawText(&glyphID, 2, 0, 0, paint);
 
-    SkPDFDocument doc;
-    doc.appendPage(dev);
-
-    SkDynamicMemoryWStream stream;
-    doc.emitPDF(&stream);
+    doc->close();
 }
 
 DEF_TEST(PDFPrimitives, reporter) {
@@ -354,18 +350,18 @@
 // Check that PDF rendering of image filters successfully falls back to
 // CPU rasterization.
 DEF_TEST(PDFImageFilter, reporter) {
-    SkISize pageSize = SkISize::Make(100, 100);
-    SkPDFCanon canon;
-    SkAutoTUnref<SkPDFDevice> pdfDevice(
-            SkPDFDevice::Create(pageSize, 72.0f, &canon));
-    SkCanvas canvas(pdfDevice.get());
+    SkDynamicMemoryWStream stream;
+    SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream));
+    SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
+
     SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter());
 
     // Filter just created; should be unvisited.
     REPORTER_ASSERT(reporter, !filter->visited());
     SkPaint paint;
     paint.setImageFilter(filter.get());
-    canvas.drawRect(SkRect::MakeWH(100, 100), paint);
+    canvas->drawRect(SkRect::MakeWH(100, 100), paint);
+    doc->close();
 
     // Filter was used in rendering; should be visited.
     REPORTER_ASSERT(reporter, filter->visited());