| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function onPickerResult(request_audio, audio_track_num, id) { | 5 function onPickerResult(audio_track_num, id, options) { |
| 6 chrome.test.assertEq("string", typeof id); | 6 chrome.test.assertEq("string", typeof id); |
| 7 chrome.test.assertTrue(id != ""); | 7 chrome.test.assertTrue(id != ""); |
| 8 var video_constraint = { mandatory: { chromeMediaSource: "desktop", | 8 var video_constraint = { mandatory: { chromeMediaSource: "desktop", |
| 9 chromeMediaSourceId: id } }; | 9 chromeMediaSourceId: id } }; |
| 10 var audio_constraint = request_audio ? video_constraint : false; | 10 var audio_constraint = |
| 11 navigator.webkitGetUserMedia({ | 11 options.canRequestAudioTrack ? video_constraint : false; |
| 12 |
| 13 navigator.mediaDevices.getUserMedia({ |
| 12 audio: audio_constraint, | 14 audio: audio_constraint, |
| 13 video: video_constraint | 15 video: video_constraint |
| 14 }, | 16 }).then( |
| 15 function(stream) { | 17 function(stream) { |
| 16 if (audio_track_num != null) | 18 if (audio_track_num != null) |
| 17 chrome.test.assertEq(audio_track_num, stream.getAudioTracks().length); | 19 chrome.test.assertEq(audio_track_num, stream.getAudioTracks().length); |
| 18 chrome.test.succeed(); | 20 chrome.test.succeed(); |
| 19 }, chrome.test.fail); | 21 }).catch(chrome.test.fail); |
| 20 } | 22 } |
| 21 | 23 |
| 22 // We can support audio for screen share on Windows. For ChromeOS, it depends | 24 // We can support audio for screen share on Windows. For ChromeOS, it depends |
| 23 // on whether USE_CRAS is on or not, thus we disable the check here. We cannot | 25 // on whether USE_CRAS is on or not, thus we disable the check here. We cannot |
| 24 // support audio on other platforms. | 26 // support audio on other platforms. |
| 25 var expected_audio_tracks_for_screen_share = 0; | 27 var expected_audio_tracks_for_screen_share = 0; |
| 26 if (navigator.appVersion.indexOf("Windows") != -1) | 28 if (navigator.appVersion.indexOf("Windows") != -1) |
| 27 expected_audio_tracks_for_screen_share = 1; | 29 expected_audio_tracks_for_screen_share = 1; |
| 28 else if (navigator.appVersion.indexOf("CrOS") != -1) | 30 else if (navigator.appVersion.indexOf("CrOS") != -1) |
| 29 expected_audio_tracks_for_screen_share = null; | 31 expected_audio_tracks_for_screen_share = null; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 }, | 67 }, |
| 66 | 68 |
| 67 function windowsOnly() { | 69 function windowsOnly() { |
| 68 chrome.desktopCapture.chooseDesktopMedia( | 70 chrome.desktopCapture.chooseDesktopMedia( |
| 69 ["window"], chrome.test.callbackPass(function(id) {})); | 71 ["window"], chrome.test.callbackPass(function(id) {})); |
| 70 }, | 72 }, |
| 71 | 73 |
| 72 function tabOnly() { | 74 function tabOnly() { |
| 73 chrome.desktopCapture.chooseDesktopMedia( | 75 chrome.desktopCapture.chooseDesktopMedia( |
| 74 ["tab"], | 76 ["tab"], |
| 75 chrome.test.succeed); | 77 chrome.test.callbackPass(function(id) {})); |
| 76 }, | 78 }, |
| 77 | 79 |
| 78 function audioShare() { | 80 function audioShareNoApproval() { |
| 79 chrome.desktopCapture.chooseDesktopMedia( | 81 chrome.desktopCapture.chooseDesktopMedia( |
| 80 ["screen", "window", "tab", "audio"], | 82 ["screen", "window", "tab", "audio"], |
| 81 chrome.test.succeed); | 83 chrome.test.callbackPass(function(id, options) { |
| 84 chrome.test.assertEq(false, options.canRequestAudioTrack); |
| 85 })); |
| 86 }, |
| 87 |
| 88 function audioShareApproval() { |
| 89 chrome.desktopCapture.chooseDesktopMedia( |
| 90 ["screen", "window", "tab", "audio"], |
| 91 chrome.test.callbackPass(function(id, options) { |
| 92 chrome.test.assertEq(true, options.canRequestAudioTrack); |
| 93 })); |
| 82 }, | 94 }, |
| 83 | 95 |
| 84 // Show window picker and then get the selected stream using | 96 // Show window picker and then get the selected stream using |
| 85 // getUserMedia(). | 97 // getUserMedia(). |
| 86 function chooseMediaAndGetStream() { | 98 function chooseMediaAndGetStream() { |
| 87 chrome.desktopCapture.chooseDesktopMedia( | 99 chrome.desktopCapture.chooseDesktopMedia( |
| 88 ["screen", "window"], onPickerResult.bind(undefined, false, 0)); | 100 ["screen", "window"], onPickerResult.bind(undefined, 0)); |
| 89 }, | 101 }, |
| 90 | 102 |
| 91 // Same as above but attempts to specify invalid source id. | 103 // Same as above but attempts to specify invalid source id. |
| 92 function chooseMediaAndTryGetStreamWithInvalidId() { | 104 function chooseMediaAndTryGetStreamWithInvalidId() { |
| 93 function onPickerResult(id) { | 105 function onPickerResult(id) { |
| 94 navigator.webkitGetUserMedia({ | 106 navigator.webkitGetUserMedia({ |
| 95 audio: false, | 107 audio: false, |
| 96 video: { mandatory: { chromeMediaSource: "desktop", | 108 video: { mandatory: { chromeMediaSource: "desktop", |
| 97 chromeMediaSourceId: id + "x" } } | 109 chromeMediaSourceId: id + "x" } } |
| 98 }, chrome.test.fail, chrome.test.succeed); | 110 }, chrome.test.fail, chrome.test.succeed); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 // In detail: | 129 // In detail: |
| 118 // 1. We cannot support audio for Window share; | 130 // 1. We cannot support audio for Window share; |
| 119 // 2. We can support audio for Tab share; | 131 // 2. We can support audio for Tab share; |
| 120 // 3. We can support audio for Screen share on Windows; | 132 // 3. We can support audio for Screen share on Windows; |
| 121 // 4. We can support audio for Screen Share on ChromeOS if USE_CRAS is on; | 133 // 4. We can support audio for Screen Share on ChromeOS if USE_CRAS is on; |
| 122 // 5. To actually get audio track, user permission is always necessary; | 134 // 5. To actually get audio track, user permission is always necessary; |
| 123 // 6. To actually get audio track, getUserMedia() should set audio | 135 // 6. To actually get audio track, getUserMedia() should set audio |
| 124 // constraint. | 136 // constraint. |
| 125 function tabShareWithAudioPermissionGetStream() { | 137 function tabShareWithAudioPermissionGetStream() { |
| 126 chrome.desktopCapture.chooseDesktopMedia( | 138 chrome.desktopCapture.chooseDesktopMedia( |
| 127 ["tab", "audio"], onPickerResult.bind(undefined, true, 1)); | 139 ["tab", "audio"], onPickerResult.bind(undefined, 1)); |
| 128 }, | 140 }, |
| 129 | 141 |
| 130 function windowShareWithAudioPermissionGetStream() { | 142 function windowShareWithAudioPermissionGetStream() { |
| 131 chrome.desktopCapture.chooseDesktopMedia( | 143 chrome.desktopCapture.chooseDesktopMedia( |
| 132 ["window", "audio"], onPickerResult.bind(undefined, true, 0)); | 144 ["window", "audio"], onPickerResult.bind(undefined, 0)); |
| 133 }, | 145 }, |
| 134 | 146 |
| 135 function screenShareWithAudioPermissionGetStream() { | 147 function screenShareWithAudioPermissionGetStream() { |
| 136 chrome.desktopCapture.chooseDesktopMedia( | 148 chrome.desktopCapture.chooseDesktopMedia( |
| 137 ["screen", "audio"], | 149 ["screen", "audio"], |
| 138 onPickerResult.bind(undefined, true, | 150 onPickerResult.bind(undefined, |
| 139 expected_audio_tracks_for_screen_share)); | 151 expected_audio_tracks_for_screen_share)); |
| 140 }, | 152 }, |
| 141 | 153 |
| 142 function tabShareWithoutAudioPermissionGetStream() { | 154 function tabShareWithoutAudioPermissionGetStream() { |
| 143 chrome.desktopCapture.chooseDesktopMedia( | 155 chrome.desktopCapture.chooseDesktopMedia( |
| 144 ["tab", "audio"], onPickerResult.bind(undefined, true, 0)); | 156 ["tab", "audio"], onPickerResult.bind(undefined, 0)); |
| 145 }, | 157 }, |
| 146 | 158 |
| 147 function windowShareWithoutAudioPermissionGetStream() { | 159 function windowShareWithoutAudioPermissionGetStream() { |
| 148 chrome.desktopCapture.chooseDesktopMedia( | 160 chrome.desktopCapture.chooseDesktopMedia( |
| 149 ["window", "audio"], onPickerResult.bind(undefined, true, 0)); | 161 ["window", "audio"], onPickerResult.bind(undefined, 0)); |
| 150 }, | 162 }, |
| 151 | 163 |
| 152 function screenShareWithoutAudioPermissionGetStream() { | 164 function screenShareWithoutAudioPermissionGetStream() { |
| 153 chrome.desktopCapture.chooseDesktopMedia( | 165 chrome.desktopCapture.chooseDesktopMedia( |
| 154 ["screen", "audio"], onPickerResult.bind(undefined, true, 0)); | 166 ["screen", "audio"], onPickerResult.bind(undefined, 0)); |
| 155 } | 167 } |
| 156 ]); | 168 ]); |
| OLD | NEW |