SEBWIN-307: Implemented configuration to enable / disable the browser application.

This commit is contained in:
dbuechel 2020-01-10 10:25:51 +01:00
parent 5e131289b0
commit 61f369a9a3
7 changed files with 82 additions and 12 deletions

View file

@ -888,6 +888,7 @@ namespace SafeExamBrowser.Client.UnitTests
[TestMethod]
public void Startup_MustAutoStartBrowser()
{
settings.Browser.EnableBrowser = true;
browser.SetupGet(b => b.AutoStart).Returns(true);
sut.TryStart();
@ -901,6 +902,17 @@ namespace SafeExamBrowser.Client.UnitTests
browser.Verify(b => b.Start(), Times.Never);
}
[TestMethod]
public void Startup_MustNotAutoStartBrowserIfNotEnabled()
{
settings.Browser.EnableBrowser = false;
browser.SetupGet(b => b.AutoStart).Returns(true);
sut.TryStart();
browser.Verify(b => b.Start(), Times.Never);
}
[TestMethod]
public void TerminationActivator_MustCorrectlyInitiateShutdown()
{

View file

@ -53,16 +53,34 @@ namespace SafeExamBrowser.Client.UnitTests.Operations
[TestMethod]
public void Perform_MustInitializeBrowserAndTaskview()
{
settings.Browser.EnableBrowser = true;
sut.Perform();
browser.Verify(c => c.Initialize(), Times.Once);
taskview.Verify(t => t.Add(It.Is<IApplication>(a => a == context.Browser)));
taskview.Verify(t => t.Add(It.Is<IApplication>(a => a == context.Browser)), Times.Once);
}
[TestMethod]
public void Perform_MustNotInitializeBrowserIfNotEnabled()
{
settings.ActionCenter.EnableActionCenter = true;
settings.Browser.EnableBrowser = false;
settings.Taskbar.EnableTaskbar = true;
sut.Perform();
actionCenter.Verify(a => a.AddApplicationControl(It.IsAny<IApplicationControl>(), true), Times.Never);
browser.Verify(c => c.Initialize(), Times.Never);
taskbar.Verify(t => t.AddApplicationControl(It.IsAny<IApplicationControl>(), true), Times.Never);
taskview.Verify(t => t.Add(It.Is<IApplication>(a => a == context.Browser)), Times.Never);
}
[TestMethod]
public void Perform_MustCorrectlyInitializeControls()
{
settings.ActionCenter.EnableActionCenter = false;
settings.Browser.EnableBrowser = true;
settings.Taskbar.EnableTaskbar = false;
sut.Perform();
@ -82,8 +100,17 @@ namespace SafeExamBrowser.Client.UnitTests.Operations
[TestMethod]
public void Revert_MustTerminateBrowser()
{
settings.Browser.EnableBrowser = true;
sut.Revert();
browser.Verify(c => c.Terminate(), Times.Once);
}
[TestMethod]
public void Revert_MustNotTerminateBrowserIfNotEnabled()
{
settings.Browser.EnableBrowser = false;
sut.Revert();
browser.Verify(c => c.Terminate(), Times.Never);
}
}
}

View file

@ -242,7 +242,7 @@ namespace SafeExamBrowser.Client
private void AutoStartApplications()
{
if (Browser.AutoStart)
if (Settings.Browser.EnableBrowser && Browser.AutoStart)
{
logger.Info("Auto-starting browser...");
Browser.Start();

View file

@ -46,20 +46,27 @@ namespace SafeExamBrowser.Client.Operations
logger.Info("Initializing browser...");
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeBrowser);
Context.Browser.Initialize();
if (Context.Settings.ActionCenter.EnableActionCenter)
if (Context.Settings.Browser.EnableBrowser)
{
actionCenter.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.ActionCenter), true);
}
Context.Browser.Initialize();
if (Context.Settings.Taskbar.EnableTaskbar)
if (Context.Settings.ActionCenter.EnableActionCenter)
{
actionCenter.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.ActionCenter), true);
}
if (Context.Settings.Taskbar.EnableTaskbar)
{
taskbar.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.Taskbar), true);
}
taskview.Add(Context.Browser);
}
else
{
taskbar.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.Taskbar), true);
logger.Info("Browser application is disabled for this session.");
}
taskview.Add(Context.Browser);
return OperationResult.Success;
}
@ -68,7 +75,14 @@ namespace SafeExamBrowser.Client.Operations
logger.Info("Terminating browser...");
StatusChanged?.Invoke(TextKey.OperationStatus_TerminateBrowser);
Context.Browser.Terminate();
if (Context.Settings.Browser.EnableBrowser)
{
Context.Browser.Terminate();
}
else
{
logger.Info("Browser application was disabled for this session.");
}
return OperationResult.Success;
}

View file

@ -54,6 +54,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
case Keys.Browser.AdditionalWindow.WindowWidth:
MapWindowWidthAdditionalWindow(settings, value);
break;
case Keys.Browser.EnableBrowser:
MapEnableBrowser(settings, value);
break;
case Keys.Browser.Filter.FilterRules:
MapFilterRules(settings, value);
break;
@ -195,6 +198,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
}
}
private void MapEnableBrowser(AppSettings settings, object value)
{
if (value is bool enable)
{
settings.Browser.EnableBrowser = enable;
}
}
private void MapMainWindowMode(AppSettings settings, object value)
{
const int FULLSCREEN = 1;

View file

@ -47,6 +47,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string AllowPageZoom = "enableZoomPage";
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
internal const string EnableBrowser = "enableSebBrowser";
internal const string PopupPolicy = "newBrowserWindowByLinkPolicy";
internal const string PopupBlockForeignHost = "newBrowserWindowByLinkBlockForeign";
internal const string QuitUrl = "quitURL";

View file

@ -46,6 +46,11 @@ namespace SafeExamBrowser.Settings.Browser
/// </summary>
public string CustomUserAgent { get; set; }
/// <summary>
/// Determines whether the user is allowed to use the integrated browser application.
/// </summary>
public bool EnableBrowser { get; set; }
/// <summary>
/// The settings to be used for the browser request filter.
/// </summary>