2010-06-16 Hayato Ito <hayato@chromium.org>
authorhamaji@chromium.org <hamaji@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Jun 2010 06:59:49 +0000 (06:59 +0000)
committerhamaji@chromium.org <hamaji@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Jun 2010 06:59:49 +0000 (06:59 +0000)
        Reviewed by Shinichiro Hamaji.

        Refactor layout tests for printing to use common code.

        https://bugs.webkit.org/show_bug.cgi?id=40559

        * printing/numberOfPages-expected.txt:
        * printing/numberOfPages.html:
        * printing/page-break-always-expected.txt:
        * printing/page-break-always-for-overflow-expected.txt:
        * printing/page-break-always-for-overflow.html:
        * printing/page-break-always.html:
        * printing/page-break-inside-avoid-expected.txt: Added.
        * printing/page-break-inside-avoid.html: Added.
        * printing/page-break-inside-expected.txt: Removed.
        * printing/page-break-inside.html: Removed.
        * printing/pageNumerForElementById-expected.txt:
        * printing/pageNumerForElementById.html:
        * printing/resources/paged-media-test-utils.js:
        (numberOfPagesShouldBe):
        (ratioToPageHeightToPixels):
        (createBlockWithRatioToPageHeight):
        (createBlockWithNumberOfLines):
        * printing/script-tests/TEMPLATE.html:
        * printing/script-tests/numberOfPages.js:
        (test):
        * printing/script-tests/page-break-always-for-overflow.js:
        (test):
        * printing/script-tests/page-break-always.js:
        (test):
        * printing/script-tests/page-break-inside-avoid.js: Added.
        (test):
        * printing/script-tests/page-break-inside.js: Removed.
        * printing/script-tests/pageNumerForElementById.js:
        (test):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@61309 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
LayoutTests/ChangeLog
LayoutTests/printing/numberOfPages-expected.txt
LayoutTests/printing/numberOfPages.html
LayoutTests/printing/page-break-always-expected.txt
LayoutTests/printing/page-break-always-for-overflow-expected.txt
LayoutTests/printing/page-break-always-for-overflow.html
LayoutTests/printing/page-break-always.html
LayoutTests/printing/page-break-inside-avoid-expected.txt [new file with mode: 0644]
LayoutTests/printing/page-break-inside-avoid.html [moved from LayoutTests/printing/page-break-inside.html with 68% similarity]
LayoutTests/printing/page-break-inside-expected.txt [deleted file]
LayoutTests/printing/pageNumerForElementById-expected.txt
LayoutTests/printing/pageNumerForElementById.html
LayoutTests/printing/resources/paged-media-test-utils.js
LayoutTests/printing/script-tests/TEMPLATE.html
LayoutTests/printing/script-tests/numberOfPages.js
LayoutTests/printing/script-tests/page-break-always-for-overflow.js
LayoutTests/printing/script-tests/page-break-always.js
LayoutTests/printing/script-tests/page-break-inside-avoid.js [new file with mode: 0644]
LayoutTests/printing/script-tests/page-break-inside.js [deleted file]
LayoutTests/printing/script-tests/pageNumerForElementById.js

