Refactor file path truncation into behavior

Change-Id: I21af00d3efc28291aa6918fde643cc6c77a7d05c
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
index 008852e..84bd586 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
@@ -16,6 +16,7 @@
 
 <link rel="import" href="../../../bower_components/polymer/polymer.html">
 <link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
+<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
 <link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
 <link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html">
 <link rel="import" href="../../../bower_components/iron-dropdown/iron-dropdown.html">
@@ -229,7 +230,7 @@
               hidden$="[[!_loggedIn]]" hidden>
           <div class="jumpToFileContainer desktop">
             <gr-button link class="dropdown-trigger" id="trigger" on-tap="_showDropdownTapHandler">
-              <span>[[_computeFileDisplayName(_path)]]</span>
+              <span>[[computeDisplayPath(_path)]]</span>
               <span class="downArrow">&#9660;</span>
             </gr-button>
             <!-- *-align="" to disable iron-dropdown's element positioning. -->
@@ -246,7 +247,7 @@
                   <a href$="[[_computeDiffURL(_change, _patchRange.*, path)]]"
                     selected$="[[_computeFileSelected(path, _path)]]"
                     data-key-nav$="[[_computeKeyNav(path, _path, _fileList)]]"
-                    on-tap="_handleFileTap">[[_computeFileDisplayName(path)]]</a>
+                    on-tap="_handleFileTap">[[computeDisplayPath(path)]]</a>
                 </template>
               </div>
             </iron-dropdown>
@@ -257,7 +258,7 @@
                 <option
                     value$="[[path]]"
                     selected$="[[_computeFileSelected(path, _path)]]">
-                  [[_computeTruncatedFileDisplayName(path)]]
+                  [[computeTruncatedPath(path)]]
                 </option>
               </template>
             </select>
@@ -331,7 +332,7 @@
         <a class="mobileNavLink"
           href$="[[_computeNavLinkURL(_change, _path, _fileList, -1, 1)]]">
           &lt;</a>
-        <div class="fullFileName mobile">[[_computeFileDisplayName(_path)]]
+        <div class="fullFileName mobile">[[computeDisplayPath(_path)]]
         </div>
         <a class="mobileNavLink"
             href$="[[_computeNavLinkURL(_change, _path, _fileList, 1, 1)]]">
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index fbd845a..ee12e34 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -14,9 +14,6 @@
 (function() {
   'use strict';
 
-  const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
-  const MERGE_LIST_PATH = '/MERGE_LIST';
-
   const ERR_REVIEW_STATUS = 'Couldn’t change file review status.';
   const MSG_LOADING_BLAME = 'Loading blame...';
   const MSG_LOADED_BLAME = 'Blame loaded';
@@ -142,6 +139,7 @@
     behaviors: [
       Gerrit.KeyboardShortcutBehavior,
       Gerrit.PatchSetBehavior,
+      Gerrit.PathListBehavior,
       Gerrit.RESTClientBehavior,
     ],
 
@@ -495,7 +493,7 @@
       // has been queued, the event can bubble up to the handler in gr-app.
       this.async(() => {
         this.fire('title-change',
-            {title: this._computeTruncatedFileDisplayName(this._path)});
+            {title: this.computeTruncatedPath(this._path)});
       });
 
       // When navigating away from the page, there is a possibility that the
@@ -568,7 +566,7 @@
     _pathChanged(path) {
       if (path) {
         this.fire('title-change',
-            {title: this._computeTruncatedFileDisplayName(path)});
+            {title: this.computeTruncatedPath(path)});
       }
 
       if (this._fileList.length == 0) { return; }
@@ -640,19 +638,6 @@
       return this._getChangePath(change, patchRangeRecord.base, revisions);
     },
 
-    _computeFileDisplayName(path) {
-      if (path === COMMIT_MESSAGE_PATH) {
-        return 'Commit message';
-      } else if (path === MERGE_LIST_PATH) {
-        return 'Merge list';
-      }
-      return path;
-    },
-
-    _computeTruncatedFileDisplayName(path) {
-      return util.truncatePath(this._computeFileDisplayName(path));
-    },
-
     _computeFileSelected(path, currentPath) {
       return path == currentPath;
     },
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
index 68c2e52..ae1404a 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
@@ -336,15 +336,6 @@
             '42-glados.txt-10-PARENT');
         assert.equal(linkEls[2].getAttribute('href'),
             '42-wheatley.md-10-PARENT');
-
-        assert.equal(element._computeFileDisplayName('/foo/bar/baz'),
-            '/foo/bar/baz');
-        assert.equal(element._computeFileDisplayName('/foobarbaz'),
-            '/foobarbaz');
-        assert.equal(element._computeFileDisplayName('/COMMIT_MSG'),
-            'Commit message');
-        assert.equal(element._computeFileDisplayName('/MERGE_LIST'),
-            'Merge list');
       });
 
       test('jump to file dropdown with patch range', () => {
@@ -614,25 +605,6 @@
       assert.equal(element.$.cursor.side, 'right');
     });
 
-    test('_shortenPath with long path should add ellipsis', () => {
-      let path = 'level1/level2/level3/level4/file.js';
-      let shortenedPath = util.truncatePath(path);
-      // The expected path is truncated with an ellipsis.
-      const expectedPath = '\u2026/file.js';
-      assert.equal(shortenedPath, expectedPath);
-
-      path = 'level2/file.js';
-      shortenedPath = util.truncatePath(path);
-      assert.equal(shortenedPath, expectedPath);
-    });
-
-    test('_shortenPath with short path should not add ellipsis', () => {
-      const path = 'file.js';
-      const expectedPath = 'file.js';
-      const shortenedPath = util.truncatePath(path);
-      assert.equal(shortenedPath, expectedPath);
-    });
-
     test('_onLineSelected', () => {
       const getUrlStub = sandbox.stub(Gerrit.Nav, 'getUrlForDiffById');
       const replaceStateStub = sandbox.stub(history, 'replaceState');