addon-sdk/source/test/addons/simple-prefs-l10n/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 } = require('chrome');
     7 const sp = require('sdk/simple-prefs');
     8 const app = require('sdk/system/xul-app');
     9 const self = require('sdk/self');
    10 const tabs = require('sdk/tabs');
    11 const { preferencesBranch } = require('sdk/self');
    13 const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {});
    15 // Once Bug 903018 is resolved, just move the application testing to
    16 // module.metadata.engines
    17 //
    18 // This should work in Fennec, needs to be refactored to work, via bug 979645
    19 if (app.is('Firefox')) {
    20   exports.testAOMLocalization = function(assert, done) {
    21       tabs.open({
    22         url: 'about:addons',
    23         onReady: function(tab) {
    24           tab.attach({
    25             contentScriptWhen: 'end',
    26             contentScript: 'function onLoad() {\n' +
    27                              'unsafeWindow.removeEventListener("load", onLoad, false);\n' +
    28                              'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {\n' +
    29                                'unsafeWindow.gViewController.viewObjects.detail.node.addEventListener("ViewChanged", function whenViewChanges() {\n' +
    30                                  'unsafeWindow.gViewController.viewObjects.detail.node.removeEventListener("ViewChanged", whenViewChanges, false);\n' +
    31                                  'setTimeout(function() {\n' + // TODO: figure out why this is necessary..
    32                                      'self.postMessage({\n' +
    33                                        'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[data-jetpack-id=\'' + self.id + '\']"))\n' +
    34                                      '});\n' +
    35                                  '}, 250);\n' +
    36                                '}, false);\n' +
    37                                'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);\n' +
    38                              '});\n' +
    39                              'function getAttributes(ele) {\n' +
    40                                'if (!ele) return {};\n' +
    41                                'return {\n' +
    42                                  'title: ele.getAttribute("title")\n' +
    43                                '}\n' +
    44                              '}\n' +
    45                            '}\n' +
    46                            // Wait for the load event ?
    47                            'if (document.readyState == "complete") {\n' +
    48                              'onLoad()\n' +
    49                            '} else {\n' +
    50                              'unsafeWindow.addEventListener("load", onLoad, false);\n' +
    51                            '}\n',
    52             onMessage: function(msg) {
    53               // test somePreference
    54               assert.equal(msg.somePreference.title, 'A', 'somePreference title is correct');
    55               tab.close(done);
    56             }
    57           });
    58         }
    59       });
    60   }
    61 } else {
    62   exports['test unsupported'] = (assert) => assert.pass('This test is unsupported.');
    63 }
    65 require('sdk/test/runner').runTestsFromModule(module);

mercurial