index 83e4544..96f2394 100644 (file)
@@ -1,3 +1,41 @@
+2010-06-16  Hayato Ito  <hayato@chromium.org>
+
+        Reviewed by Shinichiro Hamaji.
+
+        Refactor layout tests for printing to use common code.
+
+        https://bugs.webkit.org/show_bug.cgi?id=40559
+
+        * printing/numberOfPages-expected.txt:
+        * printing/numberOfPages.html:
+        * printing/page-break-always-expected.txt:
+        * printing/page-break-always-for-overflow-expected.txt:
+        * printing/page-break-always-for-overflow.html:
+        * printing/page-break-always.html:
+        * printing/page-break-inside-avoid-expected.txt: Added.
+        * printing/page-break-inside-avoid.html: Added.
+        * printing/page-break-inside-expected.txt: Removed.
+        * printing/page-break-inside.html: Removed.
+        * printing/pageNumerForElementById-expected.txt:
+        * printing/pageNumerForElementById.html:
+        * printing/resources/paged-media-test-utils.js:
+        (numberOfPagesShouldBe):
+        (ratioToPageHeightToPixels):
+        (createBlockWithRatioToPageHeight):
+        (createBlockWithNumberOfLines):
+        * printing/script-tests/TEMPLATE.html:
+        * printing/script-tests/numberOfPages.js:
+        (test):
+        * printing/script-tests/page-break-always-for-overflow.js:
+        (test):
+        * printing/script-tests/page-break-always.js:
+        (test):
+        * printing/script-tests/page-break-inside-avoid.js: Added.
+        (test):
+        * printing/script-tests/page-break-inside.js: Removed.
+        * printing/script-tests/pageNumerForElementById.js:
+        (test):
+
 2010-06-16  Qi Zhang  <qi.2.zhang@nokia.com>
 
         Reviewed by Laszlo Gombos.
index 8adb6be..9325270 100644 (file)
@@ -3,8 +3,11 @@ Test for layoutTestController.numberOfPages()
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS layoutTestController.numberOfPages(1000, 1000) is 2
-PASS layoutTestController.numberOfPages(10000, 10000) is 1
+
+PASS: number of pages is 2
+PASS: number of pages is 1
+All tests passed
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 5066821..78155fc 100644 (file)
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
 <script src="script-tests/numberOfPages.js"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
index 791a359..ef1246e 100644 (file)
@@ -3,10 +3,13 @@ Test for page-break-before:always and page-break-after:always
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS layoutTestController.pageNumberForElementById('firstPage') is 0
-PASS layoutTestController.pageNumberForElementById('secondPage1') is 1
-PASS layoutTestController.pageNumberForElementById('secondPage2') is 1
-PASS layoutTestController.pageNumberForElementById('thirdPage') is 2
+
+PASS: page number of "firstPage" is 0
+PASS: page number of "secondPage1" is 1
+PASS: page number of "secondPage2" is 1
+PASS: page number of "thirdPage" is 2
+All tests passed
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 97efad2..ddfeb31 100644 (file)
@@ -3,15 +3,18 @@ Test page-break-{before,after}:always for overflow:{visible,hidden,scroll,auto}
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS layoutTestController.pageNumberForElementById('test-page-break-before:always-for-overflow:visible') is 1
-PASS layoutTestController.pageNumberForElementById('test-page-break-before:always-for-overflow:hidden') is 2
-PASS layoutTestController.pageNumberForElementById('test-page-break-before:always-for-overflow:scroll') is 3
-PASS layoutTestController.pageNumberForElementById('test-page-break-before:always-for-overflow:auto') is 4
-PASS layoutTestController.pageNumberForElementById('test-page-break-after:always-for-overflow:visible') is 4
-PASS layoutTestController.pageNumberForElementById('test-page-break-after:always-for-overflow:hidden') is 5
-PASS layoutTestController.pageNumberForElementById('test-page-break-after:always-for-overflow:scroll') is 6
-PASS layoutTestController.pageNumberForElementById('test-page-break-after:always-for-overflow:auto') is 7
-PASS layoutTestController.pageNumberForElementById('test-last-page') is 8
+
+PASS: page number of "test-page-break-before:always-for-overflow:visible" is 1
+PASS: page number of "test-page-break-before:always-for-overflow:hidden" is 2
+PASS: page number of "test-page-break-before:always-for-overflow:scroll" is 3
+PASS: page number of "test-page-break-before:always-for-overflow:auto" is 4
+PASS: page number of "test-page-break-after:always-for-overflow:visible" is 4
+PASS: page number of "test-page-break-after:always-for-overflow:hidden" is 5
+PASS: page number of "test-page-break-after:always-for-overflow:scroll" is 6
+PASS: page number of "test-page-break-after:always-for-overflow:auto" is 7
+PASS: page number of "test-last-page" is 8
+All tests passed
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index eeab6ef..73a34f5 100644 (file)
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
 <script src="script-tests/page-break-always-for-overflow.js"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
