-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Issue 8302 add tests for ax web browser #11137
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
ricardobossan
merged 10 commits into
dotnet:main
from
ricardobossan:Issue_8302_Add_Tests_For_AxWebBrowser
Apr 3, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0000e45
Adds boilerplate for new ActiveX control tests
e4e63fd
Renamed test class for AxWebBrowser
fa646d4
Add tests for AxWebBrowserTests
95efd64
Merge branch 'main' of github.com:dotnet/winforms into Issue_8302_Add…
7936655
Remove methods from test
e6bbb63
Merge branch 'main' of github.com:dotnet/winforms into Issue_8302_Add…
2615169
Update tests for AxWebBrowser
8887e2a
Merge branch 'main' of github.com:dotnet/winforms into Issue_8302_Add…
36bb8f2
Handle feedback
e948ef0
Adds new assertion to test
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
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
143 changes: 143 additions & 0 deletions
143
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxWebBrowserTests.cs
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,143 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.ComponentModel; | ||
| using System.Reflection; | ||
| using AxSHDocVw; | ||
| using SHDocVw; | ||
|
|
||
| namespace System.Windows.Forms.Tests; | ||
| public class AxWebBrowserTests : IDisposable | ||
| { | ||
| private readonly Form _form; | ||
| private readonly AxWebBrowser _control; | ||
| private object _url = "https://github.com/dotnet/winforms"; | ||
|
|
||
| public AxWebBrowserTests() | ||
| { | ||
| _form = new Form(); | ||
| _control = new AxWebBrowser(); | ||
| ((ISupportInitialize)_control).BeginInit(); | ||
| _form.Controls.Add(_control); | ||
| ((ISupportInitialize)_control).EndInit(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_WhenInitialized_ExpectsProperties() | ||
| { | ||
| var properties = TypeDescriptor.GetProperties(_control); | ||
| var events = TypeDescriptor.GetEvents(_control); | ||
|
|
||
| properties.Count.Should().BeGreaterThan(0); | ||
| events.Count.Should().BeGreaterThan(0); | ||
|
|
||
| // Filters testing control properties and events so only those related to the AxWebBrowser assembly remain. | ||
| Type assemblyType = typeof(AxWebBrowser); | ||
| Assembly assembly = Assembly.GetAssembly(assemblyType); | ||
| string assemblyNameFromType = assembly.GetName().Name; | ||
|
|
||
| var testingControlProps = properties | ||
| .Cast<PropertyDescriptor>() | ||
| .Where(prop => prop.ComponentType.Assembly.GetName().Name == assemblyNameFromType) | ||
| .Select(prop => prop.Name) | ||
| .ToList(); | ||
|
|
||
| var testingControlEvents = events | ||
| .Cast<EventDescriptor>() | ||
| .Where(ev => ev.ComponentType.Assembly.GetName().Name == assemblyNameFromType) | ||
| .Select(ev => ev.Name) | ||
| .ToList(); | ||
|
|
||
| // Compares testing control's properties and events to those of the assembly | ||
| TypeInfo assemblyTypeInfo = assembly.GetType(assemblyType.FullName).GetTypeInfo(); | ||
| testingControlProps.All(p => assemblyTypeInfo.DeclaredProperties.Any(ap => ap.Name == p)).Should().BeTrue(); | ||
| testingControlEvents.All(e => assemblyTypeInfo.DeclaredEvents.Any(ae => ae.Name == e)).Should().BeTrue(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_GoHome_ShouldNotThrowException() | ||
| { | ||
| _control.Invoking(c => c.GoHome()).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_GoSearch_ShouldNotThrowException() | ||
| { | ||
| _control.Invoking(c => c.GoSearch()).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_Navigate_ShouldNotThrowException() | ||
| { | ||
| _control.Invoking(c => c.Navigate(_url.ToString())).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_Navigate2_ShouldRaiseBeforeNavigate2() | ||
| { | ||
| bool eventRaised = false; | ||
| _control.BeforeNavigate2 += (sender, e) => eventRaised = true; | ||
|
|
||
| _control.Invoking(c => c.Navigate2(ref _url)).Should().NotThrow(); | ||
|
|
||
| eventRaised.Should().BeTrue(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_Stop_ShouldNotThrowException() | ||
| { | ||
| _control.Invoking(c => c.Stop()).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_GetProperty_ShouldNotThrowException() | ||
| { | ||
| _control.Invoking(c => c.GetProperty("url")).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void AxWebBrowser_PutProperty_ReturnsExpected() | ||
| { | ||
| object prop = _control.GetProperty("url"); | ||
| prop.Should().BeNull(); | ||
|
|
||
| _control.Invoking(c => c.PutProperty("url", _url)).Should().NotThrow(); | ||
|
|
||
| prop = _control.GetProperty("url"); | ||
| prop.Should().NotBeNull(); | ||
|
ricardobossan marked this conversation as resolved.
|
||
| prop.Should().Be(_url.ToString()); | ||
| } | ||
|
|
||
| [WinFormsTheory] | ||
| [InlineData(OLECMDID.OLECMDID_OPEN)] | ||
| [InlineData(OLECMDID.OLECMDID_FOCUSVIEWCONTROLS)] | ||
| [InlineData(OLECMDID.OLECMDID_CLOSE)] | ||
| public void AxWebBrowser_QueryStatusWB_ShouldNotThrowException(OLECMDID cmdId) | ||
| { | ||
| _control.Invoking(c => c.QueryStatusWB(cmdId)).Should().NotThrow(); | ||
| } | ||
|
|
||
| [WinFormsTheory] | ||
| [InlineData(OLECMDID.OLECMDID_COPY, OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)] | ||
| [InlineData(OLECMDID.OLECMDID_COPY, OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_COPY, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_COPY, OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP)] | ||
| [InlineData(OLECMDID.OLECMDID_STOP, OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)] | ||
| [InlineData(OLECMDID.OLECMDID_STOP, OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_STOP, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_STOP, OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP)] | ||
| [InlineData(OLECMDID.OLECMDID_CLOSE, OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)] | ||
| [InlineData(OLECMDID.OLECMDID_CLOSE, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_CLOSE, OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)] | ||
| [InlineData(OLECMDID.OLECMDID_CLOSE, OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP)] | ||
| public void AxWebBrowser_ExecWB_ShouldNotThrowException(OLECMDID cmdId, OLECMDEXECOPT cmdExecOpt) | ||
| { | ||
| _control.Invoking(c => c.ExecWB(cmdId, cmdExecOpt)).Should().NotThrow(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _control.Dispose(); | ||
| _form.Dispose(); | ||
| } | ||
| } | ||
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.