summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_origin_attrs_in_remote_type.js
blob: 00bdb83cddf6e5d6d53d2d17fefe35b9cbd3d90f (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from helper_origin_attrs_testing.js */
loadTestSubscript("helper_origin_attrs_testing.js");

const PATH = "browser/browser/base/content/test/tabs/blank.html";

var TEST_CASES = [
  { uri: "https://example.com/" + PATH },
  { uri: "https://example.org/" + PATH },
  { uri: "about:preferences" },
  { uri: "about:config" },
  // file:// uri will be added in setup()
];

// 3 container tabs, 1 regular tab and 1 private tab
const NUM_PAGES_OPEN_FOR_EACH_TEST_CASE = 5;
var remoteTypes;

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["privacy.userContext.enabled", true],
      // don't preload tabs so we don't have extra XULFrameLoaderCreated events
      // firing
      ["browser.newtab.preload", false],
    ],
  });
  requestLongerTimeout(5);

  // Add a file:// uri
  let dir = getChromeDir(getResolvedURI(gTestPath));
  dir.append("blank.html");
  // The file can be a symbolic link on local build.  Normalize it to make sure
  // the path matches to the actual URI opened in the new tab.
  dir.normalize();
  const uriString = Services.io.newFileURI(dir).spec;
  TEST_CASES.push({ uri: uriString });
});

function setupRemoteTypes() {
  remoteTypes = getExpectedRemoteTypes(
    gFissionBrowser,
    NUM_PAGES_OPEN_FOR_EACH_TEST_CASE
  );
  remoteTypes = remoteTypes.concat(
    Array(NUM_PAGES_OPEN_FOR_EACH_TEST_CASE).fill("file")
  ); // file uri
}

add_task(async function test_user_identity_simple() {
  setupRemoteTypes();
  var currentRemoteType;

  for (let testData of TEST_CASES) {
    info(`Will open ${testData.uri} in different tabs`);
    // Open uri without a container
    info(`About to open a regular page`);
    currentRemoteType = remoteTypes.shift();
    let page_regular = await openURIInRegularTab(testData.uri, window);
    is(
      page_regular.tab.linkedBrowser.remoteType,
      currentRemoteType,
      "correct remote type"
    );

    // Open the same uri in different user contexts
    info(`About to open container pages`);
    let containerPages = [];
    for (
      var user_context_id = 1;
      user_context_id <= NUM_USER_CONTEXTS;
      user_context_id++
    ) {
      currentRemoteType = remoteTypes.shift();
      let containerPage = await openURIInContainer(
        testData.uri,
        window,
        user_context_id
      );
      is(
        containerPage.tab.linkedBrowser.remoteType,
        currentRemoteType,
        "correct remote type"
      );
      containerPages.push(containerPage);
    }

    // Open the same uri in a private browser
    currentRemoteType = remoteTypes.shift();
    let page_private = await openURIInPrivateTab(testData.uri);
    let privateRemoteType = page_private.tab.linkedBrowser.remoteType;
    is(privateRemoteType, currentRemoteType, "correct remote type");

    // Close all the tabs
    containerPages.forEach(page => {
      BrowserTestUtils.removeTab(page.tab);
    });
    BrowserTestUtils.removeTab(page_regular.tab);
    BrowserTestUtils.removeTab(page_private.tab);
  }
});