index fcd9aa3..87175ea 100644 (file)
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
 <script src="script-tests/page-break-always.js"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
diff --git a/LayoutTests/printing/page-break-inside-avoid-expected.txt b/LayoutTests/printing/page-break-inside-avoid-expected.txt
new file mode 100644 (file)
index 0000000..cebbc85
--- /dev/null
@@ -0,0 +1,22 @@
+Test for page-break-inside:avoid
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+PASS: page number of "page1-1" is 1
+PASS: page number of "page1-2" is 1
+PASS: page number of "page2" is 2
+PASS: page number of "page3" is 3
+PASS: page number of "page4" is 4
+PASS: page number of "page5" is 5
+PASS: page number of "page8" is 8
+PASS: page number of "page9-1" is 9
+PASS: page number of "page9-2" is 9
+PASS: page number of "page10" is 10
+All tests passed
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
-<script src="script-tests/page-break-inside.js"></script>
+<script src="script-tests/page-break-inside-avoid.js"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
diff --git a/LayoutTests/printing/page-break-inside-expected.txt b/LayoutTests/printing/page-break-inside-expected.txt
deleted file mode 100644 (file)
index 0dc561f..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-Test for page-break-inside:avoid
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS pageNumber('page1') is 1
-PASS pageNumber('page2') is 2
-PASS pageNumber('page3-1') is 3
-PASS pageNumber('page3-2') is 3
-PASS pageNumber('page4') is 4
-PASS pageNumber('page5') is 5
-PASS pageNumber('page6') is 6
-PASS pageNumber('page7') is 7
-PASS pageNumber('page9') is 9
-PASS pageNumber('page10-1') is 10
-PASS pageNumber('page10-2') is 10
-PASS pageNumber('page11') is 11
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
index 1a1381b..ab72fca 100644 (file)
@@ -3,10 +3,13 @@ Test for layoutTestController.pageNumberForElementById()
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS layoutTestController.pageNumberForElementById('firstPage', 1000, 1000) is 0
-PASS layoutTestController.pageNumberForElementById('secondPage', 1000, 1000) is 1
-PASS layoutTestController.pageNumberForElementById('thirdPage', 1000, 1000) is 2
-PASS layoutTestController.pageNumberForElementById('thirdPage2', 1000, 1000) is 2
+
+PASS: page number of "firstPage" is 0
+PASS: page number of "secondPage" is 1
+PASS: page number of "thirdPage" is 2
+PASS: page number of "thirdPage2" is 2
+All tests passed
+
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 0dae98e..f32e3e6 100644 (file)
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
 <script src="script-tests/pageNumerForElementById.js"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
index 1619298..e34208e 100644 (file)
@@ -21,9 +21,15 @@ function pageNumberForElementShouldBe(id, expectedPageNumber)
     }
 }
 
