Skip to content
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

Fix ILegacyIAccessibleProvider.GetSelection return type #3231

Merged
merged 2 commits into from
Jul 6, 2020

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented May 6, 2020

Proposed Changes

Running the following test

[WinFormsFact]
public void AccesibleObject_ILegacyIAccessibleProviderGetSelection_Invoke_ReturnsExpected()
{
    var o = new AccessibleObject();
    Test_ILegacyIAccessibleProviderGetSelection(o);
}

[DllImport(NativeTests, ExactSpelling = true)]
private static extern void Test_ILegacyIAccessibleProviderGetSelection(
    [MarshalAs(UnmanagedType.IUnknown)] object pUnk);
#define TEST extern "C" __declspec(dllexport)

TEST void WINAPI Test_ILegacyIAccessibleProviderGetSelection(IUnknown* pUnknown)
{
    HRESULT hr;
    ILegacyIAccessibleProvider* pLegacyIAccessibleProvider;

    hr = pUnknown->QueryInterface(IID_ILegacyIAccessibleProvider, (void**)&pLegacyIAccessibleProvider);
    assert(hr == S_OK);

#if false
    SAFEARRAY *result = (SAFEARRAY*)(long)0xdeadbeef;
    hr = pLegacyIAccessibleProvider->GetSelection(&result);
    assert(hr == S_OK);
    assert(result->cbElements == 1);
    assert(static_cast<IRawElementProviderSimple*>(result->pvData) == NULL);
    SafeArrayDestroy(result);
#endif

    // Negative tests
    hr = pLegacyIAccessibleProvider->GetSelection(NULL);
    assert(hr == S_OK);

    return S_OK;
});
}

I get an assertion failure in

hr = pLegacyIAccessibleProvider->GetSelection(&result);
assert(hr == S_OK);

Instead of S_OK, I get COR_E_SAFEARRAYTYPEMISMATCH (0x80131533) returned as the HRESULT.

Taking a look at the native definition, we seem to be returning object[] instead of an interface array. So I think we end up marshalling an array of variants (?) definitely not the interface!

From https://github.com/tpn/winsdk-10/blob/master/Include/10.0.10240.0/um/UIAutomationCore.idl#L845

HRESULT GetSelection (
    [out, retval] SAFEARRAY(IRawElementProviderSimple *) * pvarSelectedChildren );

The fix is to correct the return value.

Discussion

Following on from dotnet/runtime#35855, should we create our own SAFEARRAY type and somehow pass this in as a pointer?

Microsoft Reviewers: Open in CodeFlow

@hughbe hughbe requested a review from a team as a code owner May 6, 2020 20:52
@ghost ghost assigned hughbe May 6, 2020
@hughbe hughbe force-pushed the Fix-LegacyProvider-GetSelection branch from 612dc66 to f0bd4c0 Compare May 6, 2020 22:32
@RussKie RussKie added area-Interop tenet-accessibility MAS violation, UIA issue; problems with accessibility standards labels May 7, 2020
@hughbe hughbe force-pushed the Fix-LegacyProvider-GetSelection branch from f0bd4c0 to 8c9503c Compare May 7, 2020 08:17
@hughbe hughbe force-pushed the Fix-LegacyProvider-GetSelection branch from 8c9503c to 51139a0 Compare May 16, 2020 10:59
@codecov
Copy link

codecov bot commented May 16, 2020

Codecov Report

Merging #3231 into master will decrease coverage by 31.41342%.
The diff coverage is 68.18182%.

@@                 Coverage Diff                  @@
##              master       #3231          +/-   ##
====================================================
- Coverage   66.98140%   35.56798%   -31.41342%     
====================================================
  Files           1342         896         -446     
  Lines         505621      253239      -252382     
  Branches       40889       36734        -4155     
====================================================
- Hits          338672       90072      -248600     
+ Misses        161382      158314        -3068     
+ Partials        5567        4853         -714     
Flag Coverage Δ
#Debug 35.56798% <68.18182%> (-31.41342%) ⬇️
#production 35.56798% <68.18182%> (-0.01188%) ⬇️
#test ?

@dotnet dotnet deleted a comment from codecov bot May 19, 2020
@dotnet dotnet deleted a comment from codecov bot May 19, 2020
Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@RussKie RussKie added the 📭 waiting-author-feedback The team requires more information from the author label Jun 29, 2020
@hughbe hughbe force-pushed the Fix-LegacyProvider-GetSelection branch from 1de4cef to a05cdd4 Compare June 29, 2020 14:48
@RussKie
Copy link
Member

RussKie commented Jun 30, 2020

@vladimir-krestov please review (keeping in mind #3524 issue).

@vladimir-krestov
Copy link
Contributor

Sorry, I'm not good at Marshaling. So I can't say if it was made correctly.
But as I see, we have the same attribute implementation in ISelectionProvider.GetSelection() and it works well, also we have the same method implementation in AccessibleObjects (eg. ListBoxAccessibleObject.GetSelection()), they return an empty array instead null (it seems expected).
So, if it works it is great.
@hughbe, please test it using Inspect and Narrator if it is possible. Also, please try to add a unit test for this if it is possible.

@RussKie, I tested Hugh's branch and checked my case (#3524). This is doesn't fix my issue and I need to remove [ComImport] attribute anyway.

@vladimir-krestov
Copy link
Contributor

Testers made testing of this fix and #3524 as ane dll. They haven't found any regressions. Their automation tests are passed. ✔️
@RussKie, FYI

@vladimir-krestov
Copy link
Contributor

But these changes don't fix #3452 anyway. PR #3524 works well for it.

@RussKie RussKie merged commit f1a55bb into dotnet:master Jul 6, 2020
@ghost ghost added this to the 5.0 Preview8 milestone Jul 6, 2020
@hughbe hughbe deleted the Fix-LegacyProvider-GetSelection branch July 6, 2020 07:24
@ghost ghost locked as resolved and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Interop tenet-accessibility MAS violation, UIA issue; problems with accessibility standards
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants