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 computed view to the style editor |
michael@0 | 8 | |
michael@0 | 9 | const STYLESHEET_URL = "data:text/css,"+encodeURIComponent( |
michael@0 | 10 | [".highlight {", |
michael@0 | 11 | "color: blue", |
michael@0 | 12 | "}"].join("\n")); |
michael@0 | 13 | |
michael@0 | 14 | const DOCUMENT_URL = "data:text/html,"+encodeURIComponent( |
michael@0 | 15 | ['<html>' + |
michael@0 | 16 | '<head>' + |
michael@0 | 17 | '<title>Computed view style editor link test</title>', |
michael@0 | 18 | '<style type="text/css"> ', |
michael@0 | 19 | 'html { color: #000000; } ', |
michael@0 | 20 | 'span { font-variant: small-caps; color: #000000; } ', |
michael@0 | 21 | '.nomatches {color: #ff0000;}</style> <div id="first" style="margin: 10em; ', |
michael@0 | 22 | 'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA">', |
michael@0 | 23 | '</style>', |
michael@0 | 24 | '<link rel="stylesheet" type="text/css" href="'+STYLESHEET_URL+'">', |
michael@0 | 25 | '</head>', |
michael@0 | 26 | '<body>', |
michael@0 | 27 | '<h1>Some header text</h1>', |
michael@0 | 28 | '<p id="salutation" style="font-size: 12pt">hi.</p>', |
michael@0 | 29 | '<p id="body" style="font-size: 12pt">I am a test-case. This text exists ', |
michael@0 | 30 | 'solely to provide some things to ', |
michael@0 | 31 | '<span style="color: yellow" class="highlight">', |
michael@0 | 32 | 'highlight</span> and <span style="font-weight: bold">count</span> ', |
michael@0 | 33 | 'style list-items in the box at right. If you are reading this, ', |
michael@0 | 34 | 'you should go do something else instead. Maybe read a book. Or better ', |
michael@0 | 35 | 'yet, write some test-cases for another bit of code. ', |
michael@0 | 36 | '<span style="font-style: italic">some text</span></p>', |
michael@0 | 37 | '<p id="closing">more text</p>', |
michael@0 | 38 | '<p>even more text</p>', |
michael@0 | 39 | '</div>', |
michael@0 | 40 | '</body>', |
michael@0 | 41 | '</html>'].join("\n")); |
michael@0 | 42 | |
michael@0 | 43 | let test = asyncTest(function*() { |
michael@0 | 44 | yield addTab(DOCUMENT_URL); |
michael@0 | 45 | |
michael@0 | 46 | info("Opening the computed-view"); |
michael@0 | 47 | let {toolbox, inspector, view} = yield openComputedView(); |
michael@0 | 48 | |
michael@0 | 49 | info("Selecting the test node"); |
michael@0 | 50 | yield selectNode("span", inspector); |
michael@0 | 51 | |
michael@0 | 52 | yield testInlineStyle(view, inspector); |
michael@0 | 53 | yield testInlineStyleSheet(view, toolbox); |
michael@0 | 54 | yield testExternalStyleSheet(view, toolbox); |
michael@0 | 55 | }); |
michael@0 | 56 | |
michael@0 | 57 | function* testInlineStyle(view, inspector) { |
michael@0 | 58 | info("Testing inline style"); |
michael@0 | 59 | |
michael@0 | 60 | yield expandComputedViewPropertyByIndex(view, inspector, 0); |
michael@0 | 61 | |
michael@0 | 62 | let onWindow = waitForWindow(); |
michael@0 | 63 | info("Clicking on the first rule-link in the computed-view"); |
michael@0 | 64 | let link = getComputedViewLinkByIndex(view, 0); |
michael@0 | 65 | link.click(); |
michael@0 | 66 | |
michael@0 | 67 | let win = yield onWindow; |
michael@0 | 68 | |
michael@0 | 69 | let windowType = win.document.documentElement.getAttribute("windowtype"); |
michael@0 | 70 | is(windowType, "navigator:view-source", "View source window is open"); |
michael@0 | 71 | info("Closing window"); |
michael@0 | 72 | win.close(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function* testInlineStyleSheet(view, toolbox) { |
michael@0 | 76 | info("Testing inline stylesheet"); |
michael@0 | 77 | |
michael@0 | 78 | info("Listening for toolbox switch to the styleeditor"); |
michael@0 | 79 | let onSwitch = waitForStyleEditor(toolbox); |
michael@0 | 80 | |
michael@0 | 81 | info("Clicking an inline stylesheet"); |
michael@0 | 82 | let link = getComputedViewLinkByIndex(view, 2); |
michael@0 | 83 | link.click(); |
michael@0 | 84 | let editor = yield onSwitch; |
michael@0 | 85 | |
michael@0 | 86 | ok(true, "Switched to the style-editor panel in the toolbox"); |
michael@0 | 87 | |
michael@0 | 88 | validateStyleEditorSheet(editor, 0); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function* testExternalStyleSheet(view, toolbox) { |
michael@0 | 92 | info("Testing external stylesheet"); |
michael@0 | 93 | |
michael@0 | 94 | info("Waiting for the stylesheet editor to be selected"); |
michael@0 | 95 | let panel = toolbox.getCurrentPanel(); |
michael@0 | 96 | let onSelected = panel.UI.once("editor-selected"); |
michael@0 | 97 | |
michael@0 | 98 | info("Switching back to the inspector panel in the toolbox"); |
michael@0 | 99 | yield toolbox.selectTool("inspector"); |
michael@0 | 100 | |
michael@0 | 101 | info("Clicking on an external stylesheet link"); |
michael@0 | 102 | let link = getComputedViewLinkByIndex(view, 1); |
michael@0 | 103 | link.click(); |
michael@0 | 104 | let editor = yield onSelected; |
michael@0 | 105 | |
michael@0 | 106 | is(toolbox.currentToolId, "styleeditor", "The style editor is selected again"); |
michael@0 | 107 | validateStyleEditorSheet(editor, 1); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function validateStyleEditorSheet(editor, expectedSheetIndex) { |
michael@0 | 111 | info("Validating style editor stylesheet"); |
michael@0 | 112 | let sheet = content.document.styleSheets[expectedSheetIndex]; |
michael@0 | 113 | is(editor.styleSheet.href, sheet.href, "loaded stylesheet matches document stylesheet"); |
michael@0 | 114 | } |