-function numberOfPagesShouldBe(expectedNumberOfPages)
+function numberOfPagesShouldBe(expectedNumberOfPages, pageWidthInPixels, pageHeightInPixels)
 {
-    var actualNumberOfPages = layoutTestController.numberOfPages();
+    // pageWidthInPixels and pageHeightInPixels can be omitted. If omitted, 800x600 is used.
+    var actualNumberOfPages;
+    if (pageWidthInPixels && pageHeightInPixels)
+        actualNumberOfPages = layoutTestController.numberOfPages(pageWidthInPixels, pageHeightInPixels);
+    else
+        actualNumberOfPages = layoutTestController.numberOfPages();
+
     if (actualNumberOfPages == expectedNumberOfPages)
         appendResult('PASS: number of pages is ' + actualNumberOfPages);
     else {
@@ -50,5 +56,35 @@ function runPrintingTest(testFunction)
 
     var resultElement = document.createElement('p');
     resultElement.innerHTML = _results;
-    document.body.appendChild(resultElement);
+    var output = document.getElementById("console") || document.body;
+    output.appendChild(resultElement);
+}
+
+function ratioToPageHeightToPixels(heightInRatioToPageHeight)
+{
+  var pageHeightInPixels = 600;
+  return Math.floor(pageHeightInPixels * heightInRatioToPageHeight);
+}
+
+function createBlockWithRatioToPageHeight(id, heightInRatioToPageHeight)
+{
+    var element = document.createElement("div");
+    element.id = id;
+    element.style.height = ratioToPageHeightToPixels(heightInRatioToPageHeight) + "px";
+    document.getElementById("sandbox").appendChild(element);
+    return element;
+}
+
+function createBlockWithNumberOfLines(id, childLines)
+{
+    var element = document.createElement("div");
+    element.id = id;
+    for (var i = 0; i < childLines; ++i) {
+        element.appendChild(document.createTextNode("line" + i));
+        element.appendChild(document.createElement("br"));
+    }
+    // Make sure that one page has about 20 lines.
+    element.style.lineHeight = ratioToPageHeightToPixels(0.05) + "px";
+    document.getElementById("sandbox").appendChild(element);
+    return element;
 }
index 79caac4..6e730b1 100644 (file)
@@ -3,12 +3,14 @@
 <head>
 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
 </head>
 <body>
 <p id="description"></p>
 <div id="console"></div>
 <div id="sandbox"></div>
 <script src="YOUR_JS_FILE_HERE"></script>
+<script>runPrintingTest(test);</script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
 </html>
index ca64903..e41aac4 100644 (file)
@@ -1,23 +1,14 @@
 description("Test for layoutTestController.numberOfPages()");
 
-function createParagraph(id)
+function test()
 {
-    var element = document.createElement("div");
-    element.id = id;
-    element.width = 100;
-    document.getElementById("sandbox").appendChild(element);
-    return element;
-}
-
-var firstPage = createParagraph("firstPage");
-firstPage.style.height = 700;
+    createBlockWithRatioToPageHeight("firstPage", 0.6);
+    createBlockWithRatioToPageHeight("secondPage", 0.6);
 
-var secondPage = createParagraph("secondPage");
-secondPage.style.height = 700;
+    numberOfPagesShouldBe(2);
+    numberOfPagesShouldBe(1, 1000, 10000);
 
-shouldBe("layoutTestController.numberOfPages(1000, 1000)", "2");
-shouldBe("layoutTestController.numberOfPages(10000, 10000)", "1");
-
-document.body.removeChild(document.getElementById("sandbox"));
+    document.body.removeChild(document.getElementById("sandbox"));
+}
 
 var successfullyParsed = true;
index da10a44..7e39132 100644 (file)
@@ -1,39 +1,39 @@
 description("Test page-break-{before,after}:always for overflow:{visible,hidden,scroll,auto} elements.");
 
