Back out 38814e0bafb9 through c5d44e6e957b because of test failures

This commit is contained in:
Matt Brubeck 2011-11-30 11:44:50 -08:00
parent 1edf9249b8
commit 41aa9b3c38
19 changed files with 75 additions and 363 deletions

View File

@ -748,11 +748,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (loadAsHtml5) {
mParser = nsHtml5Module::NewHtml5Parser();
if (plainText) {
if (viewSource) {
mParser->MarkAsNotScriptCreated("view-source-plain");
} else {
mParser->MarkAsNotScriptCreated("plain-text");
}
mParser->MarkAsNotScriptCreated("plain-text");
} else if (viewSource && !contentType.EqualsLiteral("text/html")) {
mParser->MarkAsNotScriptCreated("view-source-xml");
} else {

View File

@ -76,7 +76,6 @@ EXPORTS = \
nsHtml5UTF16BufferHSupplement.h \
nsHtml5DependentUTF16Buffer.h \
nsHtml5OwningUTF16Buffer.h \
nsHtml5ViewSourceUtils.h \
$(NULL)
CPPSRCS = \
@ -109,7 +108,6 @@ CPPSRCS = \
nsHtml5SpeculativeLoad.cpp \
nsHtml5SVGLoadDispatcher.cpp \
nsHtml5Highlighter.cpp \
nsHtml5ViewSourceUtils.cpp \
$(NULL)
FORCE_STATIC_LIB = 1

View File

@ -41,7 +41,6 @@
#include "nsHtml5AttributeName.h"
#include "nsString.h"
#include "nsThreadUtils.h"
#include "nsHtml5ViewSourceUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
@ -83,11 +82,14 @@ nsHtml5Highlighter::nsHtml5Highlighter(nsAHtml5TreeOpSink* aOpSink)
, mCStart(PR_INT32_MAX)
, mPos(0)
, mLineNumber(1)
, mUnicharsInThisPre(0)
, mInlinesOpen(0)
, mInCharacters(false)
, mBuffer(nsnull)
, mSyntaxHighlight(Preferences::GetBool("view_source.syntax_highlight",
true))
, mWrapLongLines(Preferences::GetBool("view_source.wrap_long_lines", true))
, mTabSize(Preferences::GetInt("view_source.tab_size", 4))
, mOpSink(aOpSink)
, mCurrentRun(nsnull)
, mAmpersand(nsnull)
@ -104,7 +106,7 @@ nsHtml5Highlighter::~nsHtml5Highlighter()
}
void
nsHtml5Highlighter::Start(const nsAutoString& aTitle)
nsHtml5Highlighter::Start()
{
// Doctype
mOpQueue.AppendElement()->Init(nsGkAtoms::html, EmptyString(), EmptyString());
@ -119,14 +121,18 @@ nsHtml5Highlighter::Start(const nsAutoString& aTitle)
Push(nsGkAtoms::title, nsnull);
// XUL will add the "Source of: " prefix.
PRUint32 length = aTitle.Length();
if (length > PR_INT32_MAX) {
length = PR_INT32_MAX;
}
AppendCharacters(aTitle.get(), 0, (PRInt32)length);
AppendCharacters(mURL.get(), 0, mURL.Length());
Pop(); // title
Push(nsGkAtoms::link, nsHtml5ViewSourceUtils::NewLinkAttributes());
nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
nsString* href = new nsString(
NS_LITERAL_STRING("resource://gre-resources/viewsource.css"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href);
Push(nsGkAtoms::link, linkAttrs);
mOpQueue.AppendElement()->Init(eTreeOpUpdateStyleSheet, CurrentNode());
@ -134,7 +140,22 @@ nsHtml5Highlighter::Start(const nsAutoString& aTitle)
Pop(); // head
Push(nsGkAtoms::body, nsHtml5ViewSourceUtils::NewBodyAttributes());
nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
if (mWrapLongLines) {
nsString* klass = new nsString(NS_LITERAL_STRING("wrap"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass);
}
if (mTabSize > 0) {
nsString* style = new nsString(NS_LITERAL_STRING("-moz-tab-size: "));
style->AppendInt(mTabSize);
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, style);
}
Push(nsGkAtoms::body, bodyAttrs);
nsHtml5HtmlAttributes* preAttrs = new nsHtml5HtmlAttributes(0);
nsString* preId = new nsString(NS_LITERAL_STRING("line1"));
@ -607,8 +628,22 @@ nsHtml5Highlighter::FlushChars()
PRInt32 len = i - mCStart;
AppendCharacters(buf, mCStart, len);
mCStart = i;
mUnicharsInThisPre += len;
}
++mLineNumber;
if (mUnicharsInThisPre > NS_HTML5_HIGHLIGHTER_PRE_BREAK_THRESHOLD &&
!mInlinesOpen && mInCharacters) {
mUnicharsInThisPre = 0;
// Split the pre. See bug 86355.
Pop(); // span
Pop(); // pre
Push(nsGkAtoms::pre, nsnull);
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed.");
treeOp->InitAddLineNumberId(CurrentNode(), mLineNumber);
Push(nsGkAtoms::span, nsnull);
break;
}
Push(nsGkAtoms::span, nsnull);
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed.");
@ -625,6 +660,7 @@ nsHtml5Highlighter::FlushChars()
PRInt32 len = mPos - mCStart;
AppendCharacters(buf, mCStart, len);
mCStart = mPos;
mUnicharsInThisPre += len;
}
}
}

