Skip to content
This repository has been archived by the owner on Apr 14, 2018. It is now read-only.

Commit

Permalink
Merge with master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossop committed Nov 27, 2011
2 parents ca6ce0c + 44851ff commit 8407ae8
Show file tree
Hide file tree
Showing 27 changed files with 1,438 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "mozbase"]
path = mozbase
url = https://github.com/Mossop/mozbase.git
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,14 @@ The main goals are:
* The webapp should behave as well in Thunderbird as it would if opened in
Firefox

Testing
-------

All fixes should include appropriate automated testing. In order to run the unit
tests the mozbase submodule must first be pulled with `git submodule init` and
`git submodule update`. Then running `python runtests.py` should run the tests
and output any failures.

Building
--------

Expand Down
1 change: 1 addition & 0 deletions mozbase
Submodule mozbase added at 328139
288 changes: 288 additions & 0 deletions runtests.py
@@ -0,0 +1,288 @@
#! python

# ***** 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 WebApp Tabs.
#
# The Initial Developer of the Original Code is
# Dave Townsend <dtownsend@oxymoronical.com>
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****

import sys, os

basedir = os.path.abspath(os.path.dirname(sys.argv[0]))
sys.path.append(os.path.join(basedir, 'mozbase/mozprocess'))
sys.path.append(os.path.join(basedir, 'mozbase/mozinfo'))
sys.path.append(os.path.join(basedir, 'mozbase/manifestdestiny'))
sys.path.append(os.path.join(basedir, 'mozbase/mozprofile'))
sys.path.append(os.path.join(basedir, 'mozbase/mozrunner'))

from manifestparser import TestManifest
from mozprocess import ProcessHandlerMixin
from mozprofile import ThunderbirdProfile
from mozrunner import ThunderbirdRunner
import json
import threading
import SocketServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
from optparse import OptionParser

def attrIsTrue(obj, attr):
return attr in obj and obj[attr] == 'true'

class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass

class CommandFile():
commands = None

def __init__(self):
self.commands = []

def addCommand(self, command, arguments=[]):
self.commands.append({
'command': command,
'args': arguments
})

def writeCommands(self, profile):
file = open(os.path.join(profile.profile, 'commands.json'), 'w')
file.write(json.dumps(self.commands))
file.close()

class TestManager():
passCount = 0
failCount = 0
sawQuit = False

def __init__(self, profile, runner, tests):
self.profile = profile
self.runner = runner
self.tests = tests

os.chdir(os.path.join(basedir, "tests/data"))
self.server = ThreadedTCPServer(("", 8080), SimpleHTTPRequestHandler)
thread = threading.Thread(target=self.server.serve_forever)
thread.daemon = True
thread.start()

def sanityCheck(self, test, isFirst):
if attrIsTrue(test, 'resetProfile') and attrIsTrue(test, 'startDisabled'):
self.processFailLine("Cannot reset profile and start disabled for the same test")
if attrIsTrue(test, 'startDisabled') and isFirst:
self.processFailLine("Cannot start disabled for the first test")

def runTests(self):
if len(self.tests) == 0:
print("No tests to run")
return

test = self.tests[0]
self.sanityCheck(test, True)

while len(self.tests) > 0:
commands = CommandFile()

while len(self.tests) > 0:
heads = []
if 'head' in test:
heads.append(os.path.join(test['here'], test['head']))
commands.addCommand('runTest', [test['path'], heads])
self.tests = self.tests[1:]

if len(self.tests) > 0:
test = self.tests[0]
self.sanityCheck(test, False)
if attrIsTrue(test, 'startDisabled'):
commands.addCommand('disableAddon')
break
if attrIsTrue(test, 'restartBefore') or attrIsTrue(test, 'resetProfile'):
break

commands.writeCommands(self.profile)

self.sawQuit = False
self.runner.start()
self.runner.wait()
if not self.sawQuit:
self.processFailLine("Unexpected application exit")
if attrIsTrue(test, 'resetProfile'):
self.profile.reset()
print("\n%d tests passed, %d tests failed" % (self.passCount, self.failCount))

