[autotest] audio_AudioBasicBluetooth*: Use set_chrome_active_node_type

Use chrome.extension API to select node. This fix the race when
cras_test_client and Chrome select node at the same time.

Also, only select bluetooth input node when there is internal mic. Otherwise,
bluetooth input node should be automatically selected.

BUG=chromium:547100
TEST=run audio_AudioBasicBluetoothRecord.suspend and
audio_AudioBasicBluetoothPlaybackRecord.suspend on link.
Change-Id: I1a319509c6d63ee8360bf57db3268b6c6e5be30e
Reviewed-on: https://chromium-review.googlesource.com/313230
Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Kalin Stoyanov <kalin@chromium.org>
diff --git a/server/site_tests/audio_AudioBasicBluetoothPlaybackRecord/audio_AudioBasicBluetoothPlaybackRecord.py b/server/site_tests/audio_AudioBasicBluetoothPlaybackRecord/audio_AudioBasicBluetoothPlaybackRecord.py
index 4ce30e4..d53e7e4 100644
--- a/server/site_tests/audio_AudioBasicBluetoothPlaybackRecord/audio_AudioBasicBluetoothPlaybackRecord.py
+++ b/server/site_tests/audio_AudioBasicBluetoothPlaybackRecord/audio_AudioBasicBluetoothPlaybackRecord.py
@@ -163,7 +163,8 @@
 
                 # Selects bluetooth mic to be the active input node.
                 if audio_test_utils.has_internal_microphone(host):
-                    self.audio_facade.set_selected_node_types([], ['BLUETOOTH'])
+                    self.audio_facade.set_chrome_active_node_type(
+                            None, 'BLUETOOTH')
 
                 # Checks the node selected by Cras is correct.
                 audio_test_utils.check_audio_nodes(self.audio_facade,
@@ -200,8 +201,11 @@
                             timeout=self.BLUETOOTH_RECONNECT_TIMEOUT_SECS,
                             desc='bluetooth node auto-reconnect after suspend')
 
-                # Select again BT input, as default input node is INTERNAL_MIC
-                self.audio_facade.set_selected_node_types([], ['BLUETOOTH'])
+                if audio_test_utils.has_internal_microphone(host):
+                    # Select again BT input, as default input node is
+                    # INTERNAL_MIC.
+                    self.audio_facade.set_chrome_active_node_type(
+                            None, 'BLUETOOTH')
 
                 with audio_test_utils.monitor_no_nodes_changed(
                         self.audio_facade, self.dump_logs_after_nodes_changed):
diff --git a/server/site_tests/audio_AudioBasicBluetoothRecord/audio_AudioBasicBluetoothRecord.py b/server/site_tests/audio_AudioBasicBluetoothRecord/audio_AudioBasicBluetoothRecord.py
index 4b519d8..3ce287d 100644
--- a/server/site_tests/audio_AudioBasicBluetoothRecord/audio_AudioBasicBluetoothRecord.py
+++ b/server/site_tests/audio_AudioBasicBluetoothRecord/audio_AudioBasicBluetoothRecord.py
@@ -137,8 +137,8 @@
                 audio_test_utils.check_audio_nodes(self.audio_facade,
                                                    (None, ['INTERNAL_MIC']))
 
-            # Selects bluetooth mic to be the active input node.
-            self.audio_facade.set_selected_node_types([], ['BLUETOOTH'])
+                # Selects bluetooth mic to be the active input node.
+                self.audio_facade.set_chrome_active_node_type(None, 'BLUETOOTH')
 
             # Checks the node selected by Cras is correct again.
             audio_test_utils.check_audio_nodes(self.audio_facade,
@@ -174,8 +174,9 @@
                         timeout=self.BLUETOOTH_RECONNECT_TIMEOUT_SECS,
                         desc='bluetooth node auto-reconnect after suspend')
 
-            # Select again BT input as default input node is INTERNAL_MIC
-            self.audio_facade.set_selected_node_types([], ['BLUETOOTH'])
+            if audio_test_utils.has_internal_microphone(host):
+                # Select again BT input as default input node is INTERNAL_MIC
+                self.audio_facade.set_chrome_active_node_type(None, 'BLUETOOTH')
 
             with audio_test_utils.monitor_no_nodes_changed(
                     self.audio_facade, self.dump_logs_after_nodes_changed):