View File

@ -68,7 +68,7 @@ class nsHtml5Highlighter
/**
* Starts the generated document.
*/
void Start(const nsAutoString& aTitle);
void Start();
/**
* Report a tokenizer state transition.
@ -321,6 +321,12 @@ class nsHtml5Highlighter
*/
PRInt32 mLineNumber;
/**
* The number of PRUnichars flushed since the start of the current pre
* block.
*/
PRInt32 mUnicharsInThisPre;
/**
* The number of inline elements open inside the <pre> excluding the
* span potentially wrapping a run of characters.
@ -338,11 +344,26 @@ class nsHtml5Highlighter
*/
nsHtml5UTF16Buffer* mBuffer;
/**
* The URL of the document to be shown in the page title.
*/
nsString mURL;
/**
* Whether to highlight syntax visibly initially.
*/
bool mSyntaxHighlight;
/**
* Whether to wrap long lines.
*/
bool mWrapLongLines;
/**
* The tab size pref.
*/
PRInt32 mTabSize;
/**
* The outgoing tree op queue.
*/

View File

@ -218,7 +218,7 @@ nsHtml5Parser::IsComplete()
}
NS_IMETHODIMP
nsHtml5Parser::Parse(nsIURI* aURL,
nsHtml5Parser::Parse(nsIURI* aURL, // legacy parameter; ignored
nsIRequestObserver* aObserver,
void* aKey,
nsDTDMode aMode) // legacy; ignored
@ -232,7 +232,6 @@ nsHtml5Parser::Parse(nsIURI* aURL,
NS_PRECONDITION(mStreamParser,
"Can't call this Parse() variant on script-created parser");
mStreamParser->SetObserver(aObserver);
mStreamParser->SetViewSourceTitle(aURL); // In case we're viewing source
mExecutor->SetStreamParser(mStreamParser);
mExecutor->SetParser(this);
mRootContextKey = aKey;
@ -714,8 +713,6 @@ nsHtml5Parser::MarkAsNotScriptCreated(const char* aCommand)
mode = VIEW_SOURCE_HTML;
} else if (!nsCRT::strcmp(aCommand, "view-source-xml")) {
mode = VIEW_SOURCE_XML;
} else if (!nsCRT::strcmp(aCommand, "view-source-plain")) {
mode = VIEW_SOURCE_PLAIN;
} else if (!nsCRT::strcmp(aCommand, "plain-text")) {
mode = PLAIN_TEXT;
} else if (!nsCRT::strcmp(aCommand, kLoadAsData)) {

View File

@ -167,7 +167,7 @@ class nsHtml5Parser : public nsIParser,
/**
* Set up request observer.
*
* @param aURL used for View Source title
* @param aURL ignored (for interface compat only)
* @param aListener a listener to forward notifications to
* @param aKey the root context key (used for document.write)
* @param aMode ignored (for interface compat only)

View File

@ -56,7 +56,6 @@
#include "nsHtml5Highlighter.h"
#include "expat_config.h"
#include "expat.h"
#include "nsINestedURI.h"
using namespace mozilla;
@ -292,31 +291,6 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
return NS_OK;
}
void
nsHtml5StreamParser::SetViewSourceTitle(nsIURI* aURL)
{
if (aURL) {
nsCOMPtr<nsIURI> temp;
bool isViewSource;
aURL->SchemeIs("view-source", &isViewSource);
if (isViewSource) {
nsCOMPtr<nsINestedURI> nested = do_QueryInterface(aURL);
nested->GetInnerURI(getter_AddRefs(temp));
} else {
temp = aURL;
}
bool isData;
temp->SchemeIs("data", &isData);
if (isData) {
// Avoid showing potentially huge data: URLs. The three last bytes are
// UTF-8 for an ellipsis.
mViewSourceTitle.AssignLiteral("data:\xE2\x80\xA6");
} else {
temp->GetSpec(mViewSourceTitle);
}
}
}
nsresult
nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const PRUint8* aFromSegment, // can be null
PRUint32 aCount,
@ -906,9 +880,8 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
mStreamState = STREAM_BEING_READ;
if (mMode == VIEW_SOURCE_HTML || mMode == VIEW_SOURCE_XML) {
mTokenizer->StartViewSource(NS_ConvertUTF8toUTF16(mViewSourceTitle));
mTokenizer->StartViewSource();
}
// For View Source, the parser should run with scripts "enabled" if a normal
// load would have scripts enabled.
bool scriptingEnabled = mMode == LOAD_AS_DATA ?
@ -922,9 +895,6 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
if (mMode == PLAIN_TEXT) {
mTreeBuilder->StartPlainText();
mTokenizer->StartPlainText();
} else if (mMode == VIEW_SOURCE_PLAIN) {
mTreeBuilder->StartPlainTextViewSource(NS_ConvertUTF8toUTF16(mViewSourceTitle));
mTokenizer->StartPlainText();
}
/*

View File

@ -76,11 +76,6 @@ enum eParserMode {
*/
VIEW_SOURCE_XML,
/**
* View document as plain text source
*/
VIEW_SOURCE_PLAIN,
/**
* View document as plain text
*/
@ -225,13 +220,6 @@ class nsHtml5StreamParser : public nsIStreamListener,
*/
void SetEncodingFromExpat(const PRUnichar* aEncoding);
/**
* Sets the URL for View Source title in case this parser ends up being
* used for View Source. If aURL is a view-source: URL, takes the inner
* URL. data: URLs are shown with an ellipsis instead of the actual data.
*/
void SetViewSourceTitle(nsIURI* aURL);
private:
#ifdef DEBUG
@ -397,11 +385,6 @@ class nsHtml5StreamParser : public nsIStreamListener,
nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsIRequestObserver> mObserver;
/**
* The document title to use if this turns out to be a View Source parser.
*/
nsCString mViewSourceTitle;
/**
* The Unicode decoder
*/

View File

@ -54,9 +54,9 @@ nsHtml5Tokenizer::FlushViewSource()
}
void
nsHtml5Tokenizer::StartViewSource(const nsAutoString& aTitle)
nsHtml5Tokenizer::StartViewSource()
{
mViewSource->Start(aTitle);
mViewSource->Start();
}
void

View File

@ -47,7 +47,7 @@ void EnableViewSource(nsHtml5Highlighter* aHighlighter);
bool FlushViewSource();
void StartViewSource(const nsAutoString& aTitle);
void StartViewSource();
void EndViewSource();

View File

@ -52,7 +52,6 @@
#include "nsHtml5StreamParser.h"
#include "nsAHtml5TreeBuilderState.h"
#include "nsHtml5Highlighter.h"
#include "nsHtml5ViewSourceUtils.h"
#include "nsHtml5Tokenizer.h"
#include "nsHtml5MetaScanner.h"

View File

@ -53,7 +53,6 @@
#include "nsHtml5StreamParser.h"
#include "nsAHtml5TreeBuilderState.h"
#include "nsHtml5Highlighter.h"
#include "nsHtml5ViewSourceUtils.h"
class nsHtml5StreamParser;

View File

@ -700,32 +700,6 @@ nsHtml5TreeBuilder::MarkAsBroken()
mOpQueue.AppendElement()->Init(eTreeOpMarkAsBroken);
}
void
nsHtml5TreeBuilder::StartPlainTextViewSource(const nsAutoString& aTitle)
{
startTag(nsHtml5ElementName::ELT_TITLE,
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES,
false);
// XUL will add the "Source of: " prefix.
PRUint32 length = aTitle.Length();
if (length > PR_INT32_MAX) {
length = PR_INT32_MAX;
}
characters(aTitle.get(), 0, (PRInt32)length);
endTag(nsHtml5ElementName::ELT_TITLE);
startTag(nsHtml5ElementName::ELT_LINK,
nsHtml5ViewSourceUtils::NewLinkAttributes(),
false);
startTag(nsHtml5ElementName::ELT_BODY,
nsHtml5ViewSourceUtils::NewBodyAttributes(),
false);
StartPlainText();
}
void
nsHtml5TreeBuilder::StartPlainText()
{

View File

@ -95,8 +95,6 @@
~nsHtml5TreeBuilder();
void StartPlainTextViewSource(const nsAutoString& aTitle);
void StartPlainText();
bool HasScript();

View File

@ -1,79 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is HTML5 View Source code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henri Sivonen <hsivonen@iki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsHtml5ViewSourceUtils.h"
#include "nsHtml5AttributeName.h"
#include "mozilla/Preferences.h"
// static
nsHtml5HtmlAttributes*
nsHtml5ViewSourceUtils::NewBodyAttributes()
{
nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) {
nsString* klass = new nsString(NS_LITERAL_STRING("wrap"));
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass);
}
PRInt32 tabSize = mozilla::Preferences::GetInt("view_source.tab_size", 4);
if (tabSize > 0) {
nsString* style = new nsString(NS_LITERAL_STRING("-moz-tab-size: "));
style->AppendInt(tabSize);
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, style);
}
return bodyAttrs;
}
// static
nsHtml5HtmlAttributes*
nsHtml5ViewSourceUtils::NewLinkAttributes()
{
nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
nsString* href = new nsString(
NS_LITERAL_STRING("resource://gre-resources/viewsource.css"));
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href);
return linkAttrs;
}

