summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/outOfProcess/browser_basic_outofprocess.js
blob: 2ab0b0d4ff037bd5db188e362980479162869938 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * Verify that the colors were set properly. This has the effect of
 *  verifying that the processes are assigned for child frames correctly.
 */
async function verifyBaseFrameStructure(
  browsingContexts,
  testname,
  expectedHTML
) {
  function checkColorAndText(bc, desc, expectedColor, expectedText) {
    return SpecialPowers.spawn(
      bc,
      [expectedColor, expectedText, desc],
      (expectedColorChild, expectedTextChild, descChild) => {
        Assert.equal(
          content.document.documentElement.style.backgroundColor,
          expectedColorChild,
          descChild + " color"
        );
        Assert.equal(
          content.document.getElementById("insertPoint").innerHTML,
          expectedTextChild,
          descChild + " text"
        );
      }
    );
  }

  let useOOPFrames = gFissionBrowser;

  is(
    browsingContexts.length,
    TOTAL_FRAME_COUNT,
    "correct number of browsing contexts"
  );
  await checkColorAndText(
    browsingContexts[0],
    testname + " base",
    "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[1],
    testname + " frame 1",
    useOOPFrames ? "seashell" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[2],
    testname + " frame 1-1",
    useOOPFrames ? "seashell" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[3],
    testname + " frame 2",
    useOOPFrames ? "lightcyan" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[4],
    testname + " frame 2-1",
    useOOPFrames ? "seashell" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[5],
    testname + " frame 2-2",
    useOOPFrames ? "lightcyan" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[6],
    testname + " frame 2-3",
    useOOPFrames ? "palegreen" : "white",
    expectedHTML.next().value
  );
  await checkColorAndText(
    browsingContexts[7],
    testname + " frame 2-4",
    "white",
    expectedHTML.next().value
  );
}

/**
 * Test setting up all of the frames where a string of markup is passed
 * to initChildFrames.
 */
add_task(async function test_subframes_string() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    OOP_BASE_PAGE_URI
  );

  const markup = "<p>Text</p>";

  let browser = tab.linkedBrowser;
  let browsingContexts = await initChildFrames(browser, markup);

  function* getExpectedHTML() {
    for (let c = 1; c <= TOTAL_FRAME_COUNT; c++) {
      yield markup;
    }
    ok(false, "Frame count does not match actual number of frames");
  }
  await verifyBaseFrameStructure(browsingContexts, "string", getExpectedHTML());

  BrowserTestUtils.removeTab(tab);
});

/**
 * Test setting up all of the frames where a function that returns different markup
 * is passed to initChildFrames.
 */
add_task(async function test_subframes_function() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    OOP_BASE_PAGE_URI
  );
  let browser = tab.linkedBrowser;

  let counter = 0;
  let browsingContexts = await initChildFrames(browser, function(
    browsingContext
  ) {
    return "<p>Text " + ++counter + "</p>";
  });

  is(
    counter,
    TOTAL_FRAME_COUNT,
    "insert HTML function called the correct number of times"
  );

  function* getExpectedHTML() {
    for (let c = 1; c <= TOTAL_FRAME_COUNT; c++) {
      yield "<p>Text " + c + "</p>";
    }
  }
  await verifyBaseFrameStructure(
    browsingContexts,
    "function",
    getExpectedHTML()
  );

  BrowserTestUtils.removeTab(tab);
});