|
| 1 | +// <copyright file="IJavaScriptEngineManager.cs" company="WebDriver Committers"> |
| 2 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The SFC licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// </copyright> |
| 18 | + |
| 19 | +using System; |
| 20 | +using System.Collections.Generic; |
| 21 | +using System.Threading.Tasks; |
| 22 | + |
| 23 | +namespace OpenQA.Selenium |
| 24 | +{ |
| 25 | + /// <summary> |
| 26 | + /// Defines an interface allowing the user to manage settings in the browser's JavaScript engine. |
| 27 | + /// </summary> |
| 28 | + public interface IJavaScriptEngine |
| 29 | + { |
| 30 | + /// <summary> |
| 31 | + /// Occurs when a JavaScript callback with a named binding is executed. |
| 32 | + /// </summary> |
| 33 | + event EventHandler<JavaScriptCallbackExecutedEventArgs> JavaScriptCallbackExecuted; |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Occurs when an exeception is thrown by JavaScript being executed in the browser. |
| 37 | + /// </summary> |
| 38 | + event EventHandler<JavaScriptExceptionThrownEventArgs> JavaScriptExceptionThrown; |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Occurs when methods on the JavaScript console are called. |
| 42 | + /// </summary> |
| 43 | + event EventHandler<JavaScriptConsoleApiCalledEventArgs> JavaScriptConsoleApiCalled; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Gets the read-only list of initialization scripts added for this JavaScript engine. |
| 47 | + /// </summary> |
| 48 | + IReadOnlyList<InitializationScript> InitializationScripts { get; } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Gets the read-only list of binding callbacks added for this JavaScript engine. |
| 52 | + /// </summary> |
| 53 | + IReadOnlyList<string> ScriptCallbackBindings { get; } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Asynchronously starts monitoring for events from the browser's JavaScript engine. |
| 57 | + /// </summary> |
| 58 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 59 | + Task StartEventMonitoring(); |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Stops monitoring for events from the browser's JavaScript engine. |
| 63 | + /// </summary> |
| 64 | + void StopEventMonitoring(); |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Asynchronously adds JavaScript to be loaded on every document load. |
| 68 | + /// </summary> |
| 69 | + /// <param name="scriptName">The friendly name by which to refer to this initialization script.</param> |
| 70 | + /// <param name="script">The JavaScript to be loaded on every page.</param> |
| 71 | + /// <returns>A task containing an <see cref="InitializationScript"/> object representing the script to be loaded on each page.</returns> |
| 72 | + Task<InitializationScript> AddInitializationScript(string scriptName, string script); |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Asynchronously removes JavaScript from being loaded on every document load. |
| 76 | + /// </summary> |
| 77 | + /// <param name="scriptName">The friendly name of the initialization script to be removed.</param> |
| 78 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 79 | + Task RemoveInitializationScript(string scriptName); |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Asynchronously removes all intialization scripts from being |
| 83 | + /// loaded on every document load. |
| 84 | + /// </summary> |
| 85 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 86 | + Task ClearInitializationScripts(); |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// Asynchronously adds a binding to a callback method that will raise |
| 90 | + /// an event when the named binding is called by JavaScript executing |
| 91 | + /// in the browser. |
| 92 | + /// </summary> |
| 93 | + /// <param name="bindingName">The name of the callback that will trigger events when called by JavaScript executing in the browser.</param> |
| 94 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 95 | + Task AddScriptCallbackBinding(string bindingName); |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// Asynchronously removes a binding to a JavaScript callback. |
| 99 | + /// </summary> |
| 100 | + /// <param name="bindingName">The name of the callback to be removed.</param> |
| 101 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 102 | + Task RemoveScriptCallbackBinding(string bindingName); |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Asynchronously removes all bindings to JavaScript callbacks. |
| 106 | + /// </summary> |
| 107 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 108 | + Task ClearScriptCallbackBindings(); |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Asynchronously removes all bindings to JavaScript callbacks and all |
| 112 | + /// initialization scripts from being loaded for each document. |
| 113 | + /// </summary> |
| 114 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 115 | + Task ClearAll(); |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// Asynchronously removes all bindings to JavaScript callbacks, all |
| 119 | + /// initialization scripts from being loaded for each document, and |
| 120 | + /// stops listening for events. |
| 121 | + /// </summary> |
| 122 | + /// <returns>A task that represents the asynchronous operation.</returns> |
| 123 | + Task Reset(); |
| 124 | + } |
| 125 | +} |
0 commit comments