SEBWIN-342: Resolved UI dependencies in configuration download mechanism.

This commit is contained in:
dbuechel 2019-09-04 15:12:59 +02:00
parent 363f751f55
commit 66cefac874
5 changed files with 28 additions and 73 deletions

View file

@ -18,12 +18,6 @@ namespace SafeExamBrowser.Browser.Contracts
/// </summary>
public bool AllowDownload { get; set; }
// TODO
///// <summary>
///// The browser window from which the download request originated.
///// </summary>
//public IBrowserWindow BrowserWindow { get; set; }
/// <summary>
/// Callback executed once a download has been finished.
/// </summary>

View file

@ -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
{

View file

@ -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.");
}
}
}
}

View file

@ -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<TextKey>(),
It.IsAny<TextKey>(),
It.IsAny<MessageBoxAction>(),
It.IsAny<MessageBoxIcon>(),
It.IsAny<IWindow>())).Returns(MessageBoxResult.Yes);
sut.TryStart();
browserController.Raise(b => b.ConfigurationDownloadRequested += null, "filepath.seb", new DownloadEventArgs());
messageBox.Verify(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),
It.IsAny<MessageBoxAction>(),
It.IsAny<MessageBoxIcon>(),
It.IsAny<IWindow>()), Times.Once);
}
[TestMethod]
public void Reconfiguration_MustNotStartIfNotWantedByUser()
{
var args = new DownloadEventArgs();
settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
messageBox.Setup(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),
It.IsAny<MessageBoxAction>(),
It.IsAny<MessageBoxIcon>(),
It.IsAny<IWindow>())).Returns(MessageBoxResult.No);
sut.TryStart();
browserController.Raise(b => b.ConfigurationDownloadRequested += null, "filepath.seb", args);
messageBox.Verify(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),
It.IsAny<MessageBoxAction>(),
It.IsAny<MessageBoxIcon>(),
It.IsAny<IWindow>()), Times.Once);
Assert.IsFalse(args.AllowDownload);
}
[TestMethod]
public void Reconfiguration_MustDenyIfInExamMode()
{

View file

@ -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*/);
}
}