summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_e10s_about_process.js
blob: f73e8e659c911e4e9cac4cb47605e26405b3fc2e (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const CHROME = {
  id: "cb34538a-d9da-40f3-b61a-069f0b2cb9fb",
  path: "test-chrome",
  flags: 0,
};
const CANREMOTE = {
  id: "2480d3e1-9ce4-4b84-8ae3-910b9a95cbb3",
  path: "test-allowremote",
  flags: Ci.nsIAboutModule.URI_CAN_LOAD_IN_CHILD,
};
const MUSTREMOTE = {
  id: "f849cee5-e13e-44d2-981d-0fb3884aaead",
  path: "test-mustremote",
  flags: Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD,
};
const CANPRIVILEGEDREMOTE = {
  id: "a04ffafe-6c63-4266-acae-0f4b093165aa",
  path: "test-canprivilegedremote",
  flags:
    Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD |
    Ci.nsIAboutModule.URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS,
};
const MUSTEXTENSION = {
  id: "f7a1798f-965b-49e9-be83-ec6ee4d7d675",
  path: "test-mustextension",
  flags: Ci.nsIAboutModule.URI_MUST_LOAD_IN_EXTENSION_PROCESS,
};

const TEST_MODULES = [
  CHROME,
  CANREMOTE,
  MUSTREMOTE,
  CANPRIVILEGEDREMOTE,
  MUSTEXTENSION,
];

function AboutModule() {}

AboutModule.prototype = {
  newChannel(aURI, aLoadInfo) {
    throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
  },

  getURIFlags(aURI) {
    for (let module of TEST_MODULES) {
      if (aURI.pathQueryRef.startsWith(module.path)) {
        return module.flags;
      }
    }

    ok(false, "Called getURIFlags for an unknown page " + aURI.spec);
    return 0;
  },

  getIndexedDBOriginPostfix(aURI) {
    return null;
  },

  QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]),
};

var AboutModuleFactory = {
  createInstance(aIID) {
    return new AboutModule().QueryInterface(aIID);
  },

  QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),
};

add_setup(async function () {
  SpecialPowers.setBoolPref(
    "browser.tabs.remote.separatePrivilegedMozillaWebContentProcess",
    true
  );
  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
  for (let module of TEST_MODULES) {
    registrar.registerFactory(
      Components.ID(module.id),
      "",
      "@mozilla.org/network/protocol/about;1?what=" + module.path,
      AboutModuleFactory
    );
  }
});

registerCleanupFunction(() => {
  SpecialPowers.clearUserPref(
    "browser.tabs.remote.separatePrivilegedMozillaWebContentProcess"
  );
  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
  for (let module of TEST_MODULES) {
    registrar.unregisterFactory(Components.ID(module.id), AboutModuleFactory);
  }
});

add_task(async function test_chrome() {
  test_url_for_process_types({
    url: "about:" + CHROME.path,
    chromeResult: true,
    webContentResult: false,
    privilegedAboutContentResult: false,
    privilegedMozillaContentResult: false,
    extensionProcessResult: false,
  });
});

add_task(async function test_any() {
  test_url_for_process_types({
    url: "about:" + CANREMOTE.path,
    chromeResult: true,
    webContentResult: true,
    privilegedAboutContentResult: true,
    privilegedMozillaContentResult: true,
    extensionProcessResult: true,
  });
});

add_task(async function test_remote() {
  test_url_for_process_types({
    url: "about:" + MUSTREMOTE.path,
    chromeResult: false,
    webContentResult: true,
    privilegedAboutContentResult: false,
    privilegedMozillaContentResult: false,
    extensionProcessResult: false,
  });
});

add_task(async function test_privileged_remote_true() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.tabs.remote.separatePrivilegedContentProcess", true]],
  });

  // This shouldn't be taken literally. We will always use the privleged about
  // content type if the URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS flag is enabled and
  // the pref is turned on.
  test_url_for_process_types({
    url: "about:" + CANPRIVILEGEDREMOTE.path,
    chromeResult: false,
    webContentResult: false,
    privilegedAboutContentResult: true,
    privilegedMozillaContentResult: false,
    extensionProcessResult: false,
  });
});

add_task(async function test_privileged_remote_false() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.tabs.remote.separatePrivilegedContentProcess", false]],
  });

  // This shouldn't be taken literally. We will always use the privleged about
  // content type if the URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS flag is enabled and
  // the pref is turned on.
  test_url_for_process_types({
    url: "about:" + CANPRIVILEGEDREMOTE.path,
    chromeResult: false,
    webContentResult: true,
    privilegedAboutContentResult: false,
    privilegedMozillaContentResult: false,
    extensionProcessResult: false,
  });
});

add_task(async function test_extension() {
  test_url_for_process_types({
    url: "about:" + MUSTEXTENSION.path,
    chromeResult: false,
    webContentResult: false,
    privilegedAboutContentResult: false,
    privilegedMozillaContentResult: false,
    extensionProcessResult: true,
  });
});