UNPKG

quixote

Version:

CSS unit and integration testing

81 lines (60 loc) 2.46 kB
// Copyright (c) 2014-2017 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file. "use strict"; var ensure = require("./util/ensure.js"); var shim = require("./util/shim.js"); var QElement = require("./q_element.js"); var QElementList = require("./q_element_list.js"); var QViewport = require("./q_viewport.js"); var QPage = require("./q_page.js"); var Me = module.exports = function BrowsingContext(contentDocument) { ensure.signature(arguments, [Object]); this.contentWindow = contentDocument.defaultView || contentDocument.parentWindow; this.contentDocument = contentDocument; }; Me.prototype.body = function body() { ensure.signature(arguments, []); return QElement.create(this.contentDocument.body, "<body>"); }; Me.prototype.viewport = function viewport() { ensure.signature(arguments, []); return new QViewport(this); }; Me.prototype.page = function page() { ensure.signature(arguments, []); return new QPage(this); }; Me.prototype.add = function add(html, nickname) { ensure.signature(arguments, [String, [undefined, String]]); return this.body().add(html, nickname); }; Me.prototype.get = function get(selector, nickname) { ensure.signature(arguments, [String, [undefined, String]]); if (nickname === undefined) nickname = selector; var nodes = this.contentDocument.querySelectorAll(selector); ensure.that(nodes.length === 1, "Expected one element to match '" + selector + "', but found " + nodes.length); return QElement.create(nodes[0], nickname); }; Me.prototype.getAll = function getAll(selector, nickname) { ensure.signature(arguments, [String, [undefined, String]]); if (nickname === undefined) nickname = selector; return new QElementList(this.contentDocument.querySelectorAll(selector), nickname); }; Me.prototype.scroll = function scroll(x, y) { ensure.signature(arguments, [Number, Number]); this.contentWindow.scroll(x, y); }; Me.prototype.getRawScrollPosition = function getRawScrollPosition() { ensure.signature(arguments, []); return { x: shim.Window.pageXOffset(this.contentWindow, this.contentDocument), y: shim.Window.pageYOffset(this.contentWindow, this.contentDocument) }; }; // This method is not tested--don't know how. Me.prototype.forceReflow = function forceReflow() { this.body().toDomElement().offsetTop; }; Me.prototype.equals = function equals(that) { ensure.signature(arguments, [Me]); return this.contentWindow === that.contentWindow; };