tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_rules_keyframes-rule_02.js (2809B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that verifies the content of the keyframes rule and property changes
      7 // to keyframe rules.
      8 
      9 const TEST_URI = URL_ROOT + "doc_keyframeanimation.html";
     10 
     11 add_task(async function () {
     12  await addTab(TEST_URI);
     13  const { inspector, view } = await openRuleView();
     14  await testPacman(inspector, view);
     15  await testBoxy(inspector, view);
     16 });
     17 
     18 async function testPacman(inspector, view) {
     19  info("Test content in the keyframes rule of #pacman");
     20 
     21  const rules = await getKeyframeRules("#pacman", inspector, view);
     22 
     23  info("Test text properties for Keyframes #pacman");
     24 
     25  is(
     26    convertTextPropsToString(rules.keyframeRules[0].textProps),
     27    "left: 750px",
     28    "Keyframe pacman (100%) property is correct"
     29  );
     30 
     31  // Dynamic changes test disabled because of Bug 1050940
     32  // If this part of the test is ever enabled again, it should be changed to
     33  // use addProperty (in head.js) and stop using _applyingModifications
     34 
     35  // info("Test dynamic changes to keyframe rule for #pacman");
     36 
     37  // let defaultView = element.ownerDocument.defaultView;
     38  // let ruleEditor = view.element.children[5].childNodes[0]._ruleEditor;
     39  // ruleEditor.addProperty("opacity", "0", true);
     40 
     41  // yield ruleEditor._applyingModifications;
     42  // yield once(element, "animationend");
     43 
     44  // is
     45  // (
     46  //   convertTextPropsToString(rules.keyframeRules[1].textProps),
     47  //   "left: 750px; opacity: 0",
     48  //   "Keyframe pacman (100%) property is correct"
     49  // );
     50 
     51  // is(defaultView.getComputedStyle(element).getPropertyValue("opacity"), "0",
     52  //   "Added opacity property should have been used.");
     53 }
     54 
     55 async function testBoxy(inspector, view) {
     56  info("Test content in the keyframes rule of #boxy");
     57 
     58  const rules = await getKeyframeRules("#boxy", inspector, view);
     59 
     60  info("Test text properties for Keyframes #boxy");
     61 
     62  is(
     63    convertTextPropsToString(rules.keyframeRules[0].textProps),
     64    "background-color: blue",
     65    "Keyframe boxy (10%) property is correct"
     66  );
     67 
     68  is(
     69    convertTextPropsToString(rules.keyframeRules[1].textProps),
     70    "background-color: green",
     71    "Keyframe boxy (20%) property is correct"
     72  );
     73 
     74  is(
     75    convertTextPropsToString(rules.keyframeRules[2].textProps),
     76    "opacity: 0",
     77    "Keyframe boxy (100%) property is correct"
     78  );
     79 }
     80 
     81 function convertTextPropsToString(textProps) {
     82  return textProps.map(t => t.name + ": " + t.value).join("; ");
     83 }
     84 
     85 async function getKeyframeRules(selector, inspector, view) {
     86  await selectNode(selector, inspector);
     87  const elementStyle = view._elementStyle;
     88 
     89  const rules = {
     90    elementRules: elementStyle.rules.filter(rule => !rule.keyframes),
     91    keyframeRules: elementStyle.rules.filter(rule => rule.keyframes),
     92  };
     93 
     94  return rules;
     95 }