def processOutputLine(self, line):
if line[0:9] == "!!!PASS: ":
self.processPassLine(line[9:])
elif line[0:9] == "!!!FAIL: ":
self.processFailLine(line[9:])
elif line[0:12] == "!!!FAILLOG: ":
self.processFailLogLine(line[12:])
elif line[0:9] == "!!!INFO: ":
self.processInfoLine(line[9:])
else:
self.processUnknownLine(line)

def processPassLine(self, line):
self.passCount += 1
print("TEST-PASS %s" % line)

def processFailLine(self, line):
self.failCount += 1
print("TEST-FAIL %s" % line)

def processFailLogLine(self, line):
print(" %s" % line)

def processInfoLine(self, line):
if line == "TEST-QUIT":
self.sawQuit = True
return
print(line)

def processUnknownLine(self, line):
print(" %s" % line)

class TestProcess(ProcessHandlerMixin):
def __init__(self, cmd, **kwargs):
kwargs.setdefault('processOutputLine', []).append(manager.processOutputLine)
ProcessHandlerMixin.__init__(self, cmd, **kwargs)

class TestProfile(ThunderbirdProfile):
preferences = {
# Turn on debug logging
'extensions.webapptabs.loglevel': 0,
# Don't automatically update the application
'app.update.enabled': False,
# Only install add-ons from the profile and the application scope
# Also ensure that those are not getting disabled.
# see: https://developer.mozilla.org/en/Installing_extensions
'extensions.enabledScopes': 5,
'extensions.autoDisableScopes': 10,
# Don't install distribution add-ons from the app folder
'extensions.installDistroAddons': False,
# Dont' run the add-on compatibility check during start-up
'extensions.showMismatchUI': False,
# Don't automatically update add-ons
'extensions.update.enabled': False,
# say yes to debug output via dump
'browser.dom.window.dump.enabled': True,
# say no to slow script warnings
'dom.max_chrome_script_run_time': 0,
'dom.max_script_run_time': 0,
# do not ask about being the default mail client
'mail.shell.checkDefaultClient': False,
# do not tell us about the greatness that is mozilla (about:rights)
'mail.rights.override': True,
# disable non-gloda indexing daemons
'mail.winsearch.enable': False,
'mail.winsearch.firstRunDone': True,
'mail.spotlight.enable': False,
'mail.spotlight.firstRunDone': True,
# disable address books for undisclosed reasons
'ldap_2.servers.osx.position': 0,
'ldap_2.servers.oe.position': 0,
# disable the first use junk dialog
'mailnews.ui.junk.firstuse': False,
# Do not allow check new mail to be set
'mail.startup.enabledMailCheckOnce': True,
# Dont load whats new or the remote start page - keep everything local
# under our control.
'mailnews.start_page_override.mstone': 'ignore',
'mailnews.start_page.url': 'about:blank',
# Do not enable gloda
'mailnews.database.global.indexer.enabled': False,
# But do have gloda log if it does anything. (When disabled, queries
# are still serviced; they just should not result in any matches.)
'mailnews.database.global.logging.upstream': True,
# Do not allow fonts to be upgraded
'mail.font.windows.version': 2,
# No, we dont want to be prompted about Telemetry
'toolkit.telemetry.prompted': True,
# Create fake accounts so the new account wizard won't open
'mail.account.account1.server': 'server1',
'mail.account.account2.identities': 'id1,id2',
'mail.account.account2.server': 'server2',
'mail.accountmanager.accounts': 'account1,account2',
'mail.accountmanager.defaultaccount': 'account2',
'mail.accountmanager.localfoldersserver': 'server1',
'mail.identity.id1.fullName': 'Tinderbox',
'mail.identity.id1.htmlSigFormat': False,
'mail.identity.id1.htmlSigText': 'Tinderbox is soo 90ies',
'mail.identity.id1.smtpServer': 'smtp1',
'mail.identity.id1.useremail': 'tinderbox@invalid.com',
'mail.identity.id1.valid': True,
'mail.identity.id2.fullName': 'Tinderboxpushlog',
'mail.identity.id2.htmlSigFormat': True,
'mail.identity.id2.htmlSigText': 'Tinderboxpushlog is the new <b>hotness!</b>',
'mail.identity.id2.smtpServer': 'smtp1',
'mail.identity.id2.useremail': 'tinderboxpushlog@invalid.com',
'mail.identity.id2.valid': True,
'mail.server.server1.directory-rel': '[ProfD]Mail/Local Folders',
'mail.server.server1.hostname': 'Local Folders',
'mail.server.server1.name': 'Local Folders',
'mail.server.server1.type': 'none',
'mail.server.server1.userName': 'nobody',
'mail.server.server2.check_new_mail': False,
'mail.server.server2.directory-rel': '[ProfD]Mail/tinderbox',
'mail.server.server2.download_on_biff': True,
'mail.server.server2.hostname': 'tinderbox',
'mail.server.server2.login_at_startup': False,
'mail.server.server2.name': 'tinderbox@invalid.com',
'mail.server.server2.type': 'pop3',
'mail.server.server2.userName': 'tinderbox',
'mail.server.server2.whiteListAbURI': '',
'mail.smtp.defaultserver': 'smtp1',
'mail.smtpserver.smtp1.hostname': 'tinderbox',
'mail.smtpserver.smtp1.username': 'tinderbox',
'mail.smtpservers': 'smtp1',
}

