Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test the links from the rule-view to the styleeditor |
michael@0 | 8 | |
michael@0 | 9 | const STYLESHEET_URL = "data:text/css,"+encodeURIComponent( |
michael@0 | 10 | ["#first {", |
michael@0 | 11 | "color: blue", |
michael@0 | 12 | "}"].join("\n")); |
michael@0 | 13 | |
michael@0 | 14 | const EXTERNAL_STYLESHEET_FILE_NAME = "doc_style_editor_link.css"; |
michael@0 | 15 | const EXTERNAL_STYLESHEET_URL = TEST_URL_ROOT + EXTERNAL_STYLESHEET_FILE_NAME; |
michael@0 | 16 | |
michael@0 | 17 | const DOCUMENT_URL = "data:text/html,"+encodeURIComponent( |
michael@0 | 18 | ['<html>' + |
michael@0 | 19 | '<head>' + |
michael@0 | 20 | '<title>Rule view style editor link test</title>', |
michael@0 | 21 | '<style type="text/css"> ', |
michael@0 | 22 | 'html { color: #000000; } ', |
michael@0 | 23 | 'div { font-variant: small-caps; color: #000000; } ', |
michael@0 | 24 | '.nomatches {color: #ff0000;}</style> <div id="first" style="margin: 10em; ', |
michael@0 | 25 | 'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA">', |
michael@0 | 26 | '</style>', |
michael@0 | 27 | '<link rel="stylesheet" type="text/css" href="'+STYLESHEET_URL+'">', |
michael@0 | 28 | '<link rel="stylesheet" type="text/css" href="'+EXTERNAL_STYLESHEET_URL+'">', |
michael@0 | 29 | '</head>', |
michael@0 | 30 | '<body>', |
michael@0 | 31 | '<h1>Some header text</h1>', |
michael@0 | 32 | '<p id="salutation" style="font-size: 12pt">hi.</p>', |
michael@0 | 33 | '<p id="body" style="font-size: 12pt">I am a test-case. This text exists ', |
michael@0 | 34 | 'solely to provide some things to ', |
michael@0 | 35 | '<span style="color: yellow" class="highlight">', |
michael@0 | 36 | 'highlight</span> and <span style="font-weight: bold">count</span> ', |
michael@0 | 37 | 'style list-items in the box at right. If you are reading this, ', |
michael@0 | 38 | 'you should go do something else instead. Maybe read a book. Or better ', |
michael@0 | 39 | 'yet, write some test-cases for another bit of code. ', |
michael@0 | 40 | '<span style="font-style: italic">some text</span></p>', |
michael@0 | 41 | '<p id="closing">more text</p>', |
michael@0 | 42 | '<p>even more text</p>', |
michael@0 | 43 | '</div>', |
michael@0 | 44 | '</body>', |
michael@0 | 45 | '</html>'].join("\n")); |
michael@0 | 46 | |
michael@0 | 47 | let test = asyncTest(function*() { |
michael@0 | 48 | yield addTab(DOCUMENT_URL); |
michael@0 | 49 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 50 | |
michael@0 | 51 | info("Select the test node"); |
michael@0 | 52 | yield selectNode("div", inspector); |
michael@0 | 53 | |
michael@0 | 54 | yield testInlineStyle(view, inspector); |
michael@0 | 55 | yield testInlineStyleSheet(view, toolbox); |
michael@0 | 56 | yield testExternalStyleSheet(view, toolbox); |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | function* testInlineStyle(view, inspector) { |
michael@0 | 60 | info("Testing inline style"); |
michael@0 | 61 | |
michael@0 | 62 | let onWindow = waitForWindow(); |
michael@0 | 63 | info("Clicking on the first link in the rule-view"); |
michael@0 | 64 | let link = getRuleViewLinkByIndex(view, 0); |
michael@0 | 65 | link.scrollIntoView(); |
michael@0 | 66 | link.click(); |
michael@0 | 67 | |
michael@0 | 68 | let win = yield onWindow; |
michael@0 | 69 | |
michael@0 | 70 | let windowType = win.document.documentElement.getAttribute("windowtype"); |
michael@0 | 71 | is(windowType, "navigator:view-source", "View source window is open"); |
michael@0 | 72 | info("Closing window"); |
michael@0 | 73 | win.close(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function* testInlineStyleSheet(view, toolbox) { |
michael@0 | 77 | info("Testing inline stylesheet"); |
michael@0 | 78 | |
michael@0 | 79 | info("Listening for toolbox switch to the styleeditor"); |
michael@0 | 80 | let onSwitch = waitForStyleEditor(toolbox); |
michael@0 | 81 | |
michael@0 | 82 | info("Clicking an inline stylesheet"); |
michael@0 | 83 | let link = getRuleViewLinkByIndex(view, 4); |
michael@0 | 84 | link.scrollIntoView(); |
michael@0 | 85 | link.click(); |
michael@0 | 86 | let editor = yield onSwitch; |
michael@0 | 87 | |
michael@0 | 88 | ok(true, "Switched to the style-editor panel in the toolbox"); |
michael@0 | 89 | |
michael@0 | 90 | validateStyleEditorSheet(editor, 0); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function* testExternalStyleSheet(view, toolbox) { |
michael@0 | 94 | info("Testing external stylesheet"); |
michael@0 | 95 | |
michael@0 | 96 | info("Waiting for the stylesheet editor to be selected"); |
michael@0 | 97 | let panel = toolbox.getCurrentPanel(); |
michael@0 | 98 | let onSelected = panel.UI.once("editor-selected"); |
michael@0 | 99 | |
michael@0 | 100 | info("Switching back to the inspector panel in the toolbox"); |
michael@0 | 101 | yield toolbox.selectTool("inspector"); |
michael@0 | 102 | |
michael@0 | 103 | info("Clicking on an external stylesheet link"); |
michael@0 | 104 | testRuleViewLinkLabel(view); |
michael@0 | 105 | let link = getRuleViewLinkByIndex(view, 1); |
michael@0 | 106 | link.scrollIntoView(); |
michael@0 | 107 | link.click(); |
michael@0 | 108 | let editor = yield onSelected; |
michael@0 | 109 | |
michael@0 | 110 | is(toolbox.currentToolId, "styleeditor", "The style editor is selected again"); |
michael@0 | 111 | validateStyleEditorSheet(editor, 1); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function validateStyleEditorSheet(editor, expectedSheetIndex) { |
michael@0 | 115 | info("validating style editor stylesheet"); |
michael@0 | 116 | let sheet = content.document.styleSheets[expectedSheetIndex]; |
michael@0 | 117 | is(editor.styleSheet.href, sheet.href, "loaded stylesheet matches document stylesheet"); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function testRuleViewLinkLabel(view) { |
michael@0 | 121 | let link = getRuleViewLinkByIndex(view, 2); |
michael@0 | 122 | let labelElem = link.querySelector(".source-link-label"); |
michael@0 | 123 | let value = labelElem.getAttribute("value"); |
michael@0 | 124 | let tooltipText = labelElem.getAttribute("tooltiptext"); |
michael@0 | 125 | |
michael@0 | 126 | is(value, EXTERNAL_STYLESHEET_FILE_NAME + ":1", |
michael@0 | 127 | "rule view stylesheet display value matches filename and line number"); |
michael@0 | 128 | is(tooltipText, EXTERNAL_STYLESHEET_URL, |
michael@0 | 129 | "rule view stylesheet tooltip text matches the full URI path"); |
michael@0 | 130 | } |