manages when users clicks on a link with the control button pushed. issue #867

This commit is contained in:
Rémi BOURGAREL 2018-05-22 14:34:16 +02:00 committed by Steve Sanderson
parent 4427b3b773
commit 3610068929
3 changed files with 56 additions and 3 deletions

View File

@ -23,7 +23,10 @@ registerFunction(`${registeredFunctionPrefix}.enableNavigationInterception`, ()
if (anchorTarget) {
const href = anchorTarget.getAttribute('href');
const absoluteHref = toAbsoluteUri(href);
if (isWithinBaseUriSpace(absoluteHref)) {
//if the user wants to user some specific browser/OS feature, we dont handle it and let the browser/OS
const anyChangeBehaviorKeyHold = event.ctrlKey || event.shiftKey || event.altKey || event.metaKey;
if (isWithinBaseUriSpace(absoluteHref) && !anyChangeBehaviorKeyHold)
{
event.preventDefault();
performInternalNavigation(absoluteHref);
}

View File

@ -10,8 +10,8 @@
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Selenium.Support" Version="3.8.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.8.0" />
<PackageReference Include="Selenium.Support" Version="3.12.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.12.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

View File

@ -3,11 +3,13 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using BasicTestApp;
using BasicTestApp.RouterTest;
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using Xunit;
using Xunit.Abstractions;
@ -83,6 +85,54 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
AssertHighlightedLinks("Other", "Other with base-relative URL (matches all)");
}
[Fact]
public void CanFollowLinkToOtherPageWithCtrlClick()
{
var key = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Keys.Command : Keys.Control;
try
{
SetUrlViaPushState($"{ServerPathBase}/RouterTest/");
var app = MountTestComponent<TestRouter>();
var button = app.FindElement(By.LinkText("Other"));
//on mac os build we need to hold the meta button not the control for openning a popup
new Actions(Browser)
.KeyDown(Keys.Control)
.Click(button)
.Build()
.Perform();
Assert.Equal(2, Browser.WindowHandles.Count);
//closing newly opened windows if a new one was opened
Browser.SwitchTo().Window(Browser.WindowHandles.Last());
Browser.Close();
Browser.SwitchTo().Window(Browser.WindowHandles.First());
}
finally
{
// leaving the ctrl key up
new Actions(Browser)
.KeyUp(key)
.Build()
.Perform();
}
}
[Fact]
public void CanFollowLinkToOtherPageDoesNotOpenNewWindow()
{
SetUrlViaPushState($"{ServerPathBase}/RouterTest/");
var app = MountTestComponent<TestRouter>();
app.FindElement(By.LinkText("Other")).Click();
Assert.Single(Browser.WindowHandles);
}
[Fact]
public void CanFollowLinkToOtherPageWithBaseRelativeUrl()
{