Bug 1543099 - Split browser_runtime_executionContext into multiple functions r=remote-protocol-reviewers,ato
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 02 May 2019 10:11:40 +0000
changeset 531249 7c074ab51d55943c159cda38823958487967c7fc
parent 531248 4307e69edeec3abd1a0bbc5d325ff67d57822d24
child 531250 6c9b27fd6233665660bd68527c2f20a892bb7ad2
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, ato
bugs1543099
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543099 - Split browser_runtime_executionContext into multiple functions r=remote-protocol-reviewers,ato Differential Revision: https://phabricator.services.mozilla.com/D29385
remote/test/browser/browser_runtime_executionContext.js
--- a/remote/test/browser/browser_runtime_executionContext.js
+++ b/remote/test/browser/browser_runtime_executionContext.js
@@ -42,63 +42,80 @@ async function testCDP() {
   const client = await CDP({
     target(list) {
       // Ensure debugging the right target, i.e. the one for our test tab.
       return list.find(target => target.url == TEST_URI);
     },
   });
   ok(true, "CDP client has been instantiated");
 
-  const {Page, Runtime} = client;
-
-  // turn on navigation related events, such as DOMContentLoaded et al.
-  await Runtime.enable();
-  ok(true, "Runtime domain has been enabled");
-
-  // Calling Runtime.enable will emit executionContextCreated for the existing contexts
-  const { context: context1 } = await Runtime.executionContextCreated();
-  ok(!!context1.id, "The execution context has an id");
-  ok(context1.auxData.isDefault, "The execution context is the default one");
-  ok(!!context1.auxData.frameId, "The execution context has a frame id set");
-
-  info("Navigate to a new URL");
-  const executionContextDestroyed2 = Runtime.executionContextDestroyed();
-  const executionContextCreated2 = Runtime.executionContextCreated();
-
-  const url = "data:text/html;charset=utf-8,test-page";
-  const { frameId } = await Page.navigate({ url });
-  ok(true, "A new page has been loaded");
-  is(frameId, context1.auxData.frameId, "Page.navigate returns the same frameId than executionContextCreated");
-
-  let { executionContextId } = await executionContextDestroyed2;
-  is(executionContextId, context1.id, "The destroyed event reports the previous context id");
+  const firstContext = await testRuntimeEnable(client);
+  await testEvaluate(client, firstContext);
+  const secondContext = await testNavigate(client, firstContext);
+  await testNavigateBack(client, firstContext, secondContext);
 
-  const { context: context2 } = await executionContextCreated2;
-  ok(!!context2.id, "The execution context has an id");
-  isnot(context1.id, context2.id, "The new execution context has a different id");
-  ok(context2.auxData.isDefault, "The execution context is the default one");
-  is(context2.auxData.frameId, frameId, "The execution context frame id is the same " +
-    "than the one returned by Page.navigate");
-
-  isnot(executionContextId, context2.id, "The destroyed id is different from the " +
-    "created one");
-
-  // Navigates back to the previous page.
-  // This should resurect the original document from the BF Cache and recreate the
-  // context for it
-  info("Navigate back to the previous document");
-  const executionContextDestroyed3 = Runtime.executionContextDestroyed();
-  const executionContextCreated3 = Runtime.executionContextCreated();
-  gBrowser.selectedBrowser.goBack();
-  const { context: context3 } = await executionContextCreated3;
-  is(context3.id, context1.id, "The new execution context should be the same than the first one");
-  ok(context3.auxData.isDefault, "The execution context is the default one");
-  is(context3.auxData.frameId, frameId, "The execution context frame id is always the same");
-
-  ({ executionContextId } = await executionContextDestroyed3);
-  is(executionContextId, context2.id, "The destroyed event reports the previous context id");
   await client.close();
   ok(true, "The client is closed");
 
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
   await RemoteAgent.close();
 }
+
+async function testRuntimeEnable({ Runtime }) {
+  // Enable watching for new execution context
+  await Runtime.enable();
+  ok(true, "Runtime domain has been enabled");
+
+  // Calling Runtime.enable will emit executionContextCreated for the existing contexts
+  const { context } = await Runtime.executionContextCreated();
+  ok(!!context.id, "The execution context has an id");
+  ok(context.auxData.isDefault, "The execution context is the default one");
+  ok(!!context.auxData.frameId, "The execution context has a frame id set");
+
+  return context;
+}
+
+async function testNavigate({ Runtime, Page }, previousContext) {
+  info("Navigate to a new URL");
+  const executionContextDestroyed = Runtime.executionContextDestroyed();
+  const executionContextCreated = Runtime.executionContextCreated();
+
+  const url = "data:text/html;charset=utf-8,test-page";
+  const { frameId } = await Page.navigate({ url });
+  ok(true, "A new page has been loaded");
+  is(frameId, previousContext.auxData.frameId, "Page.navigate returns the same frameId than executionContextCreated");
+
+  const { executionContextId } = await executionContextDestroyed;
+  is(executionContextId, previousContext.id, "The destroyed event reports the previous context id");
+
+  const { context } = await executionContextCreated;
+  ok(!!context.id, "The execution context has an id");
+  isnot(previousContext.id, context.id, "The new execution context has a different id");
+  ok(context.auxData.isDefault, "The execution context is the default one");
+  is(context.auxData.frameId, frameId, "The execution context frame id is the same " +
+    "than the one returned by Page.navigate");
+
+  isnot(executionContextId, context.id, "The destroyed id is different from the " +
+    "created one");
+
+  return context;
+}
+
+// Navigates back to the previous page.
+// This should resurect the original document from the BF Cache and recreate the
+// context for it
+async function testNavigateBack({ Runtime }, firstContext, previousContext) {
+  info("Navigate back to the previous document");
+  const executionContextDestroyed = Runtime.executionContextDestroyed();
+  const executionContextCreated = Runtime.executionContextCreated();
+
+  gBrowser.selectedBrowser.goBack();
+
+  const { context } = await executionContextCreated;
+  is(context.id, firstContext.id, "The new execution context should be the same than the first one");
+  ok(context.auxData.isDefault, "The execution context is the default one");
+  is(context.auxData.frameId, firstContext.auxData.frameId, "The execution context frame id is always the same");
+
+  const { executionContextId } = await executionContextDestroyed;
+  is(executionContextId, previousContext.id, "The destroyed event reports the previous context id");
+
+}