Stop control display via settings page

chrome.system.display.setDisplayProperties can do the job.  This API is
limited to some use case, so we need to allow autotest extension to use
it first.

TEST=test_that display_ResolutionList
TEST=test_that platform_RotationFps
TEST=test_that video_PlaybackQuality
TEST=test_that display_Tearing
TEST=test_that video_GlitchDetection (failed, but even w/o this change)
BUG=chromium:712705

Change-Id: Ia45c6da7d72e2de5ebc8f01ca1124811f283b0f3
Reviewed-on: https://chromium-review.googlesource.com/498013
Commit-Ready: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Reviewed-by: Victor Hsieh <victorhsieh@chromium.org>
diff --git a/client/cros/chameleon/chameleon_screen_test.py b/client/cros/chameleon/chameleon_screen_test.py
index 10db8c6..cbf3abc 100644
--- a/client/cros/chameleon/chameleon_screen_test.py
+++ b/client/cros/chameleon/chameleon_screen_test.py
@@ -86,7 +86,7 @@
             self._display_facade.load_calibration_image(image_size)
         if not test_mirrored:
             self._display_facade.move_to_display(
-                    self._display_facade.get_first_external_display_index())
+                    self._display_facade.get_first_external_display_id())
         self._display_facade.set_fullscreen(True)
         logging.info('Waiting for calibration image to stabilize...')
         time.sleep(self._TEST_IMAGE_STABILIZE_TIME)
diff --git a/client/cros/multimedia/display_facade_adapter.py b/client/cros/multimedia/display_facade_adapter.py
index ce5f974..6960c0f 100644
--- a/client/cros/multimedia/display_facade_adapter.py
+++ b/client/cros/multimedia/display_facade_adapter.py
@@ -51,12 +51,12 @@
         return self._display_component.get_internal_connector_name()
 
 
-    def move_to_display(self, display_index):
+    def move_to_display(self, display_id):
         """Moves the current window to the indicated display.
 
-        @param display_index: The index of the indicated display.
+        @param display_id: The id of the indicated display.
         """
-        self._display_component.move_to_display(display_index)
+        self._display_component.move_to_display(display_id)
 
 
     def set_fullscreen(self, is_fullscreen):
@@ -257,14 +257,14 @@
         return tuple(resolution) if resolution else None
 
 
-    def set_resolution(self, display_index, width, height):
+    def set_resolution(self, display_id, width, height):
         """Sets the resolution on the specified display.
 
-        @param display_index: index of the display to set resolutions for.
+        @param display_id: id of the display to set resolutions for.
         @param width: width of the resolution
         @param height: height of the resolution
         """
-        self._display_component.set_resolution(display_index, width, height)
+        self._display_component.set_resolution(display_id, width, height)
 
 
     def get_display_info(self):
@@ -276,59 +276,66 @@
         return map(DisplayInfo, self._display_component.get_display_info())
 
 
-    def get_display_modes(self, display_index):
+    def get_display_modes(self, display_id):
         """Gets the display modes of the specified display.
 
-        @param display_index: index of the display to get modes from; the index
-            is from the DisplayInfo list obtained by get_display_info().
+        @param display_id: id of the display to get modes from; the id is from
+            the DisplayInfo list obtained by get_display_info().
 
         @return: list of DisplayMode dicts.
         """
-        return self._display_component.get_display_modes(display_index)
+        return self._display_component.get_display_modes(display_id)
 
 
-    def get_available_resolutions(self, display_index):
+    def get_available_resolutions(self, display_id):
         """Gets the resolutions from the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return a list of (width, height) tuples.
         """
         return [tuple(r) for r in
-                self._display_component.get_available_resolutions(
-                    display_index)]
+                self._display_component.get_available_resolutions(display_id)]
 
 
-    def get_display_rotation(self, display_index):
+    def get_display_rotation(self, display_id):
         """Gets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return: Degree of rotation.
         """
