michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test the links from the computed view to the style editor michael@0: michael@0: const STYLESHEET_URL = "data:text/css,"+encodeURIComponent( michael@0: [".highlight {", michael@0: "color: blue", michael@0: "}"].join("\n")); michael@0: michael@0: const DOCUMENT_URL = "data:text/html,"+encodeURIComponent( michael@0: ['' + michael@0: '' + michael@0: 'Computed view style editor link test', michael@0: '
', michael@0: '', michael@0: '', michael@0: '', michael@0: '', michael@0: '

Some header text

', michael@0: '

hi.

', michael@0: '

I am a test-case. This text exists ', michael@0: 'solely to provide some things to ', michael@0: '', michael@0: 'highlight and count ', michael@0: 'style list-items in the box at right. If you are reading this, ', michael@0: 'you should go do something else instead. Maybe read a book. Or better ', michael@0: 'yet, write some test-cases for another bit of code. ', michael@0: 'some text

', michael@0: '

more text

', michael@0: '

even more text

', michael@0: '
', michael@0: '', michael@0: ''].join("\n")); michael@0: michael@0: let test = asyncTest(function*() { michael@0: yield addTab(DOCUMENT_URL); michael@0: michael@0: info("Opening the computed-view"); michael@0: let {toolbox, inspector, view} = yield openComputedView(); michael@0: michael@0: info("Selecting the test node"); michael@0: yield selectNode("span", inspector); michael@0: michael@0: yield testInlineStyle(view, inspector); michael@0: yield testInlineStyleSheet(view, toolbox); michael@0: yield testExternalStyleSheet(view, toolbox); michael@0: }); michael@0: michael@0: function* testInlineStyle(view, inspector) { michael@0: info("Testing inline style"); michael@0: michael@0: yield expandComputedViewPropertyByIndex(view, inspector, 0); michael@0: michael@0: let onWindow = waitForWindow(); michael@0: info("Clicking on the first rule-link in the computed-view"); michael@0: let link = getComputedViewLinkByIndex(view, 0); michael@0: link.click(); michael@0: michael@0: let win = yield onWindow; michael@0: michael@0: let windowType = win.document.documentElement.getAttribute("windowtype"); michael@0: is(windowType, "navigator:view-source", "View source window is open"); michael@0: info("Closing window"); michael@0: win.close(); michael@0: } michael@0: michael@0: function* testInlineStyleSheet(view, toolbox) { michael@0: info("Testing inline stylesheet"); michael@0: michael@0: info("Listening for toolbox switch to the styleeditor"); michael@0: let onSwitch = waitForStyleEditor(toolbox); michael@0: michael@0: info("Clicking an inline stylesheet"); michael@0: let link = getComputedViewLinkByIndex(view, 2); michael@0: link.click(); michael@0: let editor = yield onSwitch; michael@0: michael@0: ok(true, "Switched to the style-editor panel in the toolbox"); michael@0: michael@0: validateStyleEditorSheet(editor, 0); michael@0: } michael@0: michael@0: function* testExternalStyleSheet(view, toolbox) { michael@0: info("Testing external stylesheet"); michael@0: michael@0: info("Waiting for the stylesheet editor to be selected"); michael@0: let panel = toolbox.getCurrentPanel(); michael@0: let onSelected = panel.UI.once("editor-selected"); michael@0: michael@0: info("Switching back to the inspector panel in the toolbox"); michael@0: yield toolbox.selectTool("inspector"); michael@0: michael@0: info("Clicking on an external stylesheet link"); michael@0: let link = getComputedViewLinkByIndex(view, 1); michael@0: link.click(); michael@0: let editor = yield onSelected; michael@0: michael@0: is(toolbox.currentToolId, "styleeditor", "The style editor is selected again"); michael@0: validateStyleEditorSheet(editor, 1); michael@0: } michael@0: michael@0: function validateStyleEditorSheet(editor, expectedSheetIndex) { michael@0: info("Validating style editor stylesheet"); michael@0: let sheet = content.document.styleSheets[expectedSheetIndex]; michael@0: is(editor.styleSheet.href, sheet.href, "loaded stylesheet matches document stylesheet"); michael@0: }