Web Inspector: Cleanup Table test utilities
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 23:29:28 +0000 (23:29 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 23:29:28 +0000 (23:29 +0000)
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:

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

LayoutTests/ChangeLog
LayoutTests/inspector/table/resources/table-utilities.js
LayoutTests/inspector/table/table-selection-expected.txt
LayoutTests/inspector/table/table-selection.html

index 113a540..73b288f 100644 (file)
@@ -1,3 +1,32 @@
+2018-10-15  Matt Baker  <mattbaker@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  <cvazac@gmail.com>
 
         Web Inspector: Expose Server Timing Response Headers in Network Tab
index 4861a35..c0d96d9 100644 (file)
@@ -3,24 +3,22 @@ TestPage.registerInitializer(() => {
     {
         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 @@ TestPage.registerInitializer(() => {
 
         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;
         }
-    }
+    };
 
-    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 createDataSource() {
+        let items = [];
+        for (let i = 0; i < 10; ++i)
+            items.push({index: i, name: `Row ${i}`});
 
-        delegate = delegate || new InspectorTest.TableDelegate(dataSource.items);
+        return new InspectorTest.TableDataSource(items);
+    }
+
+    function createTableInternal(dataSource, delegate) {
+        InspectorTest.assert(dataSource instanceof InspectorTest.TableDataSource);
+        InspectorTest.assert(delegate instanceof InspectorTest.TableDelegate);
 
         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);
+    };
 });
index 63045f8..717fce8 100644 (file)
@@ -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.
index 32ae6c4..f61b544 100644 (file)
@@ -8,15 +8,12 @@ function test()
 {
     InspectorTest.redirectRequestAnimationFrame();
 
-    let suite = InspectorTest.createSyncSuite("Table");
-
-    // Import names.
-    let {createTable, cleanupTable} = InspectorTest;
+    let suite = InspectorTest.createSyncSuite("Table.RowSelection");
 
     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 @@ function test()
 
     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 @@ function test()
         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 @@ function test()
         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 @@ function test()
         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 @@ function test()
         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 @@ function test()
         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;