Auto merge of #12703 - sjmelia:12343_test_activation, r=Manishearth

Fix Issue 12343: Add pref-gated methods and test for activatable element

<!-- Please describe your changes on the following line: -->
Add methods to activatable elements; gated by a preference, for use in servo-specific WPT tests.

I cargo-culted over the "redundant check" from #12322, I don't really understand the possible exploit.

Obvious flaw is the copypasta for each element. I understand that the webidl codegen will produce a trait for ActivatableElement, but I can't see how I can provide a default implementation for this? I guess otherwise could be an improvement to have each element just delegate to an Enter.../Exit... method on the Activatable trait?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #12343 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

…states

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12703)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-16 20:34:25 -05:00 committed by GitHub
commit 2fb4dd9ec3
6 changed files with 98 additions and 0 deletions

View file

@ -2087,6 +2087,27 @@ impl ElementMethods for Element {
// Step 4.
self.insert_adjacent(position, fragment.upcast()).map(|_| ())
}
// check-tidy: no specs after this line
fn EnterFormalActivationState(&self) -> ErrorResult {
match self.as_maybe_activatable() {
Some(a) => {
a.enter_formal_activation_state();
return Ok(());
},
None => return Err(Error::NotSupported)
}
}
fn ExitFormalActivationState(&self) -> ErrorResult {
match self.as_maybe_activatable() {
Some(a) => {
a.exit_formal_activation_state();
return Ok(());
},
None => return Err(Error::NotSupported)
}
}
}
pub fn fragment_affecting_attributes() -> [Atom; 3] {

View file

@ -0,0 +1,15 @@
/* 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/. */
// Interface for testing element activation
// This interface is entirely internal to Servo, and should not be accessible to
// web pages.
[Exposed=(Window,Worker), NoInterfaceObject]
interface ActivatableElement {
[Throws, Pref="dom.testing.element.activation.enabled"]
void enterFormalActivationState();
[Throws, Pref="dom.testing.element.activation.enabled"]
void exitFormalActivationState();
};

View file

@ -122,3 +122,4 @@ partial interface Element {
Element implements ChildNode;
Element implements NonDocumentTypeChildNode;
Element implements ParentNode;
Element implements ActivatableElement;