/* * Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ using System; using System.Collections.Specialized; using System.Net.Mime; using CefSharp; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Browser.Contracts.Filters; using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Settings.Browser.Filter; using BrowserSettings = SafeExamBrowser.Settings.Browser.BrowserSettings; using Request = SafeExamBrowser.Browser.Contracts.Filters.Request; using ResourceHandler = SafeExamBrowser.Browser.Handlers.ResourceHandler; namespace SafeExamBrowser.Browser.UnitTests.Handlers { [TestClass] public class ResourceHandlerTests { private AppConfig appConfig; private BrowserSettings settings; private Mock filter; private Mock logger; private Mock text; private TestableResourceHandler sut; [TestInitialize] public void Initialize() { appConfig = new AppConfig(); settings = new BrowserSettings(); filter = new Mock(); logger = new Mock(); text = new Mock(); sut = new TestableResourceHandler(appConfig, settings, filter.Object, logger.Object, text.Object); } [TestMethod] public void MustAppendCustomHeaders() { var headers = default(NameValueCollection); var request = new Mock(); request.SetupGet(r => r.Headers).Returns(new NameValueCollection()); request.SetupGet(r => r.Url).Returns("http://www.host.org"); request.SetupSet(r => r.Headers = It.IsAny()).Callback((h) => headers = h); settings.SendConfigurationKey = true; settings.SendExamKey = true; var result = sut.OnBeforeResourceLoad(Mock.Of(), Mock.Of(), Mock.Of