Closed Bug 1228542 Opened 6 years ago Closed 6 years ago

Multiple tests cause ASSERTIONS when system add-ons import AUTHOR_SHEET style sheets (ASSERTION: Style set already has document sheets?: 'aStyleSet->SheetCount(SheetType::Doc) == 0')


(Core :: CSS Parsing and Computation, defect)

33 Branch
Not set



Tracking Status
firefox45 --- fixed


(Reporter: standard8, Assigned: gkrizsanits)




(1 file)

In bug 1223573 we're trying to move Hello to a system add-on. As part of our code we have:

  let sheets = ["chrome://loop/content/addon/css/loop.css",
  for (let sheet of sheets) {
    let styleSheetURI =, null, null);
    if (styleSheetService.sheetRegistered(styleSheetURI,
                                          styleSheetService.AUTHOR_SHEET)) {

However, when we run it through try, there is a debug assertion raised on lots of different tests:
 14:48:52     INFO -  [1191] ###!!! ASSERTION: Style set already has document sheets?: 'aStyleSet->SheetCount(SheetType::Doc) == 0', file /builds/slave/try-m64-d-00000000000000000000/build/src/dom/base/nsDocument.cpp, line 2365
 14:49:49     INFO -  #01: nsDocument::ResetStylesheetsToURI(nsIURI*) [xpcom/glue/nsCOMPtr.h:403]
 14:49:49     INFO -  #02: nsDocument::ResetToURI(nsIURI*, nsILoadGroup*, nsIPrincipal*) [mfbt/RefPtr.h:268]
 14:49:49     INFO -  #03: nsHTMLDocument::ResetToURI(nsIURI*, nsILoadGroup*, nsIPrincipal*) [mfbt/RefPtr.h:40]
 14:49:49     INFO -  #04: nsDocument::Reset(nsIChannel*, nsILoadGroup*) [mfbt/RefPtr.h:40]
 14:49:49     INFO -  #05: nsHTMLDocument::Reset(nsIChannel*, nsILoadGroup*) [dom/html/nsHTMLDocument.cpp:234]
 14:49:49     INFO -  #06: nsHTMLDocument::Open(JSContext*, nsAString_internal const&, nsAString_internal const&, mozilla::ErrorResult&) [xpcom/glue/nsCOMPtr.h:721]
 14:49:49     INFO -  #07: mozilla::dom::HTMLDocumentBinding::open [mfbt/AlreadyAddRefed.h:138]
 14:49:49     INFO -  #08: mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) [dom/bindings/BindingUtils.cpp:2671]
 14:49:49     INFO -  #09: js::CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), JS::CallArgs const&) [js/src/jscntxtinlines.h:236]

If we change AUTHOR_SHEET to either USER_SHEET or AGENT_SHEET, then the tests no longer fail, however due to the CSS cascade doing this means we have to add a lot of !important annotations to the majority of our rules to get them to apply correctly.
For now, I've worked around this in attachment 8692901 [details] [diff] [review], but as you can see, its really ugly, and I won't be surprised if it causes us issues at some stage.
Looks like nsDocument::FillStyleSet adds style sheets from the stylesheet service to the style set, but nsDocument::ResetStylesheetsToURI never removes them, right?

Looks like a bug in the initial patch for bug 676054 which no one ever noticed, perhaps because no one ever tried to call in a debug build with any actual author sheets in the stlylesheet service...

Gabor, do you have bandwidth to look at this?
Blocks: 676054
Component: DOM → CSS Parsing and Computation
Flags: needinfo?(gkrizsanits)
Flags: needinfo?(gkrizsanits)
QA Contact: gkrizsanits
Sorry hit the wrong "assigned to".
Assignee: nobody → gkrizsanits
QA Contact: gkrizsanits
Blocks: 1228999
Thanks for spotting out the problem. I totally overlooked it. The test is not pretty but I didn't have any better idea at the moment... I'm not even sure I want to land that test, just wanted to see if it fixes the problem.
Attachment #8693554 - Flags: review?(bzbarsky)
Comment on attachment 8693554 [details] [diff] [review]
resetting AuthorStyleSheets. v1

Nice test!  r=me
Attachment #8693554 - Flags: review?(bzbarsky) → review+
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
I've just tried removing our workaround, and try shows it as working fine now.

Thank you for fixing this quickly.
No longer blocks: 1226706
You need to log in before you can comment on or make changes to this bug.