addon-sdk/source/test/addons/chrome/main.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict'
     6 const { Cu, Cc, Ci } = require('chrome');
     7 const Request = require('sdk/request').Request;
     8 const { WindowTracker } = require('sdk/deprecated/window-utils');
     9 const { close, open } = require('sdk/window/helpers');
    11 const XUL_URL = 'chrome://test/content/new-window.xul'
    13 const { Services } = Cu.import('resource://gre/modules/Services.jsm', {});
    14 const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm', {});
    16 exports.testChromeSkin = function(assert, done) {
    17   let skinURL = 'chrome://test/skin/style.css';
    19   Request({
    20     url: skinURL,
    21     overrideMimeType: 'text/plain',
    22     onComplete: function (response) {
    23       assert.equal(response.text.trim(), 'test{}', 'chrome.manifest skin folder was registered!');
    24       done();
    25     }
    26   }).get();
    28   assert.pass('requesting ' + skinURL);
    29 }
    31 exports.testChromeContent = function(assert, done) {
    32   let wt = WindowTracker({
    33     onTrack: function(window) {
    34       if (window.document.documentElement.getAttribute('windowtype') === 'test:window') {
    35       	assert.pass('test xul window was opened');
    36         wt.unload();
    38       	close(window).then(done, assert.fail);
    39       }
    40     }
    41   });
    43   open(XUL_URL).then(
    44     assert.pass.bind(assert, 'opened ' + XUL_URL),
    45     assert.fail);
    47   assert.pass('opening ' + XUL_URL);
    48 }
    50 exports.testChromeLocale = function(assert) {
    51   let jpLocalePath = Cc['@mozilla.org/chrome/chrome-registry;1'].
    52                        getService(Ci.nsIChromeRegistry).
    53                        convertChromeURL(NetUtil.newURI('chrome://test/locale/description.properties')).
    54                        spec.replace(/(en\-US|ja\-JP)/, 'ja-JP');
    55   let enLocalePath = jpLocalePath.replace(/ja\-JP/, 'en-US');
    57   let jpStringBundle = Services.strings.createBundle(jpLocalePath);
    58   assert.equal(jpStringBundle.GetStringFromName('test'),
    59                'ใƒ†ใ‚นใƒˆ',
    60                'locales ja-JP folder was copied correctly');
    62   let enStringBundle = Services.strings.createBundle(enLocalePath);
    63   assert.equal(enStringBundle.GetStringFromName('test'),
    64                'Test',
    65                'locales en-US folder was copied correctly');
    66 }
    68 require('sdk/test/runner').runTestsFromModule(module);

mercurial