addons = [
os.path.join(basedir, 'src'),
os.path.join(basedir, 'testharness')
]

manifest = TestManifest([os.path.join(basedir, 'tests/tests.ini')])
tests = manifest.active_tests(disabled=False)
profile = TestProfile(addons=addons)

parser = OptionParser()
parser.add_option('-b', "--binary",
dest="binary", help="Binary path.",
metavar=None, default=None)

(options, args) = parser.parse_args(sys.argv[1:])

runner = ThunderbirdRunner(profile=profile, process_class=TestProcess,
binary=options.binary)
manager = TestManager(profile, runner, tests)

manager.runTests()
8 changes: 4 additions & 4 deletions src/bootstrap.js
Expand Up @@ -77,11 +77,11 @@ var HttpObserver = {
if (!(aSubject instanceof Ci.nsIHttpChannel))
return;

let desc = ConfigManager.getWebAppForURL(aSubject.URI.spec);
let desc = ConfigManager.getWebAppForURL(aSubject.URI);
if (!desc) {
let win = this.getWindowFromChannel(aSubject);
if (win)
desc = ConfigManager.getWebAppForURL(win.location.toString());
desc = ConfigManager.getWebAppForURL(win.document.documentURIObject);
}

// If this isn't a load of a webapp tab then ignore it
Expand Down Expand Up @@ -128,12 +128,12 @@ function startup(aParams, aReason) {
Components.utils.import("resource://webapptabs/modules/OverlayManager.jsm");
OverlayManager.addComponent("{bd71af62-1b21-4f3a-829e-5254ec7da7f6}",
"resource://webapptabs/components/nsContentPolicy.js",
"@oxymoronical.com/webapptabs/content-policy;1");
"@fractalbrew.com/webapptabs/content-policy;1");
OverlayManager.addComponent("{4aef66b9-3afb-464c-ae14-7718481cbb72}",
"resource://webapptabs/components/nsMsgContentPolicy.js",
"@mozilla.org/messenger/content-policy;1");
OverlayManager.addCategory("content-policy", "webapptabs-content-policy",
"@oxymoronical.com/webapptabs/content-policy;1");
"@fractalbrew.com/webapptabs/content-policy;1");
OverlayManager.addOverlays(OVERLAYS);
flushContentPolicy();

Expand Down
11 changes: 5 additions & 6 deletions src/components/nsContentPolicy.js
Expand Up @@ -11,15 +11,14 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebTabs.
* The Original Code is WebApp Tabs.
*
* The Initial Developer of the Original Code is
* David Ascher.
* Portions created by the Initial Developer are Copyright (C) 2010
* Dave Townsend <dtownsend@oxymoronical.com>
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* 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
Expand Down Expand Up @@ -69,8 +68,8 @@ nsContentPolicy.prototype = {
": " + aResult + " - " + aReason);
}

let originDesc = ConfigManager.getWebAppForURL(aRequestOrigin.spec);
let desc = ConfigManager.getWebAppForURL(aContentLocation.spec);
let originDesc = ConfigManager.getWebAppForURL(aRequestOrigin);
let desc = ConfigManager.getWebAppForURL(aContentLocation);

if (aContext instanceof Ci.nsIDOMNode && aContext.localName == "browser" &&
aContext.className == "webapptab-browser") {
Expand Down

0 comments on commit 8407ae8

Please sign in to comment.