-
Notifications
You must be signed in to change notification settings - Fork 29
Device enum support #1806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Device enum support #1806
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cf82d7f
Add PoC support for device enum
jonathanKingston 3612d10
debugging
jonathanKingston 52382b3
Restore Scriptlets submodule to default master branch
jonathanKingston 875c6a5
Add typing
jonathanKingston cf5ce89
Make pass instanceof checks
jonathanKingston 1e8bb2c
Use input interface also
jonathanKingston 28b273f
Lint fixes
jonathanKingston df37fc4
Add test case
jonathanKingston 1ff64c4
Reset submodule
jonathanKingston 8f19c4a
Update remote config
jonathanKingston 86f5864
Fix test keys
jonathanKingston 5631445
Add types
jonathanKingston 3924f51
Update config
jonathanKingston 9f70296
Disable read only check
jonathanKingston ebe06fc
Fix device info definition
jonathanKingston 3716343
Lint fix
jonathanKingston ac770fa
Readonly doens't throw
jonathanKingston dec8f49
Remove unnecessary file
jonathanKingston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { gotoAndWait, testContextForExtension } from './helpers/harness.js'; | ||
import { test as base, expect } from '@playwright/test'; | ||
|
||
const test = testContextForExtension(base); | ||
|
||
test.describe('Device Enumeration Feature', () => { | ||
test.describe('disabled feature', () => { | ||
test('should not intercept enumerateDevices when disabled', async ({ page }) => { | ||
await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { | ||
site: { enabledFeatures: [] }, | ||
}); | ||
|
||
// Should use native implementation | ||
const results = await page.evaluate(() => { | ||
// @ts-expect-error - results is set by renderResults() | ||
return window.results; | ||
}); | ||
|
||
// The test should pass with native behavior | ||
expect(results).toBeDefined(); | ||
}); | ||
}); | ||
|
||
test.describe('enabled feature', () => { | ||
test('should intercept enumerateDevices when enabled', async ({ page }) => { | ||
await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { | ||
site: { | ||
enabledFeatures: ['webCompat'], | ||
}, | ||
featureSettings: { | ||
webCompat: { | ||
enumerateDevices: 'enabled', | ||
}, | ||
}, | ||
}); | ||
|
||
// Should use our implementation | ||
const results = await page.evaluate(() => { | ||
// @ts-expect-error - results is set by renderResults() | ||
return window.results; | ||
}); | ||
|
||
// The test should pass with our implementation | ||
expect(results).toBeDefined(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"readme": "This config is used to test the enumerateDevices API proxy functionality.", | ||
"version": 1, | ||
"unprotectedTemporary": [], | ||
"features": { | ||
"webCompat": { | ||
"state": "enabled", | ||
"exceptions": [], | ||
"settings": { | ||
"enumerateDevices": "enabled" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
injected/integration-test/test-pages/webcompat/pages/device-enumeration.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Device Enumeration Test</title> | ||
<link rel="stylesheet" href="../../shared/style.css"> | ||
</head> | ||
<body> | ||
<script src="../../shared/utils.js"></script> | ||
<p><a href="../index.html">[Webcompat shims]</a></p> | ||
|
||
<p>This page tests the device enumeration feature</p> | ||
|
||
<script> | ||
test('Device Enumeration', async () => { | ||
if (!navigator.mediaDevices) { | ||
return [ | ||
{ | ||
name: 'MediaDevices not available', | ||
result: 'MediaDevices API not supported', | ||
expected: 'MediaDevices API not supported' | ||
} | ||
]; | ||
} | ||
|
||
try { | ||
const devices = await navigator.mediaDevices.enumerateDevices(); | ||
|
||
// Check if we got a valid response | ||
const hasVideoInput = devices.some(device => device.kind === 'videoinput'); | ||
const hasAudioInput = devices.some(device => device.kind === 'audioinput'); | ||
const hasAudioOutput = devices.some(device => device.kind === 'audiooutput'); | ||
|
||
return [ | ||
{ | ||
name: 'enumerateDevices returns array', | ||
result: Array.isArray(devices), | ||
expected: true | ||
}, | ||
{ | ||
name: 'devices have correct structure', | ||
result: devices.every(device => | ||
typeof device.deviceId === 'string' && | ||
typeof device.kind === 'string' && | ||
typeof device.label === 'string' && | ||
typeof device.groupId === 'string' | ||
), | ||
expected: true | ||
}, | ||
{ | ||
name: 'video input devices present', | ||
result: hasVideoInput, | ||
expected: true | ||
}, | ||
{ | ||
name: 'audio input devices present', | ||
result: hasAudioInput, | ||
expected: true | ||
}, | ||
{ | ||
name: 'audio output devices present', | ||
result: hasAudioOutput, | ||
expected: true | ||
} | ||
]; | ||
} catch (error) { | ||
return [ | ||
{ | ||
name: 'enumerateDevices throws error', | ||
result: error.message, | ||
expected: 'Should not throw error' | ||
} | ||
]; | ||
} | ||
}); | ||
|
||
renderResults(); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.