-var overflowValues = ["visible", "hidden", "scroll", "auto"];
-var pageBreakPositions = ["page-break-before", "page-break-after"];
+function test()
+{
+    var overflowValues = ["visible", "hidden", "scroll", "auto"];
+    var pageBreakPositions = ["page-break-before", "page-break-after"];
 
-var testHtml = "";
-for (var position = 0; position < pageBreakPositions.length; position++) {
-    for (var value = 0; value < overflowValues.length; value++) {
-        var overflowStyle = "overflow:" + overflowValues[value];
-        var pageBreakStyle = pageBreakPositions[position] + ":always";
-        var testId = 'test-' + pageBreakStyle + '-for-' + overflowStyle;
-        testHtml += '<div style="' + overflowStyle + '"><p id="' + testId + '" style="' + pageBreakStyle + '">' + overflowStyle + ', ' + pageBreakStyle + '</p></div>\n';
+    var testHtml = "";
+    for (var position = 0; position < pageBreakPositions.length; position++) {
+        for (var value = 0; value < overflowValues.length; value++) {
+            var overflowStyle = "overflow:" + overflowValues[value];
+            var pageBreakStyle = pageBreakPositions[position] + ":always";
+            var testId = 'test-' + pageBreakStyle + '-for-' + overflowStyle;
+            testHtml += '<div style="' + overflowStyle + '"><p id="' + testId + '" style="' + pageBreakStyle + '">' + overflowStyle + ', ' + pageBreakStyle + '</p></div>\n';
+        }
     }
-}
-testHtml += '<p id="test-last-page">end</p>';
-document.getElementById("sandbox").innerHTML = testHtml;
+    testHtml += '<p id="test-last-page">end</p>';
+    document.getElementById("sandbox").innerHTML = testHtml;
 
-var expectedValues = [
-    // page-break-{before,after}:always should take effect regardless of overflow value.
-    ['test-page-break-before:always-for-overflow:visible', 1],
-    ['test-page-break-before:always-for-overflow:hidden', 2],
-    ['test-page-break-before:always-for-overflow:scroll', 3],
-    ['test-page-break-before:always-for-overflow:auto', 4],
-    ['test-page-break-after:always-for-overflow:visible', 4],
-    ['test-page-break-after:always-for-overflow:hidden', 5],
-    ['test-page-break-after:always-for-overflow:scroll', 6],
-    ['test-page-break-after:always-for-overflow:auto', 7],
-    ['test-last-page', 8]
-];
+    var expectedValues = [
+        // page-break-{before,after}:always should take effect regardless of overflow value.
+        ['test-page-break-before:always-for-overflow:visible', 1],
+        ['test-page-break-before:always-for-overflow:hidden', 2],
+        ['test-page-break-before:always-for-overflow:scroll', 3],
+        ['test-page-break-before:always-for-overflow:auto', 4],
+        ['test-page-break-after:always-for-overflow:visible', 4],
+        ['test-page-break-after:always-for-overflow:hidden', 5],
+        ['test-page-break-after:always-for-overflow:scroll', 6],
+        ['test-page-break-after:always-for-overflow:auto', 7],
+        ['test-last-page', 8]
+    ];
 
-if (window.layoutTestController) {
-    for (var i = 0; i < expectedValues.length; i++) {
-        shouldBe("layoutTestController.pageNumberForElementById('" + expectedValues[i][0] + "')", "" + expectedValues[i][1]);
-    }
-}
+    for (var i = 0; i < expectedValues.length; i++)
+        pageNumberForElementShouldBe(expectedValues[i][0], expectedValues[i][1]);
 
-document.body.removeChild(document.getElementById("sandbox"));
+    document.body.removeChild(document.getElementById("sandbox"));
+}
 
 var successfullyParsed = true;
index 1c6e5d8..f7a5bb4 100644 (file)
@@ -1,24 +1,19 @@
 description("Test for page-break-before:always and page-break-after:always");
 
-function createParagraph(id)
+function test()
 {
-    var element = document.createElement("p");
-    element.id = id;
-    element.appendChild(document.createTextNode("foobar"));
-    document.getElementById("sandbox").appendChild(element);
-    return element;
-}
-
-createParagraph("firstPage");
-createParagraph("secondPage1").style.pageBreakBefore = "always";
-createParagraph("secondPage2").style.pageBreakAfter = "always";
-createParagraph("thirdPage").style.pageBreakBefore = "always";
+    createBlockWithRatioToPageHeight("firstPage", 0.1);
+    createBlockWithRatioToPageHeight("secondPage1", 0.1).style.pageBreakBefore = "always";
+    createBlockWithRatioToPageHeight("secondPage2", 0.1).style.pageBreakAfter = "always";
+    createBlockWithRatioToPageHeight("thirdPage", 0.1).style.pageBreakBefore = "always";
 
-shouldBe("layoutTestController.pageNumberForElementById('firstPage')", "0");
-shouldBe("layoutTestController.pageNumberForElementById('secondPage1')", "1");
-shouldBe("layoutTestController.pageNumberForElementById('secondPage2')", "1");
-shouldBe("layoutTestController.pageNumberForElementById('thirdPage')", "2");
+    pageNumberForElementShouldBe('firstPage', 0);
+    pageNumberForElementShouldBe('secondPage1', 1);
+    pageNumberForElementShouldBe('secondPage2', 1);
+    // There must be only one page break between 'page-break-after: always' and 'page-break-before: always'
+    pageNumberForElementShouldBe('thirdPage', 2);
 
-document.body.removeChild(document.getElementById("sandbox"));
+    document.body.removeChild(document.getElementById("sandbox"));
+}
 
 var successfullyParsed = true;
