Commit 895077ca authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Rename `isDocumentReady` to `onDocumentReady`

The name of `isDocumentReady` gives the impressiong that the function
would return a boolean.  `onDocumentReady`, on the other hand, expresses
more clearly that the execution of the callback will be triggered after
the iframe's documen is ready (loaded and parsed).

On a follow up commit I change the `onDocumentReady` to return a Promise
instead of executing a callback.
parent 91c4b724
......@@ -40,7 +40,7 @@ export default class FrameObserver {
*/
_addFrame(frame) {
if (isAccessible(frame)) {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
const frameWindow = /** @type {Window} */ (frame.contentWindow);
frameWindow.addEventListener('unload', () => {
this._removeFrame(frame);
......@@ -92,10 +92,12 @@ function isAccessible(iframe) {
}
/**
* Triggers a callback when the iframe's DOM is ready (loaded and parsed)
*
* @param {HTMLIFrameElement} iframe
* @param {() => void} callback
*/
export function isDocumentReady(iframe, callback) {
export function onDocumentReady(iframe, callback) {
const iframeDocument = /** @type {Document} */ (iframe.contentDocument);
if (iframeDocument.readyState === 'loading') {
iframeDocument.addEventListener('DOMContentLoaded', () => {
......
import { DEBOUNCE_WAIT } from '../../frame-observer';
import { HypothesisInjector } from '../../hypothesis-injector';
import { isDocumentReady } from '../../frame-observer';
import { onDocumentReady } from '../../frame-observer';
describe('HypothesisInjector integration test', () => {
let container;
......@@ -65,7 +65,7 @@ describe('HypothesisInjector integration test', () => {
createHypothesisInjector();
const validFramePromise = new Promise(resolve => {
isDocumentReady(validFrame, () => {
onDocumentReady(validFrame, () => {
assert(
validFrame.contentDocument.body.hasChildNodes(),
'expected valid frame to be modified'
......@@ -74,7 +74,7 @@ describe('HypothesisInjector integration test', () => {
});
});
const invalidFramePromise = new Promise(resolve => {
isDocumentReady(invalidFrame, () => {
onDocumentReady(invalidFrame, () => {
assert(
!invalidFrame.contentDocument.body.hasChildNodes(),
'expected invalid frame to not be modified'
......@@ -105,7 +105,7 @@ describe('HypothesisInjector integration test', () => {
createHypothesisInjector();
return new Promise(resolve => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
const scriptElement =
frame.contentDocument.querySelector('script[src]');
assert(scriptElement, 'expected embed script to be injected');
......@@ -128,7 +128,7 @@ describe('HypothesisInjector integration test', () => {
createHypothesisInjector();
return new Promise(resolve => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
const scriptElement =
frame.contentDocument.querySelector('script[src]');
assert.isNull(
......@@ -150,7 +150,7 @@ describe('HypothesisInjector integration test', () => {
return new Promise(resolve => {
// Yield to let the DOM and CrossFrame catch up
waitForFrameObserver(() => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
assert(
frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified'
......@@ -192,7 +192,7 @@ describe('HypothesisInjector integration test', () => {
createHypothesisInjector();
return new Promise(resolve => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
assert(
frame.contentDocument.body.hasChildNodes(),
'expected initial frame to be modified'
......@@ -207,7 +207,7 @@ describe('HypothesisInjector integration test', () => {
// Yield again
waitForFrameObserver(() => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
assert(
frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified'
......@@ -230,7 +230,7 @@ describe('HypothesisInjector integration test', () => {
return new Promise(resolve => {
// Yield to let the DOM and CrossFrame catch up
waitForFrameObserver(() => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
assert(
frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified'
......@@ -245,7 +245,7 @@ describe('HypothesisInjector integration test', () => {
// Yield
waitForFrameObserver(() => {
isDocumentReady(frame, () => {
onDocumentReady(frame, () => {
assert(
frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment