Bug 1534399 - Don't allow disabling non-author sheets. r=emilio
authorCameron McCormack <cam@mcc.id.au>
Fri, 15 Mar 2019 12:54:17 +0000
changeset 464964 fddd0d8d0be510b437269ee94660b4dcda890696
parent 464963 a67a1d54f699785af11ace2af2dfa3d135f186fa
child 464965 c293763c1be24778c4733846ba0144b87c141867
push id80811
push usercmccormack@mozilla.com
push dateTue, 19 Mar 2019 08:59:56 +0000
treeherderautoland@fddd0d8d0be5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1534399
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 1534399 - Don't allow disabling non-author sheets. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D23624
layout/inspector/tests/chrome/chrome.ini
layout/inspector/tests/chrome/test_ua_sheet_disable.html
layout/style/StyleSheet.cpp
--- a/layout/inspector/tests/chrome/chrome.ini
+++ b/layout/inspector/tests/chrome/chrome.ini
@@ -24,8 +24,9 @@ support-files =
 support-files =
   test_fontFeaturesAPI.css
   DejaVuSans.ttf
 [test_fontVariationsAPI.xul]
 skip-if = ((os == 'win' && bits!=64) || (os=='linux' && bits==32) || os == 'mac') # bug 1456855, bug 1456856
 support-files =
   test_fontVariationsAPI.css
 [test_fontFaceGeneric.xul]
+[test_ua_sheet_disable.html]
new file mode 100644
--- /dev/null
+++ b/layout/inspector/tests/chrome/test_ua_sheet_disable.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<title>Test for bug 1534399</title>
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+<script>
+function start() {
+  let sheet = InspectorUtils.getAllStyleSheets(document, false)[0];
+  ok(sheet.href.indexOf("test.css") == -1, "Shouldn't have found the author sheet");
+
+  is(sheet.disabled, false, "Sheet should initially be enabled");
+
+  sheet.disabled = true;
+  is(sheet.disabled, false, "Shouldn't be able to disable a UA sheet");
+
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+document.addEventListener('DOMContentLoaded', start)
+</script>
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -236,16 +236,21 @@ void StyleSheet::ApplicableStateChanged(
   if (auto* shadow = ShadowRoot::FromNode(node)) {
     shadow->StyleSheetApplicableStateChanged(*this, aApplicable);
   } else {
     node.AsDocument()->SetStyleSheetApplicableState(this, aApplicable);
   }
 }
 
 void StyleSheet::SetDisabled(bool aDisabled) {
+  // Only allow disabling author sheets.
+  if (mParsingMode != css::eAuthorSheetFeatures) {
+    return;
+  }
+
   if (aDisabled == Disabled()) {
     return;
   }
 
   if (aDisabled) {
     mState |= State::Disabled;
   } else {
     mState &= ~State::Disabled;