From 66cefac87494c06cfe7ece7969e23e52e96da9e4 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 4 Sep 2019 15:12:59 +0200 Subject: [PATCH] SEBWIN-342: Resolved UI dependencies in configuration download mechanism. --- .../DownloadEventArgs.cs | 6 --- .../BrowserApplicationInstance.cs | 18 ++++++- .../Handlers/DownloadHandler.cs | 7 ++- .../ClientControllerTests.cs | 49 ------------------- SafeExamBrowser.Client/ClientController.cs | 21 ++------ 5 files changed, 28 insertions(+), 73 deletions(-) diff --git a/SafeExamBrowser.Browser.Contracts/DownloadEventArgs.cs b/SafeExamBrowser.Browser.Contracts/DownloadEventArgs.cs index 77592d8c..b5f4881b 100644 --- a/SafeExamBrowser.Browser.Contracts/DownloadEventArgs.cs +++ b/SafeExamBrowser.Browser.Contracts/DownloadEventArgs.cs @@ -18,12 +18,6 @@ namespace SafeExamBrowser.Browser.Contracts /// public bool AllowDownload { get; set; } - // TODO - ///// - ///// The browser window from which the download request originated. - ///// - //public IBrowserWindow BrowserWindow { get; set; } - /// /// Callback executed once a download has been finished. /// diff --git a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs index 1eef020a..945c6140 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs @@ -174,9 +174,25 @@ namespace SafeExamBrowser.Browser { if (settings.AllowConfigurationDownloads) { - // TODO args.BrowserWindow = window; logger.Debug($"Forwarding download request for configuration file '{fileName}'."); ConfigurationDownloadRequested?.Invoke(fileName, args); + + if (args.AllowDownload) + { + logger.Debug($"Download request for configuration file '{fileName}' was granted. Asking user to confirm the reconfiguration..."); + + var message = TextKey.MessageBox_ReconfigurationQuestion; + var title = TextKey.MessageBox_ReconfigurationQuestionTitle; + var result = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question, window); + + args.AllowDownload = result == MessageBoxResult.Yes; + logger.Info($"The user chose to {(args.AllowDownload ? "start" : "abort")} the reconfiguration."); + } + else + { + logger.Debug($"Download request for configuration file '{fileName}' was denied."); + messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle, parent: window); + } } else { diff --git a/SafeExamBrowser.Browser/Handlers/DownloadHandler.cs b/SafeExamBrowser.Browser/Handlers/DownloadHandler.cs index 3ed70f7a..be35a3bf 100644 --- a/SafeExamBrowser.Browser/Handlers/DownloadHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/DownloadHandler.cs @@ -81,7 +81,6 @@ namespace SafeExamBrowser.Browser.Handlers logger.Debug($"Detected download request for configuration file '{downloadItem.Url}'."); ConfigurationDownloadRequested?.Invoke(downloadItem.SuggestedFileName, args); - logger.Debug($"Download of configuration file '{downloadItem.Url}' was {(args.AllowDownload ? "granted" : "denied")}."); if (args.AllowDownload) { @@ -90,11 +89,17 @@ namespace SafeExamBrowser.Browser.Handlers callbacks[downloadItem.Id] = args.Callback; } + logger.Debug($"Starting download of configuration file '{downloadItem.Url}'..."); + using (callback) { callback.Continue(args.DownloadPath, false); } } + else + { + logger.Debug($"Download of configuration file '{downloadItem.Url}' was cancelled."); + } } } } diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index 52f3e101..914d746b 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -286,55 +286,6 @@ namespace SafeExamBrowser.Client.UnitTests Assert.IsTrue(bounds == 3); } - [TestMethod] - public void Reconfiguration_MustAskUserToConfirm() - { - appConfig.DownloadDirectory = @"C:\Folder\Does\Not\Exist"; - settings.ConfigurationMode = ConfigurationMode.ConfigureClient; - messageBox.Setup(m => m.Show( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny())).Returns(MessageBoxResult.Yes); - - sut.TryStart(); - browserController.Raise(b => b.ConfigurationDownloadRequested += null, "filepath.seb", new DownloadEventArgs()); - - messageBox.Verify(m => m.Show( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny()), Times.Once); - } - - [TestMethod] - public void Reconfiguration_MustNotStartIfNotWantedByUser() - { - var args = new DownloadEventArgs(); - - settings.ConfigurationMode = ConfigurationMode.ConfigureClient; - messageBox.Setup(m => m.Show( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny())).Returns(MessageBoxResult.No); - - sut.TryStart(); - browserController.Raise(b => b.ConfigurationDownloadRequested += null, "filepath.seb", args); - - messageBox.Verify(m => m.Show( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny()), Times.Once); - - Assert.IsFalse(args.AllowDownload); - } - [TestMethod] public void Reconfiguration_MustDenyIfInExamMode() { diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 566fe7b0..11636d23 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -227,26 +227,15 @@ namespace SafeExamBrowser.Client { if (Settings.ConfigurationMode == ConfigurationMode.ConfigureClient) { - logger.Info($"Received download request for configuration file '{fileName}'. Asking user to confirm the reconfiguration..."); - - var message = TextKey.MessageBox_ReconfigurationQuestion; - var title = TextKey.MessageBox_ReconfigurationQuestionTitle; - var result = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question/*// TODO , args.BrowserWindow*/); - var reconfigure = result == MessageBoxResult.Yes; - - logger.Info($"The user chose to {(reconfigure ? "start" : "abort")} the reconfiguration."); - - if (reconfigure) - { - args.AllowDownload = true; - args.Callback = Browser_ConfigurationDownloadFinished; - args.DownloadPath = Path.Combine(appConfig.DownloadDirectory, fileName); - } + args.AllowDownload = true; + args.Callback = Browser_ConfigurationDownloadFinished; + args.DownloadPath = Path.Combine(appConfig.DownloadDirectory, fileName); + logger.Info($"Allowed download request for configuration file '{fileName}'."); } else { + args.AllowDownload = false; logger.Info($"Denied download request for configuration file '{fileName}' due to '{Settings.ConfigurationMode}' mode."); - messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle/*,// TODO parent: args.BrowserWindow*/); } }