browser/devtools/styleinspector/test/browser_computedview_style-editor-link.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleinspector/test/browser_computedview_style-editor-link.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +// Test the links from the computed view to the style editor
    1.11 +
    1.12 +const STYLESHEET_URL = "data:text/css,"+encodeURIComponent(
    1.13 +  [".highlight {",
    1.14 +   "color: blue",
    1.15 +   "}"].join("\n"));
    1.16 +
    1.17 +const DOCUMENT_URL = "data:text/html,"+encodeURIComponent(
    1.18 +  ['<html>' +
    1.19 +   '<head>' +
    1.20 +   '<title>Computed view style editor link test</title>',
    1.21 +   '<style type="text/css"> ',
    1.22 +   'html { color: #000000; } ',
    1.23 +   'span { font-variant: small-caps; color: #000000; } ',
    1.24 +   '.nomatches {color: #ff0000;}</style> <div id="first" style="margin: 10em; ',
    1.25 +   'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA">',
    1.26 +   '</style>',
    1.27 +   '<link rel="stylesheet" type="text/css" href="'+STYLESHEET_URL+'">',
    1.28 +   '</head>',
    1.29 +   '<body>',
    1.30 +   '<h1>Some header text</h1>',
    1.31 +   '<p id="salutation" style="font-size: 12pt">hi.</p>',
    1.32 +   '<p id="body" style="font-size: 12pt">I am a test-case. This text exists ',
    1.33 +   'solely to provide some things to ',
    1.34 +   '<span style="color: yellow" class="highlight">',
    1.35 +   'highlight</span> and <span style="font-weight: bold">count</span> ',
    1.36 +   'style list-items in the box at right. If you are reading this, ',
    1.37 +   'you should go do something else instead. Maybe read a book. Or better ',
    1.38 +   'yet, write some test-cases for another bit of code. ',
    1.39 +   '<span style="font-style: italic">some text</span></p>',
    1.40 +   '<p id="closing">more text</p>',
    1.41 +   '<p>even more text</p>',
    1.42 +   '</div>',
    1.43 +   '</body>',
    1.44 +   '</html>'].join("\n"));
    1.45 +
    1.46 +let test = asyncTest(function*() {
    1.47 +  yield addTab(DOCUMENT_URL);
    1.48 +
    1.49 +  info("Opening the computed-view");
    1.50 +  let {toolbox, inspector, view} = yield openComputedView();
    1.51 +
    1.52 +  info("Selecting the test node");
    1.53 +  yield selectNode("span", inspector);
    1.54 +
    1.55 +  yield testInlineStyle(view, inspector);
    1.56 +  yield testInlineStyleSheet(view, toolbox);
    1.57 +  yield testExternalStyleSheet(view, toolbox);
    1.58 +});
    1.59 +
    1.60 +function* testInlineStyle(view, inspector) {
    1.61 +  info("Testing inline style");
    1.62 +
    1.63 +  yield expandComputedViewPropertyByIndex(view, inspector, 0);
    1.64 +
    1.65 +  let onWindow = waitForWindow();
    1.66 +  info("Clicking on the first rule-link in the computed-view");
    1.67 +  let link = getComputedViewLinkByIndex(view, 0);
    1.68 +  link.click();
    1.69 +
    1.70 +  let win = yield onWindow;
    1.71 +
    1.72 +  let windowType = win.document.documentElement.getAttribute("windowtype");
    1.73 +  is(windowType, "navigator:view-source", "View source window is open");
    1.74 +  info("Closing window");
    1.75 +  win.close();
    1.76 +}
    1.77 +
    1.78 +function* testInlineStyleSheet(view, toolbox) {
    1.79 +  info("Testing inline stylesheet");
    1.80 +
    1.81 +  info("Listening for toolbox switch to the styleeditor");
    1.82 +  let onSwitch = waitForStyleEditor(toolbox);
    1.83 +
    1.84 +  info("Clicking an inline stylesheet");
    1.85 +  let link = getComputedViewLinkByIndex(view, 2);
    1.86 +  link.click();
    1.87 +  let editor = yield onSwitch;
    1.88 +
    1.89 +  ok(true, "Switched to the style-editor panel in the toolbox");
    1.90 +
    1.91 +  validateStyleEditorSheet(editor, 0);
    1.92 +}
    1.93 +
    1.94 +function* testExternalStyleSheet(view, toolbox) {
    1.95 +  info("Testing external stylesheet");
    1.96 +
    1.97 +  info("Waiting for the stylesheet editor to be selected");
    1.98 +  let panel = toolbox.getCurrentPanel();
    1.99 +  let onSelected = panel.UI.once("editor-selected");
   1.100 +
   1.101 +  info("Switching back to the inspector panel in the toolbox");
   1.102 +  yield toolbox.selectTool("inspector");
   1.103 +
   1.104 +  info("Clicking on an external stylesheet link");
   1.105 +  let link =  getComputedViewLinkByIndex(view, 1);
   1.106 +  link.click();
   1.107 +  let editor = yield onSelected;
   1.108 +
   1.109 +  is(toolbox.currentToolId, "styleeditor", "The style editor is selected again");
   1.110 +  validateStyleEditorSheet(editor, 1);
   1.111 +}
   1.112 +
   1.113 +function validateStyleEditorSheet(editor, expectedSheetIndex) {
   1.114 +  info("Validating style editor stylesheet");
   1.115 +  let sheet = content.document.styleSheets[expectedSheetIndex];
   1.116 +  is(editor.styleSheet.href, sheet.href, "loaded stylesheet matches document stylesheet");
   1.117 +}

mercurial