-        return self._display_component.get_display_rotation(display_index)
+        return self._display_component.get_display_rotation(display_id)
 
 
-    def set_display_rotation(self, display_index, rotation,
+    def set_display_rotation(self, display_id, rotation,
                              delay_before_rotation=0, delay_after_rotation=0):
         """Sets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
         @param rotation: degree of rotation
         @param delay_before_rotation: time in second for delay before rotation
         @param delay_after_rotation: time in second for delay after rotation
         """
         self._display_component.set_display_rotation(
-                display_index, rotation, delay_before_rotation,
+                display_id, rotation, delay_before_rotation,
                 delay_after_rotation)
 
 
-    def get_first_external_display_index(self):
-        """Gets the first external display index.
+    def get_internal_display_id(self):
+        """Gets the internal display id.
 
-        @return the index of the first external display; False if not found.
+        @return the id of the internal display.
         """
-        return self._display_component.get_first_external_display_index()
+        return self._display_component.get_internal_display_id()
+
+
+    def get_first_external_display_id(self):
+        """Gets the first external display id.
+
+        @return the id of the first external display; -1 if not found.
+        """
+        return self._display_component.get_first_external_display_id()
 
 
     def reset_connector_if_applicable(self, connector_type):
diff --git a/client/cros/multimedia/display_facade_native.py b/client/cros/multimedia/display_facade_native.py
index 30e3923..311a860 100644
--- a/client/cros/multimedia/display_facade_native.py
+++ b/client/cros/multimedia/display_facade_native.py
@@ -86,124 +86,115 @@
         return extension.EvaluateJavaScript("window.__window_info")
 
 
-    def _wait_for_display_options_to_appear(self, tab, display_index,
-                                            timeout=16):
-        """Waits for option.DisplayOptions to appear.
+    def _get_display_by_id(self, display_id):
+        """Gets a display by ID.
 
-        The function waits until options.DisplayOptions appears or is timed out
-                after the specified time.
+        @param display_id: id of the display.
 
-        @param tab: the tab where the display options dialog is shown.
-        @param display_index: index of the display.
-        @param timeout: time wait for display options appear.
-
-        @raise RuntimeError when display_index is out of range
-        @raise TimeoutException when the operation is timed out.
+        @return: A dict of various display info.
         """
-
-        tab.WaitForJavaScriptCondition(
-                    "typeof options !== 'undefined' &&"
-                    "typeof options.DisplayOptions !== 'undefined' &&"
-                    "typeof options.DisplayOptions.instance_ !== 'undefined' &&"
-                    "typeof options.DisplayOptions.instance_"
-                    "       .displays_ !== 'undefined'", timeout=timeout)
-
-        if not tab.EvaluateJavaScript(
-                    "options.DisplayOptions.instance_.displays_.length > %d"
-                    % (display_index)):
-            raise RuntimeError('Display index out of range: '
-                    + str(tab.EvaluateJavaScript(
-                    "options.DisplayOptions.instance_.displays_.length")))
-
-        tab.WaitForJavaScriptCondition(
-                "typeof options.DisplayOptions.instance_"
-                "         .displays_[%(index)d] !== 'undefined' &&"
-                "typeof options.DisplayOptions.instance_"
-                "         .displays_[%(index)d].id !== 'undefined' &&"
-                "typeof options.DisplayOptions.instance_"
-                "         .displays_[%(index)d].resolutions !== 'undefined'"
-                % {'index': display_index}, timeout=timeout)
+        for display in self.get_display_info():
+            if display['id'] == display_id:
+                return display
+        raise RuntimeError('Cannot find display ' + display_id)
 
 
-    def get_display_modes(self, display_index):
+    def get_display_modes(self, display_id):
         """Gets all the display modes for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return: A list of DisplayMode dicts.
         """
-        return self.get_display_info()[display_index]['modes']
+        display = self._get_display_by_id(display_id)
+        return display['modes']
 
 
-    def get_display_rotation(self, display_index):
+    def get_display_rotation(self, display_id):
         """Gets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return: Degree of rotation.
         """
-        return self.get_display_info()[display_index]['rotation']
+        display = self._get_display_by_id(display_id)
+        return display['rotation']
 
 
-    def set_display_rotation(self, display_index, rotation,
+    def set_display_rotation(self, display_id, rotation,
                              delay_before_rotation=0, delay_after_rotation=0):
         """Sets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
         @param rotation: degree of rotation
         @param delay_before_rotation: time in second for delay before rotation
         @param delay_after_rotation: time in second for delay after rotation
         """
-        try:
-            tab_descriptor = self.load_url('chrome://settings-frame/display')
-            tab = self._resource.get_tab_by_descriptor(tab_descriptor)
-            self._wait_for_display_options_to_appear(tab, display_index)
-
-            # Hide the typing cursor to reduce interference.
-            self.hide_typing_cursor()
-
-            time.sleep(delay_before_rotation)
-            tab.ExecuteJavaScript(
-                    """
-                    var display = options.DisplayOptions.instance_
-                            .displays_[%(index)d];
-                    chrome.send('setRotation', [display.id, %(rotation)d]);
-                    """
-                    % {'index': display_index, 'rotation': rotation}
-            )
-            time.sleep(delay_after_rotation)
-        finally:
-            self.close_tab(tab_descriptor)
+        time.sleep(delay_before_rotation)
+        extension = self._resource.get_extension(
+                constants.MULTIMEDIA_TEST_EXTENSION)
+        extension.ExecuteJavaScript(
+                """
+                window.__set_display_rotation_has_error = null;
+                chrome.system.display.setDisplayProperties('%(id)s',
+                    {"rotation": %(rotation)d}, () => {
+                    if (runtime.lastError) {
+                        console.error('Failed to set display rotation',
+                            runtime.lastError);
+                        window.__set_display_rotation_has_error = "failure";
+                    } else {
+                        window.__set_display_rotation_has_error = "success";
+                    }
+                });
+                """
+                % {'id': display_id, 'rotation': rotation}
+        )
+        utils.wait_for_value(lambda: (
+                extension.EvaluateJavaScript(
+                    'window.__set_display_rotation_has_error') != None),
+                expected_value="success")
+        time.sleep(delay_after_rotation)
 
 
-    def get_available_resolutions(self, display_index):
+    def get_available_resolutions(self, display_id):
         """Gets the resolutions from the specified display.
 
         @return a list of (width, height) tuples.
         """
-        modes = self.get_display_modes(display_index)
+        modes = self.get_display_modes(display_id)
         if 'widthInNativePixels' not in modes[0]:
             raise RuntimeError('Cannot find widthInNativePixels attribute')
         return list(set([(mode['widthInNativePixels'],
                           mode['heightInNativePixels']) for mode in modes]))
 
 
-    def get_first_external_display_index(self):
-        """Gets the first external display index.
+    def get_internal_display_id(self):
+        """Gets the internal display id.
 
-        @return the index of the first external display; False if not found.
+        @return the id of the internal display.
+        """
+        for display in self.get_display_info():
+            if display['isInternal']:
+                return display['id']
+        raise RuntimeError('Cannot find internal display')
+
+
+    def get_first_external_display_id(self):
+        """Gets the first external display id.
+
+        @return the id of the first external display; -1 if not found.
         """
         # Get the first external and enabled display
-        for index, display in enumerate(self.get_display_info()):
+        for display in self.get_display_info():
             if display['isEnabled'] and not display['isInternal']:
-                return index
-        return False
+                return display['id']
+        return -1
 
 
-    def set_resolution(self, display_index, width, height, timeout=3):
+    def set_resolution(self, display_id, width, height, timeout=3):
         """Sets the resolution of the specified display.
 
-        @param display_index: index of the display to set resolution for.
+        @param display_id: id of the display to set resolution for.
         @param width: width of the resolution
         @param height: height of the resolution
         @param timeout: maximal time in seconds waiting for the new resolution
@@ -211,56 +202,52 @@
         @raise TimeoutException when the operation is timed out.
         """
 
-        try:
-            tab_descriptor = self.load_url('chrome://settings-frame/display')
-            tab = self._resource.get_tab_by_descriptor(tab_descriptor)
-            self._wait_for_display_options_to_appear(tab, display_index)
-
-            tab.ExecuteJavaScript(
-                    # Start from M38 (refer to CR:417113012), a DisplayMode dict
-                    # contains 'originalWidth'/'originalHeight' in addition to
-                    # 'width'/'height'. OriginalWidth/originalHeight is what is
-                    # supported by the display while width/height is what is
-                    # shown to users in the display setting.
-                    """
-                    var display = options.DisplayOptions.instance_
-                              .displays_[%(index)d];
-                    var modes = display.resolutions;
-                    for (index in modes) {
-                        var mode = modes[index];
-                        if (mode.originalWidth == %(width)d &&
-                                mode.originalHeight == %(height)d) {
-                            chrome.send('setDisplayMode', [display.id, mode]);
+        extension = self._resource.get_extension(
+                constants.MULTIMEDIA_TEST_EXTENSION)
+        extension.ExecuteJavaScript(
+                """
+                window.__set_resolution_progress = null;
+                chrome.system.display.getInfo((info_array) => {
+                    var mode;
+                    for (var info of info_array) {
+                        if (info['id'] == '%(id)s') {
+                            for (var m of info['modes']) {
+                                if (m['width'] == %(width)d &&
+                                    m['height'] == %(height)d) {
+                                    window.__set_resolution_progress =
+                                        "found_mode";
+                                    mode = m;
+                                    break;
+                                }
+                            }
                             break;
                         }
                     }
-                    """
-                    % {'index': display_index, 'width': width, 'height': height}
-            )
+                    if (mode === undefined) {
+                        console.error('Failed to select the resolution ' +
+                            '%(width)dx%(height)d');
+                        window.__set_resolution_progress = "mode not found";
+                        return;
+                    }
 
-            def _get_selected_resolution():
-                modes = tab.EvaluateJavaScript(
-                        """
-                        options.DisplayOptions.instance_
-                                 .displays_[%(index)d].resolutions
-                        """
-                        % {'index': display_index})
-                for mode in modes:
-                    if mode['selected']:
-                        return (mode['originalWidth'], mode['originalHeight'])
-
-            # TODO(tingyuan):
-            # Support for multiple external monitors (i.e. for chromebox)
-            end_time = time.time() + timeout
-            while time.time() < end_time:
-                r = _get_selected_resolution()
-                if (width, height) == (r[0], r[1]):
-                    return True
-                time.sleep(0.1)
-            raise TimeoutException('Failed to change resolution to %r (%r'
-                                   ' detected)' % ((width, height), r))
-        finally:
-            self.close_tab(tab_descriptor)
+                    chrome.system.display.setDisplayProperties('%(id)s',
+                        {'displayMode': mode}, () => {
+                            if (runtime.lastError) {
+                                window.__set_resolution_progress = "failed " +
+                                    runtime.lastError;
+                            } else {
+                                window.__set_resolution_progress = "succeeded";
+                            }
+                        }
+                    );
+                });
+                """
+                % {'id': display_id, 'width': width, 'height': height}
+        )
+        utils.wait_for_value(lambda: (
+                extension.EvaluateJavaScript(
+                    'window.__set_resolution_progress') != None),
+                expected_value="success")
 
 
     @_retry_display_call
@@ -509,20 +496,18 @@
 
 
     @facade_resource.retry_chrome_call
-    def move_to_display(self, display_index):
+    def move_to_display(self, display_id):
         """Moves the current window to the indicated display.
 
-        @param display_index: The index of the indicated display.
+        @param display_id: The id of the indicated display.
         @return True if success.
 
         @raise TimeoutException if it fails.
         """
-        display_info = self.get_display_info()
-        if (display_index is False or
-            display_index not in xrange(0, len(display_info)) or
-            not display_info[display_index]['isEnabled']):
+        display_info = self._get_display_by_id(display_id)
+        if not display_info['isEnabled']:
             raise RuntimeError('Cannot find the indicated display')
-        target_bounds = display_info[display_index]['bounds']
+        target_bounds = display_info['bounds']
 
         extension = self._resource.get_extension()
         # If the area of bounds is empty (here we achieve this by setting
diff --git a/client/site_tests/video_GlitchDetection/video_GlitchDetection.py b/client/site_tests/video_GlitchDetection/video_GlitchDetection.py
index 7e54fd5..840c932 100755
--- a/client/site_tests/video_GlitchDetection/video_GlitchDetection.py
+++ b/client/site_tests/video_GlitchDetection/video_GlitchDetection.py
@@ -79,7 +79,7 @@
                 player.verify_video_can_play()
 
                 display_facade.move_to_display(
-                    display_facade.get_first_external_display_index())
+                    display_facade.get_first_external_display_id())
                 display_facade.set_fullscreen(True)
                 # HACK: Unset and reset fullscreen. There is a bug in Chrome
                 # that fails to move the window to a correct position.
diff --git a/server/cros/multimedia/display_facade_adapter.py b/server/cros/multimedia/display_facade_adapter.py
index a9b4d38..276e4ef 100644
--- a/server/cros/multimedia/display_facade_adapter.py
+++ b/server/cros/multimedia/display_facade_adapter.py
@@ -59,12 +59,12 @@
         return self._display_proxy.get_internal_connector_name()
 
 
-    def move_to_display(self, display_index):
+    def move_to_display(self, display_id):
         """Moves the current window to the indicated display.
 
-        @param display_index: The index of the indicated display.
+        @param display_id: The id of the indicated display.
         """
-        self._display_proxy.move_to_display(display_index)
+        self._display_proxy.move_to_display(display_id)
 
 
     def set_fullscreen(self, is_fullscreen):
@@ -269,14 +269,14 @@
         return tuple(resolution) if resolution else None
 
 
-    def set_resolution(self, display_index, width, height):
+    def set_resolution(self, display_id, width, height):
         """Sets the resolution on the specified display.
 
-        @param display_index: index of the display to set resolutions for.
+        @param display_id: id of the display to set resolutions for.
         @param width: width of the resolution
         @param height: height of the resolution
         """
-        self._display_proxy.set_resolution(display_index, width, height)
+        self._display_proxy.set_resolution(display_id, width, height)
 
 
     # pylint: disable = W0141
@@ -289,58 +289,66 @@
         return map(DisplayInfo, self._display_proxy.get_display_info())
 
 
-    def get_display_modes(self, display_index):
+    def get_display_modes(self, display_id):
         """Gets the display modes of the specified display.
 
-        @param display_index: index of the display to get modes from; the index
-            is from the DisplayInfo list obtained by get_display_info().
+        @param display_id: id of the display to get modes from; the id is from
+            the DisplayInfo list obtained by get_display_info().
 
         @return: list of DisplayMode dicts.
         """
-        return self._display_proxy.get_display_modes(display_index)
+        return self._display_proxy.get_display_modes(display_id)
 
 
-    def get_available_resolutions(self, display_index):
+    def get_available_resolutions(self, display_id):
         """Gets the resolutions from the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return a list of (width, height) tuples.
         """
         return [tuple(r) for r in
-                self._display_proxy.get_available_resolutions(display_index)]
+                self._display_proxy.get_available_resolutions(display_id)]
 
 
-    def get_display_rotation(self, display_index):
+    def get_display_rotation(self, display_id):
         """Gets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
 
         @return: Degree of rotation.
         """
-        return self._display_proxy.get_display_rotation(display_index)
+        return self._display_proxy.get_display_rotation(display_id)
 
 
-    def set_display_rotation(self, display_index, rotation,
+    def set_display_rotation(self, display_id, rotation,
                              delay_before_rotation=0, delay_after_rotation=0):
         """Sets the display rotation for the specified display.
 
-        @param display_index: index of the display to get modes from.
+        @param display_id: id of the display to get modes from.
         @param rotation: degree of rotation
         @param delay_before_rotation: time in second for delay before rotation
         @param delay_after_rotation: time in second for delay after rotation
         """
         self._display_proxy.set_display_rotation(
-                display_index, rotation, delay_before_rotation,
+                display_id, rotation, delay_before_rotation,
                 delay_after_rotation)
 
 
-    def get_first_external_display_index(self):
-        """Gets the first external display index.
+    def get_internal_display_id(self):
+        """Gets the internal display id.
 
-        @return the index of the first external display; False if not found.
+        @return the id of the internal display.
         """
-        return self._display_proxy.get_first_external_display_index()
+        return self._display_proxy.get_internal_display_id()
+
+
+    def get_first_external_display_id(self):
+        """Gets the first external display id.
+
+        @return the id of the first external display; -1 if not found.
+        """
+        return self._display_proxy.get_first_external_display_id()
 
 
     def reset_connector_if_applicable(self, connector_type):
diff --git a/server/site_tests/display_ResolutionList/display_ResolutionList.py b/server/site_tests/display_ResolutionList/display_ResolutionList.py
index 767295b..335792d 100644
--- a/server/site_tests/display_ResolutionList/display_ResolutionList.py
+++ b/server/site_tests/display_ResolutionList/display_ResolutionList.py
@@ -62,24 +62,25 @@
                 logging.info('Use EDID: %s', test_name)
 
                 with chameleon_port.use_edid_file(edid_path):
-                    index = utils.wait_for_value_changed(
-                            display_facade.get_first_external_display_index,
+                    display_id = utils.wait_for_value_changed(
+                            display_facade.get_first_external_display_id,
                             old_value=False)
-                    if not index:
+                    if display_id < 0:
                         raise error.TestFail("No external display is found.")
 
-                    # In mirror mode only display index is '0', as external
+                    # In mirror mode only display id is '0', as external
                     # is treated same as internal(single resolution applies)
                     if test_mirrored:
-                        index = 0
+                        display_id = display_facade.get_internal_display_id()
                     logging.info('Set mirrored: %s', test_mirrored)
                     display_facade.set_mirrored(test_mirrored)
                     settings_resolution_list = (
-                            display_facade.get_available_resolutions(index))
+                            display_facade.get_available_resolutions(
+                                    display_id))
                     if len(settings_resolution_list) == 0:
                         raise error.TestFail("No resolution list is found.")
-                    logging.info('External display %d: %d resolutions found.',
-                                index, len(settings_resolution_list))
+                    logging.info('External display %s: %d resolutions found.',
+                                display_id, len(settings_resolution_list))
 
                     for r in settings_resolution_list:
                         # FIXME: send a keystroke to keep display on.
@@ -90,7 +91,7 @@
                         display_facade.hide_cursor()
 
                         logging.info('Set resolution to %dx%d', *r)
-                        display_facade.set_resolution(index, *r)
+                        display_facade.set_resolution(display_id, *r)
                         time.sleep(self.RESOLUTION_CHANGE_TIME)
 
                         chameleon_port.wait_video_input_stable()
diff --git a/server/site_tests/display_Tearing/display_Tearing.py b/server/site_tests/display_Tearing/display_Tearing.py
index 7e49f9c..d468766 100644
--- a/server/site_tests/display_Tearing/display_Tearing.py
+++ b/server/site_tests/display_Tearing/display_Tearing.py
@@ -55,7 +55,7 @@
         self._test_tab_descriptor = self._display_facade.load_url('about:blank')
         if not test_mirrored:
             self._display_facade.move_to_display(
-                    self._display_facade.get_first_external_display_index())
+                    self._display_facade.get_first_external_display_id())
         self._display_facade.set_fullscreen(True)
         logging.info('Waiting for the new tab to stabilize...')
         time.sleep(self.NEW_PAGE_STABILIZE_TIME)
diff --git a/server/site_tests/platform_RotationFps/platform_RotationFps.py b/server/site_tests/platform_RotationFps/platform_RotationFps.py
index be5dad6..bf54ac5 100644
--- a/server/site_tests/platform_RotationFps/platform_RotationFps.py
+++ b/server/site_tests/platform_RotationFps/platform_RotationFps.py
@@ -39,7 +39,7 @@
         with measurer.start_dock_mode_measurement() as chameleon_port:
             chameleon_port_name = chameleon_port.get_connector_type()
             logging.info('Detected %s chameleon port.', chameleon_port_name)
-            index = display_facade.get_first_external_display_index()
+            display_id = display_facade.get_first_external_display_id()
 
             # Ask Chameleon to capture the video during rotation
             chameleon_port.start_capturing_video()
@@ -47,11 +47,11 @@
             # Adding delays before and after rotation such that we can easily
             # know the rotation fps, not other animation like opening a tab.
             display_facade.set_display_rotation(
-                    index, 90, self.DELAY_BEFORE_ROTATION,
+                    display_id, 90, self.DELAY_BEFORE_ROTATION,
                     self.DELAY_AFTER_ROTATION)
             chameleon_port.stop_capturing_video()
             # Restore back to 0 degree.
-            display_facade.set_display_rotation(index, 0)
+            display_facade.set_display_rotation(display_id, 0)
 
             # Retrieve the FPS info
             fps_list = chameleon_port.get_captured_fps_list()
diff --git a/server/site_tests/video_PlaybackQuality/video_PlaybackQuality.py b/server/site_tests/video_PlaybackQuality/video_PlaybackQuality.py
index 9812523..bff7665 100644
--- a/server/site_tests/video_PlaybackQuality/video_PlaybackQuality.py
+++ b/server/site_tests/video_PlaybackQuality/video_PlaybackQuality.py
@@ -361,7 +361,7 @@
                     raise error.TestFail('No external display detected on DUT')
 
             display_facade.move_to_display(
-                display_facade.get_first_external_display_index())
+                display_facade.get_first_external_display_id())
 
             for description, capture_dimension in test_regions:
                 self._get_playback_quality('%s_%s' % (connector_type,