Bug 1379762 part 1. Don't call MediaFeaturesChanged if our override device pixel ratio is set to its current value. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 17 Jul 2017 23:21:41 -0400
changeset 418109 68dccd8c146891ac1dd846bb0fde903351303de3
parent 418108 59532b5342bc526921aca2538784b5d85df0ea3c
child 418110 aa65fd52fbcc7c6f7dc6111ad89471df9f38d9f8
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1379762
milestone56.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 1379762 part 1. Don't call MediaFeaturesChanged if our override device pixel ratio is set to its current value. r=dbaron
docshell/test/navigation/file_bug1379762-1.html
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_sessionhistory.html
layout/base/nsPresContext.cpp
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_bug1379762-1.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Bug 1379762</title>
+  </head>
+  <img srcset> <!-- This tries to add load blockers during bfcache restoration -->
+  <script>
+    onunload = null; // enable bfcache
+    opener.is(opener.testCount, 0,
+              "We should only run once; otherwise the loadCount variable makes no sense");
+    var loadCount = 0;
+    onpageshow = function() {
+      ++opener.testCount;
+      if (opener.testCount == 1) {
+        // Navigate forward and then back.
+        setTimeout(function() { location = "goback.html"; }, 0);
+      } else if (opener.testCount == 2) {
+        // Do this async so our load event gets a chance to fire if it plans to
+        // do it.
+        setTimeout(function() {
+          opener.nextTest();
+          window.close();
+        });
+      }
+    };
+    onload = function() {
+      ++loadCount;
+      opener.is(loadCount, 1, "Should only get one onload");
+    }
+  </script>
+</html>
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -59,15 +59,16 @@ skip-if = (toolkit == 'android') || (!de
 [test_grandchild.html]
 [test_not-opener.html]
 [test_opener.html]
 [test_popup-navigates-children.html]
 [test_reserved.html]
 skip-if = (toolkit == 'android') || (debug && e10s) #too slow on Android 4.3 aws only; bug 1030403; bug 1263213 for debug e10s
 [test_sessionhistory.html]
 skip-if = toolkit == 'android' #RANDOM
+support-files = file_bug1379762-1.html
 [test_sibling-matching-parent.html]
 [test_sibling-off-domain.html]
 [test_triggeringprincipal_frame_nav.html]
 [test_triggeringprincipal_window_open.html]
 [test_triggeringprincipal_parent_iframe_window_open.html]
 [test_triggeringprincipal_iframe_iframe_window_open.html]
 [test_contentpolicy_block_window.html]
--- a/docshell/test/navigation/test_sessionhistory.html
+++ b/docshell/test/navigation/test_sessionhistory.html
@@ -28,16 +28,17 @@ var testFiles =
     //"file_static_and_dynamic_1.html",// Static and dynamic frames and forward-back
     "file_bug534178.html",           // Session history transaction clean-up.
     "file_fragment_handling_during_load.html",
     "file_nested_frames.html",
     "file_shiftReload_and_pushState.html",
     "file_scrollRestoration.html",
     "file_bug1300461.html",
     "file_bug1326251.html",
+    "file_bug1379762-1.html",
   ];
 var testCount = 0; // Used by the test files.
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("untriaged");
 
 var testWindow;
 function nextTest_() {
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1408,20 +1408,25 @@ nsPresContext::SetFullZoom(float aZoom)
   AppUnitsPerDevPixelChanged();
 
   mSuppressResizeReflow = false;
 }
 
 void
 nsPresContext::SetOverrideDPPX(float aDPPX)
 {
-  mOverrideDPPX = aDPPX;
-
-  if (HasCachedStyleData()) {
-    MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
+  // SetOverrideDPPX is called during navigations, including history
+  // traversals.  In that case, it's typically called with our current value,
+  // and we don't need to actually do anything.
+  if (aDPPX != mOverrideDPPX) {
+    mOverrideDPPX = aDPPX;
+
+    if (HasCachedStyleData()) {
+      MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
+    }
   }
 }
 
 gfxSize
 nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged)
 {
   if (aChanged) {
     *aChanged = false;