コード例 #1
0
ファイル: Document.cs プロジェクト: zidanfei/AngleSharp
 internal Document(IBrowsingContext context, TextSource source)
     : base(null, "#document", NodeType.Document)
 {
     _async             = true;
     _designMode        = false;
     _firedUnload       = false;
     _salvageable       = true;
     _shown             = false;
     _context           = context;
     _source            = source;
     Referrer           = String.Empty;
     ContentType        = MimeTypeNames.ApplicationXml;
     _ready             = DocumentReadyState.Loading;
     _sandbox           = Sandboxes.None;
     _quirksMode        = QuirksMode.Off;
     _loadingScripts    = new Queue <HtmlScriptElement>();
     _location          = new Location("about:blank");
     _ranges            = new List <WeakReference <Range> >();
     _location.Changed += LocationChanged;
     _view              = new Window(this);
     _loader            = context.CreateService <IResourceLoader>();
     _loop              = context.CreateService <IEventLoop>();
     _mutations         = new MutationHost(_loop);
     _subtasks          = new List <Task>();
     _statusCode        = HttpStatusCode.OK;
 }
コード例 #2
0
        /// <summary>
        ///     The Document.readyState property should be equal to the given value.
        /// </summary>
        /// <param name="documentReadyState">The Document.readyState property describes the loading state of the document.</param>
        /// <exception cref="InvalidEnumArgumentException"></exception>
        /// <exception cref="WebDriverException"></exception>
        public static Func <IWebDriver, bool> DocumentReadyStateToBe(DocumentReadyState documentReadyState)
        {
            if (!Enum.IsDefined(typeof(DocumentReadyState), documentReadyState))
            {
                throw new InvalidEnumArgumentException(nameof(documentReadyState), (int)documentReadyState,
                                                       typeof(DocumentReadyState));
            }

            return(driver => driver.Document().ReadyState == documentReadyState);
        }
コード例 #3
0
        /// <summary>
        ///     Waits, until the Document.readyState is equals with the expected value.
        /// </summary>
        /// <param name="expectedDocumentReadyState">The Document.readyState property describes the loading state of the document.</param>
        /// <param name="wait">The <see cref="WebDriverWait" /> instance, that is used to command the browser for wait.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="WebDriverTimeoutException"></exception>
        /// <exception cref="WebDriverException"></exception>
        public static bool UntilDocumentReadyState(
            [NotNull] this WebDriverWait wait,
            DocumentReadyState expectedDocumentReadyState)
        {
            if (wait == null)
            {
                throw new ArgumentNullException(nameof(wait));
            }

            wait.Message += " Waited for " +
                            $"({expectedDocumentReadyState.ToString().ToLower()}) document readyState " +
                            $"to be ({expectedDocumentReadyState})";

            return(wait.Until(WebDriverWaitConditions.DocumentReadyStateToBe(expectedDocumentReadyState)));
        }
コード例 #4
0
        public IDocument Open(String type = "text/html", String replace = null)
        {
            if (!ContentType.Is(MimeTypeNames.Html))
            {
                throw new DomException(DomError.InvalidState);
            }

            if (!IsInBrowsingContext || Object.ReferenceEquals(_context.Active, this))
            {
                var responsibleDocument = _context?.Parent.Active;

                if (responsibleDocument != null && !responsibleDocument.Origin.Is(Origin))
                {
                    throw new DomException(DomError.Security);
                }

                if (!_firedUnload && _loadingScripts.Count == 0)
                {
                    var shallReplace = replace.Isi(Keywords.Replace);
                    var history      = _context.SessionHistory;
                    var index        = type?.IndexOf(Symbols.Semicolon) ?? -1;

                    if (!shallReplace && history != null)
                    {
                        shallReplace = history.Length == 1 && history[0].Url.Is("about:blank");
                    }

                    _salvageable = false;

                    var shouldUnload = PromptToUnloadAsync().Result;

                    if (!shouldUnload)
                    {
                        return(this);
                    }

                    Unload(recycle: true);
                    Abort();
                    RemoveEventListeners();

                    foreach (var element in this.Descendents <Element>())
                    {
                        element.RemoveEventListeners();
                    }

                    _loop.CancelAll();
                    ReplaceAll(null, suppressObservers: true);
                    _source.CurrentEncoding = TextEncoding.Utf8;
                    _salvageable            = true;
                    _ready = DocumentReadyState.Loading;

                    if (type.Isi(Keywords.Replace))
                    {
                        type = MimeTypeNames.Html;
                    }
                    else if (index >= 0)
                    {
                        type = type.Substring(0, index);
                    }

                    type = type.StripLeadingTrailingSpaces();

                    if (!type.Isi(MimeTypeNames.Html))
                    {
                        //Act as if the tokenizer had emitted a start tag token with the tag name "pre" followed by a single
                        //U+000A LINE FEED(LF) character, then switch the HTML parser's tokenizer to the PLAINTEXT state.
                    }

                    ContentType   = type;
                    _firedUnload  = false;
                    _source.Index = _source.Length;
                }

                return(this);
            }

            return(null);
        }
コード例 #5
0
 /// <summary>
 /// Creates a new document node.
 /// </summary>
 /// <param name="context">The context of the document.</param>
 /// <param name="source">The underlying source.</param>
 internal Document(IBrowsingContext context, TextSource source)
     : base(null, "#document", NodeType.Document)
 {
     _async = true;
     _designMode = false;
     _firedUnload = false;
     _salvageable = true;
     _shown = false;
     _preferredStyleSheetSet = String.Empty;
     _context = context ?? BrowsingContext.New();
     _source = source;
     _referrer = String.Empty;
     _contentType = MimeTypes.ApplicationXml;
     _ready = DocumentReadyState.Loading;
     _sandbox = Sandboxes.None;
     _quirksMode = QuirksMode.Off;
     _tasks = new CancellableTasks();
     _mutations = new MutationHost(Options);
     _loadingScripts = new Queue<HtmlScriptElement>();
     _location = new Location(AboutBlank);
     _ranges = new List<WeakReference<Range>>();
     _location.Changed += LocationChanged;
     _styleSheets = this.CreateStyleSheets();
     _view = this.CreateWindow();
     _loader = this.CreateLoader();
 }