Updated printing test patch
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jul 2008 23:17:50 +0000 (23:17 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jul 2008 23:17:50 +0000 (23:17 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35078 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/printing/media-queries-print-expected.pdf [new file with mode: 0644]
LayoutTests/printing/media-queries-print.html [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm

index e0ddc50..4fbecc6 100644 (file)
@@ -1,5 +1,16 @@
 2008-07-09  Eric Seidel  <eric@webkit.org>
 
+        Reviewed by aroben.
+
+        * platform/mac/printing: Added.
+        * platform/mac/printing/media-queries-print-expected.txt: Added.
+        * platform/qt/Skipped: skip printing and webarchives
+        * platform/win/Skipped: skip printing tests
+        * printing: Added.
+        * printing/media-queries-print.html: Added.
+
+2008-07-09  Eric Seidel  <eric@webkit.org>
+
         Reviewed by weinig.
 
         Add Content-Type support to DumpRenderTree and run-webkit-tests
index fbeca10..e2d70a2 100644 (file)
@@ -7,3 +7,4 @@ storage/success-callback.html
 http/tests/appcache
 # Missing AccessibilityController implementation
 accessibility
+printing
index ac526c8..b3c6e94 100644 (file)
@@ -1,5 +1,6 @@
 # ------- missing features in DRT
 accessibility
+printing
 editing/selection/4975120.html
 editing/selection/5109817.html
 editing/selection/5354455-1.html
@@ -864,20 +865,6 @@ svg/hixie/viewbox/003.xml
 svg/hixie/viewbox/004.xml
 svg/hixie/viewbox/preserveAspectRatio/001.xml
 svg/hixie/viewbox/preserveAspectRatio/002.xml
-webarchive/archive-empty-frame-dom.html
-webarchive/archive-empty-frame-source.html
-webarchive/archive-with-unencoded-url.html
-webarchive/test-body-background.html
-webarchive/test-duplicate-resources.html
-webarchive/test-frameset.html
-webarchive/test-img-src.html
-webarchive/test-input-src.html
-webarchive/test-link-href.html
-webarchive/test-object-data.html
-webarchive/test-script-src.html
-webarchive/test-table-background.html
-webarchive/test-td-background.html
-webarchive/loading/test-loading-archive.html
 
 # ------- <video> support
 media
index 5306c16..99c5e94 100644 (file)
@@ -407,3 +407,7 @@ http/tests/xmlhttprequest/access-control-basic-not-get-allow.html
 
 # Still need to implement AccessibilityController for DumpRenderTree on Windows
 accessibility
+
+# No support for print-to-pdf in Windows DRT
+printing
+
diff --git a/LayoutTests/printing/media-queries-print-expected.pdf b/LayoutTests/printing/media-queries-print-expected.pdf
new file mode 100644 (file)
index 0000000..728c81f
Binary files /dev/null and b/LayoutTests/printing/media-queries-print-expected.pdf differ
diff --git a/LayoutTests/printing/media-queries-print.html b/LayoutTests/printing/media-queries-print.html
new file mode 100644 (file)
index 0000000..cb8a163
--- /dev/null
@@ -0,0 +1,25 @@
+<html>
+<style>
+div {
+  background: red;
+  width: 100px;
+  height: 100px;
+}
+@media print {
+  div {
+    background: green;
+  }
+  span {
+    font-style: italic;
+  }
+}
+</style>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.printToPDF();
+</script>
+<body>
+  <div></div>
+  <span>When printing, you should see a green square above and this text should be italic.</span>
+</body>
+</html>
index a2ac038..874a538 100644 (file)
@@ -1,5 +1,20 @@
 2008-07-09  Eric Seidel  <eric@webkit.org>
 
+        Reviewed by aroben.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (LayoutTestController::LayoutTestController):
+        (dumpAsPDFCallback):
+        (LayoutTestController::staticFunctions):
+        * DumpRenderTree/LayoutTestController.h:
+        (LayoutTestController::dumpAsPDF):
+        (LayoutTestController::setDumpAsPDF):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (dumpFrameAsPDF):
+        (dump):
+
+2008-07-09  Eric Seidel  <eric@webkit.org>
+
         Reviewed by weinig.
 
         Add Content-Type support to DumpRenderTree and run-webkit-tests
index d5955c2..120d48f 100644 (file)
@@ -36,6 +36,7 @@
 
 LayoutTestController::LayoutTestController(bool testRepaintDefault, bool testRepaintSweepHorizontallyDefault)
     : m_dumpAsText(false)
+    , m_dumpAsPDF(false)
     , m_dumpBackForwardList(false)
     , m_dumpChildFrameScrollPositions(false)
     , m_dumpChildFramesAsText(false)
@@ -70,6 +71,13 @@ static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function,
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef dumpAsPDFCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    controller->setDumpAsPDF(true);
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef dumpBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
@@ -669,6 +677,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "decodeHostName", decodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "display", displayCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "dumpAsText", dumpAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "printToPDF", dumpAsPDFCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "dumpBackForwardList", dumpBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "dumpChildFramesAsText", dumpChildFramesAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "dumpChildFrameScrollPositions", dumpChildFrameScrollPositionsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index fd4d297..ecd5426 100644 (file)
@@ -72,6 +72,9 @@ public:
     bool dumpAsText() const { return m_dumpAsText; }
     void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; }
 
+    bool dumpAsPDF() const { return m_dumpAsPDF; }
+    void setDumpAsPDF(bool dumpAsPDF) { m_dumpAsPDF = dumpAsPDF; }
+    
     bool dumpBackForwardList() const { return m_dumpBackForwardList; }
     void setDumpBackForwardList(bool dumpBackForwardList) { m_dumpBackForwardList = dumpBackForwardList; }
 
@@ -140,6 +143,7 @@ public:
     
 private:
     bool m_dumpAsText;
+    bool m_dumpAsPDF;
     bool m_dumpBackForwardList;
     bool m_dumpChildFrameScrollPositions;
     bool m_dumpChildFramesAsText;
index 66b4ccd..4365be5 100644 (file)
@@ -606,6 +606,39 @@ static NSString *dumpFramesAsText(WebFrame *frame)
     return result;
 }
 
+static NSData *dumpFrameAsPDF(WebFrame *frame)
+{
+    if (!frame)
+        return nil;
+
+    // Sadly we have to dump to a file and then read from that file again
+    // +[NSPrintOperation PDFOperationWithView:insideRect:] requires a rect and prints to a single page
+    // likewise +[NSView dataWithPDFInsideRect:] also prints to a single continuous page
+    // The goal of this function is to test "real" printing across multiple pages.
+    // FIXME: It's possible there might be printing SPI to let us print a multi-page PDF to an NSData object
+    NSString *path = @"/tmp/test.pdf";
+
+    NSMutableDictionary *printInfoDict = [NSMutableDictionary dictionaryWithDictionary:[[NSPrintInfo sharedPrintInfo] dictionary]];
+    [printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
+    [printInfoDict setObject:path forKey:NSPrintSavePath];
+
+    NSPrintInfo *printInfo = [[NSPrintInfo alloc] initWithDictionary:printInfoDict];
+    [printInfo setHorizontalPagination:NSAutoPagination];
+    [printInfo setVerticalPagination:NSAutoPagination];
+    [printInfo setVerticallyCentered:NO];
+
+    NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView:[frame frameView] printInfo:printInfo];
+    [printOperation setShowPanels:NO];
+    [printOperation runOperation];
+
+    [printInfo release];
+
+    NSData *pdfData = [NSData dataWithContentsOfFile:path];
+    [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
+
+    return pdfData;
+}
+
 static void convertMIMEType(NSMutableString *mimeType)
 {
     if ([mimeType isEqualToString:@"application/x-javascript"])
@@ -830,6 +863,9 @@ void dump()
         layoutTestController->setDumpAsText(dumpAsText);
         if (layoutTestController->dumpAsText()) {
             resultString = dumpFramesAsText(mainFrame);
+        } else if (layoutTestController->dumpAsPDF()) {
+            resultData = dumpFrameAsPDF(mainFrame);
+            resultMimeType = @"application/pdf";
         } else if (layoutTestController->dumpDOMAsWebArchive()) {
             WebArchive *webArchive = [[mainFrame DOMDocument] webArchive];
             resultString = serializeWebArchiveToXML(webArchive);