Title: [237155] trunk/LayoutTests
Revision
237155
Author
mattba...@apple.com
Date
2018-10-15 16:29:28 -0700 (Mon, 15 Oct 2018)

Log Message

Web Inspector: Cleanup Table test utilities
https://bugs.webkit.org/show_bug.cgi?id=190538
<rdar://problem/45237730>

Reviewed by Joseph Pecoraro.

Cleanup Table test utilities by exposing removing the artificial dependency
between TableDelegate and TableDataSource, and exposing a cleaner set of
utility methods to InspectorTest. This patch changes `InspectorTest.createTable`
to take no parameters, and adds `InspectorTest.createTableWithDelegate` for
tests that need to supply a custom delegate.

* inspector/table/resources/table-utilities.js:
(TestPage.registerInitializer.InspectorTest.TableDataSource):
(TestPage.registerInitializer.InspectorTest.TableDelegate):
(TestPage.registerInitializer.InspectorTest.TableDelegate.prototype.tablePopulateCell):
(TestPage.registerInitializer.createDataSource):
(TestPage.registerInitializer.createTableInternal):
(TestPage.registerInitializer.InspectorTest.createTable):
(TestPage.registerInitializer.InspectorTest.createTableWithDelegate):
(TestPage.registerInitializer):

* inspector/table/table-selection-expected.txt:
Update with new test suite name.

* inspector/table/table-selection.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237154 => 237155)


--- trunk/LayoutTests/ChangeLog	2018-10-15 23:18:52 UTC (rev 237154)
+++ trunk/LayoutTests/ChangeLog	2018-10-15 23:29:28 UTC (rev 237155)
@@ -1,3 +1,32 @@
+2018-10-15  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: Cleanup Table test utilities
+        https://bugs.webkit.org/show_bug.cgi?id=190538
+        <rdar://problem/45237730>
+
+        Reviewed by Joseph Pecoraro.
+
+        Cleanup Table test utilities by exposing removing the artificial dependency
+        between TableDelegate and TableDataSource, and exposing a cleaner set of
+        utility methods to InspectorTest. This patch changes `InspectorTest.createTable`
+        to take no parameters, and adds `InspectorTest.createTableWithDelegate` for
+        tests that need to supply a custom delegate.
+
+        * inspector/table/resources/table-utilities.js:
+        (TestPage.registerInitializer.InspectorTest.TableDataSource):
+        (TestPage.registerInitializer.InspectorTest.TableDelegate):
+        (TestPage.registerInitializer.InspectorTest.TableDelegate.prototype.tablePopulateCell):
+        (TestPage.registerInitializer.createDataSource):
+        (TestPage.registerInitializer.createTableInternal):
+        (TestPage.registerInitializer.InspectorTest.createTable):
+        (TestPage.registerInitializer.InspectorTest.createTableWithDelegate):
+        (TestPage.registerInitializer):
+
+        * inspector/table/table-selection-expected.txt:
+        Update with new test suite name.
+
+        * inspector/table/table-selection.html:
+
 2018-10-15  Charles Vazac  <cva...@gmail.com>
 
         Web Inspector: Expose Server Timing Response Headers in Network Tab

Modified: trunk/LayoutTests/inspector/table/resources/table-utilities.js (237154 => 237155)


--- trunk/LayoutTests/inspector/table/resources/table-utilities.js	2018-10-15 23:18:52 UTC (rev 237154)
+++ trunk/LayoutTests/inspector/table/resources/table-utilities.js	2018-10-15 23:29:28 UTC (rev 237155)
@@ -3,24 +3,22 @@
     {
         constructor(items)
         {
-            this._items = items;
+            this._items = items || [];
         }
 
         get items() { return this._items; }
 
-        // Table DataSource
-
         tableNumberOfRows(table)
         {
             return this._items.length;
         }
-    }
+    };
 
     InspectorTest.TableDelegate = class TableDelegate
     {
         constructor(items)
         {
-            this._items = items;
+            this.items = items || [];
         }
 
         tableSelectionDidChange(table)
@@ -30,35 +28,47 @@
 
         tablePopulateCell(table, cell, column, rowIndex)
         {
-            let item = this._items[rowIndex];
+            let item = this.items[rowIndex];
             InspectorTest.assert(item, "Should have an item for row " + rowIndex);
             InspectorTest.assert(item[column.identifier], "Should have data for column " + column.identifier);
             cell.textContent = item[column.identifier];
             return cell;
         }
+    };
+
+    function createDataSource() {
+        let items = [];
+        for (let i = 0; i < 10; ++i)
+            items.push({index: i, name: `Row ${i}`});
+
+        return new InspectorTest.TableDataSource(items);
     }
 