View File

@ -1,50 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is HTML5 View Source code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henri Sivonen <hsivonen@iki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsHtml5ViewSourceUtils_h_
#define nsHtml5ViewSourceUtils_h_
#include "nsHtml5HtmlAttributes.h"
class nsHtml5ViewSourceUtils
{
public:
static nsHtml5HtmlAttributes* NewBodyAttributes();
static nsHtml5HtmlAttributes* NewLinkAttributes();
};
#endif // nsHtml5ViewSourceUtils_h_

View File

@ -47,7 +47,6 @@ include $(topsrcdir)/config/rules.mk
_BROWSER_CHROME_FILES = \
browser_bug699356.js \
browser_viewsourceprefs.js \
browser_viewsourceprefs_nonhtml.js \
head.js \
$(NULL)

View File

@ -9,7 +9,7 @@ function test() {
openViewSourceWindow(source, function(aWindow) {
let gBrowser = aWindow.gBrowser;
is(gBrowser.contentDocument.title, source, "Correct document title");
todo(gBrowser.contentDocument.title == source, "Correct document title");
todo(aWindow.document.documentElement.getAttribute("title") == "Source of: " + source, "Correct window title");
closeViewSourceWindow(aWindow, finish);
});

View File

@ -1,129 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
let source = "data:text/plain,hello+world";
let mWindow, wrapMenuItem, syntaxMenuItem;
// Check the default values are set.
function test() {
waitForExplicitFinish();
openViewSourceWindow(source, function(aWindow) {
mWindow = aWindow;
wrapMenuItem = aWindow.document.getElementById('menu_wrapLongLines');
syntaxMenuItem = aWindow.document.getElementById('menu_highlightSyntax');
// Strip checked="false" attributes, since we're not interested in them.
if (wrapMenuItem.getAttribute("checked") == "false")
wrapMenuItem.removeAttribute("checked");
if (syntaxMenuItem.getAttribute("checked") == "false")
syntaxMenuItem.removeAttribute("checked");
is(wrapMenuItem.hasAttribute("checked"), false, "Wrap menu item not checked by default");
is(syntaxMenuItem.hasAttribute("checked"), true, "Syntax menu item checked by default");
checkStyle(aWindow, "-moz-tab-size", 4);
checkStyle(aWindow, "white-space", "pre");
test1();
});
}
// Check that the Wrap Long Lines menu item works.
function test1() {
simulateClick(wrapMenuItem);
is(wrapMenuItem.hasAttribute("checked"), true, "Wrap menu item checked");
is(SpecialPowers.getBoolPref("view_source.wrap_long_lines"), true, "Wrap pref set");
checkStyle(mWindow, "white-space", "pre-wrap");
test2();
}
function test2() {
simulateClick(wrapMenuItem);
is(wrapMenuItem.hasAttribute("checked"), false, "Wrap menu item unchecked");
is(SpecialPowers.getBoolPref("view_source.wrap_long_lines"), false, "Wrap pref set");
checkStyle(mWindow, "white-space", "pre");
test3();
}
// Check that the Syntax Highlighting menu item works.
function test3() {
mWindow.gBrowser.addEventListener("pageshow", function test3Handler() {
mWindow.gBrowser.removeEventListener("pageshow", test3Handler, false);
is(syntaxMenuItem.hasAttribute("checked"), false, "Syntax menu item unchecked");
is(SpecialPowers.getBoolPref("view_source.syntax_highlight"), false, "Syntax highlighting pref set");
checkHighlight(mWindow, false);
test4();
}, false);
simulateClick(syntaxMenuItem);
}
function test4() {
mWindow.gBrowser.addEventListener("pageshow", function test4Handler() {
mWindow.gBrowser.removeEventListener("pageshow", test4Handler, false);
is(syntaxMenuItem.hasAttribute("checked"), true, "Syntax menu item checked");
is(SpecialPowers.getBoolPref("view_source.syntax_highlight"), true, "Syntax highlighting pref set");
checkHighlight(mWindow, false);
closeViewSourceWindow(mWindow, test5);
}, false);
simulateClick(syntaxMenuItem);
}
// Open a new view-source window to check prefs are obeyed.
function test5() {
SpecialPowers.pushPrefEnv({'set': [
["view_source.tab_size", 2],
["view_source.wrap_long_lines", true],
["view_source.syntax_highlight", false]
]}, function() {
openViewSourceWindow(source, function(aWindow) {
wrapMenuItem = aWindow.document.getElementById('menu_wrapLongLines');
syntaxMenuItem = aWindow.document.getElementById('menu_highlightSyntax');
// Strip checked="false" attributes, since we're not interested in them.
if (wrapMenuItem.getAttribute("checked") == "false")
wrapMenuItem.removeAttribute("checked");
if (syntaxMenuItem.getAttribute("checked") == "false")
syntaxMenuItem.removeAttribute("checked");
is(wrapMenuItem.hasAttribute("checked"), true, "Wrap menu item checked");
is(syntaxMenuItem.hasAttribute("checked"), false, "Syntax menu item unchecked");
checkStyle(aWindow, "-moz-tab-size", 2);
checkStyle(aWindow, "white-space", "pre-wrap");
checkHighlight(aWindow, false);
closeViewSourceWindow(aWindow, finish);
});
});
}
// Simulate a menu item click, including toggling the checked state.
// This saves us from opening the menu and trying to click on the item,
// which doesn't work on Mac OS X.
function simulateClick(aMenuItem) {
if (aMenuItem.hasAttribute("checked"))
aMenuItem.removeAttribute("checked");
else
aMenuItem.setAttribute("checked", "true");
aMenuItem.click();
}
function checkStyle(aWindow, aStyleProperty, aExpectedValue) {
let gBrowser = aWindow.gBrowser;
let computedStyle = gBrowser.contentWindow.getComputedStyle(gBrowser.contentDocument.body, null);
is(computedStyle.getPropertyValue(aStyleProperty), aExpectedValue, "Correct value of " + aStyleProperty);
}
function checkHighlight(aWindow, aExpected) {
let spans = aWindow.gBrowser.contentDocument.getElementsByTagName("span");
is(Array.some(spans, function(aSpan) {
return aSpan.className != "";
}), aExpected, "Syntax highlighting " + (aExpected ? "on" : "off"));
}