☠☠ backed out by 6d386a2162b9 ☠ ☠ | |
author | Sylvestre Ledru <sledru@mozilla.com> |
Thu, 04 Apr 2019 21:36:16 +0000 | |
changeset 468084 | 4ad80127f89f58dd562fba3e8cececb66b29e62f |
parent 468083 | dd4d744643a31e8817f15b07fe610bc0fbe0b671 |
child 468085 | 6d386a2162b90d72529adbc283391fc4732eff32 |
push id | 35817 |
push user | btara@mozilla.com |
push date | Fri, 05 Apr 2019 09:48:43 +0000 |
treeherder | mozilla-central@20750a2dc85b [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | Ehsan |
bugs | 1519636 |
milestone | 68.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
|
--- a/accessible/base/MarkupMap.h +++ b/accessible/base/MarkupMap.h @@ -1,60 +1,61 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:expandtab:shiftwidth=2:tabstop=2: */ /* 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/. */ -MARKUPMAP(a, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // Only some roles truly enjoy life as HTMLLinkAccessibles, for - // details see closed bug 494807. - const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aElement); - if (roleMapEntry && roleMapEntry->role != roles::NOTHING && - roleMapEntry->role != roles::LINK) { - return new HyperTextAccessibleWrap(aElement, - aContext->Document()); - } +MARKUPMAP( + a, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // Only some roles truly enjoy life as HTMLLinkAccessibles, for + // details see closed bug 494807. + const nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aElement); + if (roleMapEntry && roleMapEntry->role != roles::NOTHING && + roleMapEntry->role != roles::LINK) { + return new HyperTextAccessibleWrap(aElement, aContext->Document()); + } - return new HTMLLinkAccessible(aElement, aContext->Document()); - }, - roles::LINK) + return new HTMLLinkAccessible(aElement, aContext->Document()); + }, + roles::LINK); MARKUPMAP(abbr, New_HyperText, 0) MARKUPMAP(acronym, New_HyperText, 0) MARKUPMAP(article, New_HyperText, roles::ARTICLE, Attr(xmlroles, article)) MARKUPMAP(aside, New_HyperText, roles::LANDMARK) MARKUPMAP(blockquote, New_HyperText, roles::BLOCKQUOTE) -MARKUPMAP(button, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLButtonAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + button, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLButtonAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(caption, - [](Element* aElement, Accessible* aContext) -> Accessible* { - if (aContext->IsTable()) { - dom::HTMLTableElement* tableEl = - dom::HTMLTableElement::FromNode(aContext->GetContent()); - if (tableEl && tableEl == aElement->GetParent() && - tableEl->GetCaption() == aElement) { - return new HTMLCaptionAccessible(aElement, - aContext->Document()); - } - } - return nullptr; - }, - 0) +MARKUPMAP( + caption, + [](Element* aElement, Accessible* aContext) -> Accessible* { + if (aContext->IsTable()) { + dom::HTMLTableElement* tableEl = + dom::HTMLTableElement::FromNode(aContext->GetContent()); + if (tableEl && tableEl == aElement->GetParent() && + tableEl->GetCaption() == aElement) { + return new HTMLCaptionAccessible(aElement, aContext->Document()); + } + } + return nullptr; + }, + 0) MARKUPMAP(dd, New_HTMLDtOrDd<HyperTextAccessibleWrap>, roles::DEFINITION) MARKUPMAP(del, New_HyperText, roles::CONTENT_DELETION) MARKUPMAP(details, New_HyperText, roles::DETAILS) MARKUPMAP( @@ -115,139 +116,148 @@ MARKUPMAP( return new HyperTextAccessibleWrap(aElement, aContext->Document()); } } } return nullptr; }, roles::SECTION) -MARKUPMAP(dl, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLListAccessible(aElement, aContext->Document()); - }, - roles::DEFINITION_LIST) +MARKUPMAP( + dl, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLListAccessible(aElement, aContext->Document()); + }, + roles::DEFINITION_LIST) MARKUPMAP(dt, New_HTMLDtOrDd<HTMLLIAccessible>, roles::TERM) -MARKUPMAP(figcaption, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLFigcaptionAccessible(aElement, aContext->Document()); - }, - roles::CAPTION) +MARKUPMAP( + figcaption, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLFigcaptionAccessible(aElement, aContext->Document()); + }, + roles::CAPTION) -MARKUPMAP(figure, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLFigureAccessible(aElement, aContext->Document()); - }, - roles::FIGURE, Attr(xmlroles, figure)) +MARKUPMAP( + figure, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLFigureAccessible(aElement, aContext->Document()); + }, + roles::FIGURE, Attr(xmlroles, figure)) -MARKUPMAP(fieldset, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLGroupboxAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + fieldset, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLGroupboxAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(form, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLFormAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + form, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLFormAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(footer, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLHeaderOrFooterAccessible(aElement, - aContext->Document()); - }, - 0) +MARKUPMAP( + footer, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(header, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLHeaderOrFooterAccessible(aElement, - aContext->Document()); - }, - 0) +MARKUPMAP( + header, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document()); + }, + 0) MARKUPMAP(h1, New_HyperText, roles::HEADING) MARKUPMAP(h2, New_HyperText, roles::HEADING) MARKUPMAP(h3, New_HyperText, roles::HEADING) MARKUPMAP(h4, New_HyperText, roles::HEADING) MARKUPMAP(h5, New_HyperText, roles::HEADING) MARKUPMAP(h6, New_HyperText, roles::HEADING) -MARKUPMAP(hr, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLHRAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + hr, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLHRAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(input, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // TODO(emilio): This would be faster if it used - // HTMLInputElement's already-parsed representation. - if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, - nsGkAtoms::checkbox, eIgnoreCase)) { - return new CheckboxAccessible(aElement, aContext->Document()); - } - if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, - nsGkAtoms::image, eIgnoreCase)) { - return new HTMLButtonAccessible(aElement, aContext->Document()); - } - if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, - nsGkAtoms::radio, eIgnoreCase)) { - return new HTMLRadioButtonAccessible(aElement, - aContext->Document()); - } - if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, - nsGkAtoms::time, eIgnoreCase)) { - return new EnumRoleAccessible<roles::GROUPING>( - aElement, aContext->Document()); - } - if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, - nsGkAtoms::date, eIgnoreCase)) { - return new EnumRoleAccessible<roles::DATE_EDITOR>( - aElement, aContext->Document()); - } - return nullptr; - }, - 0) +MARKUPMAP( + input, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // TODO(emilio): This would be faster if it used + // HTMLInputElement's already-parsed representation. + if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::checkbox, eIgnoreCase)) { + return new CheckboxAccessible(aElement, aContext->Document()); + } + if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::image, eIgnoreCase)) { + return new HTMLButtonAccessible(aElement, aContext->Document()); + } + if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::radio, eIgnoreCase)) { + return new HTMLRadioButtonAccessible(aElement, aContext->Document()); + } + if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::time, eIgnoreCase)) { + return new EnumRoleAccessible<roles::GROUPING>(aElement, + aContext->Document()); + } + if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::date, eIgnoreCase)) { + return new EnumRoleAccessible<roles::DATE_EDITOR>(aElement, + aContext->Document()); + } + return nullptr; + }, + 0) MARKUPMAP(ins, New_HyperText, roles::CONTENT_INSERTION) -MARKUPMAP(label, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLLabelAccessible(aElement, aContext->Document()); - }, - roles::LABEL) +MARKUPMAP( + label, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLLabelAccessible(aElement, aContext->Document()); + }, + roles::LABEL) -MARKUPMAP(legend, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLLegendAccessible(aElement, aContext->Document()); - }, - roles::LABEL) +MARKUPMAP( + legend, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLLegendAccessible(aElement, aContext->Document()); + }, + roles::LABEL) -MARKUPMAP(li, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // If list item is a child of accessible list then create an - // accessible for it unconditionally by tag name. nsBlockFrame - // creates the list item accessible for other elements styled as - // list items. - if (aContext->IsList() && - aContext->GetContent() == aElement->GetParent()) { - return new HTMLLIAccessible(aElement, aContext->Document()); - } +MARKUPMAP( + li, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // If list item is a child of accessible list then create an + // accessible for it unconditionally by tag name. nsBlockFrame + // creates the list item accessible for other elements styled as + // list items. + if (aContext->IsList() && + aContext->GetContent() == aElement->GetParent()) { + return new HTMLLIAccessible(aElement, aContext->Document()); + } - return nullptr; - }, - 0) + return nullptr; + }, + 0) MARKUPMAP(main, New_HyperText, roles::LANDMARK) MARKUPMAP(map, nullptr, roles::TEXT_CONTAINER) MARKUPMAP(math, New_HyperText, roles::MATHML_MATH) MARKUPMAP(mi_, New_HyperText, roles::MATHML_IDENTIFIER) @@ -296,41 +306,44 @@ MARKUPMAP(mover_, New_HyperText, roles:: AttrFromDOM(accent_, accent_), AttrFromDOM(align, align)) MARKUPMAP(munderover_, New_HyperText, roles::MATHML_UNDER_OVER, AttrFromDOM(accent_, accent_), AttrFromDOM(accentunder_, accentunder_), AttrFromDOM(align, align)) MARKUPMAP(mmultiscripts_, New_HyperText, roles::MATHML_MULTISCRIPTS) -MARKUPMAP(mtable_, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLTableAccessible(aElement, aContext->Document()); - }, - roles::MATHML_TABLE, AttrFromDOM(align, align), - AttrFromDOM(columnlines_, columnlines_), - AttrFromDOM(rowlines_, rowlines_)) +MARKUPMAP( + mtable_, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLTableAccessible(aElement, aContext->Document()); + }, + roles::MATHML_TABLE, AttrFromDOM(align, align), + AttrFromDOM(columnlines_, columnlines_), AttrFromDOM(rowlines_, rowlines_)) -MARKUPMAP(mlabeledtr_, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLTableRowAccessible(aElement, aContext->Document()); - }, - roles::MATHML_LABELED_ROW) +MARKUPMAP( + mlabeledtr_, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLTableRowAccessible(aElement, aContext->Document()); + }, + roles::MATHML_LABELED_ROW) -MARKUPMAP(mtr_, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLTableRowAccessible(aElement, aContext->Document()); - }, - roles::MATHML_TABLE_ROW) +MARKUPMAP( + mtr_, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLTableRowAccessible(aElement, aContext->Document()); + }, + roles::MATHML_TABLE_ROW) -MARKUPMAP(mtd_, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLTableCellAccessible(aElement, aContext->Document()); - }, - roles::MATHML_CELL) +MARKUPMAP( + mtd_, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLTableCellAccessible(aElement, aContext->Document()); + }, + roles::MATHML_CELL) MARKUPMAP(maction_, New_HyperText, roles::MATHML_ACTION, AttrFromDOM(actiontype_, actiontype_), AttrFromDOM(selection_, selection_)) MARKUPMAP(merror_, New_HyperText, roles::MATHML_ERROR) MARKUPMAP(mstack_, New_HyperText, roles::MATHML_STACK, @@ -351,178 +364,188 @@ MARKUPMAP(mscarries_, New_HyperText, rol MARKUPMAP(mscarry_, New_HyperText, roles::MATHML_STACK_CARRY, AttrFromDOM(crossout_, crossout_)) MARKUPMAP(msline_, New_HyperText, roles::MATHML_STACK_LINE, AttrFromDOM(position, position)) MARKUPMAP(nav, New_HyperText, roles::LANDMARK) -MARKUPMAP(ol, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLListAccessible(aElement, aContext->Document()); - }, - roles::LIST) +MARKUPMAP( + ol, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLListAccessible(aElement, aContext->Document()); + }, + roles::LIST) -MARKUPMAP(option, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLSelectOptionAccessible(aElement, - aContext->Document()); - }, - 0) +MARKUPMAP( + option, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLSelectOptionAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(optgroup, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLSelectOptGroupAccessible(aElement, - aContext->Document()); - }, - 0) +MARKUPMAP( + optgroup, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLSelectOptGroupAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(output, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLOutputAccessible(aElement, aContext->Document()); - }, - roles::SECTION, Attr(live, polite)) +MARKUPMAP( + output, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLOutputAccessible(aElement, aContext->Document()); + }, + roles::SECTION, Attr(live, polite)) MARKUPMAP(p, nullptr, roles::PARAGRAPH) -MARKUPMAP(progress, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLProgressAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + progress, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLProgressAccessible(aElement, aContext->Document()); + }, + 0) MARKUPMAP(q, New_HyperText, 0) -MARKUPMAP(section, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLSectionAccessible(aElement, aContext->Document()); - }, - 0) +MARKUPMAP( + section, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLSectionAccessible(aElement, aContext->Document()); + }, + 0) -MARKUPMAP(summary, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLSummaryAccessible(aElement, aContext->Document()); - }, - roles::SUMMARY) +MARKUPMAP( + summary, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLSummaryAccessible(aElement, aContext->Document()); + }, + roles::SUMMARY) -MARKUPMAP(table, - [](Element* aElement, Accessible* aContext) -> Accessible* { - if (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->AccessibleType() != - eHTMLTableType) { - return new ARIAGridAccessibleWrap(aElement, aContext->Document()); - } - return nullptr; - }, - 0) +MARKUPMAP( + table, + [](Element* aElement, Accessible* aContext) -> Accessible* { + if (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->AccessibleType() != eHTMLTableType) { + return new ARIAGridAccessibleWrap(aElement, aContext->Document()); + } + return nullptr; + }, + 0) MARKUPMAP(time, New_HyperText, 0, Attr(xmlroles, time), AttrFromDOM(datetime, datetime)) -MARKUPMAP(tbody, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // Expose this as a grouping if its frame type is non-standard. - if (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { - return nullptr; - } - return new HyperTextAccessibleWrap(aElement, aContext->Document()); - }, - roles::GROUPING) +MARKUPMAP( + tbody, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // Expose this as a grouping if its frame type is non-standard. + if (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { + return nullptr; + } + return new HyperTextAccessibleWrap(aElement, aContext->Document()); + }, + roles::GROUPING) -MARKUPMAP(td, - [](Element* aElement, Accessible* aContext) -> Accessible* { - if (aContext->IsTableRow() && - aContext->GetContent() == aElement->GetParent()) { - // If HTML:td element is part of its HTML:table, which has CSS - // display style other than 'table', then create a generic table - // cell accessible, because there's no underlying table layout and - // thus native HTML table cell class doesn't work. The same is - // true if the cell itself has CSS display:block;. - if (!aContext->IsHTMLTableRow() || - (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->AccessibleType() != - eHTMLTableCellType)) { - return new ARIAGridCellAccessibleWrap(aElement, - aContext->Document()); - } - if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::scope)) { - return new HTMLTableHeaderCellAccessibleWrap( - aElement, aContext->Document()); - } - } - return nullptr; - }, - 0) +MARKUPMAP( + td, + [](Element* aElement, Accessible* aContext) -> Accessible* { + if (aContext->IsTableRow() && + aContext->GetContent() == aElement->GetParent()) { + // If HTML:td element is part of its HTML:table, which has CSS + // display style other than 'table', then create a generic table + // cell accessible, because there's no underlying table layout and + // thus native HTML table cell class doesn't work. The same is + // true if the cell itself has CSS display:block;. + if (!aContext->IsHTMLTableRow() || + (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->AccessibleType() != + eHTMLTableCellType)) { + return new ARIAGridCellAccessibleWrap(aElement, aContext->Document()); + } + if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::scope)) { + return new HTMLTableHeaderCellAccessibleWrap(aElement, + aContext->Document()); + } + } + return nullptr; + }, + 0) -MARKUPMAP(tfoot, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // Expose this as a grouping if its frame type is non-standard. - if (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { - return nullptr; - } - return new HyperTextAccessibleWrap(aElement, aContext->Document()); - }, - roles::GROUPING) +MARKUPMAP( + tfoot, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // Expose this as a grouping if its frame type is non-standard. + if (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { + return nullptr; + } + return new HyperTextAccessibleWrap(aElement, aContext->Document()); + }, + roles::GROUPING) -MARKUPMAP(th, - [](Element* aElement, Accessible* aContext) -> Accessible* { - if (aContext->IsTableRow() && - aContext->GetContent() == aElement->GetParent()) { - if (!aContext->IsHTMLTableRow()) { - return new ARIAGridCellAccessibleWrap(aElement, - aContext->Document()); - } - return new HTMLTableHeaderCellAccessibleWrap( - aElement, aContext->Document()); - } - return nullptr; - }, - 0) +MARKUPMAP( + th, + [](Element* aElement, Accessible* aContext) -> Accessible* { + if (aContext->IsTableRow() && + aContext->GetContent() == aElement->GetParent()) { + if (!aContext->IsHTMLTableRow()) { + return new ARIAGridCellAccessibleWrap(aElement, aContext->Document()); + } + return new HTMLTableHeaderCellAccessibleWrap(aElement, + aContext->Document()); + } + return nullptr; + }, + 0) -MARKUPMAP(tfoot, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // Expose this as a grouping if its frame type is non-standard. - if (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { - return nullptr; - } - return new HyperTextAccessibleWrap(aElement, aContext->Document()); - }, - roles::GROUPING) +MARKUPMAP( + tfoot, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // Expose this as a grouping if its frame type is non-standard. + if (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->IsTableRowGroupFrame()) { + return nullptr; + } + return new HyperTextAccessibleWrap(aElement, aContext->Document()); + }, + roles::GROUPING) -MARKUPMAP(tr, - [](Element* aElement, Accessible* aContext) -> Accessible* { - // If HTML:tr element is part of its HTML:table, which has CSS - // display style other than 'table', then create a generic table row - // accessible, because there's no underlying table layout and thus - // native HTML table row class doesn't work. Refer to - // CreateAccessibleByFrameType dual logic. - Accessible* table = aContext->IsTable() ? aContext : nullptr; - if (!table && aContext->Parent() && aContext->Parent()->IsTable()) { - table = aContext->Parent(); - } - if (table) { - nsIContent* parentContent = aElement->GetParent(); - nsIFrame* parentFrame = parentContent->GetPrimaryFrame(); - if (parentFrame && !parentFrame->IsTableWrapperFrame()) { - parentContent = parentContent->GetParent(); - parentFrame = parentContent->GetPrimaryFrame(); - if (table->GetContent() == parentContent && - ((parentFrame && !parentFrame->IsTableWrapperFrame()) || - (aElement->GetPrimaryFrame() && - aElement->GetPrimaryFrame()->AccessibleType() != - eHTMLTableRowType))) { - return new ARIARowAccessible(aElement, aContext->Document()); - } - } - } - return nullptr; - }, - 0) +MARKUPMAP( + tr, + [](Element* aElement, Accessible* aContext) -> Accessible* { + // If HTML:tr element is part of its HTML:table, which has CSS + // display style other than 'table', then create a generic table row + // accessible, because there's no underlying table layout and thus + // native HTML table row class doesn't work. Refer to + // CreateAccessibleByFrameType dual logic. + Accessible* table = aContext->IsTable() ? aContext : nullptr; + if (!table && aContext->Parent() && aContext->Parent()->IsTable()) { + table = aContext->Parent(); + } + if (table) { + nsIContent* parentContent = aElement->GetParent(); + nsIFrame* parentFrame = parentContent->GetPrimaryFrame(); + if (parentFrame && !parentFrame->IsTableWrapperFrame()) { + parentContent = parentContent->GetParent(); + parentFrame = parentContent->GetPrimaryFrame(); + if (table->GetContent() == parentContent && + ((parentFrame && !parentFrame->IsTableWrapperFrame()) || + (aElement->GetPrimaryFrame() && + aElement->GetPrimaryFrame()->AccessibleType() != + eHTMLTableRowType))) { + return new ARIARowAccessible(aElement, aContext->Document()); + } + } + } + return nullptr; + }, + 0) -MARKUPMAP(ul, - [](Element* aElement, Accessible* aContext) -> Accessible* { - return new HTMLListAccessible(aElement, aContext->Document()); - }, - roles::LIST) +MARKUPMAP( + ul, + [](Element* aElement, Accessible* aContext) -> Accessible* { + return new HTMLListAccessible(aElement, aContext->Document()); + }, + roles::LIST)
--- a/caps/tests/gtest/TestOriginAttributes.cpp +++ b/caps/tests/gtest/TestOriginAttributes.cpp @@ -12,22 +12,25 @@ static void TestSuffix(const OriginAttri OriginAttributes attrsFromSuffix; bool success = attrsFromSuffix.PopulateFromSuffix(suffix); EXPECT_TRUE(success); EXPECT_EQ(attrs, attrsFromSuffix); } -TEST(OriginAttributes, Suffix_default) { +TEST(OriginAttributes, Suffix_default) +{ OriginAttributes attrs; TestSuffix(attrs); } -TEST(OriginAttributes, Suffix_appId_inIsolatedMozBrowser) { +TEST(OriginAttributes, Suffix_appId_inIsolatedMozBrowser) +{ OriginAttributes attrs(1, true); TestSuffix(attrs); } -TEST(OriginAttributes, Suffix_maxAppId_inIsolatedMozBrowser) { +TEST(OriginAttributes, Suffix_maxAppId_inIsolatedMozBrowser) +{ OriginAttributes attrs(4294967295, true); TestSuffix(attrs); }
--- a/dom/base/AnonymousContent.cpp +++ b/dom/base/AnonymousContent.cpp @@ -192,18 +192,17 @@ void AnonymousContent::GetComputedStyleP } RefPtr<nsComputedDOMStyle> cs = new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), element->OwnerDoc(), nsComputedDOMStyle::eAll); aRv = cs->GetPropertyValue(aPropertyName, aResult); } -void AnonymousContent::GetTargetIdForEvent(Event& aEvent, DOMString& aResult) -{ +void AnonymousContent::GetTargetIdForEvent(Event& aEvent, DOMString& aResult) { nsCOMPtr<Element> el = do_QueryInterface(aEvent.GetOriginalTarget()); if (el && el->IsInNativeAnonymousSubtree() && mContentNode->Contains(el)) { aResult.SetKnownLiveAtom(el->GetID(), DOMString::eTreatNullAsNull); return; } aResult.SetNull(); }
--- a/dom/base/DocGroup.cpp +++ b/dom/base/DocGroup.cpp @@ -138,30 +138,31 @@ RefPtr<PerformanceInfoPromise> DocGroup: items), __func__); } MOZ_ASSERT(mainThread); RefPtr<DocGroup> self = this; return CollectMemoryInfo(top, mainThread) - ->Then(mainThread, __func__, - [self, host, pid, windowID, duration, isTopLevel, - items](const PerformanceMemoryInfo& aMemoryInfo) { - PerformanceInfo info = - PerformanceInfo(host, pid, windowID, duration, - self->mPerformanceCounter->GetID(), false, - isTopLevel, aMemoryInfo, items); + ->Then( + mainThread, __func__, + [self, host, pid, windowID, duration, isTopLevel, + items](const PerformanceMemoryInfo& aMemoryInfo) { + PerformanceInfo info = + PerformanceInfo(host, pid, windowID, duration, + self->mPerformanceCounter->GetID(), false, + isTopLevel, aMemoryInfo, items); - return PerformanceInfoPromise::CreateAndResolve(std::move(info), - __func__); - }, - [self](const nsresult rv) { - return PerformanceInfoPromise::CreateAndReject(rv, __func__); - }); + return PerformanceInfoPromise::CreateAndResolve(std::move(info), + __func__); + }, + [self](const nsresult rv) { + return PerformanceInfoPromise::CreateAndReject(rv, __func__); + }); } nsresult DocGroup::Dispatch(TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable) { if (mPerformanceCounter) { mPerformanceCounter->IncrementDispatchCounter(DispatchCategory(aCategory)); } return mTabGroup->DispatchWithDocGroup(aCategory, std::move(aRunnable), this);
--- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -12622,29 +12622,30 @@ already_AddRefed<mozilla::dom::Promise> sapr->RequestDelayedTask( inner->EventTargetFor(TaskCategory::Other), ContentPermissionRequestBase::DelayedTaskType::Request); return p.forget(); }; AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor( NodePrincipal(), inner, AntiTrackingCommon::eStorageAccessAPI, performFinalChecks) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [outer, promise] { - // Step 10. Grant the document access to cookies and store - // that fact for - // the purposes of future calls to - // hasStorageAccess() and requestStorageAccess(). - outer->SetHasStorageAccess(true); - promise->MaybeResolveWithUndefined(); - }, - [outer, promise] { - outer->SetHasStorageAccess(false); - promise->MaybeRejectWithUndefined(); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [outer, promise] { + // Step 10. Grant the document access to cookies and store + // that fact for + // the purposes of future calls to + // hasStorageAccess() and requestStorageAccess(). + outer->SetHasStorageAccess(true); + promise->MaybeResolveWithUndefined(); + }, + [outer, promise] { + outer->SetHasStorageAccess(false); + promise->MaybeRejectWithUndefined(); + }); return promise.forget(); } } outer->SetHasStorageAccess(true); promise->MaybeResolveWithUndefined(); return promise.forget();
--- a/dom/base/TreeOrderedArrayInlines.h +++ b/dom/base/TreeOrderedArrayInlines.h @@ -42,17 +42,16 @@ size_t TreeOrderedArray<Node>::Insert(No if (nsContentUtils::PositionIsBefore(&mNode, curNode)) { return -1; } return 1; } }; size_t idx; - BinarySearchIf(mList, 0, mList.Length(), - PositionComparator(aNode), &idx); + BinarySearchIf(mList, 0, mList.Length(), PositionComparator(aNode), &idx); mList.InsertElementAt(idx, &aNode); return idx; } } // namespace dom } // namespace mozilla #endif
--- a/dom/base/UIDirectionManager.cpp +++ b/dom/base/UIDirectionManager.cpp @@ -46,18 +46,17 @@ void OnPrefChange(const char* aPrefName, } } } /* static */ void UIDirectionManager::Initialize() { DebugOnly<nsresult> rv = Preferences::RegisterCallback(OnPrefChange, "intl.uidirection"); - MOZ_ASSERT(NS_SUCCEEDED(rv), - "Failed to observe \"intl.uidirection\""); + MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed to observe \"intl.uidirection\""); } /* static */ void UIDirectionManager::Shutdown() { Preferences::UnregisterCallback(OnPrefChange, "intl.uidirection"); } } // namespace dom
--- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -1640,17 +1640,19 @@ MiscContainer* nsAttrValue::ClearMiscCon case eAtomArray: { delete cont->mValue.mAtomArray; break; } case eIntMarginValue: { delete cont->mValue.mIntMargin; break; } - default: { break; } + default: { + break; + } } } ResetMiscAtomOrString(); } else { ResetIfSet(); } return cont;
--- a/dom/base/nsAttrValueInlines.h +++ b/dom/base/nsAttrValueInlines.h @@ -237,13 +237,15 @@ inline void nsAttrValue::ToString(mozill // else aResult is already empty return; } case eAtom: { nsAtom* atom = static_cast<nsAtom*>(GetPtr()); aResult.SetKnownLiveAtom(atom, mozilla::dom::DOMString::eNullNotExpected); break; } - default: { ToString(aResult.AsAString()); } + default: { + ToString(aResult.AsAString()); + } } } #endif
--- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -421,17 +421,19 @@ nsresult nsCCUncollectableMarker::Observ mozilla::services::GetObserverService(); static_cast<nsObserverService*>(obs.get())->UnmarkGrayStrongObservers(); break; } case eUnmarkJSHolders: { xpc_UnmarkSkippableJSHolders(); break; } - default: { break; } + default: { + break; + } } return NS_OK; } void mozilla::dom::TraceBlackJS(JSTracer* aTrc, bool aIsShutdownGC) { #ifdef MOZ_XUL // Mark the scripts held in the XULPrototypeCache. This is required to keep
--- a/dom/base/test/gtest/TestContentUtils.cpp +++ b/dom/base/test/gtest/TestContentUtils.cpp @@ -6,31 +6,33 @@ #include "gtest/gtest.h" #include "jsapi.h" #include "nsContentUtils.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/SimpleGlobalObject.h" -TEST(DOM_Base_ContentUtils, StringifyJSON_EmptyValue) { +TEST(DOM_Base_ContentUtils, StringifyJSON_EmptyValue) +{ JSObject* globalObject = mozilla::dom::SimpleGlobalObject::Create( mozilla::dom::SimpleGlobalObject::GlobalType::BindingDetail); mozilla::dom::AutoJSAPI jsAPI; ASSERT_TRUE(jsAPI.Init(globalObject)); JSContext* cx = jsAPI.cx(); nsAutoString serializedValue; JS::RootedValue jsValue(cx); ASSERT_TRUE(nsContentUtils::StringifyJSON(cx, &jsValue, serializedValue)); ASSERT_TRUE(serializedValue.EqualsLiteral("null")); } -TEST(DOM_Base_ContentUtils, StringifyJSON_Object) { +TEST(DOM_Base_ContentUtils, StringifyJSON_Object) +{ JSObject* globalObject = mozilla::dom::SimpleGlobalObject::Create( mozilla::dom::SimpleGlobalObject::GlobalType::BindingDetail); mozilla::dom::AutoJSAPI jsAPI; ASSERT_TRUE(jsAPI.Init(globalObject)); JSContext* cx = jsAPI.cx(); nsAutoString serializedValue; JS::RootedObject jsObj(cx, JS_NewPlainObject(cx));
--- a/dom/base/test/gtest/TestMimeType.cpp +++ b/dom/base/test/gtest/TestMimeType.cpp @@ -6,600 +6,715 @@ #include "gtest/gtest.h" #include "MimeType.h" #include "nsString.h" using mozilla::UniquePtr; -TEST(MimeType, EmptyString) { +TEST(MimeType, EmptyString) +{ const auto in = NS_LITERAL_STRING(""); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Empty string"; } -TEST(MimeType, JustWhitespace) { +TEST(MimeType, JustWhitespace) +{ const auto in = NS_LITERAL_STRING(" \t\r\n "); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Just whitespace"; } -TEST(MimeType, JustBackslash) { +TEST(MimeType, JustBackslash) +{ const auto in = NS_LITERAL_STRING("\\"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Just backslash"; } -TEST(MimeType, JustForwardslash) { +TEST(MimeType, JustForwardslash) +{ const auto in = NS_LITERAL_STRING("/"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Just forward slash"; } -TEST(MimeType, MissingType1) { +TEST(MimeType, MissingType1) +{ const auto in = NS_LITERAL_STRING("/bogus"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing type #1"; } -TEST(MimeType, MissingType2) { +TEST(MimeType, MissingType2) +{ const auto in = NS_LITERAL_STRING(" \r\n\t/bogus"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing type #2"; } -TEST(MimeType, MissingSubtype1) { +TEST(MimeType, MissingSubtype1) +{ const auto in = NS_LITERAL_STRING("bogus"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing subtype #1"; } -TEST(MimeType, MissingSubType2) { +TEST(MimeType, MissingSubType2) +{ const auto in = NS_LITERAL_STRING("bogus/"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing subtype #2"; } -TEST(MimeType, MissingSubType3) { +TEST(MimeType, MissingSubType3) +{ const auto in = NS_LITERAL_STRING("bogus;"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing subtype #3"; } -TEST(MimeType, MissingSubType4) { +TEST(MimeType, MissingSubType4) +{ const auto in = NS_LITERAL_STRING("bogus; \r\n\t"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Missing subtype #3"; } -TEST(MimeType, ExtraForwardSlash) { +TEST(MimeType, ExtraForwardSlash) +{ const auto in = NS_LITERAL_STRING("bogus/bogus/;"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Extra forward slash"; } -TEST(MimeType, WhitespaceInType) { +TEST(MimeType, WhitespaceInType) +{ const auto in = NS_LITERAL_STRING("t\re\nx\tt /html"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Type with whitespace"; } -TEST(MimeType, WhitespaceInSubtype) { +TEST(MimeType, WhitespaceInSubtype) +{ const auto in = NS_LITERAL_STRING("text/ h\rt\nm\tl"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Subtype with whitespace"; } -TEST(MimeType, NonAlphanumericMediaType1) { +TEST(MimeType, NonAlphanumericMediaType1) +{ const auto in = NS_LITERAL_STRING("</>"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #1"; } -TEST(MimeType, NonAlphanumericMediaType2) { +TEST(MimeType, NonAlphanumericMediaType2) +{ const auto in = NS_LITERAL_STRING("(/)"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #2"; } -TEST(MimeType, NonAlphanumericMediaType3) { +TEST(MimeType, NonAlphanumericMediaType3) +{ const auto in = NS_LITERAL_STRING("{/}"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #3"; } -TEST(MimeType, NonAlphanumericMediaType4) { +TEST(MimeType, NonAlphanumericMediaType4) +{ const auto in = NS_LITERAL_STRING("\"/\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #4"; } -TEST(MimeType, NonAlphanumericMediaType5) { +TEST(MimeType, NonAlphanumericMediaType5) +{ const auto in = NS_LITERAL_STRING("\0/\0"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #5"; } -TEST(MimeType, NonAlphanumericMediaType6) { +TEST(MimeType, NonAlphanumericMediaType6) +{ const auto in = NS_LITERAL_STRING("text/html(;doesnot=matter"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-alphanumeric media type #6"; } -TEST(MimeType, NonLatin1MediaType1) { +TEST(MimeType, NonLatin1MediaType1) +{ const auto in = NS_LITERAL_STRING("ÿ/ÿ"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-latin1 media type #1"; } -TEST(MimeType, NonLatin1MediaType2) { +TEST(MimeType, NonLatin1MediaType2) +{ const auto in = NS_LITERAL_STRING(u"\x0100/\x0100"); UniquePtr<MimeType> parsed = MimeType::Parse(in); ASSERT_FALSE(parsed) << "Non-latin1 media type #2"; } -TEST(MimeType, MultipleParameters) { +TEST(MimeType, MultipleParameters) +{ const auto in = NS_LITERAL_STRING("text/html;charset=gbk;no=1;charset_=gbk_;yes=2"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsString out; parsed->Serialize(out); ASSERT_TRUE(out.Equals( NS_LITERAL_STRING("text/html;charset=gbk;no=1;charset_=gbk_;yes=2"))) - << "Multiple parameters"; + << "Multiple parameters"; } -TEST(MimeType, DuplicateParameter1) { +TEST(MimeType, DuplicateParameter1) +{ const auto in = NS_LITERAL_STRING("text/html;charset=gbk;charset=windows-1255"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsString out; parsed->Serialize(out); ASSERT_TRUE(out.Equals(NS_LITERAL_STRING("text/html;charset=gbk"))) - << "Duplicate parameter #1"; + << "Duplicate parameter #1"; } -TEST(MimeType, DuplicateParameter2) { +TEST(MimeType, DuplicateParameter2) +{ const auto in = NS_LITERAL_STRING("text/html;charset=();charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsString out; parsed->Serialize(out); ASSERT_TRUE(out.Equals(NS_LITERAL_STRING("text/html;charset=\"()\""))) - << "Duplicate parameter #2"; + << "Duplicate parameter #2"; } -TEST(MimeType, CString) { +TEST(MimeType, CString) +{ const auto in = NS_LITERAL_CSTRING("text/html;charset=();charset=GBK"); UniquePtr<CMimeType> parsed = CMimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsCString out; parsed->Serialize(out); ASSERT_TRUE(out.Equals(NS_LITERAL_CSTRING("text/html;charset=\"()\""))) - << "Duplicate parameter #2"; + << "Duplicate parameter #2"; } #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable : 4819) #endif -TEST(MimeType, NonAlphanumericParametersAreQuoted) { +TEST(MimeType, NonAlphanumericParametersAreQuoted) +{ const auto in = NS_LITERAL_STRING("text/html;test=\x00FF\\;charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsString out; parsed->Serialize(out); ASSERT_TRUE(out.Equals( NS_LITERAL_STRING("text/html;test=\"\x00FF\\\\\";charset=gbk"))) - << "Non-alphanumeric parameters are quoted"; + << "Non-alphanumeric parameters are quoted"; } #ifdef _MSC_VER # pragma warning(pop) #endif -TEST(MimeType, ParameterQuotedIfHasLeadingWhitespace1) { +TEST(MimeType, ParameterQuotedIfHasLeadingWhitespace1) +{ const auto in = NS_LITERAL_STRING("text/html;charset= g\\\"bk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\" g\\\\\\\"bk\"")) - << "Parameter is quoted if has leading whitespace #1"; + << "Parameter is quoted if has leading whitespace #1"; } -TEST(MimeType, ParameterQuotedIfHasLeadingWhitespace2) { +TEST(MimeType, ParameterQuotedIfHasLeadingWhitespace2) +{ const auto in = NS_LITERAL_STRING("text/html;charset= \"g\\bk\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\" \\\"g\\\\bk\\\"\"")) - << "Parameter is quoted if has leading whitespace #2"; + << "Parameter is quoted if has leading whitespace #2"; } -TEST(MimeType, ParameterQuotedIfHasInternalWhitespace) { +TEST(MimeType, ParameterQuotedIfHasInternalWhitespace) +{ const auto in = NS_LITERAL_STRING("text/html;charset=g \\b\"k"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"g \\\\b\\\"k\"")) - << "Parameter is quoted if has internal whitespace"; + << "Parameter is quoted if has internal whitespace"; } -TEST(MimeType, ImproperlyQuotedParameter1) { +TEST(MimeType, ImproperlyQuotedParameter1) +{ const auto in = NS_LITERAL_STRING("x/x;test=\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("x/x;test=\"\"")) - << "Improperly-quoted parameter is handled properly #1"; + << "Improperly-quoted parameter is handled properly #1"; } -TEST(MimeType, ImproperlyQuotedParameter2) { +TEST(MimeType, ImproperlyQuotedParameter2) +{ const auto in = NS_LITERAL_STRING("x/x;test=\"\\"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("x/x;test=\"\\\\\"")) - << "Improperly-quoted parameter is handled properly #2"; + << "Improperly-quoted parameter is handled properly #2"; } -TEST(MimeType, NonLatin1ParameterIgnored) { +TEST(MimeType, NonLatin1ParameterIgnored) +{ const auto in = NS_LITERAL_STRING(u"x/x;test=\xFFFD;x=x"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("x/x;x=x")) - << "Non latin-1 parameters are ignored"; + << "Non latin-1 parameters are ignored"; } -TEST(MimeType, ParameterIgnoredIfWhitespaceInName1) { +TEST(MimeType, ParameterIgnoredIfWhitespaceInName1) +{ const auto in = NS_LITERAL_STRING("text/html;charset =gbk;charset=123"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=123")) - << "Parameter ignored if whitespace in name #1"; + << "Parameter ignored if whitespace in name #1"; } -TEST(MimeType, ParameterIgnoredIfWhitespaceInName2) { +TEST(MimeType, ParameterIgnoredIfWhitespaceInName2) +{ const auto in = NS_LITERAL_STRING("text/html;cha rset =gbk;charset=123"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=123")) - << "Parameter ignored if whitespace in name #2"; + << "Parameter ignored if whitespace in name #2"; } -TEST(MimeType, WhitespaceTrimmed) { +TEST(MimeType, WhitespaceTrimmed) +{ const auto in = NS_LITERAL_STRING( "\n\r\t text/plain\n\r\t ;\n\r\t charset=123\n\r\t "); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/plain;charset=123")) - << "Whitespace appropriately ignored"; + << "Whitespace appropriately ignored"; } -TEST(MimeType, WhitespaceOnlyParameterIgnored) { +TEST(MimeType, WhitespaceOnlyParameterIgnored) +{ const auto in = NS_LITERAL_STRING("x/x;x= \r\n\t"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; + nsAutoString out; + parsed->Serialize(out); + ASSERT_TRUE(out.EqualsLiteral("x/x")) + << "Whitespace-only parameter is ignored"; +} + +TEST(MimeType, IncompleteParameterIgnored1) +{ + const auto in = NS_LITERAL_STRING("x/x;test"); + UniquePtr<MimeType> parsed = MimeType::Parse(in); + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("x/x")) - << "Whitespace-only parameter is ignored"; + << "Incomplete parameter is ignored #1"; } -TEST(MimeType, IncompleteParameterIgnored1) { - const auto in = NS_LITERAL_STRING("x/x;test"); - UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; - nsAutoString out; - parsed->Serialize(out); - ASSERT_TRUE(out.EqualsLiteral("x/x")) << "Incomplete parameter is ignored #1"; -} - -TEST(MimeType, IncompleteParameterIgnored2) { +TEST(MimeType, IncompleteParameterIgnored2) +{ const auto in = NS_LITERAL_STRING("x/x;test="); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); - ASSERT_TRUE(out.EqualsLiteral("x/x")) << "Incomplete parameter is ignored #2"; + ASSERT_TRUE(out.EqualsLiteral("x/x")) + << "Incomplete parameter is ignored #2"; } -TEST(MimeType, IncompleteParameterIgnored3) { +TEST(MimeType, IncompleteParameterIgnored3) +{ const auto in = NS_LITERAL_STRING("x/x;test= \r\n\t"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); - ASSERT_TRUE(out.EqualsLiteral("x/x")) << "Incomplete parameter is ignored #3"; + ASSERT_TRUE(out.EqualsLiteral("x/x")) + << "Incomplete parameter is ignored #3"; } -TEST(MimeType, IncompleteParameterIgnored4) { +TEST(MimeType, IncompleteParameterIgnored4) +{ const auto in = NS_LITERAL_STRING("text/html;test;charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Incomplete parameter is ignored #4"; + << "Incomplete parameter is ignored #4"; } -TEST(MimeType, IncompleteParameterIgnored5) { +TEST(MimeType, IncompleteParameterIgnored5) +{ const auto in = NS_LITERAL_STRING("text/html;test=;charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; - nsAutoString out; - parsed->Serialize(out); - ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Incomplete parameter is ignored #5"; -} - -TEST(MimeType, EmptyParameterIgnored1) { - const auto in = NS_LITERAL_STRING("text/html ; ; charset=gbk"); - UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Empty parameter ignored #1"; + << "Incomplete parameter is ignored #5"; } -TEST(MimeType, EmptyParameterIgnored2) { - const auto in = NS_LITERAL_STRING("text/html;;;;charset=gbk"); +TEST(MimeType, EmptyParameterIgnored1) +{ + const auto in = NS_LITERAL_STRING("text/html ; ; charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Empty parameter ignored #2"; + << "Empty parameter ignored #1"; } -TEST(MimeType, InvalidParameterIgnored1) { - const auto in = NS_LITERAL_STRING("text/html;';charset=gbk"); +TEST(MimeType, EmptyParameterIgnored2) +{ + const auto in = NS_LITERAL_STRING("text/html;;;;charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Invalid parameter ignored #1"; + << "Empty parameter ignored #2"; } -TEST(MimeType, InvalidParameterIgnored2) { - const auto in = NS_LITERAL_STRING("text/html;\";charset=gbk;=123; =321"); +TEST(MimeType, InvalidParameterIgnored1) +{ + const auto in = NS_LITERAL_STRING("text/html;';charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Invalid parameter ignored #2"; + << "Invalid parameter ignored #1"; } -TEST(MimeType, InvalidParameterIgnored3) { +TEST(MimeType, InvalidParameterIgnored2) +{ + const auto in = NS_LITERAL_STRING("text/html;\";charset=gbk;=123; =321"); + UniquePtr<MimeType> parsed = MimeType::Parse(in); + ASSERT_TRUE(parsed) + << "Parsing succeeded"; + nsAutoString out; + parsed->Serialize(out); + ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) + << "Invalid parameter ignored #2"; +} + +TEST(MimeType, InvalidParameterIgnored3) +{ const auto in = NS_LITERAL_STRING("text/html;charset= \"\u007F;charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=GBK")) - << "Invalid parameter ignored #3"; + << "Invalid parameter ignored #3"; } -TEST(MimeType, InvalidParameterIgnored4) { +TEST(MimeType, InvalidParameterIgnored4) +{ const auto in = NS_LITERAL_STRING( "text/html;charset=\"\u007F;charset=foo\";charset=GBK;charset="); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=GBK")) - << "Invalid parameter ignored #4"; + << "Invalid parameter ignored #4"; } -TEST(MimeType, SingleQuotes1) { +TEST(MimeType, SingleQuotes1) +{ const auto in = NS_LITERAL_STRING("text/html;charset='gbk'"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset='gbk'")) - << "Single quotes handled properly #1"; + << "Single quotes handled properly #1"; } -TEST(MimeType, SingleQuotes2) { +TEST(MimeType, SingleQuotes2) +{ const auto in = NS_LITERAL_STRING("text/html;charset='gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset='gbk")) - << "Single quotes handled properly #2"; + << "Single quotes handled properly #2"; } -TEST(MimeType, SingleQuotes3) { +TEST(MimeType, SingleQuotes3) +{ const auto in = NS_LITERAL_STRING("text/html;charset=gbk'"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk'")) - << "Single quotes handled properly #3"; + << "Single quotes handled properly #3"; } -TEST(MimeType, SingleQuotes4) { +TEST(MimeType, SingleQuotes4) +{ const auto in = NS_LITERAL_STRING("text/html;charset=';charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset='")) - << "Single quotes handled properly #4"; + << "Single quotes handled properly #4"; } -TEST(MimeType, SingleQuotes5) { +TEST(MimeType, SingleQuotes5) +{ const auto in = NS_LITERAL_STRING("text/html;charset=''';charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset='''")) - << "Single quotes handled properly #5"; + << "Single quotes handled properly #5"; } -TEST(MimeType, DoubleQuotes1) { +TEST(MimeType, DoubleQuotes1) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"gbk\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; - nsAutoString out; - parsed->Serialize(out); - ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Double quotes handled properly #1"; -} - -TEST(MimeType, DoubleQuotes2) { - const auto in = NS_LITERAL_STRING("text/html;charset=\"gbk"); - UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Double quotes handled properly #2"; + << "Double quotes handled properly #1"; } -TEST(MimeType, DoubleQuotes3) { +TEST(MimeType, DoubleQuotes2) +{ + const auto in = NS_LITERAL_STRING("text/html;charset=\"gbk"); + UniquePtr<MimeType> parsed = MimeType::Parse(in); + ASSERT_TRUE(parsed) + << "Parsing succeeded"; + nsAutoString out; + parsed->Serialize(out); + ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) + << "Double quotes handled properly #2"; +} + +TEST(MimeType, DoubleQuotes3) +{ const auto in = NS_LITERAL_STRING("text/html;charset=gbk\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"gbk\\\"\"")) - << "Double quotes handled properly #3"; + << "Double quotes handled properly #3"; } -TEST(MimeType, DoubleQuotes4) { +TEST(MimeType, DoubleQuotes4) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\" gbk\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\" gbk\"")) - << "Double quotes handled properly #4"; + << "Double quotes handled properly #4"; } -TEST(MimeType, DoubleQuotes5) { +TEST(MimeType, DoubleQuotes5) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"gbk \""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"gbk \"")) - << "Double quotes handled properly #5"; + << "Double quotes handled properly #5"; } -TEST(MimeType, DoubleQuotes6) { +TEST(MimeType, DoubleQuotes6) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"\\ gbk\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\" gbk\"")) - << "Double quotes handled properly #6"; + << "Double quotes handled properly #6"; } -TEST(MimeType, DoubleQuotes7) { +TEST(MimeType, DoubleQuotes7) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"\\g\\b\\k\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Double quotes handled properly #7"; + << "Double quotes handled properly #7"; } -TEST(MimeType, DoubleQuotes8) { +TEST(MimeType, DoubleQuotes8) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"gbk\"x"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=gbk")) - << "Double quotes handled properly #8"; + << "Double quotes handled properly #8"; } -TEST(MimeType, DoubleQuotes9) { +TEST(MimeType, DoubleQuotes9) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\"\";charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"\"")) - << "Double quotes handled properly #9"; + << "Double quotes handled properly #9"; } -TEST(MimeType, DoubleQuotes10) { +TEST(MimeType, DoubleQuotes10) +{ const auto in = NS_LITERAL_STRING("text/html;charset=\";charset=GBK"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\";charset=GBK\"")) - << "Double quotes handled properly #10"; + << "Double quotes handled properly #10"; } -TEST(MimeType, UnexpectedCodePoints) { +TEST(MimeType, UnexpectedCodePoints) +{ const auto in = NS_LITERAL_STRING("text/html;charset={gbk}"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"{gbk}\"")) - << "Unexpected code points handled properly"; + << "Unexpected code points handled properly"; } -TEST(MimeType, LongTypesSubtypesAccepted) { +TEST(MimeType, LongTypesSubtypesAccepted) +{ const auto in = NS_LITERAL_STRING( "012345678901234567890123456789012345678901234567890123456789012345678901" "2345678901234567890123456789012345678901234567890123456789/" "012345678901234567890123456789012345678901234567890123456789012345678901" "2345678901234567890123456789012345678901234567890123456789"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); - ASSERT_TRUE(out.Equals(in)) << "Long type/subtype accepted"; + ASSERT_TRUE(out.Equals(in)) + << "Long type/subtype accepted"; } -TEST(MimeType, LongParametersAccepted) { +TEST(MimeType, LongParametersAccepted) +{ const auto in = NS_LITERAL_STRING( "text/" "html;" "012345678901234567890123456789012345678901234567890123456789012345678901" "2345678901234567890123456789012345678901234567890123456789=x;charset=" "gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); - ASSERT_TRUE(out.Equals(in)) << "Long parameters accepted"; + ASSERT_TRUE(out.Equals(in)) + << "Long parameters accepted"; } -TEST(MimeType, AllValidCharactersAccepted1) { +TEST(MimeType, AllValidCharactersAccepted1) +{ const auto in = NS_LITERAL_STRING( u"x/x;x=\"\t " u"!\\\"#$%&'()*+,-./" u"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`" u"abcdefghijklmnopqrstuvwxyz{|}~" u"\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A" u"\u008B\u008C\u008D\u008E\u008F\u0090\u0091\u0092\u0093\u0094\u0095" u"\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009D\u009E\u009F\u00A0" @@ -608,67 +723,77 @@ TEST(MimeType, AllValidCharactersAccepte u"\u00B7\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF\u00C0\u00C1" u"\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC" u"\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7" u"\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF\u00E0\u00E1\u00E2" u"\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED" u"\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8" u"\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF\""); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); - ASSERT_TRUE(out.Equals(in)) << "All valid characters accepted #1"; + ASSERT_TRUE(out.Equals(in)) + << "All valid characters accepted #1"; } -TEST(MimeType, CaseNormalization1) { +TEST(MimeType, CaseNormalization1) +{ const auto in = NS_LITERAL_STRING("TEXT/PLAIN;CHARSET=TEST"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/plain;charset=TEST")) - << "Case normalized properly #1"; + << "Case normalized properly #1"; } -TEST(MimeType, CaseNormalization2) { +TEST(MimeType, CaseNormalization2) +{ const auto in = NS_LITERAL_STRING( "!#$%&'*+-.^_`|~" "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/" "!#$%&'*+-.^_`|~" "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;!#$%&'*+-" ".^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=!#$" "%&'*+-.^_`|~" "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral( "!#$%&'*+-.^_`|~" "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/" "!#$%&'*+-.^_`|~" "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz;!#$%&'*+-" ".^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz=!#$" "%&'*+-.^_`|~" "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) - << "Case normalized properly #2"; + << "Case normalized properly #2"; } -TEST(MimeType, LegacyCommentSyntax1) { +TEST(MimeType, LegacyCommentSyntax1) +{ const auto in = NS_LITERAL_STRING("text/html;charset=gbk("); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;charset=\"gbk(\"")) - << "Legacy comment syntax #1"; + << "Legacy comment syntax #1"; } -TEST(MimeType, LegacyCommentSyntax2) { +TEST(MimeType, LegacyCommentSyntax2) +{ const auto in = NS_LITERAL_STRING("text/html;x=(;charset=gbk"); UniquePtr<MimeType> parsed = MimeType::Parse(in); - ASSERT_TRUE(parsed) << "Parsing succeeded"; + ASSERT_TRUE(parsed) + << "Parsing succeeded"; nsAutoString out; parsed->Serialize(out); ASSERT_TRUE(out.EqualsLiteral("text/html;x=\"(\";charset=gbk")) - << "Legacy comment syntax #2"; + << "Legacy comment syntax #2"; }
--- a/dom/base/test/gtest/TestPlainTextSerializer.cpp +++ b/dom/base/test/gtest/TestPlainTextSerializer.cpp @@ -13,17 +13,18 @@ #include "nsIParserUtils.h" void ConvertBufToPlainText(nsString &aConBuf, int aFlag) { nsCOMPtr<nsIParserUtils> utils = do_GetService(NS_PARSERUTILS_CONTRACTID); utils->ConvertToPlainText(aConBuf, aFlag, 72, aConBuf); } // Test for ASCII with format=flowed; delsp=yes -TEST(PlainTextSerializer, ASCIIWithFlowedDelSp) { +TEST(PlainTextSerializer, ASCIIWithFlowedDelSp) +{ nsString test; nsString result; test.AssignLiteral( "<html><body>" "Firefox Firefox Firefox Firefox " "Firefox Firefox Firefox Firefox " "Firefox Firefox Firefox Firefox" @@ -37,21 +38,22 @@ TEST(PlainTextSerializer, ASCIIWithFlowe // create result case result.AssignLiteral( "Firefox Firefox Firefox Firefox " "Firefox Firefox Firefox Firefox " "Firefox \r\nFirefox Firefox Firefox\r\n"); ASSERT_TRUE(test.Equals(result)) - << "Wrong HTML to ASCII text serialization with format=flowed; delsp=yes"; + << "Wrong HTML to ASCII text serialization with format=flowed; delsp=yes"; } // Test for CJK with format=flowed; delsp=yes -TEST(PlainTextSerializer, CJKWithFlowedDelSp) { +TEST(PlainTextSerializer, CJKWithFlowedDelSp) +{ nsString test; nsString result; test.AssignLiteral("<html><body>"); for (uint32_t i = 0; i < 40; i++) { // Insert Kanji (U+5341) test.Append(0x5341); } @@ -69,21 +71,22 @@ TEST(PlainTextSerializer, CJKWithFlowedD } result.AppendLiteral(" \r\n"); for (uint32_t i = 0; i < 4; i++) { result.Append(0x5341); } result.AppendLiteral("\r\n"); ASSERT_TRUE(test.Equals(result)) - << "Wrong HTML to CJK text serialization with format=flowed; delsp=yes"; + << "Wrong HTML to CJK text serialization with format=flowed; delsp=yes"; } // Test for CJK with DisallowLineBreaking -TEST(PlainTextSerializer, CJKWithDisallowLineBreaking) { +TEST(PlainTextSerializer, CJKWithDisallowLineBreaking) +{ nsString test; nsString result; test.AssignLiteral("<html><body>"); for (uint32_t i = 0; i < 400; i++) { // Insert Kanji (U+5341) test.Append(0x5341); } @@ -98,21 +101,22 @@ TEST(PlainTextSerializer, CJKWithDisallo // create result case for (uint32_t i = 0; i < 400; i++) { result.Append(0x5341); } result.AppendLiteral("\r\n"); ASSERT_TRUE(test.Equals(result)) - << "Wrong HTML to CJK text serialization with OutputDisallowLineBreaking"; + << "Wrong HTML to CJK text serialization with OutputDisallowLineBreaking"; } // Test for ASCII with format=flowed; and quoted lines in preformatted span. -TEST(PlainTextSerializer, PreformatFlowedQuotes) { +TEST(PlainTextSerializer, PreformatFlowedQuotes) +{ nsString test; nsString result; test.AssignLiteral( "<html><body>" "<span style=\"white-space: pre-wrap;\">" "> Firefox Firefox Firefox Firefox <br>" "> Firefox Firefox Firefox Firefox<br>" @@ -129,79 +133,85 @@ TEST(PlainTextSerializer, PreformatFlowe // create result case result.AssignLiteral( "> Firefox Firefox Firefox Firefox \r\n" "> Firefox Firefox Firefox Firefox\r\n" ">\r\n" ">> Firefox Firefox Firefox Firefox \r\n" ">> Firefox Firefox Firefox Firefox\r\n"); - ASSERT_TRUE(test.Equals(result)) << "Wrong HTML to ASCII text serialization " - "with format=flowed; and quoted " - "lines"; + ASSERT_TRUE(test.Equals(result)) + << "Wrong HTML to ASCII text serialization " + "with format=flowed; and quoted " + "lines"; } -TEST(PlainTextSerializer, PrettyPrintedHtml) { +TEST(PlainTextSerializer, PrettyPrintedHtml) +{ nsString test; test.AppendLiteral("<html>" NS_LINEBREAK "<body>" NS_LINEBREAK " first<br>" NS_LINEBREAK " second<br>" NS_LINEBREAK "</body>" NS_LINEBREAK "</html>"); ConvertBufToPlainText(test, 0); ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK)) - << "Wrong prettyprinted html to text serialization"; + << "Wrong prettyprinted html to text serialization"; } -TEST(PlainTextSerializer, PreElement) { +TEST(PlainTextSerializer, PreElement) +{ nsString test; test.AppendLiteral("<html>" NS_LINEBREAK "<body>" NS_LINEBREAK "<pre>" NS_LINEBREAK " first" NS_LINEBREAK " second" NS_LINEBREAK "</pre>" NS_LINEBREAK "</body>" NS_LINEBREAK "</html>"); ConvertBufToPlainText(test, 0); ASSERT_TRUE(test.EqualsLiteral(" first" NS_LINEBREAK " second" NS_LINEBREAK NS_LINEBREAK)) - << "Wrong prettyprinted html to text serialization"; + << "Wrong prettyprinted html to text serialization"; } -TEST(PlainTextSerializer, BlockElement) { +TEST(PlainTextSerializer, BlockElement) +{ nsString test; test.AppendLiteral("<html>" NS_LINEBREAK "<body>" NS_LINEBREAK "<div>" NS_LINEBREAK " first" NS_LINEBREAK "</div>" NS_LINEBREAK "<div>" NS_LINEBREAK " second" NS_LINEBREAK "</div>" NS_LINEBREAK "</body>" NS_LINEBREAK "</html>"); ConvertBufToPlainText(test, 0); ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK)) - << "Wrong prettyprinted html to text serialization"; + << "Wrong prettyprinted html to text serialization"; } -TEST(PlainTextSerializer, PreWrapElementForThunderbird) { +TEST(PlainTextSerializer, PreWrapElementForThunderbird) +{ // This test examines the magic pre-wrap setup that Thunderbird relies on. nsString test; test.AppendLiteral( "<html>" NS_LINEBREAK "<body style=\"white-space: pre-wrap; width: 10ch;\">" NS_LINEBREAK "<pre>" NS_LINEBREAK " first line is too long" NS_LINEBREAK " second line is even loooonger " NS_LINEBREAK "</pre>" NS_LINEBREAK "</body>" NS_LINEBREAK "</html>"); ConvertBufToPlainText(test, nsIDocumentEncoder::OutputWrap); // "\n\n first\nline is\ntoo long\n second\nline is\neven\nloooonger\n\n\n" ASSERT_TRUE(test.EqualsLiteral( NS_LINEBREAK NS_LINEBREAK " first" NS_LINEBREAK "line is" NS_LINEBREAK "too long" NS_LINEBREAK " second" NS_LINEBREAK "line is" NS_LINEBREAK "even" NS_LINEBREAK "loooonger" NS_LINEBREAK NS_LINEBREAK NS_LINEBREAK)) - << "Wrong prettyprinted html to text serialization"; + << "Wrong prettyprinted html to text serialization"; } -TEST(PlainTextSerializer, Simple) { +TEST(PlainTextSerializer, Simple) +{ nsString test; test.AppendLiteral( "<html><base>base</base><head><span>span</span></head>" "<body>body</body></html>"); ConvertBufToPlainText(test, 0); ASSERT_TRUE(test.EqualsLiteral("basespanbody")) - << "Wrong html to text serialization"; + << "Wrong html to text serialization"; }
--- a/dom/base/test/gtest/TestXPathGenerator.cpp +++ b/dom/base/test/gtest/TestXPathGenerator.cpp @@ -3,134 +3,143 @@ /* 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/. */ #include "gtest/gtest.h" #include "XPathGenerator.h" #include "nsString.h" -TEST(TestXPathGenerator, TestQuoteArgumentWithoutQuote) { +TEST(TestXPathGenerator, TestQuoteArgumentWithoutQuote) +{ nsAutoString arg; arg.AssignLiteral(u"testing"); nsAutoString expectedResult; expectedResult.AssignLiteral(u"\'testing\'"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); ASSERT_TRUE(expectedResult.Equals(result)); } -TEST(TestXPathGenerator, TestQuoteArgumentWithSingleQuote) { +TEST(TestXPathGenerator, TestQuoteArgumentWithSingleQuote) +{ nsAutoString arg; arg.AssignLiteral(u"\'testing\'"); nsAutoString expectedResult; expectedResult.AssignLiteral(u"\"\'testing\'\""); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); ASSERT_TRUE(expectedResult.Equals(result)); } -TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuote) { +TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuote) +{ nsAutoString arg; arg.AssignLiteral(u"\"testing\""); nsAutoString expectedResult; expectedResult.AssignLiteral(u"\'\"testing\"\'"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); ASSERT_TRUE(expectedResult.Equals(result)); } -TEST(TestXPathGenerator, TestQuoteArgumentWithSingleAndDoubleQuote) { +TEST(TestXPathGenerator, TestQuoteArgumentWithSingleAndDoubleQuote) +{ nsAutoString arg; arg.AssignLiteral(u"\'testing\""); nsAutoString expectedResult; expectedResult.AssignLiteral(u"concat(\'\',\"\'\",\'testing\"\')"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); ASSERT_TRUE(expectedResult.Equals(result)); } TEST(TestXPathGenerator, - TestQuoteArgumentWithDoubleQuoteAndASequenceOfSingleQuote) { + TestQuoteArgumentWithDoubleQuoteAndASequenceOfSingleQuote) +{ nsAutoString arg; arg.AssignLiteral(u"\'\'\'\'testing\""); nsAutoString expectedResult; expectedResult.AssignLiteral(u"concat(\'\',\"\'\'\'\'\",\'testing\"\')"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); ASSERT_TRUE(expectedResult.Equals(result)); } TEST(TestXPathGenerator, - TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuote) { + TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuote) +{ nsAutoString arg; arg.AssignLiteral(u"\'\'\'\'testing\'\'\'\'\'\'\""); nsAutoString expectedResult; expectedResult.AssignLiteral( u"concat(\'\',\"\'\'\'\'\",\'testing\',\"\'\'\'\'\'\'\",\'\"\')"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); ASSERT_TRUE(expectedResult.Equals(result)); } TEST(TestXPathGenerator, - TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuoteInMiddle) { + TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuoteInMiddle) +{ nsAutoString arg; arg.AssignLiteral(u"t\'\'\'\'estin\'\'\'\'\'\'\"g"); nsAutoString expectedResult; expectedResult.AssignLiteral( u"concat(\'t\',\"\'\'\'\'\",\'estin\',\"\'\'\'\'\'\'\",\'\"g\')"); nsAutoString result; XPathGenerator::QuoteArgument(arg, result); printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); ASSERT_TRUE(expectedResult.Equals(result)); } -TEST(TestXPathGenerator, TestEscapeNameWithNormalCharacters) { +TEST(TestXPathGenerator, TestEscapeNameWithNormalCharacters) +{ nsAutoString arg; arg.AssignLiteral(u"testing"); nsAutoString expectedResult; expectedResult.AssignLiteral(u"testing"); nsAutoString result; XPathGenerator::EscapeName(arg, result); ASSERT_TRUE(expectedResult.Equals(result)); } -TEST(TestXPathGenerator, TestEscapeNameWithSpecialCharacters) { +TEST(TestXPathGenerator, TestEscapeNameWithSpecialCharacters) +{ nsAutoString arg; arg.AssignLiteral(u"^testing!"); nsAutoString expectedResult; expectedResult.AssignLiteral(u"*[local-name()=\'^testing!\']"); nsAutoString result; XPathGenerator::EscapeName(arg, result);
--- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -432,17 +432,19 @@ Context::QuotaInitRunnable::Run() { // Explicitly cleanup here as the destructor could fire on any of // the threads we have bounced through. Clear(); break; } // ----- case STATE_WAIT_FOR_DIRECTORY_LOCK: - default: { MOZ_CRASH("unexpected state in QuotaInitRunnable"); } + default: { + MOZ_CRASH("unexpected state in QuotaInitRunnable"); + } } if (resolver->Resolved()) { Complete(resolver->Result()); } return NS_OK; }
--- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -888,17 +888,17 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_B NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CanvasRenderingContext2D) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -CanvasRenderingContext2D::ContextState::ContextState() = default; +CanvasRenderingContext2D::ContextState::ContextState() = default; CanvasRenderingContext2D::ContextState::ContextState(const ContextState& aOther) : fontGroup(aOther.fontGroup), fontLanguage(aOther.fontLanguage), fontFont(aOther.fontFont), gradientStyles(aOther.gradientStyles), patternStyles(aOther.patternStyles), colorStyles(aOther.colorStyles),
--- a/dom/canvas/WebGLContextVertices.cpp +++ b/dom/canvas/WebGLContextVertices.cpp @@ -397,18 +397,18 @@ void WebGLContext::VertexAttribAnyPointe gl->fVertexAttribIPointer(index, size, type, stride, reinterpret_cast<void*>(byteOffset)); } else { gl->fVertexAttribPointer(index, size, type, normalized, stride, reinterpret_cast<void*>(byteOffset)); } WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index]; - vd.VertexAttribPointer(isFuncInt, buffer, AutoAssertCast(size), type, normalized, stride, - byteOffset); + vd.VertexAttribPointer(isFuncInt, buffer, AutoAssertCast(size), type, + normalized, stride, byteOffset); mBoundVertexArray->InvalidateCaches(); } //////////////////////////////////////// void WebGLContext::VertexAttribDivisor(GLuint index, GLuint divisor) { const FuncScope funcScope(*this, "vertexAttribDivisor"); if (IsContextLost()) return;
--- a/dom/canvas/WebGLTexelConversions.h +++ b/dom/canvas/WebGLTexelConversions.h @@ -957,42 +957,44 @@ pack<WebGLTexelFormat::RG32F, WebGLTexel //////////////////////////////////////////////////////////////////////////////// // 3-channel formats template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { *dst = uint16_t(((src[0] & 0xF8) << 8) | ((src[1] & 0xFC) << 3) | - ((src[2] & 0xF8) >> 3)); + ((src[2] & 0xF8) >> 3)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] / 255.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); - *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xFC) << 3) | ((srcB & 0xF8) >> 3)); + *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xFC) << 3) | + ((srcB & 0xF8) >> 3)); } // FIXME: this routine is lossy and must be removed. template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); - *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xFC) << 3) | ((srcB & 0xF8) >> 3)); + *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xFC) << 3) | + ((srcB & 0xF8) >> 3)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGB8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst) { dst[0] = src[0]; dst[1] = src[1]; @@ -1116,80 +1118,80 @@ pack<WebGLTexelFormat::RGB32F, WebGLTexe } //////////////////////////////////////////////////////////////////////////////// // 4-channel formats template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { - *dst = uint16_t(((src[0] & 0xF0) << 8) | ((src[1] & 0xF0) << 4) | (src[2] & 0xF0) | - (src[3] >> 4)); + *dst = uint16_t(((src[0] & 0xF0) << 8) | ((src[1] & 0xF0) << 4) | + (src[2] & 0xF0) | (src[3] >> 4)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] / 255.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); *dst = uint16_t(((srcR & 0xF0) << 8) | ((srcG & 0xF0) << 4) | (srcB & 0xF0) | - (src[3] >> 4)); + (src[3] >> 4)); } // FIXME: this routine is lossy and must be removed. template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); *dst = uint16_t(((srcR & 0xF0) << 8) | ((srcG & 0xF0) << 4) | (srcB & 0xF0) | - (src[3] >> 4)); + (src[3] >> 4)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { *dst = uint16_t(((src[0] & 0xF8) << 8) | ((src[1] & 0xF8) << 3) | - ((src[2] & 0xF8) >> 2) | (src[3] >> 7)); + ((src[2] & 0xF8) >> 2) | (src[3] >> 7)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] / 255.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); - *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xF8) << 3) | ((srcB & 0xF8) >> 2) | - (src[3] >> 7)); + *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xF8) << 3) | + ((srcB & 0xF8) >> 2) | (src[3] >> 7)); } // FIXME: this routine is lossy and must be removed. template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst) { float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f; uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor); uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor); uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor); - *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xF8) << 3) | ((srcB & 0xF8) >> 2) | - (src[3] >> 7)); + *dst = uint16_t(((srcR & 0xF8) << 8) | ((srcG & 0xF8) << 3) | + ((srcB & 0xF8) >> 2) | (src[3] >> 7)); } template <> MOZ_ALWAYS_INLINE void pack<WebGLTexelFormat::RGBA8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst) { dst[0] = src[0]; dst[1] = src[1];
--- a/dom/canvas/WebGLTexture.h +++ b/dom/canvas/WebGLTexture.h @@ -265,17 +265,18 @@ class WebGLTexture final : public nsWrap GLenum rawTexImageTarget = texImageTarget.get(); switch (rawTexImageTarget) { case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X: case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - return AutoAssertCast(rawTexImageTarget - LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X); + return AutoAssertCast(rawTexImageTarget - + LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X); default: return 0; } } auto& ImageInfoAtFace(uint8_t face, uint32_t level) { MOZ_ASSERT(face < mFaceCount);
--- a/dom/canvas/WebGLTypes.h +++ b/dom/canvas/WebGLTypes.h @@ -55,32 +55,32 @@ inline void* calloc(const ForbidNarrowin const ForbidNarrowing<size_t> size) { return ::calloc(size_t(n), size_t(size)); } // - namespace detail { -template<typename From> +template <typename From> class AutoAssertCastT final { const From mVal; -public: - explicit AutoAssertCastT(const From val) : mVal(val) { } + public: + explicit AutoAssertCastT(const From val) : mVal(val) {} - template<typename To> + template <typename To> operator To() const { return AssertedCast<To>(mVal); } }; } // namespace detail -template<typename From> +template <typename From> inline auto AutoAssertCast(const From val) { return detail::AutoAssertCastT<From>(val); } /* * Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires * emulating the vertex attrib 0 array when it's not enabled. Indeed, * OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
--- a/dom/canvas/gtest/TestImageBitmapColorUtils.cpp +++ b/dom/canvas/gtest/TestImageBitmapColorUtils.cpp @@ -715,17 +715,18 @@ class LabData : public SimpleImage<float mData[i + 7] = 0.0f; mData[i + 8] = 0.0f; } }; /* * From RGB24. */ -TEST(ImageBitmapColorUtils, RGB24ToBGR24_) { +TEST(ImageBitmapColorUtils, RGB24ToBGR24_) +{ const RGB24Data srcData; const BGR24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = RGB24ToBGR24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -740,17 +741,18 @@ TEST(ImageBitmapColorUtils, RGB24ToBGR24 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, RGB24ToRGBA32) { +TEST(ImageBitmapColorUtils, RGB24ToRGBA32) +{ const RGB24Data srcData; const RGBA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = RGB24ToRGBA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -768,17 +770,18 @@ TEST(ImageBitmapColorUtils, RGB24ToRGBA3 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], 255); } } } -TEST(ImageBitmapColorUtils, RGB24ToBGRA32) { +TEST(ImageBitmapColorUtils, RGB24ToBGRA32) +{ const RGB24Data srcData; const BGRA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = RGB24ToBGRA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -840,17 +843,18 @@ TEST(ImageBitmapColorUtils, RGB24ToBGRA3 // 1, 1); // // printf_stderr( // "\nlibyuv: (%hhu, %hhu, %hhu) --> (%hhu, %hhu, %hhu, %hhu) \n", // yuvPixel[0], yuvPixel[1], yuvPixel[2], // gbaPixel[0], rgbaPixel[1], rgbaPixel[2], rgbaPixel[3]); //} -TEST(ImageBitmapColorUtils, RGB24ToYUV444P) { +TEST(ImageBitmapColorUtils, RGB24ToYUV444P) +{ const RGB24Data srcData; const YUV444PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride); int rv = RGB24ToYUV444P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -867,17 +871,18 @@ TEST(ImageBitmapColorUtils, RGB24ToYUV44 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGB24ToYUV422P) { +TEST(ImageBitmapColorUtils, RGB24ToYUV422P) +{ const RGB24Data srcData; const YUV422PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride); int rv = RGB24ToYUV422P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -899,17 +904,18 @@ TEST(ImageBitmapColorUtils, RGB24ToYUV42 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGB24ToYUV420P) { +TEST(ImageBitmapColorUtils, RGB24ToYUV420P) +{ const RGB24Data srcData; const YUV420PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride); @@ -932,17 +938,18 @@ TEST(ImageBitmapColorUtils, RGB24ToYUV42 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGB24ToNV12) { +TEST(ImageBitmapColorUtils, RGB24ToNV12) +{ const RGB24Data srcData; const NV12Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = RGB24ToNV12(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -963,17 +970,18 @@ TEST(ImageBitmapColorUtils, RGB24ToNV12) EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, RGB24ToNV21) { +TEST(ImageBitmapColorUtils, RGB24ToNV21) +{ const RGB24Data srcData; const NV21Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = RGB24ToNV21(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -994,17 +1002,18 @@ TEST(ImageBitmapColorUtils, RGB24ToNV21) EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, RGB24ToHSV) { +TEST(ImageBitmapColorUtils, RGB24ToHSV) +{ const RGB24Data srcData; const HSVData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = RGB24ToHSV(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1017,17 +1026,18 @@ TEST(ImageBitmapColorUtils, RGB24ToHSV) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, RGB24ToLab) { +TEST(ImageBitmapColorUtils, RGB24ToLab) +{ const RGB24Data srcData; const LabData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = RGB24ToLab(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1040,17 +1050,18 @@ TEST(ImageBitmapColorUtils, RGB24ToLab) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, RGB24ToGray8) { +TEST(ImageBitmapColorUtils, RGB24ToGray8) +{ const RGB24Data srcData; const GrayData dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, 1); int rv = RGB24ToGray8(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1063,17 +1074,18 @@ TEST(ImageBitmapColorUtils, RGB24ToGray8 } } } /* * From BGR24. */ -TEST(ImageBitmapColorUtils, BGR24ToRGB24_) { +TEST(ImageBitmapColorUtils, BGR24ToRGB24_) +{ const BGR24Data srcData; const RGB24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = BGR24ToRGB24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1088,17 +1100,18 @@ TEST(ImageBitmapColorUtils, BGR24ToRGB24 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, BGR24ToRGBA32) { +TEST(ImageBitmapColorUtils, BGR24ToRGBA32) +{ const BGR24Data srcData; const RGBA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = BGR24ToRGBA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1116,17 +1129,18 @@ TEST(ImageBitmapColorUtils, BGR24ToRGBA3 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], 255); } } } -TEST(ImageBitmapColorUtils, BGR24ToBGRA32) { +TEST(ImageBitmapColorUtils, BGR24ToBGRA32) +{ const BGR24Data srcData; const BGRA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = BGR24ToBGRA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1144,17 +1158,18 @@ TEST(ImageBitmapColorUtils, BGR24ToBGRA3 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], 255); } } } -TEST(ImageBitmapColorUtils, BGR24ToYUV444P) { +TEST(ImageBitmapColorUtils, BGR24ToYUV444P) +{ const BGR24Data srcData; const YUV444PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride); int rv = BGR24ToYUV444P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1171,17 +1186,18 @@ TEST(ImageBitmapColorUtils, BGR24ToYUV44 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGR24ToYUV422P) { +TEST(ImageBitmapColorUtils, BGR24ToYUV422P) +{ const BGR24Data srcData; const YUV422PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride); int rv = BGR24ToYUV422P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1203,17 +1219,18 @@ TEST(ImageBitmapColorUtils, BGR24ToYUV42 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGR24ToYUV420P) { +TEST(ImageBitmapColorUtils, BGR24ToYUV420P) +{ const BGR24Data srcData; const YUV420PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride); @@ -1236,17 +1253,18 @@ TEST(ImageBitmapColorUtils, BGR24ToYUV42 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGR24ToNV12) { +TEST(ImageBitmapColorUtils, BGR24ToNV12) +{ const BGR24Data srcData; const NV12Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = BGR24ToNV12(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1267,17 +1285,18 @@ TEST(ImageBitmapColorUtils, BGR24ToNV12) EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, BGR24ToNV21) { +TEST(ImageBitmapColorUtils, BGR24ToNV21) +{ const BGR24Data srcData; const NV21Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = BGR24ToNV21(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1298,17 +1317,18 @@ TEST(ImageBitmapColorUtils, BGR24ToNV21) EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, BGR24ToHSV) { +TEST(ImageBitmapColorUtils, BGR24ToHSV) +{ const BGR24Data srcData; const HSVData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = BGR24ToHSV(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1321,17 +1341,18 @@ TEST(ImageBitmapColorUtils, BGR24ToHSV) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, BGR24ToLab) { +TEST(ImageBitmapColorUtils, BGR24ToLab) +{ const BGR24Data srcData; const LabData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = BGR24ToLab(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1344,17 +1365,18 @@ TEST(ImageBitmapColorUtils, BGR24ToLab) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, BGR24ToGray8) { +TEST(ImageBitmapColorUtils, BGR24ToGray8) +{ const BGR24Data srcData; const GrayData dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, 1); int rv = BGR24ToGray8(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1366,17 +1388,18 @@ TEST(ImageBitmapColorUtils, BGR24ToGray8 dstData.mData[i * dstData.mStride + j]); } } } /* * From RGBA32. */ -TEST(ImageBitmapColorUtils, RGBA32ToRGB24) { +TEST(ImageBitmapColorUtils, RGBA32ToRGB24) +{ const RGBA32Data srcData; const RGB24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = RGBA32ToRGB24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1391,17 +1414,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToRGB2 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToBGR24) { +TEST(ImageBitmapColorUtils, RGBA32ToBGR24) +{ const RGBA32Data srcData; const BGR24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = RGBA32ToBGR24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1416,17 +1440,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToBGR2 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToYUV444P) { +TEST(ImageBitmapColorUtils, RGBA32ToYUV444P) +{ const RGBA32Data srcData; const YUV444PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride); int rv = RGBA32ToYUV444P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1443,17 +1468,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToYUV422P) { +TEST(ImageBitmapColorUtils, RGBA32ToYUV422P) +{ const RGBA32Data srcData; const YUV422PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride); int rv = RGBA32ToYUV422P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1475,17 +1501,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToYUV420P) { +TEST(ImageBitmapColorUtils, RGBA32ToYUV420P) +{ const RGBA32Data srcData; const YUV420PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride); @@ -1508,17 +1535,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToNV12) { +TEST(ImageBitmapColorUtils, RGBA32ToNV12) +{ const RGBA32Data srcData; const NV12Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = RGBA32ToNV12(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1539,17 +1567,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToNV12 EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToNV21) { +TEST(ImageBitmapColorUtils, RGBA32ToNV21) +{ const RGBA32Data srcData; const NV21Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = RGBA32ToNV21(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1570,17 +1599,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToNV21 EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, RGBA32ToHSV) { +TEST(ImageBitmapColorUtils, RGBA32ToHSV) +{ const RGBA32Data srcData; const HSVData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = RGBA32ToHSV(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1593,17 +1623,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToHSV) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, RGBA32ToLab) { +TEST(ImageBitmapColorUtils, RGBA32ToLab) +{ const RGBA32Data srcData; const LabData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = RGBA32ToLab(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1616,17 +1647,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToLab) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, RGBA32ToGray8) { +TEST(ImageBitmapColorUtils, RGBA32ToGray8) +{ const RGBA32Data srcData; const GrayData dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, 1); int rv = RGBA32ToGray8(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1638,17 +1670,18 @@ TEST(ImageBitmapColorUtils, RGBA32ToGray dstData.mData[i * dstData.mStride + j]); } } } /* * From BGRA32. */ -TEST(ImageBitmapColorUtils, BGRA32ToRGB24) { +TEST(ImageBitmapColorUtils, BGRA32ToRGB24) +{ const BGRA32Data srcData; const RGB24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = BGRA32ToRGB24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1663,17 +1696,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToRGB2 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToBGR24) { +TEST(ImageBitmapColorUtils, BGRA32ToBGR24) +{ const BGRA32Data srcData; const BGR24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = BGRA32ToBGR24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -1688,17 +1722,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToBGR2 dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.mData[i * dstData.mStride + j * dstData.mChannelCount + 2]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToYUV444P) { +TEST(ImageBitmapColorUtils, BGRA32ToYUV444P) +{ const BGRA32Data srcData; const YUV444PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth, srcData.mHeight, srcData.mStride); int rv = BGRA32ToYUV444P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1715,17 +1750,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToYUV422P) { +TEST(ImageBitmapColorUtils, BGRA32ToYUV422P) +{ const BGRA32Data srcData; const YUV422PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight, srcData.mStride); int rv = BGRA32ToYUV422P(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1747,17 +1783,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToYUV420P) { +TEST(ImageBitmapColorUtils, BGRA32ToYUV420P) +{ const BGRA32Data srcData; const YUV420PData dstData; YUVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride); @@ -1780,17 +1817,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToYUV4 EXPECT_EQ(dstData.UBuffer()[i * dstData.mUStride + j], result_.UBuffer()[i * result_.mUStride + j]); EXPECT_EQ(dstData.VBuffer()[i * dstData.mVStride + j], result_.VBuffer()[i * result_.mVStride + j]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToNV12) { +TEST(ImageBitmapColorUtils, BGRA32ToNV12) +{ const BGRA32Data srcData; const NV12Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = BGRA32ToNV12(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1811,17 +1849,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToNV12 EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToNV21) { +TEST(ImageBitmapColorUtils, BGRA32ToNV21) +{ const BGRA32Data srcData; const NV21Data dstData; NVImage result_(srcData.mWidth, srcData.mHeight, srcData.mStride, srcData.mWidth / 2 + 1, srcData.mHeight / 2 + 1, srcData.mStride + 10); int rv = BGRA32ToNV21(srcData.mData, srcData.mStride, result_.YBuffer(), @@ -1842,17 +1881,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToNV21 EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 0], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 0]); EXPECT_EQ(dstData.UVBuffer()[i * dstData.mUVStride + j * 2 + 1], result_.UVBuffer()[i * result_.mUVStride + j * 2 + 1]); } } } -TEST(ImageBitmapColorUtils, BGRA32ToHSV) { +TEST(ImageBitmapColorUtils, BGRA32ToHSV) +{ const BGRA32Data srcData; const HSVData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = BGRA32ToHSV(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1865,17 +1905,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToHSV) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, BGRA32ToLab) { +TEST(ImageBitmapColorUtils, BGRA32ToLab) +{ const BGRA32Data srcData; const LabData dstData; SimpleImage<float> result_(srcData.mWidth, srcData.mHeight, 3); int rv = BGRA32ToLab(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1888,17 +1929,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToLab) const double expectedValue = dstData.GetPixelValue(i, j, c); const double diff = std::abs(actualValue - expectedValue); EXPECT_LT(diff, 1.0); } } } } -TEST(ImageBitmapColorUtils, BGRA32ToGray8) { +TEST(ImageBitmapColorUtils, BGRA32ToGray8) +{ const BGRA32Data srcData; const GrayData dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, 1); int rv = BGRA32ToGray8(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1910,17 +1952,18 @@ TEST(ImageBitmapColorUtils, BGRA32ToGray dstData.mData[i * dstData.mStride + j]); } } } /* * From YUV444P. */ -TEST(ImageBitmapColorUtils, YUV444PToRGB24) { +TEST(ImageBitmapColorUtils, YUV444PToRGB24) +{ const YUV444PData srcData; const RGBA32DataFromYUV444PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV444PToRGB24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1936,17 +1979,18 @@ TEST(ImageBitmapColorUtils, YUV444PToRGB dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[2]); } } } -TEST(ImageBitmapColorUtils, YUV444PToBGR24) { +TEST(ImageBitmapColorUtils, YUV444PToBGR24) +{ const YUV444PData srcData; const RGBA32DataFromYUV444PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV444PToBGR24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -1962,17 +2006,18 @@ TEST(ImageBitmapColorUtils, YUV444PToBGR dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[0]); } } } -TEST(ImageBitmapColorUtils, YUV444PToRGBA32) { +TEST(ImageBitmapColorUtils, YUV444PToRGBA32) +{ const YUV444PData srcData; const RGBA32DataFromYUV444PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV444PToRGBA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -1992,17 +2037,18 @@ TEST(ImageBitmapColorUtils, YUV444PToRGB dstData.GetPixel(j, i)[2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV444PToBGRA32) { +TEST(ImageBitmapColorUtils, YUV444PToBGRA32) +{ const YUV444PData srcData; const RGBA32DataFromYUV444PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV444PToBGRA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -2022,17 +2068,18 @@ TEST(ImageBitmapColorUtils, YUV444PToBGR dstData.GetPixel(j, i)[0]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV444PToGray8) { +TEST(ImageBitmapColorUtils, YUV444PToGray8) +{ const YUV444PData srcData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 1); int rv = YUV444PToGray8(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2044,17 +2091,18 @@ TEST(ImageBitmapColorUtils, YUV444PToGra srcData.YBuffer()[i * srcData.mYStride + j]); } } } /* * From YUV422P. */ -TEST(ImageBitmapColorUtils, YUV422PToRGB24) { +TEST(ImageBitmapColorUtils, YUV422PToRGB24) +{ const YUV422PData srcData; const RGBA32DataFromYUV422PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV422PToRGB24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2070,17 +2118,18 @@ TEST(ImageBitmapColorUtils, YUV422PToRGB dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[2]); } } } -TEST(ImageBitmapColorUtils, YUV422PToBGR24) { +TEST(ImageBitmapColorUtils, YUV422PToBGR24) +{ const YUV422PData srcData; const RGBA32DataFromYUV422PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV422PToBGR24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2096,17 +2145,18 @@ TEST(ImageBitmapColorUtils, YUV422PToBGR dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[0]); } } } -TEST(ImageBitmapColorUtils, YUV422PToRGBA32) { +TEST(ImageBitmapColorUtils, YUV422PToRGBA32) +{ const YUV422PData srcData; const RGBA32DataFromYUV422PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV422PToRGBA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -2126,17 +2176,18 @@ TEST(ImageBitmapColorUtils, YUV422PToRGB dstData.GetPixel(j, i)[2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV422PToBGRA32) { +TEST(ImageBitmapColorUtils, YUV422PToBGRA32) +{ const YUV422PData srcData; const RGBA32DataFromYUV422PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV422PToBGRA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -2156,17 +2207,18 @@ TEST(ImageBitmapColorUtils, YUV422PToBGR dstData.GetPixel(j, i)[0]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV422PToGray8) { +TEST(ImageBitmapColorUtils, YUV422PToGray8) +{ const YUV422PData srcData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 1); int rv = YUV422PToGray8(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2178,17 +2230,18 @@ TEST(ImageBitmapColorUtils, YUV422PToGra srcData.YBuffer()[i * srcData.mYStride + j]); } } } /* * From YUV420P. */ -TEST(ImageBitmapColorUtils, YUV420PToRGB24) { +TEST(ImageBitmapColorUtils, YUV420PToRGB24) +{ const YUV420PData srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV420PToRGB24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2204,17 +2257,18 @@ TEST(ImageBitmapColorUtils, YUV420PToRGB dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[2]); } } } -TEST(ImageBitmapColorUtils, YUV420PToBGR24) { +TEST(ImageBitmapColorUtils, YUV420PToBGR24) +{ const YUV420PData srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = YUV420PToBGR24(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2230,17 +2284,18 @@ TEST(ImageBitmapColorUtils, YUV420PToBGR dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[0]); } } } -TEST(ImageBitmapColorUtils, YUV420PToRGBA32) { +TEST(ImageBitmapColorUtils, YUV420PToRGBA32) +{ const YUV420PData srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV420PToRGBA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -2260,17 +2315,18 @@ TEST(ImageBitmapColorUtils, YUV420PToRGB dstData.GetPixel(j, i)[2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV420PToBGRA32) { +TEST(ImageBitmapColorUtils, YUV420PToBGRA32) +{ const YUV420PData srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = YUV420PToBGRA32(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, @@ -2290,17 +2346,18 @@ TEST(ImageBitmapColorUtils, YUV420PToBGR dstData.GetPixel(j, i)[0]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, YUV420PToGray8) { +TEST(ImageBitmapColorUtils, YUV420PToGray8) +{ const YUV420PData srcData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 1); int rv = YUV420PToGray8(srcData.YBuffer(), srcData.mYStride, srcData.UBuffer(), srcData.mUStride, srcData.VBuffer(), srcData.mVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2312,17 +2369,18 @@ TEST(ImageBitmapColorUtils, YUV420PToGra srcData.YBuffer()[i * srcData.mYStride + j]); } } } /* * From NV12. */ -TEST(ImageBitmapColorUtils, NV12ToRGB24) { +TEST(ImageBitmapColorUtils, NV12ToRGB24) +{ const NV12Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = NV12ToRGB24(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2337,17 +2395,18 @@ TEST(ImageBitmapColorUtils, NV12ToRGB24) dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[2]); } } } -TEST(ImageBitmapColorUtils, NV12ToBGR24) { +TEST(ImageBitmapColorUtils, NV12ToBGR24) +{ const NV12Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = NV12ToBGR24(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2362,17 +2421,18 @@ TEST(ImageBitmapColorUtils, NV12ToBGR24) dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[0]); } } } -TEST(ImageBitmapColorUtils, NV12ToRGBA32) { +TEST(ImageBitmapColorUtils, NV12ToRGBA32) +{ const NV12Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = NV12ToRGBA32(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2391,17 +2451,18 @@ TEST(ImageBitmapColorUtils, NV12ToRGBA32 dstData.GetPixel(j, i)[2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, NV12ToBGRA32) { +TEST(ImageBitmapColorUtils, NV12ToBGRA32) +{ const NV12Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = NV12ToBGRA32(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2420,17 +2481,18 @@ TEST(ImageBitmapColorUtils, NV12ToBGRA32 dstData.GetPixel(j, i)[0]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, NV12ToGray8) { +TEST(ImageBitmapColorUtils, NV12ToGray8) +{ const NV12Data srcData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 1); int rv = NV12ToGray8(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2441,17 +2503,18 @@ TEST(ImageBitmapColorUtils, NV12ToGray8) srcData.YBuffer()[i * srcData.mYStride + j]); } } } /* * From NV21. */ -TEST(ImageBitmapColorUtils, NV21ToRGB24) { +TEST(ImageBitmapColorUtils, NV21ToRGB24) +{ const NV21Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = NV21ToRGB24(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2466,17 +2529,18 @@ TEST(ImageBitmapColorUtils, NV21ToRGB24) dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[2]); } } } -TEST(ImageBitmapColorUtils, NV21ToBGR24) { +TEST(ImageBitmapColorUtils, NV21ToBGR24) +{ const NV21Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 3); int rv = NV21ToBGR24(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2491,17 +2555,18 @@ TEST(ImageBitmapColorUtils, NV21ToBGR24) dstData.GetPixel(j, i)[1]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 2], dstData.GetPixel(j, i)[0]); } } } -TEST(ImageBitmapColorUtils, NV21ToRGBA32) { +TEST(ImageBitmapColorUtils, NV21ToRGBA32) +{ const NV21Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = NV21ToRGBA32(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2520,17 +2585,18 @@ TEST(ImageBitmapColorUtils, NV21ToRGBA32 dstData.GetPixel(j, i)[2]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, NV21ToBGRA32) { +TEST(ImageBitmapColorUtils, NV21ToBGRA32) +{ const NV21Data srcData; const RGBA32DataFromYUV420PData dstData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, dstData.mChannelCount); int rv = NV21ToBGRA32(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2549,17 +2615,18 @@ TEST(ImageBitmapColorUtils, NV21ToBGRA32 dstData.GetPixel(j, i)[0]); EXPECT_EQ( result_.mData[i * result_.mStride + j * result_.mChannelCount + 3], dstData.GetPixel(j, i)[3]); } } } -TEST(ImageBitmapColorUtils, NV21ToGray8) { +TEST(ImageBitmapColorUtils, NV21ToGray8) +{ const NV21Data srcData; SimpleImage<uint8_t> result_(srcData.mYWidth, srcData.mYHeight, 1); int rv = NV21ToGray8(srcData.YBuffer(), srcData.mYStride, srcData.UVBuffer(), srcData.mUVStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); ASSERT_TRUE(rv == 0); @@ -2570,17 +2637,18 @@ TEST(ImageBitmapColorUtils, NV21ToGray8) srcData.YBuffer()[i * srcData.mYStride + j]); } } } /* * From HSV. */ -TEST(ImageBitmapColorUtils, HSVToRGB24) { +TEST(ImageBitmapColorUtils, HSVToRGB24) +{ const HSVData srcData; const RGB24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = HSVToRGB24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2591,17 +2659,18 @@ TEST(ImageBitmapColorUtils, HSVToRGB24) for (int c = 0; c < dstData.mChannelCount; ++c) { EXPECT_EQ(result_.GetPixelValue(i, j, c), dstData.GetPixelValue(i, j, c)); } } } } -TEST(ImageBitmapColorUtils, HSVToBGR24) { +TEST(ImageBitmapColorUtils, HSVToBGR24) +{ const HSVData srcData; const BGR24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = HSVToBGR24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2612,17 +2681,18 @@ TEST(ImageBitmapColorUtils, HSVToBGR24) for (int c = 0; c < dstData.mChannelCount; ++c) { EXPECT_EQ(result_.GetPixelValue(i, j, c), dstData.GetPixelValue(i, j, c)); } } } } -TEST(ImageBitmapColorUtils, HSVToRGBA32) { +TEST(ImageBitmapColorUtils, HSVToRGBA32) +{ const HSVData srcData; const RGBA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = HSVToRGBA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2633,17 +2703,18 @@ TEST(ImageBitmapColorUtils, HSVToRGBA32) for (int c = 0; c < dstData.mChannelCount; ++c) { EXPECT_EQ(result_.GetPixelValue(i, j, c), dstData.GetPixelValue(i, j, c)); } } } } -TEST(ImageBitmapColorUtils, HSVToBGRA32) { +TEST(ImageBitmapColorUtils, HSVToBGRA32) +{ const HSVData srcData; const BGRA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = HSVToBGRA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2657,17 +2728,18 @@ TEST(ImageBitmapColorUtils, HSVToBGRA32) } } } } /* * From Lab. */ -TEST(ImageBitmapColorUtils, LabToRGB24) { +TEST(ImageBitmapColorUtils, LabToRGB24) +{ const LabData srcData; const RGB24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = LabToRGB24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2680,17 +2752,18 @@ TEST(ImageBitmapColorUtils, LabToRGB24) const uint8_t expectedValue = dstData.GetPixelValue(i, j, c); const int diff = std::abs(actualValue - expectedValue); EXPECT_LE(diff, 1); } } } } -TEST(ImageBitmapColorUtils, LabToBGR24) { +TEST(ImageBitmapColorUtils, LabToBGR24) +{ const LabData srcData; const BGR24Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = LabToBGR24(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2703,17 +2776,18 @@ TEST(ImageBitmapColorUtils, LabToBGR24) const uint8_t expectedValue = dstData.GetPixelValue(i, j, c); const int diff = std::abs(actualValue - expectedValue); EXPECT_LE(diff, 1); } } } } -TEST(ImageBitmapColorUtils, LabToRGBA32) { +TEST(ImageBitmapColorUtils, LabToRGBA32) +{ const LabData srcData; const RGBA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = LabToRGBA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight); @@ -2726,17 +2800,18 @@ TEST(ImageBitmapColorUtils, LabToRGBA32) const uint8_t expectedValue = dstData.GetPixelValue(i, j, c); const int diff = std::abs(actualValue - expectedValue); EXPECT_LE(diff, 1); } } } } -TEST(ImageBitmapColorUtils, LabToBGRA32) { +TEST(ImageBitmapColorUtils, LabToBGRA32) +{ const LabData srcData; const BGRA32Data dstData; SimpleImage<uint8_t> result_(srcData.mWidth, srcData.mHeight, dstData.mChannelCount); int rv = LabToBGRA32(srcData.mData, srcData.mStride, result_.mData, result_.mStride, result_.mWidth, result_.mHeight);
--- a/dom/clients/api/Client.cpp +++ b/dom/clients/api/Client.cpp @@ -145,29 +145,30 @@ already_AddRefed<Promise> Client::Focus( EnsureHandle(); IPCClientInfo ipcClientInfo(mData->info()); auto holder = MakeRefPtr<DOMMozPromiseRequestHolder<ClientStatePromise>>(mGlobal); mHandle->Focus() - ->Then(mGlobal->EventTargetFor(TaskCategory::Other), __func__, - [ipcClientInfo, holder, outerPromise](const ClientState& aResult) { - holder->Complete(); - NS_ENSURE_TRUE_VOID(holder->GetParentObject()); - RefPtr<Client> newClient = new Client( - holder->GetParentObject(), - ClientInfoAndState(ipcClientInfo, aResult.ToIPC())); - outerPromise->MaybeResolve(newClient); - }, - [holder, outerPromise](nsresult aResult) { - holder->Complete(); - outerPromise->MaybeReject(aResult); - }) + ->Then( + mGlobal->EventTargetFor(TaskCategory::Other), __func__, + [ipcClientInfo, holder, outerPromise](const ClientState& aResult) { + holder->Complete(); + NS_ENSURE_TRUE_VOID(holder->GetParentObject()); + RefPtr<Client> newClient = + new Client(holder->GetParentObject(), + ClientInfoAndState(ipcClientInfo, aResult.ToIPC())); + outerPromise->MaybeResolve(newClient); + }, + [holder, outerPromise](nsresult aResult) { + holder->Complete(); + outerPromise->MaybeReject(aResult); + }) ->Track(*holder); return outerPromise.forget(); } already_AddRefed<Promise> Client::Navigate(const nsAString& aURL, ErrorResult& aRv) { MOZ_ASSERT(!NS_IsMainThread());
--- a/dom/clients/api/ClientDOMUtil.h +++ b/dom/clients/api/ClientDOMUtil.h @@ -27,24 +27,25 @@ void StartClientManagerOp(Func aFunc, co nsCOMPtr<nsISerialEventTarget> target = aGlobal->EventTargetFor(TaskCategory::Other); auto holder = MakeRefPtr<DOMMozPromiseRequestHolder<ClientOpPromise>>(aGlobal); aFunc(aArg, target) - ->Then(target, __func__, - [aResolve, holder](const ClientOpResult& aResult) { - holder->Complete(); - aResolve(aResult); - }, - [aReject, holder](nsresult aResult) { - holder->Complete(); - aReject(aResult); - }) + ->Then( + target, __func__, + [aResolve, holder](const ClientOpResult& aResult) { + holder->Complete(); + aResolve(aResult); + }, + [aReject, holder](nsresult aResult) { + holder->Complete(); + aReject(aResult); + }) ->Track(*holder); } } // namespace dom } // namespace mozilla #endif // _mozilla_dom_ClientDOMUtil_h
--- a/dom/clients/api/Clients.cpp +++ b/dom/clients/api/Clients.cpp @@ -75,40 +75,41 @@ already_AddRefed<Promise> Clients::Get(c RefPtr<ClientOpPromise> innerPromise = ClientManager::GetInfoAndState( ClientGetInfoAndStateArgs(id, principalInfo), target); nsCString scope = workerPrivate->ServiceWorkerScope(); auto holder = MakeRefPtr<DOMMozPromiseRequestHolder<ClientOpPromise>>(mGlobal); innerPromise - ->Then(target, __func__, - [outerPromise, holder, scope](const ClientOpResult& aResult) { - holder->Complete(); - NS_ENSURE_TRUE_VOID(holder->GetParentObject()); - RefPtr<Client> client = new Client( - holder->GetParentObject(), aResult.get_ClientInfoAndState()); - if (client->GetStorageAccess() == - nsContentUtils::StorageAccess::eAllow) { - outerPromise->MaybeResolve(std::move(client)); - return; - } - nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction( - "Clients::Get() storage denied", [scope] { - ServiceWorkerManager::LocalizeAndReportToAllClients( - scope, "ServiceWorkerGetClientStorageError", - nsTArray<nsString>()); - }); - SystemGroup::Dispatch(TaskCategory::Other, r.forget()); - outerPromise->MaybeResolveWithUndefined(); - }, - [outerPromise, holder](nsresult aResult) { - holder->Complete(); - outerPromise->MaybeResolveWithUndefined(); - }) + ->Then( + target, __func__, + [outerPromise, holder, scope](const ClientOpResult& aResult) { + holder->Complete(); + NS_ENSURE_TRUE_VOID(holder->GetParentObject()); + RefPtr<Client> client = new Client( + holder->GetParentObject(), aResult.get_ClientInfoAndState()); + if (client->GetStorageAccess() == + nsContentUtils::StorageAccess::eAllow) { + outerPromise->MaybeResolve(std::move(client)); + return; + } + nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction( + "Clients::Get() storage denied", [scope] { + ServiceWorkerManager::LocalizeAndReportToAllClients( + scope, "ServiceWorkerGetClientStorageError", + nsTArray<nsString>()); + }); + SystemGroup::Dispatch(TaskCategory::Other, r.forget()); + outerPromise->MaybeResolveWithUndefined(); + }, + [outerPromise, holder](nsresult aResult) { + holder->Complete(); + outerPromise->MaybeResolveWithUndefined(); + }) ->Track(*holder); return outerPromise.forget(); } namespace { class MatchAllComparator final {
--- a/dom/clients/manager/ClientHandle.cpp +++ b/dom/clients/manager/ClientHandle.cpp @@ -105,39 +105,41 @@ RefPtr<GenericPromise> ClientHandle::Con RefPtr<GenericPromise::Private> outerPromise = new GenericPromise::Private(__func__); // We should never have a cross-origin controller. Since this would be // same-origin policy violation we do a full release assertion here. MOZ_RELEASE_ASSERT(ClientMatchPrincipalInfo(mClientInfo.PrincipalInfo(), aServiceWorker.PrincipalInfo())); - StartOp(ClientControlledArgs(aServiceWorker.ToIPC()), - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Resolve(true, __func__); - }, - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Reject(aResult.get_nsresult(), __func__); - }); + StartOp( + ClientControlledArgs(aServiceWorker.ToIPC()), + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Resolve(true, __func__); + }, + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Reject(aResult.get_nsresult(), __func__); + }); return outerPromise.forget(); } RefPtr<ClientStatePromise> ClientHandle::Focus() { RefPtr<ClientStatePromise::Private> outerPromise = new ClientStatePromise::Private(__func__); - StartOp(ClientFocusArgs(), - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Resolve( - ClientState::FromIPC(aResult.get_IPCClientState()), __func__); - }, - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Reject(aResult.get_nsresult(), __func__); - }); + StartOp( + ClientFocusArgs(), + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Resolve( + ClientState::FromIPC(aResult.get_IPCClientState()), __func__); + }, + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Reject(aResult.get_nsresult(), __func__); + }); return outerPromise.forget(); } RefPtr<GenericPromise> ClientHandle::PostMessage( StructuredCloneData& aData, const ServiceWorkerDescriptor& aSource) { if (IsShutdown()) { return GenericPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR, @@ -151,23 +153,24 @@ RefPtr<GenericPromise> ClientHandle::Pos GetActor()->Manager()->Manager(), args.clonedData())) { return GenericPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__); } RefPtr<GenericPromise::Private> outerPromise = new GenericPromise::Private(__func__); - StartOp(args, - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Resolve(true, __func__); - }, - [outerPromise](const ClientOpResult& aResult) { - outerPromise->Reject(aResult.get_nsresult(), __func__); - }); + StartOp( + args, + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Resolve(true, __func__); + }, + [outerPromise](const ClientOpResult& aResult) { + outerPromise->Reject(aResult.get_nsresult(), __func__); + }); return outerPromise.forget(); } RefPtr<GenericPromise> ClientHandle::OnDetach() { NS_ASSERT_OWNINGTHREAD(ClientSource); if (!mDetachPromise) {
--- a/dom/clients/manager/ClientHandleOpParent.cpp +++ b/dom/clients/manager/ClientHandleOpParent.cpp @@ -57,22 +57,23 @@ void ClientHandleOpParent::Init(const Cl // Other argument types can just be forwarded straight through. else { p = source->StartOp(aArgs); } // Capturing 'this' is safe here because we disconnect the promise in // ActorDestroy() which ensures neither lambda is called if the actor // is destroyed before the source operation completes. - p->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this](const ClientOpResult& aResult) { - mPromiseRequestHolder.Complete(); - Unused << PClientHandleOpParent::Send__delete__(this, aResult); - }, - [this](nsresult aRv) { - mPromiseRequestHolder.Complete(); - Unused << PClientHandleOpParent::Send__delete__(this, aRv); - }) + p->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this](const ClientOpResult& aResult) { + mPromiseRequestHolder.Complete(); + Unused << PClientHandleOpParent::Send__delete__(this, aResult); + }, + [this](nsresult aRv) { + mPromiseRequestHolder.Complete(); + Unused << PClientHandleOpParent::Send__delete__(this, aRv); + }) ->Track(mPromiseRequestHolder); } } // namespace dom } // namespace mozilla
--- a/dom/clients/manager/ClientManagerOpParent.cpp +++ b/dom/clients/manager/ClientManagerOpParent.cpp @@ -19,25 +19,26 @@ void ClientManagerOpParent::DoServiceOp( // Note, we need perfect forarding of the template type in order // to allow already_AddRefed<> to be passed as an arg. RefPtr<ClientOpPromise> p = (mService->*aMethod)(std::forward<Args>(aArgs)...); // Capturing `this` is safe here because we disconnect the promise in // ActorDestroy() which ensures neither lambda is called if the actor // is destroyed before the source operation completes. - p->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this](const mozilla::dom::ClientOpResult& aResult) { - mPromiseRequestHolder.Complete(); - Unused << PClientManagerOpParent::Send__delete__(this, aResult); - }, - [this](nsresult aRv) { - mPromiseRequestHolder.Complete(); - Unused << PClientManagerOpParent::Send__delete__(this, aRv); - }) + p->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this](const mozilla::dom::ClientOpResult& aResult) { + mPromiseRequestHolder.Complete(); + Unused << PClientManagerOpParent::Send__delete__(this, aResult); + }, + [this](nsresult aRv) { + mPromiseRequestHolder.Complete(); + Unused << PClientManagerOpParent::Send__delete__(this, aRv); + }) ->Track(mPromiseRequestHolder); } void ClientManagerOpParent::ActorDestroy(ActorDestroyReason aReason) { mPromiseRequestHolder.DisconnectIfExists(); } ClientManagerOpParent::ClientManagerOpParent(ClientManagerService* aService)
--- a/dom/clients/manager/ClientNavigateOpChild.cpp +++ b/dom/clients/manager/ClientNavigateOpChild.cpp @@ -282,22 +282,23 @@ void ClientNavigateOpChild::Init(const C // target. if (!mSerialEventTarget) { mSerialEventTarget = GetCurrentThreadSerialEventTarget(); } // Capturing `this` is safe here since we clear the mPromiseRequestHolder in // ActorDestroy. promise - ->Then(mSerialEventTarget, __func__, - [this](const ClientOpResult& aResult) { - mPromiseRequestHolder.Complete(); - PClientNavigateOpChild::Send__delete__(this, aResult); - }, - [this](nsresult aResult) { - mPromiseRequestHolder.Complete(); - PClientNavigateOpChild::Send__delete__(this, aResult); - }) + ->Then( + mSerialEventTarget, __func__, + [this](const ClientOpResult& aResult) { + mPromiseRequestHolder.Complete(); + PClientNavigateOpChild::Send__delete__(this, aResult); + }, + [this](nsresult aResult) { + mPromiseRequestHolder.Complete(); + PClientNavigateOpChild::Send__delete__(this, aResult); + }) ->Track(mPromiseRequestHolder); } } // namespace dom } // namespace mozilla
--- a/dom/clients/manager/ClientOpenWindowOpChild.cpp +++ b/dom/clients/manager/ClientOpenWindowOpChild.cpp @@ -17,22 +17,23 @@ RefPtr<ClientOpPromise> ClientOpenWindow } void ClientOpenWindowOpChild::ActorDestroy(ActorDestroyReason aReason) { mPromiseRequestHolder.DisconnectIfExists(); } void ClientOpenWindowOpChild::Init(const ClientOpenWindowArgs& aArgs) { DoOpenWindow(aArgs) - ->Then(SystemGroup::EventTargetFor(TaskCategory::Other), __func__, - [this](const ClientOpResult& aResult) { - mPromiseRequestHolder.Complete(); - PClientOpenWindowOpChild::Send__delete__(this, aResult); - }, - [this](nsresult aResult) { - mPromiseRequestHolder.Complete(); - PClientOpenWindowOpChild::Send__delete__(this, aResult); - }) + ->Then( + SystemGroup::EventTargetFor(TaskCategory::Other), __func__, + [this](const ClientOpResult& aResult) { + mPromiseRequestHolder.Complete(); + PClientOpenWindowOpChild::Send__delete__(this, aResult); + }, + [this](nsresult aResult) { + mPromiseRequestHolder.Complete(); + PClientOpenWindowOpChild::Send__delete__(this, aResult); + }) ->Track(mPromiseRequestHolder); } } // namespace dom } // namespace mozilla
--- a/dom/clients/manager/ClientOpenWindowUtils.cpp +++ b/dom/clients/manager/ClientOpenWindowUtils.cpp @@ -297,19 +297,20 @@ void WaitForLoad(const ClientOpenWindowA rv = webProgress->AddProgressListener(listener, nsIWebProgress::NOTIFY_STATE_DOCUMENT); if (NS_WARN_IF(NS_FAILED(rv))) { promise->Reject(rv, __func__); return; } // Hold the listener alive until the promise settles - ref->Then(aOuterWindow->EventTargetFor(TaskCategory::Other), __func__, - [listener](const ClientOpResult& aResult) {}, - [listener](nsresult aResult) {}); + ref->Then( + aOuterWindow->EventTargetFor(TaskCategory::Other), __func__, + [listener](const ClientOpResult& aResult) {}, + [listener](nsresult aResult) {}); } #ifdef MOZ_WIDGET_ANDROID class LaunchObserver final : public nsIObserver { RefPtr<GenericPromise::Private> mPromise; LaunchObserver() : mPromise(new GenericPromise::Private(__func__)) {}
--- a/dom/clients/manager/ClientPrincipalUtils.cpp +++ b/dom/clients/manager/ClientPrincipalUtils.cpp @@ -30,17 +30,19 @@ bool ClientMatchPrincipalInfo(const Prin case PrincipalInfo::TSystemPrincipalInfo: { // system principal always matches return true; } case PrincipalInfo::TNullPrincipalInfo: { // null principal never matches return false; } - default: { break; } + default: { + break; + } } // Clients (windows/workers) should never have an expanded principal type. MOZ_CRASH("unexpected principal type!"); } } // namespace dom } // namespace mozilla
--- a/dom/clients/manager/ClientSource.cpp +++ b/dom/clients/manager/ClientSource.cpp @@ -598,25 +598,26 @@ RefPtr<ClientOpPromise> ClientSource::Cl } RefPtr<ClientOpPromise::Private> outerPromise = new ClientOpPromise::Private(__func__); auto holder = MakeRefPtr<DOMMozPromiseRequestHolder<GenericPromise>>(global); innerPromise - ->Then(mEventTarget, __func__, - [outerPromise, holder](bool aResult) { - holder->Complete(); - outerPromise->Resolve(NS_OK, __func__); - }, - [outerPromise, holder](nsresult aResult) { - holder->Complete(); - outerPromise->Reject(aResult, __func__); - }) + ->Then( + mEventTarget, __func__, + [outerPromise, holder](bool aResult) { + holder->Complete(); + outerPromise->Resolve(NS_OK, __func__); + }, + [outerPromise, holder](nsresult aResult) { + holder->Complete(); + outerPromise->Reject(aResult, __func__); + }) ->Track(*holder); return outerPromise.forget(); } RefPtr<ClientOpPromise> ClientSource::GetInfoAndState( const ClientGetInfoAndStateArgs& aArgs) { ClientState state;
--- a/dom/clients/manager/ClientSourceOpChild.cpp +++ b/dom/clients/manager/ClientSourceOpChild.cpp @@ -51,25 +51,26 @@ void ClientSourceOpChild::DoSourceOp(Met // ActorDestroy() which ensures neither lambda is called if the // actor is destroyed before the source operation completes. // // Also capture the promise to ensure it lives until we get a reaction // or the actor starts shutting down and we disconnect our Thenable. // If the ClientSource is doing something async it may throw away the // promise on its side if the global is closed. promise - ->Then(target, __func__, - [this, promise](const mozilla::dom::ClientOpResult& aResult) { - mPromiseRequestHolder.Complete(); - Unused << PClientSourceOpChild::Send__delete__(this, aResult); - }, - [this, promise](nsresult aRv) { - mPromiseRequestHolder.Complete(); - Unused << PClientSourceOpChild::Send__delete__(this, aRv); - }) + ->Then( + target, __func__, + [this, promise](const mozilla::dom::ClientOpResult& aResult) { + mPromiseRequestHolder.Complete(); + Unused << PClientSourceOpChild::Send__delete__(this, aResult); + }, + [this, promise](nsresult aRv) { + mPromiseRequestHolder.Complete(); + Unused << PClientSourceOpChild::Send__delete__(this, aRv); + }) ->Track(mPromiseRequestHolder); } void ClientSourceOpChild::ActorDestroy(ActorDestroyReason aReason) { mPromiseRequestHolder.DisconnectIfExists(); } void ClientSourceOpChild::Init(const ClientOpConstructorArgs& aArgs) {
--- a/dom/clients/manager/ClientThing.h +++ b/dom/clients/manager/ClientThing.h @@ -63,18 +63,18 @@ class ClientThing { // Returns true if ShutdownThing() has been called. bool IsShutdown() const { AssertIsValid(); return mShutdown; } // Conditionally execute the given callable based on the current state. template <typename Callable> - void MaybeExecute(const Callable& aSuccess, - const std::function<void()>& aFailure = [] {}) { + void MaybeExecute( + const Callable& aSuccess, const std::function<void()>& aFailure = [] {}) { AssertIsValid(); if (mShutdown) { aFailure(); return; } MOZ_DIAGNOSTIC_ASSERT(mActor); aSuccess(mActor); }
--- a/dom/clients/manager/ClientValidation.cpp +++ b/dom/clients/manager/ClientValidation.cpp @@ -53,17 +53,19 @@ bool ClientIsValidPrincipalInfo(const Pr // For now require Clients to have a principal where both its // originNoSuffix and spec have the same origin. This will // exclude a variety of unusual combinations within the browser // but its adequate for the features need to support right now. // If necessary we could expand this function to handle more // cases in the future. return specOrigin == originOrigin; } - default: { break; } + default: { + break; + } } // Windows and workers should not have expanded URLs, etc. return false; } bool ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo, const nsACString& aURL) { @@ -139,17 +141,19 @@ bool ClientIsValidCreationURL(const Prin case PrincipalInfo::TNullPrincipalInfo: { // A wide variety of clients can have a null principal. For example, // sandboxed iframes can have a normal content URL. For now allow // any parsable URL for null principals. This is relatively safe since // null principals have unique origins and won't most ClientManagerService // queries anyway. return true; } - default: { break; } + default: { + break; + } } // Clients (windows/workers) should never have an expanded principal type. return false; } } // namespace dom } // namespace mozilla
--- a/dom/encoding/FallbackEncoding.cpp +++ b/dom/encoding/FallbackEncoding.cpp @@ -24,21 +24,22 @@ struct EncodingProp { NotNull<const Encoding*> mValue; }; template <int32_t N> static NotNull<const Encoding*> SearchEncodingProp( const EncodingProp (&aProperties)[N], const nsACString& aKey) { const nsCString& flat = PromiseFlatCString(aKey); size_t index; - if (!BinarySearchIf(aProperties, 0, ArrayLength(aProperties), - [&flat](const EncodingProp& aProperty) { - return flat.Compare(aProperty.mKey); - }, - &index)) { + if (!BinarySearchIf( + aProperties, 0, ArrayLength(aProperties), + [&flat](const EncodingProp& aProperty) { + return flat.Compare(aProperty.mKey); + }, + &index)) { return WINDOWS_1252_ENCODING; } return aProperties[index].mValue; } static const EncodingProp localesFallbacks[] = { #include "localesfallbacks.properties.h" };
--- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -1291,17 +1291,19 @@ void EventStateManager::DispatchCrossPro IPC::Principal(principal)); return; } case ePluginEventClass: { *aStatus = nsEventStatus_eConsumeNoDefault; remote->SendPluginEvent(*aEvent->AsPluginEvent()); return; } - default: { MOZ_CRASH("Attempt to send non-whitelisted event?"); } + default: { + MOZ_CRASH("Attempt to send non-whitelisted event?"); + } } } bool EventStateManager::IsRemoteTarget(nsIContent* target) { return !!TabParent::GetFrom(target); } bool EventStateManager::HandleCrossProcessEvent(WidgetEvent* aEvent,
--- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -6445,34 +6445,35 @@ bool HTMLMediaElement::TryRemoveMediaKey // let this object's attaching media keys value be false and reject promise // with a new DOMException whose name is NotSupportedError. // 5.2.2 If the association cannot currently be removed, let this object's // attaching media keys value be false and reject promise with a new // DOMException whose name is InvalidStateError. if (mDecoder) { RefPtr<HTMLMediaElement> self = this; mDecoder->SetCDMProxy(nullptr) - ->Then(mAbstractMainThread, __func__, - [self]() { - self->mSetCDMRequest.Complete(); - - self->RemoveMediaKeys(); - if (self->AttachNewMediaKeys()) { - // No incoming MediaKeys object or MediaDecoder is not - // created yet. - self->MakeAssociationWithCDMResolved(); - } - }, - [self](const MediaResult& aResult) { - self->mSetCDMRequest.Complete(); - // 5.2.4 If the preceding step failed, let this object's - // attaching media keys value be false and reject promise with - // a new DOMException whose name is the appropriate error name. - self->SetCDMProxyFailure(aResult); - }) + ->Then( + mAbstractMainThread, __func__, + [self]() { + self->mSetCDMRequest.Complete(); + + self->RemoveMediaKeys(); + if (self->AttachNewMediaKeys()) { + // No incoming MediaKeys object or MediaDecoder is not + // created yet. + self->MakeAssociationWithCDMResolved(); + } + }, + [self](const MediaResult& aResult) { + self->mSetCDMRequest.Complete(); + // 5.2.4 If the preceding step failed, let this object's + // attaching media keys value be false and reject promise with + // a new DOMException whose name is the appropriate error name. + self->SetCDMProxyFailure(aResult); + }) ->Track(mSetCDMRequest); return false; } RemoveMediaKeys(); return true; } @@ -6518,25 +6519,26 @@ bool HTMLMediaElement::TryMakeAssociatio // 5.3.3 Queue a task to run the "Attempt to Resume Playback If Necessary" // algorithm on the media element. // Note: Setting the CDMProxy on the MediaDecoder will unblock playback. if (mDecoder) { // CDMProxy is set asynchronously in MediaFormatReader, once it's done, // HTMLMediaElement should resolve or reject the DOM promise. RefPtr<HTMLMediaElement> self = this; mDecoder->SetCDMProxy(aProxy) - ->Then(mAbstractMainThread, __func__, - [self]() { - self->mSetCDMRequest.Complete(); - self->MakeAssociationWithCDMResolved(); - }, - [self](const MediaResult& aResult) { - self->mSetCDMRequest.Complete(); - self->SetCDMProxyFailure(aResult); - }) + ->Then( + mAbstractMainThread, __func__, + [self]() { + self->mSetCDMRequest.Complete(); + self->MakeAssociationWithCDMResolved(); + }, + [self](const MediaResult& aResult) { + self->mSetCDMRequest.Complete(); + self->SetCDMProxyFailure(aResult); + }) ->Track(mSetCDMRequest); return false; } return true; } bool HTMLMediaElement::AttachNewMediaKeys() { LOG(LogLevel::Debug,
--- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -1715,23 +1715,24 @@ mozilla::ipc::IPCResult BackgroundFactor } RefPtr<TabChild> tabChild = mFactory->GetTabChild(); MOZ_ASSERT(tabChild); IPC::Principal ipcPrincipal(principal); tabChild->SendIndexedDBPermissionRequest(ipcPrincipal) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this](const uint32_t& aPermission) { - this->AssertIsOnOwningThread(); - MaybeCollectGarbageOnIPCMessage(); - this->SendPermissionRetry(); - }, - [](const mozilla::ipc::ResponseRejectReason) {}); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this](const uint32_t& aPermission) { + this->AssertIsOnOwningThread(); + MaybeCollectGarbageOnIPCMessage(); + this->SendPermissionRetry(); + }, + [](const mozilla::ipc::ResponseRejectReason) {}); return IPC_OK(); } mozilla::ipc::IPCResult BackgroundFactoryRequestChild::RecvBlocked( const uint64_t& aCurrentVersion) { AssertIsOnOwningThread(); MOZ_ASSERT(mRequest);
--- a/dom/ipc/SharedStringMap.cpp +++ b/dom/ipc/SharedStringMap.cpp @@ -62,21 +62,22 @@ bool SharedStringMap::Get(const nsCStrin aValue.Assign(ValueTable().Get(entries[index].mValue)); return true; } bool SharedStringMap::Find(const nsCString& aKey, size_t* aIndex) { const auto& keys = KeyTable(); - return BinarySearchIf(Entries(), 0, EntryCount(), - [&](const Entry& aEntry) { - return aKey.Compare(keys.GetBare(aEntry.mKey)); - }, - aIndex); + return BinarySearchIf( + Entries(), 0, EntryCount(), + [&](const Entry& aEntry) { + return aKey.Compare(keys.GetBare(aEntry.mKey)); + }, + aIndex); } void SharedStringMapBuilder::Add(const nsCString& aKey, const nsString& aValue) { mEntries.Put(aKey, {mKeyTable.Add(aKey), mValueTable.Add(aValue)}); } Result<Ok, nsresult> SharedStringMapBuilder::Finalize(
--- a/dom/ipc/TabContext.cpp +++ b/dom/ipc/TabContext.cpp @@ -214,17 +214,19 @@ MaybeInvalidTabContext::MaybeInvalidTabC // it might be used to escalate privileges. if (!StaticPrefs::dom_serviceWorkers_enabled()) { mInvalidReason = "ServiceWorkers should be enabled."; return; } break; } - default: { MOZ_CRASH(); } + default: { + MOZ_CRASH(); + } } bool rv; if (jsPluginId >= 0) { rv = mTabContext.SetTabContextForJSPluginFrame(jsPluginId); } else { rv = mTabContext.SetTabContext(isMozBrowserElement, chromeOuterWindowID, showAccelerators, showFocusRings,
--- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -153,17 +153,18 @@ namespace dom { TabParent::LayerToTabParentTable* TabParent::sLayerToTabParentTable = nullptr; NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TabParent) NS_INTERFACE_MAP_ENTRY(nsITabParent) NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITabParent) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION(TabParent, mFrameElement, mBrowserDOMWindow, mLoadContext, mFrameLoader, mBrowsingContext) +NS_IMPL_CYCLE_COLLECTION(TabParent, mFrameElement, mBrowserDOMWindow, + mLoadContext, mFrameLoader, mBrowsingContext) NS_IMPL_CYCLE_COLLECTING_ADDREF(TabParent) NS_IMPL_CYCLE_COLLECTING_RELEASE(TabParent) TabParent::TabParent(ContentParent* aManager, const TabId& aTabId, const TabContext& aContext, CanonicalBrowsingContext* aBrowsingContext, uint32_t aChromeFlags, BrowserBridgeParent* aBrowserBridgeParent) @@ -3042,28 +3043,29 @@ TabParent::GetContentBlockingLog(Promise if (rv.Failed()) { return NS_ERROR_FAILURE; } RefPtr<Promise> copy(jsPromise); copy.forget(aPromise); auto cblPromise = SendGetContentBlockingLog(); - cblPromise->Then(GetMainThreadSerialEventTarget(), __func__, - [jsPromise](Tuple<nsCString, bool>&& aResult) { - if (Get<1>(aResult)) { - NS_ConvertUTF8toUTF16 utf16(Get<0>(aResult)); - jsPromise->MaybeResolve(std::move(utf16)); - } else { - jsPromise->MaybeRejectWithUndefined(); - } - }, - [jsPromise](ResponseRejectReason&& aReason) { - jsPromise->MaybeRejectWithUndefined(); - }); + cblPromise->Then( + GetMainThreadSerialEventTarget(), __func__, + [jsPromise](Tuple<nsCString, bool>&& aResult) { + if (Get<1>(aResult)) { + NS_ConvertUTF8toUTF16 utf16(Get<0>(aResult)); + jsPromise->MaybeResolve(std::move(utf16)); + } else { + jsPromise->MaybeRejectWithUndefined(); + } + }, + [jsPromise](ResponseRejectReason&& aReason) { + jsPromise->MaybeRejectWithUndefined(); + }); return NS_OK; } void TabParent::SuppressDisplayport(bool aEnabled) { if (IsDestroyed()) { return; } @@ -3153,38 +3155,40 @@ void TabParent::LayerTreeUpdate(const La } void TabParent::RequestRootPaint(gfx::CrossProcessPaint* aPaint, IntRect aRect, float aScale, nscolor aBackgroundColor) { auto promise = SendRequestRootPaint(aRect, aScale, aBackgroundColor); RefPtr<gfx::CrossProcessPaint> paint(aPaint); TabId tabId(GetTabId()); - promise->Then(GetMainThreadSerialEventTarget(), __func__, - [paint, tabId](PaintFragment&& aFragment) { - paint->ReceiveFragment(tabId, std::move(aFragment)); - }, - [paint, tabId](ResponseRejectReason&& aReason) { - paint->LostFragment(tabId); - }); + promise->Then( + GetMainThreadSerialEventTarget(), __func__, + [paint, tabId](PaintFragment&& aFragment) { + paint->ReceiveFragment(tabId, std::move(aFragment)); + }, + [paint, tabId](ResponseRejectReason&& aReason) { + paint->LostFragment(tabId); + }); } void TabParent::RequestSubPaint(gfx::CrossProcessPaint* aPaint, float aScale, nscolor aBackgroundColor) { auto promise = SendRequestSubPaint(aScale, aBackgroundColor); RefPtr<gfx::CrossProcessPaint> paint(aPaint); TabId tabId(GetTabId()); - promise->Then(GetMainThreadSerialEventTarget(), __func__, - [paint, tabId](PaintFragment&& aFragment) { - paint->ReceiveFragment(tabId, std::move(aFragment)); - }, - [paint, tabId](ResponseRejectReason&& aReason) { - paint->LostFragment(tabId); - }); + promise->Then( + GetMainThreadSerialEventTarget(), __func__, + [paint, tabId](PaintFragment&& aFragment) { + paint->ReceiveFragment(tabId, std::move(aFragment)); + }, + [paint, tabId](ResponseRejectReason&& aReason) { + paint->LostFragment(tabId); + }); } mozilla::ipc::IPCResult TabParent::RecvPaintWhileInterruptingJSNoOp( const LayersObserverEpoch& aEpoch) { // We sent a PaintWhileInterruptingJS message when layers were already // visible. In this case, we should act as if an update occurred even though // we already have the layers. LayerTreeUpdate(aEpoch, true);
--- a/dom/localstorage/test/gtest/TestLocalStorage.cpp +++ b/dom/localstorage/test/gtest/TestLocalStorage.cpp @@ -64,31 +64,35 @@ void CheckGeneratedOriginKey(nsIPrincipa EXPECT_TRUE(originKey == nsDependentCString(aOriginKey)); } else { ASSERT_NE(rv, NS_OK) << "GenerateOriginKey2 should fail"; } } } // namespace -TEST(LocalStorage, OriginKey) { +TEST(LocalStorage, OriginKey) +{ // Check the system principal. nsCOMPtr<nsIScriptSecurityManager> secMan = nsContentUtils::GetSecurityManager(); - ASSERT_TRUE(secMan) << "GetSecurityManager() should not fail"; + ASSERT_TRUE(secMan) + << "GetSecurityManager() should not fail"; nsCOMPtr<nsIPrincipal> principal; secMan->GetSystemPrincipal(getter_AddRefs(principal)); - ASSERT_TRUE(principal) << "GetSystemPrincipal() should not fail"; + ASSERT_TRUE(principal) + << "GetSystemPrincipal() should not fail"; CheckGeneratedOriginKey(principal, nullptr); // Check the null principal. principal = NullPrincipal::CreateWithoutOriginAttributes(); - ASSERT_TRUE(principal) << "CreateWithoutOriginAttributes() should not fail"; + ASSERT_TRUE(principal) + << "CreateWithoutOriginAttributes() should not fail"; CheckGeneratedOriginKey(principal, nullptr); // Check content principals. static const OriginKeyTest tests[] = { {"http://www.mozilla.org", "gro.allizom.www.:http:80"}, {"https://www.mozilla.org", "gro.allizom.www.:https:443"}, {"http://www.mozilla.org:32400", "gro.allizom.www.:http:32400"}, @@ -101,13 +105,14 @@ TEST(LocalStorage, OriginKey) { {"moz-extension://53711a8f-65ed-e742-9671-1f02e267c0bc/" "_generated_background_page.html", "cb0c762e20f1-1769-247e-de56-f8a11735.:moz-extension"}, {"http://[::1]:8/test.html", "1::.:http:8"}, }; for (const auto& test : tests) { principal = GetCodebasePrincipal(test.mSpec); - ASSERT_TRUE(principal) << "GetCodebasePrincipal() should not fail"; + ASSERT_TRUE(principal) + << "GetCodebasePrincipal() should not fail"; CheckGeneratedOriginKey(principal, test.mOriginKey); } }
--- a/dom/media/Benchmark.cpp +++ b/dom/media/Benchmark.cpp @@ -277,25 +277,25 @@ void BenchmarkPlayback::GlobalShutdown() MOZ_ASSERT(OnThread()); MOZ_ASSERT(!mFinished, "We've already shutdown"); mFinished = true; if (mDecoder) { RefPtr<Benchmark> ref(mGlobalState); - mDecoder->Flush()->Then(Thread(), __func__, - [ref, this]() { - mDecoder->Shutdown()->Then( - Thread(), __func__, - [ref, this]() { FinalizeShutdown(); }, - []() { MOZ_CRASH("not reached"); }); - mDecoder = nullptr; - }, - []() { MOZ_CRASH("not reached"); }); + mDecoder->Flush()->Then( + Thread(), __func__, + [ref, this]() { + mDecoder->Shutdown()->Then( + Thread(), __func__, [ref, this]() { FinalizeShutdown(); }, + []() { MOZ_CRASH("not reached"); }); + mDecoder = nullptr; + }, + []() { MOZ_CRASH("not reached"); }); } else { FinalizeShutdown(); } } void BenchmarkPlayback::Output(MediaDataDecoder::DecodedData&& aResults) { MOZ_ASSERT(OnThread()); MOZ_ASSERT(!mFinished); @@ -340,40 +340,42 @@ void BenchmarkPlayback::InputExhausted() RefPtr<MediaRawData> sample = mSamples[mSampleIndex]; RefPtr<Benchmark> ref(mGlobalState); RefPtr<MediaDataDecoder::DecodePromise> p = mDecoder->Decode(sample); mSampleIndex++; if (mSampleIndex == mSamples.Length() && !ref->mParameters.mStopAtFrame) { // Complete current frame decode then drain if still necessary. - p->Then(Thread(), __func__, - [ref, this](MediaDataDecoder::DecodedData&& aResults) { - Output(std::move(aResults)); - if (!mFinished) { - mDecoder->Drain()->Then( - Thread(), __func__, - [ref, this](MediaDataDecoder::DecodedData&& aResults) { - mDrained = true; - Output(std::move(aResults)); - MOZ_ASSERT(mFinished, "We must be done now"); - }, - [ref, this](const MediaResult& aError) { Error(aError); }); - } - }, - [ref, this](const MediaResult& aError) { Error(aError); }); + p->Then( + Thread(), __func__, + [ref, this](MediaDataDecoder::DecodedData&& aResults) { + Output(std::move(aResults)); + if (!mFinished) { + mDecoder->Drain()->Then( + Thread(), __func__, + [ref, this](MediaDataDecoder::DecodedData&& aResults) { + mDrained = true; + Output(std::move(aResults)); + MOZ_ASSERT(mFinished, "We must be done now"); + }, + [ref, this](const MediaResult& aError) { Error(aError); }); + } + }, + [ref, this](const MediaResult& aError) { Error(aError); }); } else { if (mSampleIndex == mSamples.Length() && ref->mParameters.mStopAtFrame) { mSampleIndex = 0; } // Continue decoding - p->Then(Thread(), __func__, - [ref, this](MediaDataDecoder::DecodedData&& aResults) { - Output(std::move(aResults)); - if (!mFinished) { - InputExhausted(); - } - }, - [ref, this](const MediaResult& aError) { Error(aError); }); + p->Then( + Thread(), __func__, + [ref, this](MediaDataDecoder::DecodedData&& aResults) { + Output(std::move(aResults)); + if (!mFinished) { + InputExhausted(); + } + }, + [ref, this](const MediaResult& aError) { Error(aError); }); } } } // namespace mozilla
--- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -382,29 +382,30 @@ void ChannelMediaDecoder::DownloadProgre [playbackStats = mPlaybackStatistics, res = RefPtr<BaseMediaResource>(mResource), duration = mDuration, pos = mPlaybackPosition]() { auto rate = ComputePlaybackRate(playbackStats, res, duration); UpdatePlaybackRate(rate, res); MediaStatistics stats = GetStatistics(rate, res, pos); return StatsPromise::CreateAndResolve(stats, __func__); }) - ->Then(mAbstractMainThread, __func__, - [=, self = RefPtr<ChannelMediaDecoder>(this)]( - MediaStatistics aStats) { - if (IsShutdown()) { - return; - } - mCanPlayThrough = aStats.CanPlayThrough(); - GetStateMachine()->DispatchCanPlayThrough(mCanPlayThrough); - mResource->ThrottleReadahead(ShouldThrottleDownload(aStats)); - // Update readyState since mCanPlayThrough might have changed. - GetOwner()->UpdateReadyState(); - }, - []() { MOZ_ASSERT_UNREACHABLE("Promise not resolved"); }); + ->Then( + mAbstractMainThread, __func__, + [=, + self = RefPtr<ChannelMediaDecoder>(this)](MediaStatistics aStats) { + if (IsShutdown()) { + return; + } + mCanPlayThrough = aStats.CanPlayThrough(); + GetStateMachine()->DispatchCanPlayThrough(mCanPlayThrough); + mResource->ThrottleReadahead(ShouldThrottleDownload(aStats)); + // Update readyState since mCanPlayThrough might have changed. + GetOwner()->UpdateReadyState(); + }, + []() { MOZ_ASSERT_UNREACHABLE("Promise not resolved"); }); } /* static */ ChannelMediaDecoder::PlaybackRateInfo ChannelMediaDecoder::ComputePlaybackRate(const MediaChannelStatistics& aStats, BaseMediaResource* aResource, double aDuration) { MOZ_ASSERT(!NS_IsMainThread());
--- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -1050,21 +1050,22 @@ nsresult DOMMediaStream::DispatchTrackEv } void DOMMediaStream::BlockPlaybackTrack(TrackPort* aTrack) { MOZ_ASSERT(aTrack); ++mTracksPendingRemoval; RefPtr<DOMMediaStream> that = this; aTrack ->BlockSourceTrackId(aTrack->GetTrack()->mTrackID, BlockingMode::CREATION) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this, that](bool aIgnore) { NotifyPlaybackTrackBlocked(); }, - [](const nsresult& aIgnore) { - NS_ERROR("Could not remove track from MSG"); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this, that](bool aIgnore) { NotifyPlaybackTrackBlocked(); }, + [](const nsresult& aIgnore) { + NS_ERROR("Could not remove track from MSG"); + }); } void DOMMediaStream::NotifyPlaybackTrackBlocked() { MOZ_ASSERT(mTracksPendingRemoval > 0, "A track reported finished blocking more times than we asked for"); if (--mTracksPendingRemoval == 0) { // The MediaStreamGraph has reported a track was blocked and we are not // waiting for any further tracks to get blocked. It is now safe to
--- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -311,21 +311,22 @@ class MediaDecoderStateMachine::DecodeMe MOZ_ASSERT(!mMaster->mVideoDecodeSuspended); MOZ_ASSERT(!mMetadataRequest.Exists()); SLOG("Dispatching AsyncReadMetadata"); // We disconnect mMetadataRequest in Exit() so it is fine to capture // a raw pointer here. Reader() ->ReadMetadata() - ->Then(OwnerThread(), __func__, - [this](MetadataHolder&& aMetadata) { - OnMetadataRead(std::move(aMetadata)); - }, - [this](const MediaResult& aError) { OnMetadataNotRead(aError); }) + ->Then( + OwnerThread(), __func__, + [this](MetadataHolder&& aMetadata) { + OnMetadataRead(std::move(aMetadata)); + }, + [this](const MediaResult& aError) { OnMetadataNotRead(aError); }) ->Track(mMetadataRequest); } void Exit() override { mMetadataRequest.DisconnectIfExists(); } State GetState() const override { return DECODER_STATE_DECODING_METADATA; } RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override { @@ -705,22 +706,23 @@ class MediaDecoderStateMachine::Decoding if (mMaster->mMinimizePreroll) { SetState<DormantState>(); return; } TimeStamp target = TimeStamp::Now() + TimeDuration::FromMilliseconds(timeout); - mDormantTimer.Ensure(target, - [this]() { - mDormantTimer.CompleteRequest(); - SetState<DormantState>(); - }, - [this]() { mDormantTimer.CompleteRequest(); }); + mDormantTimer.Ensure( + target, + [this]() { + mDormantTimer.CompleteRequest(); + SetState<DormantState>(); + }, + [this]() { mDormantTimer.CompleteRequest(); }); } // Time at which we started decoding. TimeStamp mDecodeStartTime; // When we start decoding (either for the first time, or after a pause) // we may be low on decoded data. We don't want our "low data" logic to // kick in and decide that we're low on decoded data because the download @@ -813,48 +815,49 @@ class MediaDecoderStateMachine::LoopingD RequestAudioDataFromStartPosition(); } private: void RequestAudioDataFromStartPosition() { Reader()->ResetDecode(TrackInfo::kAudioTrack); Reader() ->Seek(SeekTarget(media::TimeUnit::Zero(), SeekTarget::Accurate)) - ->Then(OwnerThread(), __func__, - [this]() -> void { - mAudioSeekRequest.Complete(); - SLOG( - "seeking completed, start to request first sample, " - "queueing audio task - queued=%zu, decoder-queued=%zu", - AudioQueue().GetSize(), - Reader()->SizeOfAudioQueueInFrames()); - - Reader() - ->RequestAudioData() - ->Then(OwnerThread(), __func__, - [this](RefPtr<AudioData> aAudio) { - mIsReachingAudioEOS = false; - mAudioDataRequest.Complete(); - SLOG( - "got audio decoded sample " - "[%" PRId64 ",%" PRId64 "]", - aAudio->mTime.ToMicroseconds(), - aAudio->GetEndTime().ToMicroseconds()); - HandleAudioDecoded(aAudio); - }, - [this](const MediaResult& aError) { - mAudioDataRequest.Complete(); - HandleError(aError); - }) - ->Track(mAudioDataRequest); - }, - [this](const SeekRejectValue& aReject) -> void { - mAudioSeekRequest.Complete(); - HandleError(aReject.mError); - }) + ->Then( + OwnerThread(), __func__, + [this]() -> void { + mAudioSeekRequest.Complete(); + SLOG( + "seeking completed, start to request first sample, " + "queueing audio task - queued=%zu, decoder-queued=%zu", + AudioQueue().GetSize(), Reader()->SizeOfAudioQueueInFrames()); + + Reader() + ->RequestAudioData() + ->Then( + OwnerThread(), __func__, + [this](RefPtr<AudioData> aAudio) { + mIsReachingAudioEOS = false; + mAudioDataRequest.Complete(); + SLOG( + "got audio decoded sample " + "[%" PRId64 ",%" PRId64 "]", + aAudio->mTime.ToMicroseconds(), + aAudio->GetEndTime().ToMicroseconds()); + HandleAudioDecoded(aAudio); + }, + [this](const MediaResult& aError) { + mAudioDataRequest.Complete(); + HandleError(aError); + }) + ->Track(mAudioDataRequest); + }, + [this](const SeekRejectValue& aReject) -> void { + mAudioSeekRequest.Complete(); + HandleError(aReject.mError); + }) ->Track(mAudioSeekRequest); } void UpdatePlaybackPositionToZeroIfNeeded() { MOZ_ASSERT(mIsReachingAudioEOS); MOZ_ASSERT(mAudioLoopingOffset == media::TimeUnit::Zero()); // If we have already reached EOS before starting media sink, the sink // has not started yet and the current position is larger than last decoded @@ -1228,27 +1231,28 @@ class MediaDecoderStateMachine::Accurate !mMaster->IsWaitingVideoData()); // Fire 'waiting' to notify the player that we are waiting for data. mMaster->mOnNextFrameStatus.Notify( MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_SEEKING); Reader() ->WaitForData(aReject.mType) - ->Then(OwnerThread(), __func__, - [this](MediaData::Type aType) { - SLOG("OnSeekRejected wait promise resolved"); - mWaitRequest.Complete(); - DemuxerSeek(); - }, - [this](const WaitForDataRejectValue& aRejection) { - SLOG("OnSeekRejected wait promise rejected"); - mWaitRequest.Complete(); - mMaster->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); - }) + ->Then( + OwnerThread(), __func__, + [this](MediaData::Type aType) { + SLOG("OnSeekRejected wait promise resolved"); + mWaitRequest.Complete(); + DemuxerSeek(); + }, + [this](const WaitForDataRejectValue& aRejection) { + SLOG("OnSeekRejected wait promise rejected"); + mWaitRequest.Complete(); + mMaster->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + }) ->Track(mWaitRequest); return; } if (aReject.mError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) { if (!mDoneAudioSeeking) { HandleEndOfAudioInternal(); } @@ -2126,19 +2130,20 @@ void MediaDecoderStateMachine::StateObje seekJob.mTarget.emplace(aTarget, type, true /* aVideoOnly */); // Hold mMaster->mAbstractMainThread here because this->mMaster will be // invalid after the current state object is deleted in SetState(); RefPtr<AbstractThread> mainThread = mMaster->mAbstractMainThread; SetSeekingState(std::move(seekJob), EventVisibility::Suppressed) - ->Then(mainThread, __func__, - [start, info, hw]() { ReportRecoveryTelemetry(start, info, hw); }, - []() {}); + ->Then( + mainThread, __func__, + [start, info, hw]() { ReportRecoveryTelemetry(start, info, hw); }, + []() {}); } RefPtr<MediaDecoder::SeekPromise> MediaDecoderStateMachine::StateObject::SetSeekingState( SeekJob&& aSeekJob, EventVisibility aVisibility) { if (aSeekJob.mTarget->IsAccurate() || aSeekJob.mTarget->IsFast()) { if (aSeekJob.mTarget->IsVideoOnly()) { return SetState<VideoOnlySeekingState>(std::move(aSeekJob), aVisibility); @@ -2963,19 +2968,19 @@ void MediaDecoderStateMachine::SetVideoD // Set new video decode mode. mVideoDecodeMode = aMode; // Start timer to trigger suspended video decoding. if (mVideoDecodeMode == VideoDecodeMode::Suspend) { TimeStamp target = TimeStamp::Now() + SuspendBackgroundVideoDelay(); RefPtr<MediaDecoderStateMachine> self = this; - mVideoDecodeSuspendTimer.Ensure(target, - [=]() { self->OnSuspendTimerResolved(); }, - []() { MOZ_DIAGNOSTIC_ASSERT(false); }); + mVideoDecodeSuspendTimer.Ensure( + target, [=]() { self->OnSuspendTimerResolved(); }, + []() { MOZ_DIAGNOSTIC_ASSERT(false); }); mOnPlaybackEvent.Notify(MediaPlaybackEvent::StartVideoSuspendTimer); return; } // Resuming from suspended decoding // If suspend timer exists, destroy it. CancelSuspendTimer(); @@ -3059,46 +3064,47 @@ void MediaDecoderStateMachine::RequestAu MOZ_ASSERT(IsAudioDecoding()); MOZ_ASSERT(!IsRequestingAudioData()); MOZ_ASSERT(!IsWaitingAudioData()); LOGV("Queueing audio task - queued=%zu, decoder-queued=%zu", AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames()); RefPtr<MediaDecoderStateMachine> self = this; mReader->RequestAudioData() - ->Then(OwnerThread(), __func__, - [this, self](RefPtr<AudioData> aAudio) { - MOZ_ASSERT(aAudio); - mAudioDataRequest.Complete(); - // audio->GetEndTime() is not always mono-increasing in chained - // ogg. - mDecodedAudioEndTime = - std::max(aAudio->GetEndTime(), mDecodedAudioEndTime); - LOGV("OnAudioDecoded [%" PRId64 ",%" PRId64 "]", - aAudio->mTime.ToMicroseconds(), - aAudio->GetEndTime().ToMicroseconds()); - mStateObj->HandleAudioDecoded(aAudio); - }, - [this, self](const MediaResult& aError) { - LOGV("OnAudioNotDecoded aError=%s", aError.ErrorName().get()); - mAudioDataRequest.Complete(); - switch (aError.Code()) { - case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: - mStateObj->HandleWaitingForAudio(); - break; - case NS_ERROR_DOM_MEDIA_CANCELED: - mStateObj->HandleAudioCanceled(); - break; - case NS_ERROR_DOM_MEDIA_END_OF_STREAM: - mStateObj->HandleEndOfAudio(); - break; - default: - DecodeError(aError); - } - }) + ->Then( + OwnerThread(), __func__, + [this, self](RefPtr<AudioData> aAudio) { + MOZ_ASSERT(aAudio); + mAudioDataRequest.Complete(); + // audio->GetEndTime() is not always mono-increasing in chained + // ogg. + mDecodedAudioEndTime = + std::max(aAudio->GetEndTime(), mDecodedAudioEndTime); + LOGV("OnAudioDecoded [%" PRId64 ",%" PRId64 "]", + aAudio->mTime.ToMicroseconds(), + aAudio->GetEndTime().ToMicroseconds()); + mStateObj->HandleAudioDecoded(aAudio); + }, + [this, self](const MediaResult& aError) { + LOGV("OnAudioNotDecoded aError=%s", aError.ErrorName().get()); + mAudioDataRequest.Complete(); + switch (aError.Code()) { + case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: + mStateObj->HandleWaitingForAudio(); + break; + case NS_ERROR_DOM_MEDIA_CANCELED: + mStateObj->HandleAudioCanceled(); + break; + case NS_ERROR_DOM_MEDIA_END_OF_STREAM: + mStateObj->HandleEndOfAudio(); + break; + default: + DecodeError(aError); + } + }) ->Track(mAudioDataRequest); } void MediaDecoderStateMachine::RequestVideoData( const media::TimeUnit& aCurrentTime) { MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(IsVideoDecoding()); MOZ_ASSERT(!IsRequestingVideoData()); @@ -3107,78 +3113,81 @@ void MediaDecoderStateMachine::RequestVi "Queueing video task - queued=%zu, decoder-queued=%zo" ", stime=%" PRId64, VideoQueue().GetSize(), mReader->SizeOfVideoQueueInFrames(), aCurrentTime.ToMicroseconds()); TimeStamp videoDecodeStartTime = TimeStamp::Now(); RefPtr<MediaDecoderStateMachine> self = this; mReader->RequestVideoData(aCurrentTime) - ->Then(OwnerThread(), __func__, - [this, self, videoDecodeStartTime](RefPtr<VideoData> aVideo) { - MOZ_ASSERT(aVideo); - mVideoDataRequest.Complete(); - // Handle abnormal or negative timestamps. - mDecodedVideoEndTime = - std::max(mDecodedVideoEndTime, aVideo->GetEndTime()); - LOGV("OnVideoDecoded [%" PRId64 ",%" PRId64 "]", - aVideo->mTime.ToMicroseconds(), - aVideo->GetEndTime().ToMicroseconds()); - mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime); - }, - [this, self](const MediaResult& aError) { - LOGV("OnVideoNotDecoded aError=%s", aError.ErrorName().get()); - mVideoDataRequest.Complete(); - switch (aError.Code()) { - case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: - mStateObj->HandleWaitingForVideo(); - break; - case NS_ERROR_DOM_MEDIA_CANCELED: - mStateObj->HandleVideoCanceled(); - break; - case NS_ERROR_DOM_MEDIA_END_OF_STREAM: - mStateObj->HandleEndOfVideo(); - break; - default: - DecodeError(aError); - } - }) + ->Then( + OwnerThread(), __func__, + [this, self, videoDecodeStartTime](RefPtr<VideoData> aVideo) { + MOZ_ASSERT(aVideo); + mVideoDataRequest.Complete(); + // Handle abnormal or negative timestamps. + mDecodedVideoEndTime = + std::max(mDecodedVideoEndTime, aVideo->GetEndTime()); + LOGV("OnVideoDecoded [%" PRId64 ",%" PRId64 "]", + aVideo->mTime.ToMicroseconds(), + aVideo->GetEndTime().ToMicroseconds()); + mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime); + }, + [this, self](const MediaResult& aError) { + LOGV("OnVideoNotDecoded aError=%s", aError.ErrorName().get()); + mVideoDataRequest.Complete(); + switch (aError.Code()) { + case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: + mStateObj->HandleWaitingForVideo(); + break; + case NS_ERROR_DOM_MEDIA_CANCELED: + mStateObj->HandleVideoCanceled(); + break; + case NS_ERROR_DOM_MEDIA_END_OF_STREAM: + mStateObj->HandleEndOfVideo(); + break; + default: + DecodeError(aError); + } + }) ->Track(mVideoDataRequest); } void MediaDecoderStateMachine::WaitForData(MediaData::Type aType) { MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(aType == MediaData::Type::AUDIO_DATA || aType == MediaData::Type::VIDEO_DATA); RefPtr<MediaDecoderStateMachine> self = this; if (aType == MediaData::Type::AUDIO_DATA) { mReader->WaitForData(MediaData::Type::AUDIO_DATA) - ->Then(OwnerThread(), __func__, - [self](MediaData::Type aType) { - self->mAudioWaitRequest.Complete(); - MOZ_ASSERT(aType == MediaData::Type::AUDIO_DATA); - self->mStateObj->HandleAudioWaited(aType); - }, - [self](const WaitForDataRejectValue& aRejection) { - self->mAudioWaitRequest.Complete(); - self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); - }) + ->Then( + OwnerThread(), __func__, + [self](MediaData::Type aType) { + self->mAudioWaitRequest.Complete(); + MOZ_ASSERT(aType == MediaData::Type::AUDIO_DATA); + self->mStateObj->HandleAudioWaited(aType); + }, + [self](const WaitForDataRejectValue& aRejection) { + self->mAudioWaitRequest.Complete(); + self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + }) ->Track(mAudioWaitRequest); } else { mReader->WaitForData(MediaData::Type::VIDEO_DATA) - ->Then(OwnerThread(), __func__, - [self](MediaData::Type aType) { - self->mVideoWaitRequest.Complete(); - MOZ_ASSERT(aType == MediaData::Type::VIDEO_DATA); - self->mStateObj->HandleVideoWaited(aType); - }, - [self](const WaitForDataRejectValue& aRejection) { - self->mVideoWaitRequest.Complete(); - self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); - }) + ->Then( + OwnerThread(), __func__, + [self](MediaData::Type aType) { + self->mVideoWaitRequest.Complete(); + MOZ_ASSERT(aType == MediaData::Type::VIDEO_DATA); + self->mStateObj->HandleVideoWaited(aType); + }, + [self](const WaitForDataRejectValue& aRejection) { + self->mVideoWaitRequest.Complete(); + self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + }) ->Track(mVideoWaitRequest); } } nsresult MediaDecoderStateMachine::StartMediaSink() { MOZ_ASSERT(OnTaskQueue()); if (mMediaSink->IsStarted()) { @@ -3459,22 +3468,23 @@ void MediaDecoderStateMachine::ScheduleS return; } TimeStamp target = TimeStamp::Now() + aTime.ToTimeDuration(); // It is OK to capture 'this' without causing UAF because the callback // always happens before shutdown. RefPtr<MediaDecoderStateMachine> self = this; - mDelayedScheduler.Ensure(target, - [self]() { - self->mDelayedScheduler.CompleteRequest(); - self->RunStateMachine(); - }, - []() { MOZ_DIAGNOSTIC_ASSERT(false); }); + mDelayedScheduler.Ensure( + target, + [self]() { + self->mDelayedScheduler.CompleteRequest(); + self->RunStateMachine(); + }, + []() { MOZ_DIAGNOSTIC_ASSERT(false); }); } bool MediaDecoderStateMachine::OnTaskQueue() const { return OwnerThread()->IsCurrentThreadIn(); } bool MediaDecoderStateMachine::IsStateMachineScheduled() const { MOZ_ASSERT(OnTaskQueue());
--- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -60,104 +60,107 @@ already_AddRefed<Promise> MediaDevices:: ErrorResult& aRv) { RefPtr<Promise> p = Promise::Create(GetParentObject(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<MediaDevices> self(this); MediaManager::Get() ->GetUserMedia(GetOwner(), aConstraints, aCallerType) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this, self, p](RefPtr<DOMMediaStream>&& aStream) { - if (!GetWindowIfCurrent()) { - return; // Leave Promise pending after navigation by design. - } - p->MaybeResolve(std::move(aStream)); - }, - [this, self, p](const RefPtr<MediaMgrError>& error) { - nsPIDOMWindowInner* window = GetWindowIfCurrent(); - if (!window) { - return; // Leave Promise pending after navigation by design. - } - p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this, self, p](RefPtr<DOMMediaStream>&& aStream) { + if (!GetWindowIfCurrent()) { + return; // Leave Promise pending after navigation by design. + } + p->MaybeResolve(std::move(aStream)); + }, + [this, self, p](const RefPtr<MediaMgrError>& error) { + nsPIDOMWindowInner* window = GetWindowIfCurrent(); + if (!window) { + return; // Leave Promise pending after navigation by design. + } + p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); + }); return p.forget(); } already_AddRefed<Promise> MediaDevices::EnumerateDevices(CallerType aCallerType, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); RefPtr<Promise> p = Promise::Create(GetParentObject(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<MediaDevices> self(this); MediaManager::Get() ->EnumerateDevices(GetOwner(), aCallerType) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this, self, - p](RefPtr<MediaManager::MediaDeviceSetRefCnt>&& aDevices) { - nsPIDOMWindowInner* window = GetWindowIfCurrent(); - if (!window) { - return; // Leave Promise pending after navigation by design. - } - auto windowId = window->WindowID(); - nsTArray<RefPtr<MediaDeviceInfo>> infos; - for (auto& device : *aDevices) { - MOZ_ASSERT(device->mKind == dom::MediaDeviceKind::Audioinput || - device->mKind == dom::MediaDeviceKind::Videoinput || - device->mKind == dom::MediaDeviceKind::Audiooutput); - // Include name only if page currently has a gUM stream active - // or persistent permissions (audio or video) have been granted - nsString label; - if (MediaManager::Get()->IsActivelyCapturingOrHasAPermission( - windowId) || - Preferences::GetBool("media.navigator.permission.disabled", - false)) { - label = device->mName; - } - infos.AppendElement(MakeRefPtr<MediaDeviceInfo>( - device->mID, device->mKind, label, device->mGroupID)); - } - p->MaybeResolve(std::move(infos)); - }, - [this, self, p](const RefPtr<MediaMgrError>& error) { - nsPIDOMWindowInner* window = GetWindowIfCurrent(); - if (!window) { - return; // Leave Promise pending after navigation by design. - } - p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this, self, + p](RefPtr<MediaManager::MediaDeviceSetRefCnt>&& aDevices) { + nsPIDOMWindowInner* window = GetWindowIfCurrent(); + if (!window) { + return; // Leave Promise pending after navigation by design. + } + auto windowId = window->WindowID(); + nsTArray<RefPtr<MediaDeviceInfo>> infos; + for (auto& device : *aDevices) { + MOZ_ASSERT(device->mKind == dom::MediaDeviceKind::Audioinput || + device->mKind == dom::MediaDeviceKind::Videoinput || + device->mKind == dom::MediaDeviceKind::Audiooutput); + // Include name only if page currently has a gUM stream active + // or persistent permissions (audio or video) have been granted + nsString label; + if (MediaManager::Get()->IsActivelyCapturingOrHasAPermission( + windowId) || + Preferences::GetBool("media.navigator.permission.disabled", + false)) { + label = device->mName; + } + infos.AppendElement(MakeRefPtr<MediaDeviceInfo>( + device->mID, device->mKind, label, device->mGroupID)); + } + p->MaybeResolve(std::move(infos)); + }, + [this, self, p](const RefPtr<MediaMgrError>& error) { + nsPIDOMWindowInner* window = GetWindowIfCurrent(); + if (!window) { + return; // Leave Promise pending after navigation by design. + } + p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); + }); return p.forget(); } already_AddRefed<Promise> MediaDevices::GetDisplayMedia( const DisplayMediaStreamConstraints& aConstraints, CallerType aCallerType, ErrorResult& aRv) { RefPtr<Promise> p = Promise::Create(GetParentObject(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<MediaDevices> self(this); MediaManager::Get() ->GetDisplayMedia(GetOwner(), aConstraints, aCallerType) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [this, self, p](RefPtr<DOMMediaStream>&& aStream) { - if (!GetWindowIfCurrent()) { - return; // leave promise pending after navigation. - } - p->MaybeResolve(std::move(aStream)); - }, - [this, self, p](RefPtr<MediaMgrError>&& error) { - nsPIDOMWindowInner* window = GetWindowIfCurrent(); - if (!window) { - return; // leave promise pending after navigation. - } - p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [this, self, p](RefPtr<DOMMediaStream>&& aStream) { + if (!GetWindowIfCurrent()) { + return; // leave promise pending after navigation. + } + p->MaybeResolve(std::move(aStream)); + }, + [this, self, p](RefPtr<MediaMgrError>&& error) { + nsPIDOMWindowInner* window = GetWindowIfCurrent(); + if (!window) { + return; // leave promise pending after navigation. + } + p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); + }); return p.forget(); } NS_IMPL_ADDREF_INHERITED(MediaDevices, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(MediaDevices, DOMEventTargetHelper) NS_INTERFACE_MAP_BEGIN(MediaDevices) NS_INTERFACE_MAP_ENTRY(MediaDevices) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
--- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -331,27 +331,28 @@ void MediaFormatReader::DecoderFactory:: RunStage(aTrack == TrackInfo::kAudioTrack ? mAudio : mVideo); } void MediaFormatReader::DecoderFactory::RunStage(Data& aData) { switch (aData.mStage) { case Stage::None: { MOZ_ASSERT(!aData.mToken); aData.mPolicy->Alloc() - ->Then(mOwner->OwnerThread(), __func__, - [this, &aData](RefPtr<Token> aToken) { - aData.mTokenRequest.Complete(); - aData.mToken = aToken.forget(); - aData.mStage = Stage::CreateDecoder; - RunStage(aData); - }, - [&aData]() { - aData.mTokenRequest.Complete(); - aData.mStage = Stage::None; - }) + ->Then( + mOwner->OwnerThread(), __func__, + [this, &aData](RefPtr<Token> aToken) { + aData.mTokenRequest.Complete(); + aData.mToken = aToken.forget(); + aData.mStage = Stage::CreateDecoder; + RunStage(aData); + }, + [&aData]() { + aData.mTokenRequest.Complete(); + aData.mStage = Stage::None; + }) ->Track(aData.mTokenRequest); aData.mStage = Stage::WaitForToken; break; } case Stage::WaitForToken: { MOZ_ASSERT(!aData.mToken); MOZ_ASSERT(aData.mTokenRequest.Exists()); @@ -470,43 +471,43 @@ MediaResult MediaFormatReader::DecoderFa } void MediaFormatReader::DecoderFactory::DoInitDecoder(Data& aData) { auto& ownerData = aData.mOwnerData; DDLOGEX2("MediaFormatReader::DecoderFactory", this, DDLogCategory::Log, "initialize_decoder", DDNoValue{}); aData.mDecoder->Init() - ->Then(mOwner->OwnerThread(), __func__, - [this, &aData, &ownerData](TrackType aTrack) { - aData.mInitRequest.Complete(); - aData.mStage = Stage::None; - MutexAutoLock lock(ownerData.mMutex); - ownerData.mDecoder = aData.mDecoder.forget(); - ownerData.mDescription = - ownerData.mDecoder->GetDescriptionName(); - DDLOGEX2("MediaFormatReader::DecoderFactory", this, - DDLogCategory::Log, "decoder_initialized", DDNoValue{}); - DecoderDoctorLogger::LinkParentAndChild( - "MediaFormatReader::DecoderData", &ownerData, "decoder", - ownerData.mDecoder.get()); - mOwner->SetVideoDecodeThreshold(); - mOwner->ScheduleUpdate(aTrack); - }, - [this, &aData, &ownerData](const MediaResult& aError) { - aData.mInitRequest.Complete(); - MOZ_RELEASE_ASSERT(!ownerData.mDecoder, - "Can't have a decoder already set"); - aData.mStage = Stage::None; - mOwner->mShutdownPromisePool->ShutdownDecoder( - aData.mDecoder.forget()); - DDLOGEX2("MediaFormatReader::DecoderFactory", this, - DDLogCategory::Log, "initialize_decoder_error", aError); - mOwner->NotifyError(aData.mTrack, aError); - }) + ->Then( + mOwner->OwnerThread(), __func__, + [this, &aData, &ownerData](TrackType aTrack) { + aData.mInitRequest.Complete(); + aData.mStage = Stage::None; + MutexAutoLock lock(ownerData.mMutex); + ownerData.mDecoder = aData.mDecoder.forget(); + ownerData.mDescription = ownerData.mDecoder->GetDescriptionName(); + DDLOGEX2("MediaFormatReader::DecoderFactory", this, + DDLogCategory::Log, "decoder_initialized", DDNoValue{}); + DecoderDoctorLogger::LinkParentAndChild( + "MediaFormatReader::DecoderData", &ownerData, "decoder", + ownerData.mDecoder.get()); + mOwner->SetVideoDecodeThreshold(); + mOwner->ScheduleUpdate(aTrack); + }, + [this, &aData, &ownerData](const MediaResult& aError) { + aData.mInitRequest.Complete(); + MOZ_RELEASE_ASSERT(!ownerData.mDecoder, + "Can't have a decoder already set"); + aData.mStage = Stage::None; + mOwner->mShutdownPromisePool->ShutdownDecoder( + aData.mDecoder.forget()); + DDLOGEX2("MediaFormatReader::DecoderFactory", this, + DDLogCategory::Log, "initialize_decoder_error", aError); + mOwner->NotifyError(aData.mTrack, aError); + }) ->Track(aData.mInitRequest); } // DemuxerProxy ensures that the original main demuxer is only ever accessed // via its own dedicated task queue. // This ensure that the reader's taskqueue will never blocked while a demuxer // is itself blocked attempting to access the MediaCache or the MediaResource. class MediaFormatReader::DemuxerProxy { @@ -648,43 +649,45 @@ class MediaFormatReader::DemuxerProxy::W return mInfo->Clone(); } RefPtr<SeekPromise> Seek(const TimeUnit& aTime) override { RefPtr<Wrapper> self = this; return InvokeAsync( mTaskQueue, __func__, [self, aTime]() { return self->mTrackDemuxer->Seek(aTime); }) - ->Then(mTaskQueue, __func__, - [self](const TimeUnit& aTime) { - self->UpdateRandomAccessPoint(); - return SeekPromise::CreateAndResolve(aTime, __func__); - }, - [self](const MediaResult& aError) { - self->UpdateRandomAccessPoint(); - return SeekPromise::CreateAndReject(aError, __func__); - }); + ->Then( + mTaskQueue, __func__, + [self](const TimeUnit& aTime) { + self->UpdateRandomAccessPoint(); + return SeekPromise::CreateAndResolve(aTime, __func__); + }, + [self](const MediaResult& aError) { + self->UpdateRandomAccessPoint(); + return SeekPromise::CreateAndReject(aError, __func__); + }); } RefPtr<SamplesPromise> GetSamples(int32_t aNumSamples) override { RefPtr<Wrapper> self = this; return InvokeAsync(mTaskQueue, __func__, [self, aNumSamples]() { return self->mTrackDemuxer->GetSamples(aNumSamples); }) - ->Then(mTaskQueue, __func__, - [self](RefPtr<SamplesHolder> aSamples) { - self->UpdateRandomAccessPoint(); - return SamplesPromise::CreateAndResolve(aSamples.forget(), - __func__); - }, - [self](const MediaResult& aError) { - self->UpdateRandomAccessPoint(); - return SamplesPromise::CreateAndReject(aError, __func__); - }); + ->Then( + mTaskQueue, __func__, + [self](RefPtr<SamplesHolder> aSamples) { + self->UpdateRandomAccessPoint(); + return SamplesPromise::CreateAndResolve(aSamples.forget(), + __func__); + }, + [self](const MediaResult& aError) { + self->UpdateRandomAccessPoint(); + return SamplesPromise::CreateAndReject(aError, __func__); + }); } bool GetSamplesMayBlock() const override { return mGetSamplesMayBlock; } void Reset() override { RefPtr<Wrapper> self = this; nsresult rv = mTaskQueue->Dispatch(NS_NewRunnableFunction( "MediaFormatReader::DemuxerProxy::Wrapper::Reset", @@ -783,66 +786,67 @@ RefPtr<MediaDataDemuxer::InitPromise> Me return InvokeAsync(mTaskQueue, __func__, [data, taskQueue]() { if (!data->mDemuxer) { return InitPromise::CreateAndReject( NS_ERROR_DOM_MEDIA_CANCELED, __func__); } return data->mDemuxer->Init(); }) - ->Then(taskQueue, __func__, - [data, taskQueue]() { - if (!data->mDemuxer) { // Was shutdown. - return InitPromise::CreateAndReject( - NS_ERROR_DOM_MEDIA_CANCELED, __func__); - } - data->mNumAudioTrack = - data->mDemuxer->GetNumberTracks(TrackInfo::kAudioTrack); - if (data->mNumAudioTrack) { - RefPtr<MediaTrackDemuxer> d = - data->mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0); - if (d) { - RefPtr<Wrapper> wrapper = - new DemuxerProxy::Wrapper(d, taskQueue); - wrapper->UpdateBuffered(); - data->mAudioDemuxer = wrapper; - DecoderDoctorLogger::LinkParentAndChild( - data->mDemuxer.get(), "decoder factory wrapper", - "MediaFormatReader::DecoderFactory::Wrapper", - wrapper.get()); - } - } - data->mNumVideoTrack = - data->mDemuxer->GetNumberTracks(TrackInfo::kVideoTrack); - if (data->mNumVideoTrack) { - RefPtr<MediaTrackDemuxer> d = - data->mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0); - if (d) { - RefPtr<Wrapper> wrapper = - new DemuxerProxy::Wrapper(d, taskQueue); - wrapper->UpdateBuffered(); - data->mVideoDemuxer = wrapper; - DecoderDoctorLogger::LinkParentAndChild( - data->mDemuxer.get(), "decoder factory wrapper", - "MediaFormatReader::DecoderFactory::Wrapper", - wrapper.get()); - } - } - data->mCrypto = data->mDemuxer->GetCrypto(); - data->mSeekable = data->mDemuxer->IsSeekable(); - data->mSeekableOnlyInBufferedRange = - data->mDemuxer->IsSeekableOnlyInBufferedRanges(); - data->mShouldComputeStartTime = - data->mDemuxer->ShouldComputeStartTime(); - data->mInitDone = true; - return InitPromise::CreateAndResolve(NS_OK, __func__); - }, - [](const MediaResult& aError) { - return InitPromise::CreateAndReject(aError, __func__); - }); + ->Then( + taskQueue, __func__, + [data, taskQueue]() { + if (!data->mDemuxer) { // Was shutdown. + return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED, + __func__); + } + data->mNumAudioTrack = + data->mDemuxer->GetNumberTracks(TrackInfo::kAudioTrack); + if (data->mNumAudioTrack) { + RefPtr<MediaTrackDemuxer> d = + data->mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0); + if (d) { + RefPtr<Wrapper> wrapper = + new DemuxerProxy::Wrapper(d, taskQueue); + wrapper->UpdateBuffered(); + data->mAudioDemuxer = wrapper; + DecoderDoctorLogger::LinkParentAndChild( + data->mDemuxer.get(), "decoder factory wrapper", + "MediaFormatReader::DecoderFactory::Wrapper", + wrapper.get()); + } + } + data->mNumVideoTrack = + data->mDemuxer->GetNumberTracks(TrackInfo::kVideoTrack); + if (data->mNumVideoTrack) { + RefPtr<MediaTrackDemuxer> d = + data->mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0); + if (d) { + RefPtr<Wrapper> wrapper = + new DemuxerProxy::Wrapper(d, taskQueue); + wrapper->UpdateBuffered(); + data->mVideoDemuxer = wrapper; + DecoderDoctorLogger::LinkParentAndChild( + data->mDemuxer.get(), "decoder factory wrapper", + "MediaFormatReader::DecoderFactory::Wrapper", + wrapper.get()); + } + } + data->mCrypto = data->mDemuxer->GetCrypto(); + data->mSeekable = data->mDemuxer->IsSeekable(); + data->mSeekableOnlyInBufferedRange = + data->mDemuxer->IsSeekableOnlyInBufferedRanges(); + data->mShouldComputeStartTime = + data->mDemuxer->ShouldComputeStartTime(); + data->mInitDone = true; + return InitPromise::CreateAndResolve(NS_OK, __func__); + }, + [](const MediaResult& aError) { + return InitPromise::CreateAndReject(aError, __func__); + }); } RefPtr<MediaFormatReader::NotifyDataArrivedPromise> MediaFormatReader::DemuxerProxy::NotifyDataArrived() { RefPtr<Data> data = mData; return InvokeAsync(mTaskQueue, __func__, [data]() { if (!data->mDemuxer) { // Was shutdown. @@ -1439,30 +1443,30 @@ void MediaFormatReader::OnDemuxFailed(Tr void MediaFormatReader::DoDemuxVideo() { using SamplesPromise = MediaTrackDemuxer::SamplesPromise; DDLOG(DDLogCategory::Log, "video_demuxing", DDNoValue{}); auto p = mVideo.mTrackDemuxer->GetSamples(1); if (mVideo.mFirstDemuxedSampleTime.isNothing()) { RefPtr<MediaFormatReader> self = this; - p = p->Then(OwnerThread(), __func__, - [self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) { - DDLOGEX(self.get(), DDLogCategory::Log, "video_first_demuxed", - DDNoValue{}); - self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples); - return SamplesPromise::CreateAndResolve(aSamples.forget(), - __func__); - }, - [self](const MediaResult& aError) { - DDLOGEX(self.get(), DDLogCategory::Log, - "video_first_demuxing_error", aError); - self->OnFirstDemuxFailed(TrackInfo::kVideoTrack, aError); - return SamplesPromise::CreateAndReject(aError, __func__); - }); + p = p->Then( + OwnerThread(), __func__, + [self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) { + DDLOGEX(self.get(), DDLogCategory::Log, "video_first_demuxed", + DDNoValue{}); + self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples); + return SamplesPromise::CreateAndResolve(aSamples.forget(), __func__); + }, + [self](const MediaResult& aError) { + DDLOGEX(self.get(), DDLogCategory::Log, "video_first_demuxing_error", + aError); + self->OnFirstDemuxFailed(TrackInfo::kVideoTrack, aError); + return SamplesPromise::CreateAndReject(aError, __func__); + }); } p->Then(OwnerThread(), __func__, this, &MediaFormatReader::OnVideoDemuxCompleted, &MediaFormatReader::OnVideoDemuxFailed) ->Track(mVideo.mDemuxRequest); } @@ -1517,30 +1521,30 @@ MediaFormatReader::RequestAudioData() { void MediaFormatReader::DoDemuxAudio() { using SamplesPromise = MediaTrackDemuxer::SamplesPromise; DDLOG(DDLogCategory::Log, "audio_demuxing", DDNoValue{}); auto p = mAudio.mTrackDemuxer->GetSamples(1); if (mAudio.mFirstDemuxedSampleTime.isNothing()) { RefPtr<MediaFormatReader> self = this; - p = p->Then(OwnerThread(), __func__, - [self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) { - DDLOGEX(self.get(), DDLogCategory::Log, "audio_first_demuxed", - DDNoValue{}); - self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples); - return SamplesPromise::CreateAndResolve(aSamples.forget(), - __func__); - }, - [self](const MediaResult& aError) { - DDLOGEX(self.get(), DDLogCategory::Log, - "audio_first_demuxing_error", aError); - self->OnFirstDemuxFailed(TrackInfo::kAudioTrack, aError); - return SamplesPromise::CreateAndReject(aError, __func__); - }); + p = p->Then( + OwnerThread(), __func__, + [self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) { + DDLOGEX(self.get(), DDLogCategory::Log, "audio_first_demuxed", + DDNoValue{}); + self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples); + return SamplesPromise::CreateAndResolve(aSamples.forget(), __func__); + }, + [self](const MediaResult& aError) { + DDLOGEX(self.get(), DDLogCategory::Log, "audio_first_demuxing_error", + aError); + self->OnFirstDemuxFailed(TrackInfo::kAudioTrack, aError); + return SamplesPromise::CreateAndReject(aError, __func__); + }); } p->Then(OwnerThread(), __func__, this, &MediaFormatReader::OnAudioDemuxCompleted, &MediaFormatReader::OnAudioDemuxFailed) ->Track(mAudio.mDemuxRequest); } @@ -1988,56 +1992,57 @@ void MediaFormatReader::InternalSeek(Tra auto& decoder = GetDecoderData(aTrack); decoder.Flush(); decoder.ResetDemuxer(); decoder.mTimeThreshold = Some(aTarget); DDLOG(DDLogCategory::Log, "seeking", DDNoValue{}); RefPtr<MediaFormatReader> self = this; decoder.mTrackDemuxer->Seek(decoder.mTimeThreshold.ref().Time()) - ->Then(OwnerThread(), __func__, - [self, aTrack](TimeUnit aTime) { - DDLOGEX(self.get(), DDLogCategory::Log, "seeked", DDNoValue{}); - auto& decoder = self->GetDecoderData(aTrack); - decoder.mSeekRequest.Complete(); - MOZ_ASSERT(decoder.mTimeThreshold, - "Seek promise must be disconnected when " - "timethreshold is reset"); - decoder.mTimeThreshold.ref().mHasSeeked = true; - self->SetVideoDecodeThreshold(); - self->ScheduleUpdate(aTrack); - }, - [self, aTrack](const MediaResult& aError) { - auto& decoder = self->GetDecoderData(aTrack); - decoder.mSeekRequest.Complete(); - switch (aError.Code()) { - case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: - DDLOGEX(self.get(), DDLogCategory::Log, - "seeking_interrupted", aError); - self->NotifyWaitingForData(aTrack); - break; - case NS_ERROR_DOM_MEDIA_END_OF_STREAM: - DDLOGEX(self.get(), DDLogCategory::Log, - "seeking_interrupted", aError); - decoder.mTimeThreshold.reset(); - self->NotifyEndOfStream(aTrack); - break; - case NS_ERROR_DOM_MEDIA_CANCELED: - DDLOGEX(self.get(), DDLogCategory::Log, - "seeking_interrupted", aError); - decoder.mTimeThreshold.reset(); - break; - default: - DDLOGEX(self.get(), DDLogCategory::Log, "seeking_error", - aError); - decoder.mTimeThreshold.reset(); - self->NotifyError(aTrack, aError); - break; - } - }) + ->Then( + OwnerThread(), __func__, + [self, aTrack](TimeUnit aTime) { + DDLOGEX(self.get(), DDLogCategory::Log, "seeked", DDNoValue{}); + auto& decoder = self->GetDecoderData(aTrack); + decoder.mSeekRequest.Complete(); + MOZ_ASSERT(decoder.mTimeThreshold, + "Seek promise must be disconnected when " + "timethreshold is reset"); + decoder.mTimeThreshold.ref().mHasSeeked = true; + self->SetVideoDecodeThreshold(); + self->ScheduleUpdate(aTrack); + }, + [self, aTrack](const MediaResult& aError) { + auto& decoder = self->GetDecoderData(aTrack); + decoder.mSeekRequest.Complete(); + switch (aError.Code()) { + case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA: + DDLOGEX(self.get(), DDLogCategory::Log, "seeking_interrupted", + aError); + self->NotifyWaitingForData(aTrack); + break; + case NS_ERROR_DOM_MEDIA_END_OF_STREAM: + DDLOGEX(self.get(), DDLogCategory::Log, "seeking_interrupted", + aError); + decoder.mTimeThreshold.reset(); + self->NotifyEndOfStream(aTrack); + break; + case NS_ERROR_DOM_MEDIA_CANCELED: + DDLOGEX(self.get(), DDLogCategory::Log, "seeking_interrupted", + aError); + decoder.mTimeThreshold.reset(); + break; + default: + DDLOGEX(self.get(), DDLogCategory::Log, "seeking_error", + aError); + decoder.mTimeThreshold.reset(); + self->NotifyError(aTrack, aError); + break; + } + }) ->Track(decoder.mSeekRequest); } void MediaFormatReader::DrainDecoder(TrackType aTrack) { MOZ_ASSERT(OnTaskQueue()); auto& decoder = GetDecoderData(aTrack); if (decoder.mDrainState == DrainState::Draining) { @@ -2864,27 +2869,28 @@ void MediaFormatReader::NotifyDataArrive if (mNotifyDataArrivedPromise.Exists()) { // Already one in progress. Set the dirty flag so we can process it later. mPendingNotifyDataArrived = true; return; } RefPtr<MediaFormatReader> self = this; mDemuxer->NotifyDataArrived() - ->Then(OwnerThread(), __func__, - [self]() { - self->mNotifyDataArrivedPromise.Complete(); - self->UpdateBuffered(); - self->NotifyTrackDemuxers(); - if (self->mPendingNotifyDataArrived) { - self->mPendingNotifyDataArrived = false; - self->NotifyDataArrived(); - } - }, - [self]() { self->mNotifyDataArrivedPromise.Complete(); }) + ->Then( + OwnerThread(), __func__, + [self]() { + self->mNotifyDataArrivedPromise.Complete(); + self->UpdateBuffered(); + self->NotifyTrackDemuxers(); + if (self->mPendingNotifyDataArrived) { + self->mPendingNotifyDataArrived = false; + self->NotifyDataArrived(); + } + }, + [self]() { self->mNotifyDataArrivedPromise.Complete(); }) ->Track(mNotifyDataArrivedPromise); } void MediaFormatReader::UpdateBuffered() { MOZ_ASSERT(OnTaskQueue()); if (mShutdown) { return;
--- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -3134,56 +3134,56 @@ RefPtr<MediaManager::MgrPromise> MediaMa [](nsresult rs) { NS_WARNING( "EnumerateDevicesImpl failed to get Principal Key. Enumeration " "will not continue."); return MgrPromise::CreateAndReject( MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError), __func__); }) - ->Then(GetMainThreadSerialEventTarget(), __func__, - [aWindowId, originKey, aVideoInputEnumType, aAudioInputEnumType, - aVideoInputType, aAudioInputType, aOutDevices](bool) { - // Only run if window is still on our active list. - MediaManager* mgr = MediaManager::GetIfExists(); - if (!mgr || !mgr->IsWindowStillActive(aWindowId)) { - return MgrPromise::CreateAndReject( - MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError), - __func__); - } - - // If we fetched any real cameras or mics, remove the - // "default" part of their IDs. - if (aVideoInputType == MediaSourceEnum::Camera && - aAudioInputType == MediaSourceEnum::Microphone && - (aVideoInputEnumType != DeviceEnumerationType::Fake || - aAudioInputEnumType != DeviceEnumerationType::Fake)) { - mgr->mDeviceIDs.Clear(); - for (auto& device : *aOutDevices) { - nsString id; - device->GetId(id); - id.ReplaceSubstring(NS_LITERAL_STRING("default: "), - NS_LITERAL_STRING("")); - if (!mgr->mDeviceIDs.Contains(id)) { - mgr->mDeviceIDs.AppendElement(id); - } - } - } - if (!mgr->IsWindowStillActive(aWindowId)) { - return MgrPromise::CreateAndReject( - MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError), - __func__); - } - MediaManager::AnonymizeDevices(*aOutDevices, *originKey, - aWindowId); - return MgrPromise::CreateAndResolve(false, __func__); - }, - [](RefPtr<MediaMgrError>&& aError) { - return MgrPromise::CreateAndReject(std::move(aError), __func__); - }); + ->Then( + GetMainThreadSerialEventTarget(), __func__, + [aWindowId, originKey, aVideoInputEnumType, aAudioInputEnumType, + aVideoInputType, aAudioInputType, aOutDevices](bool) { + // Only run if window is still on our active list. + MediaManager* mgr = MediaManager::GetIfExists(); + if (!mgr || !mgr->IsWindowStillActive(aWindowId)) { + return MgrPromise::CreateAndReject( + MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError), + __func__); + } + + // If we fetched any real cameras or mics, remove the + // "default" part of their IDs. + if (aVideoInputType == MediaSourceEnum::Camera && + aAudioInputType == MediaSourceEnum::Microphone && + (aVideoInputEnumType != DeviceEnumerationType::Fake || + aAudioInputEnumType != DeviceEnumerationType::Fake)) { + mgr->mDeviceIDs.Clear(); + for (auto& device : *aOutDevices) { + nsString id; + device->GetId(id); + id.ReplaceSubstring(NS_LITERAL_STRING("default: "), + NS_LITERAL_STRING("")); + if (!mgr->mDeviceIDs.Contains(id)) { + mgr->mDeviceIDs.AppendElement(id); + } + } + } + if (!mgr->IsWindowStillActive(aWindowId)) { + return MgrPromise::CreateAndReject( + MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError), + __func__); + } + MediaManager::AnonymizeDevices(*aOutDevices, *originKey, aWindowId); + return MgrPromise::CreateAndResolve(false, __func__); + }, + [](RefPtr<MediaMgrError>&& aError) { + return MgrPromise::CreateAndReject(std::move(aError), __func__); + }); } RefPtr<MediaManager::DevicesPromise> MediaManager::EnumerateDevices( nsPIDOMWindowInner* aWindow, dom::CallerType aCallerType) { MOZ_ASSERT(NS_IsMainThread()); if (sHasShutdown) { return DevicesPromise::CreateAndReject( MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError, @@ -3245,31 +3245,31 @@ RefPtr<MediaManager::DevicesPromise> Med if (Preferences::GetBool("media.setsinkid.enabled")) { audioOutputType = MediaSinkEnum::Speaker; } auto devices = MakeRefPtr<MediaDeviceSetRefCnt>(); return EnumerateDevicesImpl(windowId, MediaSourceEnum::Camera, MediaSourceEnum::Microphone, audioOutputType, videoEnumerationType, audioEnumerationType, false, devices) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [windowListener, sourceListener, devices](bool) { - DebugOnly<bool> rv = windowListener->Remove(sourceListener); - MOZ_ASSERT(rv); - return DevicesPromise::CreateAndResolve(devices, __func__); - }, - [windowListener, sourceListener](RefPtr<MediaMgrError>&& aError) { - // This may fail, if a new doc has been set the OnNavigation - // method should have removed all previous active listeners. - // Attempt to clean it here, just in case, but ignore the return - // value. - Unused << windowListener->Remove(sourceListener); - return DevicesPromise::CreateAndReject(std::move(aError), - __func__); - }); + ->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [windowListener, sourceListener, devices](bool) { + DebugOnly<bool> rv = windowListener->Remove(sourceListener); + MOZ_ASSERT(rv); + return DevicesPromise::CreateAndResolve(devices, __func__); + }, + [windowListener, sourceListener](RefPtr<MediaMgrError>&& aError) { + // This may fail, if a new doc has been set the OnNavigation + // method should have removed all previous active listeners. + // Attempt to clean it here, just in case, but ignore the return + // value. + Unused << windowListener->Remove(sourceListener); + return DevicesPromise::CreateAndReject(std::move(aError), __func__); + }); } RefPtr<SinkInfoPromise> MediaManager::GetSinkDevice(nsPIDOMWindowInner* aWindow, const nsString& aDeviceId) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aWindow); // We have to add the window id here because enumerate methods @@ -3293,41 +3293,42 @@ RefPtr<SinkInfoPromise> MediaManager::Ge windowListener->Register(sourceListener); bool isSecure = aWindow->IsSecureContext(); auto devices = MakeRefPtr<MediaDeviceSetRefCnt>(); return EnumerateDevicesImpl(aWindow->WindowID(), MediaSourceEnum::Other, MediaSourceEnum::Other, MediaSinkEnum::Speaker, DeviceEnumerationType::Normal, DeviceEnumerationType::Normal, true, devices) - ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [aDeviceId, isSecure, devices](bool) { - for (RefPtr<MediaDevice>& device : *devices) { - if (aDeviceId.IsEmpty() && device->mSinkInfo->Preferred()) { - return SinkInfoPromise::CreateAndResolve(device->mSinkInfo, - __func__); - } - if (device->mID.Equals(aDeviceId)) { - // TODO: Check if the application is authorized