summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/page/browser_frameStoppedLoading.js
blob: 9d7c37ddc450c57e6d7b7c244511d9cd54e90502 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function noEventWhenPageDomainDisabled({ client }) {
  await runFrameStoppedLoadingTest(client, 0, async () => {
    info("Navigate to a page with nested iframes");
    await loadURL(FRAMESET_NESTED_URL);
  });
});

add_task(async function noEventAfterPageDomainDisabled({ client }) {
  const { Page } = client;

  await Page.enable();
  await Page.disable();

  await runFrameStoppedLoadingTest(client, 0, async () => {
    info("Navigate to a page with nested iframes");
    await loadURL(FRAMESET_NESTED_URL);
  });
});

add_task(async function eventWhenNavigatingWithNoFrames({ client }) {
  const { Page } = client;

  await Page.enable();

  await runFrameStoppedLoadingTest(client, 1, async () => {
    info("Navigate to a page with no iframes");
    await loadURL(PAGE_URL);
  });
});

add_task(async function eventsWhenNavigatingWithFrames({ client }) {
  const { Page } = client;

  await Page.enable();

  await runFrameStoppedLoadingTest(client, 3, async () => {
    info("Navigate to a page with iframes");
    await loadURL(FRAMESET_MULTI_URL);
  });
});

add_task(async function eventsWhenNavigatingWithNestedFrames({ client }) {
  const { Page } = client;

  await Page.enable();

  await runFrameStoppedLoadingTest(client, 4, async () => {
    info("Navigate to a page with nested iframes");
    await loadURL(FRAMESET_NESTED_URL);
  });
});

async function runFrameStoppedLoadingTest(
  client,
  expectedEventCount,
  callback
) {
  const { Page } = client;

  const STOPPED_LOADING = "Page.frameStoppedLoading";

  const history = new RecordEvents(expectedEventCount);
  history.addRecorder({
    event: Page.frameStoppedLoading,
    eventName: STOPPED_LOADING,
    messageFn: payload => {
      return `Received ${STOPPED_LOADING} for frame id ${payload.frameId}`;
    },
  });

  await callback();

  const frameStoppedLoadingEvents = await history.record();

  is(
    frameStoppedLoadingEvents.length,
    expectedEventCount,
    "Got expected amount of frameStoppedLoading events"
  );
  if (expectedEventCount == 0) {
    return;
  }

  const frames = await getFlattenedFrameTree(client);

  frameStoppedLoadingEvents.forEach(({ payload }) => {
    const { frameId } = payload;

    info(`Check frame id ${frameId}`);
    const expectedFrame = frames.get(frameId);

    ok(expectedFrame, `Found expected frame with id ${frameId}`);
    is(
      frameId,
      expectedFrame.id,
      "Got expected frame id for frameStartedLoading event"
    );
  });
}