-    InspectorTest.createTable = function(delegate, dataSource) {
-        if (!dataSource) {
-            let items = [];
-            for (let i = 0; i < 10; ++i) {
-                items.push({
-                    index: i,
-                    name: "Row " + i,
-                });
-            }
-            dataSource = new InspectorTest.TableDataSource(items);
-        }
+    function createTableInternal(dataSource, delegate) {
+        InspectorTest.assert(dataSource instanceof InspectorTest.TableDataSource);
+        InspectorTest.assert(delegate instanceof InspectorTest.TableDelegate);
 
-        delegate = delegate || new InspectorTest.TableDelegate(dataSource.items);
-
         const rowHeight = 20;
         let table = new WI.Table("test", dataSource, delegate, rowHeight);
-        table.addColumn(new WI.TableColumn("index", WI.UIString("Index")));
-        table.addColumn(new WI.TableColumn("name", WI.UIString("Name")));
+        table.addColumn(new WI.TableColumn("index", "Index"));
+        table.addColumn(new WI.TableColumn("name", "Name"));
 
         table.updateLayout();
 
         return table;
     }
+
+    InspectorTest.createTable = function() {
+        let dataSource = createDataSource();
+        let delegate = new InspectorTest.TableDelegate(dataSource.items);
+        return createTableInternal(dataSource, delegate);
+    };
+
+    InspectorTest.createTableWithDelegate = function(delegate) {
+        InspectorTest.assert(delegate instanceof InspectorTest.TableDelegate);
+
+        let dataSource = createDataSource();
+        delegate.items = dataSource.items;
+        return createTableInternal(dataSource, delegate);
+    };
 });

Modified: trunk/LayoutTests/inspector/table/table-selection-expected.txt (237154 => 237155)


--- trunk/LayoutTests/inspector/table/table-selection-expected.txt	2018-10-15 23:18:52 UTC (rev 237154)
+++ trunk/LayoutTests/inspector/table/table-selection-expected.txt	2018-10-15 23:29:28 UTC (rev 237155)
@@ -1,7 +1,7 @@
 Tests for WI.Table.
 
 
-== Running test suite: Table
+== Running test suite: Table.RowSelection
 -- Running test case: Table.constructor
 PASS: selectedRow should be NaN.
 PASS: Should have no selected rows.

Modified: trunk/LayoutTests/inspector/table/table-selection.html (237154 => 237155)


--- trunk/LayoutTests/inspector/table/table-selection.html	2018-10-15 23:18:52 UTC (rev 237154)
+++ trunk/LayoutTests/inspector/table/table-selection.html	2018-10-15 23:29:28 UTC (rev 237155)
@@ -8,15 +8,12 @@
 {
     InspectorTest.redirectRequestAnimationFrame();
 
-    let suite = InspectorTest.createSyncSuite("Table");
+    let suite = InspectorTest.createSyncSuite("Table.RowSelection");
 
-    // Import names.
-    let {createTable, cleanupTable} = InspectorTest;
-
     suite.addTestCase({
         name: "Table.constructor",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
 
             InspectorTest.expectThat(isNaN(table.selectedRow), "selectedRow should be NaN.");
             InspectorTest.expectEqual(table.selectedRows.length, 0, "Should have no selected rows.");
@@ -40,9 +37,9 @@
 
     suite.addTestCase({
         name: "Table.SelectRow",
-        description: "Select a row, then select another row causing the frist to become deselected.",
+        description: "Select a row, then select another row causing the first to become deselected.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
 
             triggerSelectRow(table, 0);
             InspectorTest.expectShallowEqual(table.selectedRows, [0], "selectedRows should be [0].");
@@ -57,7 +54,7 @@
         name: "Table.DeselectRow",
         description: "Deselect the selected row.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
 
             triggerSelectRow(table, 0);
             triggerDeselectRow(table, 0);
@@ -71,7 +68,7 @@
         name: "Table.AllowsMultipleSelection",
         description: "Should be able to enable multiple selection.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
 
             table.allowsMultipleSelection = true;
             InspectorTest.expectThat(table.allowsMultipleSelection, "allowsMultipleSelection enabled.");
@@ -85,7 +82,7 @@
         name: "Table.SelectMultipleRows.ExtendSelection",
         description: "Select multiple rows, extending the selection.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
             table.allowsMultipleSelection = true;
             InspectorTest.expectThat(table.allowsMultipleSelection, "allowsMultipleSelection enabled.");
 
@@ -104,7 +101,7 @@
         name: "Table.SelectMultipleRows.SelectTheSameRowTwice.ExtendSelection",
         description: "Select an already selected row, and extend the selection.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
             table.allowsMultipleSelection = true;
 
             const extendSelection = true;
@@ -122,7 +119,7 @@
         name: "Table.SelectMultipleRows.SelectTheSameRowTwice.NoExtendSelection",
         description: "Select an already selected row, and do not extend the selection.",
         test() {
-            let table = createTable();
+            let table = InspectorTest.createTable();
             table.allowsMultipleSelection = true;
 
             const extendSelection = true;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to