diff --git a/LayoutTests/printing/script-tests/page-break-inside-avoid.js b/LayoutTests/printing/script-tests/page-break-inside-avoid.js
new file mode 100644 (file)
index 0000000..fb8c477
--- /dev/null
@@ -0,0 +1,42 @@
+description("Test for page-break-inside:avoid");
+
+function test()
+{
+    createBlockWithRatioToPageHeight("page1-1", 0.5).style.pageBreakBefore = "always";
+    // block 'page1-2' should be splitted.
+    createBlockWithNumberOfLines("page1-2", 20);
+    createBlockWithRatioToPageHeight("page2", 0.1);
+
+    createBlockWithRatioToPageHeight("page3", 0.5).style.pageBreakBefore = "always";
+    // We should place block 'page4' in the next page because of 'page-break-inside: avoid'.
+    createBlockWithNumberOfLines("page4", 20).style.pageBreakInside = "avoid";
+
+    createBlockWithRatioToPageHeight("page5", 0.8).style.pageBreakBefore = "always";
+    // block 'page5-2' is a very large block, occupying more than 2 pages.
+    // We don't define from where this large block starts. Maybe from the next page.
+    createBlockWithNumberOfLines("page5or6", 20 * 2 + 10).style.pageBreakInside = "avoid";
+    createBlockWithRatioToPageHeight("page8", 0.1);
+
+    createBlockWithRatioToPageHeight("page9-1", 0.1).style.pageBreakBefore = "always";
+    createBlockWithRatioToPageHeight("page9-2", 0.1).style.pageBreakAfter = "always";
+    // Make sure page-break only happens once, not twice.
+    createBlockWithNumberOfLines("page10", 20).style.pageBreakInside = "avoid";
+
+    pageNumberForElementShouldBe('page1-1', 1);
+    pageNumberForElementShouldBe('page1-2', 1);
+    pageNumberForElementShouldBe('page2', 2);
+
+    pageNumberForElementShouldBe('page3', 3);
+    pageNumberForElementShouldBe('page4', 4);
+
+    pageNumberForElementShouldBe('page5', 5);
+    pageNumberForElementShouldBe('page8', 8);
+
+    pageNumberForElementShouldBe('page9-1', 9);
+    pageNumberForElementShouldBe('page9-2', 9);
+    pageNumberForElementShouldBe('page10', 10);
+
+    document.body.removeChild(document.getElementById("sandbox"));
+}
+
+var successfullyParsed = true;
diff --git a/LayoutTests/printing/script-tests/page-break-inside.js b/LayoutTests/printing/script-tests/page-break-inside.js
deleted file mode 100644 (file)
index 28a8181..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-description("Test for page-break-inside:avoid");
-
-function createParagraph(id, height)
-{
-    var element = document.createElement("div");
-    element.id = id;
-    element.style.height = height;
-    element.appendChild(document.createTextNode("foobar"));
-    document.getElementById("sandbox").appendChild(element);
-    return element;
-}
-
-var pageHeightInPixels = 1000;
-
-function pageNumber(id) {
-  return layoutTestController.pageNumberForElementById(id, 1000, pageHeightInPixels);
-}
-
-createParagraph("page1", 900).style.pageBreakBefore = "always";
-createParagraph("page2", 900).style.pageBreakInside = "avoid";
-
-createParagraph("page3-1", 900).style.pageBreakBefore = "always";
-createParagraph("page3-2", 100).style.pageBreakInside = "avoid";
-
-createParagraph("page4", 900).style.pageBreakBefore = "always";
-createParagraph("page5", 101).style.pageBreakInside = "avoid";
-
-createParagraph("page6", 100).style.pageBreakBefore = "always";
-createParagraph("page7", 2100).style.pageBreakInside = "avoid";
-createParagraph("page9", 100);
-
-createParagraph("page10-1", 100).style.pageBreakBefore = "always";
-createParagraph("page10-2", 100).style.pageBreakAfter = "always";
-// Make sure page-break only happens once, not twice.
-createParagraph("page11", 900).style.pageBreakInside = "avoid";
-
-// Before calling "shouldBe" tests, sets "display: none" style to |console| element so that the results of pageNumber should not be affected.
-// FIXME: Use functions defined in printing/resources/paged-media-test-utils.js instead of this hack.
-document.getElementById("console").style.display = 'none';
-
-shouldBe("pageNumber('page1')", "1");
-shouldBe("pageNumber('page2')", "2");
-
-shouldBe("pageNumber('page3-1')", "3");
-shouldBe("pageNumber('page3-2')", "3");
-
-shouldBe("pageNumber('page4')", "4");
-shouldBe("pageNumber('page5')", "5");
-
-shouldBe("pageNumber('page6')", "6");
-shouldBe("pageNumber('page7')", "7");
-shouldBe("pageNumber('page9')", "9");
-
-shouldBe("pageNumber('page10-1')", "10");
-shouldBe("pageNumber('page10-2')", "10");
-shouldBe("pageNumber('page11')", "11");
-
-document.getElementById("console").style.display = 'block';
-
-document.body.removeChild(document.getElementById("sandbox"));
-
-var successfullyParsed = true;
index 87d88ec..2688539 100644 (file)
@@ -1,31 +1,20 @@
 description("Test for layoutTestController.pageNumberForElementById()");
 
