Merge "Update highlight.js" into stable-2.16
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
index 85f316c..41048cb 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
@@ -1409,7 +1409,7 @@
         theme: 'DEFAULT',
         ignore_whitespace: 'IGNORE_NONE',
       };
-      diff._diff = mock.diffResponse;
+      diff.diff = mock.diffResponse;
     };
 
     const renderAndGetNewDiffs = function(index) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.html b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.html
index e3bf866..305374b 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.html
@@ -47,7 +47,7 @@
         base-image="[[_baseImage]]"
         revision-image=[[_revisionImage]]
         blame="[[_blame]]"
-        diff="[[_diff]]"></gr-diff>
+        diff="[[diff]]"></gr-diff>
     <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
     <gr-reporting id="reporting" category="diff"></gr-reporting>
   </template>
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.js b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.js
index 6f61fb9..fa1d9ca 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.js
@@ -94,7 +94,7 @@
       },
       isImageDiff: {
         type: Boolean,
-        computed: '_computeIsImageDiff(_diff)',
+        computed: '_computeIsImageDiff(diff)',
         notify: true,
       },
       commitRange: Object,
@@ -164,8 +164,13 @@
       _baseImage: Object,
       /** @type {?Object} */
       _revisionImage: Object,
-
-      _diff: Object,
+      /**
+       * This is a DiffInfo object.
+       */
+      diff: {
+        type: Object,
+        notify: true,
+      },
 
       /** @type {?Object} */
       _blame: {
@@ -237,7 +242,7 @@
                 this.removeEventListener('render', callback);
               };
               this.addEventListener('render', callback);
