Enable lit based unified diff (still flag protected)

But this is enabling the test that compares legacy and lit unified diff.

Release-Notes: skip
Google-Bug-Id: b/237393560
Change-Id: I5cbcd4fc2358901027b16b630ed983a7de4159bf
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-builder-element.ts b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-builder-element.ts
index 804d101..12d7ec2 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-builder-element.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-builder-element.ts
@@ -433,6 +433,7 @@
     }
 
     let builder = null;
+    const useLit = this.renderPrefs?.use_lit_components ?? false;
     if (this.isImageDiff) {
       builder = new GrDiffBuilderImage(
         this.diff,
@@ -447,7 +448,10 @@
       // If the diff is binary, but not an image.
       return new GrDiffBuilderBinary(this.diff, localPrefs, this.diffElement);
     } else if (this.viewMode === DiffViewMode.SIDE_BY_SIDE) {
-      const useLit = this.renderPrefs?.use_lit_components;
+      this.renderPrefs = {
+        ...this.renderPrefs,
+        view_mode: DiffViewMode.SIDE_BY_SIDE,
+      };
       if (useLit) {
         builder = new GrDiffBuilderLit(
           this.diff,
@@ -466,13 +470,27 @@
         );
       }
     } else if (this.viewMode === DiffViewMode.UNIFIED) {
-      builder = new GrDiffBuilderUnified(
-        this.diff,
-        localPrefs,
-        this.diffElement,
-        this.layersInternal,
-        this.renderPrefs
-      );
+      this.renderPrefs = {
+        ...this.renderPrefs,
+        view_mode: DiffViewMode.UNIFIED,
+      };
+      if (useLit) {
+        builder = new GrDiffBuilderLit(
+          this.diff,
+          localPrefs,
+          this.diffElement,
+          this.layersInternal,
+          this.renderPrefs
+        );
+      } else {
+        builder = new GrDiffBuilderUnified(
+          this.diff,
+          localPrefs,
+          this.diffElement,
+          this.layersInternal,
+          this.renderPrefs
+        );
+      }
     }
     if (!builder) {
       throw Error(`Unsupported diff view mode: ${this.viewMode}`);
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-row.ts b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-row.ts
index 16aea1d..e496cca 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-row.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-row.ts
@@ -12,7 +12,6 @@
   Side,
   LineNumber,
   DiffLayer,
-  DiffViewMode,
 } from '../../../api/diff';
 import {BlameInfo} from '../../../types/common';
 import {assertIsDefined} from '../../../utils/common-util';
@@ -48,8 +47,12 @@
   @property({type: Object})
   responsiveMode?: DiffResponsiveMode;
 
-  @property({type: Object})
-  viewMode?: DiffViewMode;
+  /**
+   * true: side-by-side diff
+   * false: unified diff
+   */
+  @property({type: Boolean})
+  unifiedDiff = false;
 
   @property({type: Number})
   tabSize = 2;
@@ -136,9 +139,9 @@
 
   override render() {
     if (!this.left || !this.right) return;
-    const classes = this.isUnifiedDiff() ? ['unified'] : ['side-by-side'];
+    const classes = this.unifiedDiff ? ['unified'] : ['side-by-side'];
     const unifiedType = this.unifiedType();
-    if (this.isUnifiedDiff() && unifiedType) classes.push(unifiedType);
+    if (this.unifiedDiff && unifiedType) classes.push(unifiedType);
     const row = html`
       <tr
         ${ref(this.tableRowRef)}
@@ -165,10 +168,10 @@
   private ariaLabelIds() {
     const ids: string[] = [];
     ids.push(this.lineNumberId(Side.LEFT));
-    if (!this.isUnifiedDiff()) ids.push(this.contentId(Side.LEFT));
+    if (!this.unifiedDiff) ids.push(this.contentId(Side.LEFT));
     ids.push(this.lineNumberId(Side.RIGHT));
-    if (!this.isUnifiedDiff()) ids.push(this.contentId(Side.RIGHT));
-    if (this.isUnifiedDiff()) ids.push(this.contentId(this.unifiedSide()));
+    if (!this.unifiedDiff) ids.push(this.contentId(Side.RIGHT));
+    if (this.unifiedDiff) ids.push(this.contentId(this.unifiedSide()));
     return ids.filter(id => !!id).join(' ');
   }
 
@@ -253,8 +256,7 @@
     const lineNumber = this.lineNumber(side);
     const isBlank = line?.type === GrDiffLineType.BLANK;
     if (!line || !lineNumber || isBlank || this.layersApplied) {
-      const blankClass =
-        isBlank && this.isSideBySideDiff() ? 'blankLineNum' : '';
+      const blankClass = isBlank && !this.unifiedDiff ? 'blankLineNum' : '';
       return html`<td
         ${ref(this.lineNumberRef(side))}
         class=${diffClasses(side, blankClass)}
@@ -318,7 +320,7 @@
 
   private renderContentCell(side: Side) {
     let line = this.line(side);
-    if (this.isUnifiedDiff()) {
+    if (this.unifiedDiff) {
       if (side === Side.LEFT) return nothing;
       if (line?.type === GrDiffLineType.BLANK) {
         side = Side.LEFT;
@@ -351,7 +353,7 @@
   }
 
   private renderSignCell(side: Side) {
-    if (this.isUnifiedDiff()) return nothing;
+    if (this.unifiedDiff) return nothing;
     const line = this.line(side);
     assertIsDefined(line, 'line');
     const isBlank = line.type === GrDiffLineType.BLANK;
@@ -393,20 +395,12 @@
   }
 
   private getType(side?: Side): string | undefined {
-    if (this.isUnifiedDiff()) return undefined;
+    if (this.unifiedDiff) return undefined;
     if (side === Side.LEFT) return this.left?.type;
     if (side === Side.RIGHT) return this.right?.type;
     return undefined;
   }
 
-  private isUnifiedDiff() {
-    return this.viewMode === DiffViewMode.UNIFIED;
-  }
-
-  private isSideBySideDiff() {
-    return !this.isUnifiedDiff();
-  }
-
   private unifiedType() {
     return this.left?.type === GrDiffLineType.BLANK
       ? this.right?.type
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-section.ts b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-section.ts
index e8dca18..1c09372 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-section.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-builder/gr-diff-section.ts
@@ -85,9 +85,7 @@
               .layers=${this.layers}
               .lineLength=${this.diffPrefs?.line_length ?? 80}
               .tabSize=${this.diffPrefs?.tab_size ?? 2}
-              .viewMode=${this.isUnifiedDiff()
-                ? DiffViewMode.UNIFIED
-                : DiffViewMode.SIDE_BY_SIDE}
+              .unifiedDiff=${this.isUnifiedDiff()}
             >
             </gr-diff-row>
           `;
diff --git a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff_test.ts b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff_test.ts
index 989815c..bbe091f 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff/gr-diff_test.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff/gr-diff_test.ts
@@ -75,8 +75,6 @@
 
     test('a unified diff lit', async () => {
       element.viewMode = DiffViewMode.UNIFIED;
-      // TODO(brohlfs): Write a lit based builder for unified diff. At the
-      // moment setting `use_lit_components:true` is a no-op for unified diff.
       element.renderPrefs = {...element.renderPrefs, use_lit_components: true};
       await testUnified();
     });