-function createParagraph(id)
+function test()
 {
-    var element = document.createElement("div");
-    element.id = id;
-    element.width = 100;
-    document.getElementById("sandbox").appendChild(element);
-    return element;
-}
-
-var firstPage = createParagraph("firstPage");
-firstPage.style.height = 1000;
-
-var secondPage = createParagraph("secondPage");
-secondPage.style.height = 1000;
+    // Assuming that one page has about 20 lines.
+    createBlockWithNumberOfLines("firstPage", 20);
+    createBlockWithNumberOfLines("secondPage", 20);
 
-var thirdPage = createParagraph("thirdPage");
-thirdPage.style.height = 100;
+    createBlockWithNumberOfLines("thirdPage", 5);
+    createBlockWithNumberOfLines("thirdPage2", 5);
 
-var thirdPage2 = createParagraph("thirdPage2");
-thirdPage2.style.height = 700;
+    pageNumberForElementShouldBe('firstPage', 0);
+    pageNumberForElementShouldBe('secondPage', 1);
+    pageNumberForElementShouldBe('thirdPage', 2);
+    pageNumberForElementShouldBe('thirdPage2', 2);
 
-shouldBe("layoutTestController.pageNumberForElementById('firstPage', 1000, 1000)", "0");
-shouldBe("layoutTestController.pageNumberForElementById('secondPage', 1000, 1000)", "1");
-shouldBe("layoutTestController.pageNumberForElementById('thirdPage', 1000, 1000)", "2");
-shouldBe("layoutTestController.pageNumberForElementById('thirdPage2', 1000, 1000)", "2");
-
-document.body.removeChild(document.getElementById("sandbox"));
+    document.body.removeChild(document.getElementById("sandbox"));
+}
 
 var successfullyParsed = true;