-              this._diff = diff;
+              this.diff = diff;
             });
           })
           .catch(err => {
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 3a5b3a1..ab1d668 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
@@ -269,7 +269,7 @@
             <gr-dropdown
                 link
                 down-arrow
-                items="[[_computeDownloadDropdownLinks(_change.project, _changeNum, _patchRange, _path)]]"
+                items="[[_computeDownloadDropdownLinks(_change.project, _changeNum, _patchRange, _path, _diff)]]"
                 horizontal-align="left">
               <span class="downloadTitle">
                 Download
@@ -330,6 +330,7 @@
         class$="[[_computeDiffClass(_panelFloatingDisabled)]]"
         is-image-diff="{{_isImageDiff}}"
         files-weblinks="{{_filesWeblinks}}"
+        diff="{{_diff}}"
         change-num="[[_changeNum]]"
         commit-range="[[_commitRange]]"
         patch-range="[[_patchRange]]"
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 76a0bef..6b17b9a 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
@@ -84,6 +84,10 @@
       /** @type {?} */
       _changeComments: Object,
       _changeNum: String,
+      /**
+       * This is a DiffInfo object.
+       * This is retrieved and owned by a child component.
+       */
       _diff: Object,
       // An array specifically formatted to be used in a gr-dropdown-list
       // element for selected a file to view.
@@ -880,33 +884,63 @@
       history.replaceState(null, '', url);
     },
 
-    _computeDownloadDropdownLinks(project, changeNum, patchRange, path) {
+    _computeDownloadDropdownLinks(
+        project, changeNum, patchRange, path, diff) {
       if (!patchRange || !patchRange.patchNum) { return []; }
 
-      return [
+      const links = [
         {
           url: this._computeDownloadPatchLink(
               project, changeNum, patchRange, path),
           name: 'Patch',
         },
-        {
-          // We pass 1 here to indicate this is parent 1.
-          url: this._computeDownloadFileLink(
-              project, changeNum, patchRange, path, 1),
-          name: 'Left Content',
-        },
-        {
-          // We pass 0 here to indicate this is parent 0.
-          url: this._computeDownloadFileLink(
-              project, changeNum, patchRange, path, 0),
-          name: 'Right Content',
-        },
       ];
+
+      if (diff && diff.meta_a) {
+        let leftPath = path;
+        if (diff.change_type === 'RENAMED') {
+          leftPath = diff.meta_a.name;
+        }
+        links.push(
+            {
+              url: this._computeDownloadFileLink(
+                  project, changeNum, patchRange, leftPath, true),
+              name: 'Left Content',
+            }
+        );
+      }
+
+      if (diff && diff.meta_b) {
+        links.push(
+            {
+              url: this._computeDownloadFileLink(
+                  project, changeNum, patchRange, path, false),
+              name: 'Right Content',
+            }
+        );
+      }
+
+      return links;
     },
 
-    _computeDownloadFileLink(project, changeNum, patchRange, path, parent) {
-      return this.changeBaseURL(project, changeNum, patchRange.patchNum) +
-          `/files/${encodeURIComponent(path)}/download?parent=${parent}`;
+    _computeDownloadFileLink(
+        project, changeNum, patchRange, path, isBase) {
+      let patchNum = patchRange.patchNum;
+
+      const comparedAgainsParent = patchRange.basePatchNum === 'PARENT';
+
+      if (isBase && !comparedAgainsParent) {
+        patchNum = patchRange.basePatchNum;
+      }
+
+      let url = this.changeBaseURL(project, changeNum, patchNum) +
+          `/files/${encodeURIComponent(path)}/download`;
+
+      if (isBase && comparedAgainsParent) {
+        url += '?parent=1';
+      }
+
+      return url;
     },
 
     _computeDownloadPatchLink(project, changeNum, patchRange, path) {
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 92e2c52..c47bfee 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
@@ -1122,26 +1122,79 @@
         },
         {
           url: '/changes/test~12/revisions/1' +
-              '/files/index.php/download?parent=0',
+              '/files/index.php/download',
           name: 'Right Content',
         },
       ];
+
+      const side = {
+        meta_a: true,
+        meta_b: true,
+      };
+
+      const base = {
+        patchNum: 1,
+        basePatchNum: 'PARENT',
+      };
+
       assert.deepEqual(
           element._computeDownloadDropdownLinks(
-              'test', 12, {patchNum: 1}, 'index.php'),
+              'test', 12, base, 'index.php', side),
+          downloadLinks);
+    });
+
+    test('_computeDownloadDropdownLinks diff returns renamed', () => {
+      const downloadLinks = [
+        {
+          url: '/changes/test~12/revisions/3/patch?zip&path=index.php',
+          name: 'Patch',
+        },
+        {
+          url: '/changes/test~12/revisions/2' +
+              '/files/index2.php/download',
+          name: 'Left Content',
+        },
+        {
+          url: '/changes/test~12/revisions/3' +
+              '/files/index.php/download',
+          name: 'Right Content',
+        },
+      ];
+
+      const side = {
+        change_type: 'RENAMED',
+        meta_a: {
+          name: 'index2.php',
+        },
+        meta_b: true,
+      };
+
+      const base = {
+        patchNum: 3,
+        basePatchNum: 2,
+      };
+
+      assert.deepEqual(
+          element._computeDownloadDropdownLinks(
+              'test', 12, base, 'index.php', side),
           downloadLinks);
     });
 
     test('_computeDownloadFileLink', () => {
+      const base = {
+        patchNum: 1,
+        basePatchNum: 'PARENT',
+      };
+
       assert.equal(
           element._computeDownloadFileLink(
-              'test', 12, {patchNum: 1}, 'index.php', 1),
+              'test', 12, base, 'index.php', true),
           '/changes/test~12/revisions/1/files/index.php/download?parent=1');
 
       assert.equal(
           element._computeDownloadFileLink(
-              'test', 12, {patchNum: 1}, 'index.php', 0),
-          '/changes/test~12/revisions/1/files/index.php/download?parent=0');
+              'test', 12, base, 'index.php', false),
+          '/changes/test~12/revisions/1/files/index.php/download');
     });
 
     test('_computeDownloadPatchLink', () => {