diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index c77397b0..940961ea 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -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() { diff --git a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs index 0b4f87d4..be8bfd3e 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs @@ -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(a => a == context.Browser))); + taskview.Verify(t => t.Add(It.Is(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(), true), Times.Never); + browser.Verify(c => c.Initialize(), Times.Never); + taskbar.Verify(t => t.AddApplicationControl(It.IsAny(), true), Times.Never); + taskview.Verify(t => t.Add(It.Is(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); + } } } diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 082ba2bd..7f9227af 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -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(); diff --git a/SafeExamBrowser.Client/Operations/BrowserOperation.cs b/SafeExamBrowser.Client/Operations/BrowserOperation.cs index f14af798..dbede18c 100644 --- a/SafeExamBrowser.Client/Operations/BrowserOperation.cs +++ b/SafeExamBrowser.Client/Operations/BrowserOperation.cs @@ -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; } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs index a5592eeb..2e0ef3fb 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs @@ -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; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index 4dc72a51..d028ab10 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -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"; diff --git a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs index 3ccc8ef5..1a7cf322 100644 --- a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs +++ b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs @@ -46,6 +46,11 @@ namespace SafeExamBrowser.Settings.Browser /// public string CustomUserAgent { get; set; } + /// + /// Determines whether the user is allowed to use the integrated browser application. + /// + public bool EnableBrowser { get; set; } + /// /// The settings to be used for the browser request filter. ///