Verified Commit 7cbf6257 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez Committed by ma1
Browse files

Bug 2083733. r=arai

parent 39c0db5e
Loading
Loading
Loading
Loading
Loading
+3 −4
Changes for layout/style/Loader.cpp: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -1548,14 +1548,13 @@ Loader::Completed Loader::ParseSheet(

void Loader::AddPerformanceEntryForCachedSheet(SheetLoadData& aLoadData) {
  MOZ_ASSERT(aLoadData.mURI);

  if (!aLoadData.mNetworkMetadata) {
  if (!mDocument || !aLoadData.mNetworkMetadata) {
    return;
  }
  if (!mDocument) {
  if (aLoadData.mParentData &&
      !aLoadData.mParentData->mSheet->IsOriginClean()) {
    return;
  }

  nsAutoCString name;
  aLoadData.mURI->GetSpec(name);
  NS_ConvertUTF8toUTF16 entryName(name);
+53 −0
Changes for testing/web-platform/tests/resource-timing/no-entries-for-cached-import-of-cross-origin-css.html: 53 added lines, 0 removed lines.
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Resource timing entries for cached @import children of stylesheets</title>
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=2083733">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<body>
<script>
const {ORIGIN, HTTP_REMOTE_ORIGIN} = get_host_info();
const RESOURCES = "/resource-timing/resources/";

async function loadInFrame(t, href) {
  const iframe = document.createElement("iframe");
  iframe.srcdoc = `<link rel="stylesheet" href="${href}">`;
  await new Promise(resolve => {
    iframe.onload = resolve;
    document.body.appendChild(iframe);
  });
  t.add_cleanup(() => iframe.remove());
  return iframe.contentWindow;
}

// The first load caches the child stylesheet, but not the parent, which is
// no-store, so the second load re-parses the parent and gets the child from
// the cache.
async function loadTwice(t, parentOrigin, childOrigin) {
  const id = token();
  const child = `${childOrigin}${RESOURCES}cacheable-import-child.css?${id}`;
  const parent = v =>
    `${parentOrigin}${RESOURCES}no-store-importer.sub.css?import=${encodeURIComponent(child)}&v=${v}`;
  await loadInFrame(t, parent(1));
  const win = await loadInFrame(t, parent(2));
  await new Promise(resolve => t.step_timeout(resolve, 0));
  assert_equals(win.performance.getEntriesByName(parent(2)).length, 1,
                "Parent stylesheet should be in the timeline");
  return win.performance.getEntriesByName(child).length;
}

promise_test(async t => {
  assert_equals(await loadTwice(t, HTTP_REMOTE_ORIGIN, HTTP_REMOTE_ORIGIN), 0);
}, "Cached @import children of cross-origin stylesheets are not in the timeline");

promise_test(async t => {
  assert_equals(await loadTwice(t, ORIGIN, ORIGIN), 1);
}, "Cached same-origin @import children of same-origin stylesheets are in the timeline");

promise_test(async t => {
  assert_equals(await loadTwice(t, ORIGIN, HTTP_REMOTE_ORIGIN), 1);
}, "Cached cross-origin @import children of same-origin stylesheets are in the timeline");
</script>
</body>
+1 −0
Changes for testing/web-platform/tests/resource-timing/resources/cacheable-import-child.css: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
.child { color: blue }
+2 −0
Changes for testing/web-platform/tests/resource-timing/resources/cacheable-import-child.css.headers: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
Content-Type: text/css
Cache-Control: max-age=600
+1 −0
Changes for testing/web-platform/tests/resource-timing/resources/no-store-importer.sub.css: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@import "{{GET[import]}}";
Loading