Bug 1543632 - Part 3: Add some tests for profile page information r=mstange
authorNazım Can Altınova <canaltinova@gmail.com>
Tue, 30 Apr 2019 09:50:24 +0000
changeset 530723 ecc00867becd5fd0509c8c64ae866a12578527f6
parent 530722 86177fbcca6284a9f3d66224fcb8289f038330cb
child 530724 d59b5153250dc33091def93327d1134164fadbbb
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)
reviewersmstange
bugs1543632
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 1543632 - Part 3: Add some tests for profile page information r=mstange Differential Revision: https://phabricator.services.mozilla.com/D27679
tools/profiler/moz.build
tools/profiler/tests/browser/browser.ini
tools/profiler/tests/browser/browser_test_profile_history_page_info.js
tools/profiler/tests/browser/browser_test_profile_page_info.js
tools/profiler/tests/browser/head.js
tools/profiler/tests/browser/multi_frame.html
tools/profiler/tests/browser/single_frame.html
tools/profiler/tests/browser/single_frame_pushstate.html
tools/profiler/tests/browser/single_frame_replacestate.html
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -158,16 +158,17 @@ if CONFIG['MOZ_TASK_TRACER']:
     ]
     UNIFIED_SOURCES += [
         'tasktracer/GeckoTaskTracer.cpp',
         'tasktracer/TracedTaskCommon.cpp',
     ]
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
+BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += [
         '-Wno-error=shadow',
         '-Wno-ignored-qualifiers', # due to use of breakpad headers
     ]
 
 with Files('**'):
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/browser.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+  head.js
+  multi_frame.html
+  single_frame.html
+  single_frame_pushstate.html
+  single_frame_replacestate.html
+
+[browser_test_profile_page_info.js]
+[browser_test_profile_history_page_info.js]
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/browser_test_profile_history_page_info.js
@@ -0,0 +1,90 @@
+/* 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/. */
+
+add_task(async function test_profile_single_frame_pushstate_page_info() {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  Assert.ok(!Services.profiler.IsActive());
+  // Clear all pages in case we have some pages registered before.
+  await Services.profiler.ClearAllPages();
+  startProfiler();
+
+  const url = BASE_URL + "single_frame_pushstate.html";
+  let contentPid;
+  await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
+    contentPid = await ContentTask.spawn(contentBrowser, null, () => {
+      return Services.appinfo.processID;
+    });
+  });
+
+  const profile = await Services.profiler.getProfileDataAsync();
+  Services.profiler.StopProfiler();
+
+  let foundPage = 0;
+  // We need to find the correct content process for that tab.
+  let contentProcess = profile.processes.find(p => p.threads[0].pid == contentPid);
+  for (const page of contentProcess.pages) {
+    // Before pushState
+    if (page.url == url) {
+      Assert.equal(page.url, url);
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, false);
+      foundPage++;
+    }
+
+    // After pushState
+    if (page.url == BASE_URL + "single_frame.html") {
+      Assert.equal(page.url, BASE_URL + "single_frame.html");
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, false);
+      foundPage++;
+    }
+  }
+
+  Assert.equal(foundPage, 2);
+});
+
+add_task(async function test_profile_single_frame_replacestate_page_info() {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  Assert.ok(!Services.profiler.IsActive());
+  // Clear all pages in case we have some pages registered before.
+  await Services.profiler.ClearAllPages();
+  startProfiler();
+
+  const url = BASE_URL + "single_frame_replacestate.html";
+  let contentPid;
+  await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
+    contentPid = await ContentTask.spawn(contentBrowser, null, () => {
+      return Services.appinfo.processID;
+    });
+  });
+
+  const profile = await Services.profiler.getProfileDataAsync();
+  Services.profiler.StopProfiler();
+
+  let foundPage = 0;
+  // We need to find the correct content process for that tab.
+  let contentProcess = profile.processes.find(p => p.threads[0].pid == contentPid);
+  for (const page of contentProcess.pages) {
+    // Before replaceState
+    if (page.url == url) {
+      Assert.equal(page.url, url);
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, false);
+      foundPage++;
+    }
+
+    // Shoudn't record the frame on replaceState since it's not changing
+    // DocShell ID or DocShell History ID.
+    Assert.notEqual(page.url, BASE_URL + "single_frame.html");
+  }
+
+  Assert.equal(foundPage, 1);
+});
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/browser_test_profile_page_info.js
@@ -0,0 +1,85 @@
+/* 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/. */
+
+add_task(async function test_profile_single_frame_page_info() {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  Assert.ok(!Services.profiler.IsActive());
+  // Clear all pages in case we have some pages registered before.
+  await Services.profiler.ClearAllPages();
+  startProfiler();
+
+  const url = BASE_URL + "single_frame.html";
+  let contentPid;
+  await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
+    contentPid = await ContentTask.spawn(contentBrowser, null, () => {
+      return Services.appinfo.processID;
+    });
+  });
+
+  const profile = await Services.profiler.getProfileDataAsync();
+  Services.profiler.StopProfiler();
+
+  let pageFound = false;
+  // We need to find the correct content process for that tab.
+  let contentProcess = profile.processes.find(p => p.threads[0].pid == contentPid);
+  for (const page of contentProcess.pages) {
+    if (page.url == url) {
+      Assert.equal(page.url, url);
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, false);
+      pageFound = true;
+      break;
+    }
+  }
+  Assert.equal(pageFound, true);
+});
+
+add_task(async function test_profile_multi_frame_page_info() {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  Assert.ok(!Services.profiler.IsActive());
+  // Clear all pages in case we have some pages registered before.
+  await Services.profiler.ClearAllPages();
+  startProfiler();
+
+  // multi_frame.html embeds single_frame.html inside an iframe.
+  const url = BASE_URL + "multi_frame.html";
+  let contentPid;
+  await BrowserTestUtils.withNewTab(url, async function(contentBrowser) {
+    contentPid = await ContentTask.spawn(contentBrowser, null, () => {
+      return Services.appinfo.processID;
+    });
+  });
+
+  const profile = await Services.profiler.getProfileDataAsync();
+  Services.profiler.StopProfiler();
+
+  let foundPage = 0;
+  // We need to find the correct content process for that tab.
+  let contentProcess = profile.processes.find(p => p.threads[0].pid == contentPid);
+  for (const page of contentProcess.pages) {
+    // Parent page
+    if (page.url == url) {
+      Assert.equal(page.url, url);
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, false);
+      foundPage++;
+    }
+
+    // Child page (iframe)
+    if (page.url == BASE_URL + "single_frame.html") {
+      Assert.equal(page.url, BASE_URL + "single_frame.html");
+      Assert.equal(typeof page.docshellId, "string");
+      Assert.equal(typeof page.historyId, "number");
+      Assert.equal(page.isSubFrame, true);
+      foundPage++;
+    }
+  }
+  Assert.equal(foundPage, 2);
+});
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/head.js
@@ -0,0 +1,22 @@
+
+const { BrowserTestUtils } = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
+
+const BASE_URL = "http://example.com/browser/tools/profiler/tests/browser/";
+
+function startProfiler() {
+  const settings = {
+    entries: 1000000, // 9MB
+    interval: 1, // ms
+    features: ["threads"],
+    threads: ["GeckoMain"],
+  };
+  Services.profiler.StartProfiler(
+    settings.entries,
+    settings.interval,
+    settings.features,
+    settings.features.length,
+    settings.threads,
+    settings.threads.length,
+    settings.duration
+  );
+}
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/multi_frame.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Multi Frame</title>
+</head>
+<body>
+  Multi Frame
+  <iframe src="single_frame.html"></iframe>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/single_frame.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Single Frame</title>
+</head>
+<body>
+  Single Frame
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/single_frame_pushstate.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Single Frame with window.history.pushState</title>
+  <script>
+      window.history.pushState(null, "Second State", "single_frame.html");
+  </script>
+</head>
+<body>
+  Single Frame before window.history.pushState
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/browser/single_frame_replacestate.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Single Frame with window.history.replaceState</title>
+  <script>
+      window.history.replaceState(null, "Second State", "single_frame.html");
+  </script>
+</head>
+<body>
+  Single Frame before window.history.replaceState
+</body>
+</html>