addon-sdk/source/test/test-window-loader.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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 'use strict';
michael@0 5
michael@0 6 // Opening new windows in Fennec causes issues
michael@0 7 module.metadata = {
michael@0 8 engines: {
michael@0 9 'Firefox': '*'
michael@0 10 }
michael@0 11 };
michael@0 12
michael@0 13 const { WindowLoader } = require('sdk/windows/loader'),
michael@0 14 { Trait } = require('sdk/deprecated/traits');
michael@0 15
michael@0 16 const Loader = Trait.compose(
michael@0 17 WindowLoader,
michael@0 18 {
michael@0 19 constructor: function Loader(options) {
michael@0 20 this._onLoad = options.onLoad;
michael@0 21 this._onUnload = options.onUnload;
michael@0 22 if ('window' in options)
michael@0 23 this._window = options.window;
michael@0 24 this._load();
michael@0 25 this.window = this._window;
michael@0 26 },
michael@0 27 window: null,
michael@0 28 _onLoad: null,
michael@0 29 _onUnload: null,
michael@0 30 _tabOptions: []
michael@0 31 }
michael@0 32 );
michael@0 33
michael@0 34 exports['test compositions with missing required properties'] = function(assert) {
michael@0 35 assert.throws(
michael@0 36 function() WindowLoader.compose({})(),
michael@0 37 /Missing required property: _onLoad/,
michael@0 38 'should throw missing required property exception'
michael@0 39 );
michael@0 40 assert.throws(
michael@0 41 function() WindowLoader.compose({ _onLoad: null, _tabOptions: null })(),
michael@0 42 /Missing required property: _onUnload/,
michael@0 43 'should throw missing required property `_onUnload`'
michael@0 44 );
michael@0 45 assert.throws(
michael@0 46 function() WindowLoader.compose({ _onUnload: null, _tabOptions: null })(),
michael@0 47 /Missing required property: _onLoad/,
michael@0 48 'should throw missing required property `_onLoad`'
michael@0 49 );
michael@0 50 assert.throws(
michael@0 51 function() WindowLoader.compose({ _onUnload: null, _onLoad: null })(),
michael@0 52 /Missing required property: _tabOptions/,
michael@0 53 'should throw missing required property `_tabOptions`'
michael@0 54 );
michael@0 55 };
michael@0 56
michael@0 57 exports['test `load` events'] = function(assert, done) {
michael@0 58 let onLoadCalled = false;
michael@0 59 Loader({
michael@0 60 onLoad: function(window) {
michael@0 61 onLoadCalled = true;
michael@0 62 assert.equal(window, this._window, 'windows should match');
michael@0 63 assert.equal(
michael@0 64 window.document.readyState, 'complete', 'window must be fully loaded'
michael@0 65 );
michael@0 66 window.close();
michael@0 67 },
michael@0 68 onUnload: function(window) {
michael@0 69 assert.equal(window, this._window, 'windows should match');
michael@0 70 assert.equal(
michael@0 71 window.document.readyState, 'complete', 'window must be fully loaded'
michael@0 72 );
michael@0 73 assert.ok(onLoadCalled, 'load callback is supposed to be called');
michael@0 74 done();
michael@0 75 }
michael@0 76 });
michael@0 77 };
michael@0 78
michael@0 79 exports['test removeing listeners'] = function(assert, done) {
michael@0 80 Loader({
michael@0 81 onLoad: function(window) {
michael@0 82 assert.equal(window, this._window, 'windows should match');
michael@0 83 window.close();
michael@0 84 },
michael@0 85 onUnload: done
michael@0 86 });
michael@0 87 };
michael@0 88
michael@0 89 exports['test create loader from opened window'] = function(assert, done) {
michael@0 90 let onUnloadCalled = false;
michael@0 91 Loader({
michael@0 92 onLoad: function(window) {
michael@0 93 assert.equal(window, this._window, 'windows should match');
michael@0 94 assert.equal(window.document.readyState, 'complete', 'window must be fully loaded');
michael@0 95 Loader({
michael@0 96 window: window,
michael@0 97 onLoad: function(win) {
michael@0 98 assert.equal(win, window, 'windows should match');
michael@0 99 window.close();
michael@0 100 },
michael@0 101 onUnload: function(window) {
michael@0 102 assert.ok(onUnloadCalled, 'first handler should be called already');
michael@0 103 done();
michael@0 104 }
michael@0 105 });
michael@0 106 },
michael@0 107 onUnload: function(window) {
michael@0 108 onUnloadCalled = true;
michael@0 109 }
michael@0 110 });
michael@0 111 };
michael@0 112
michael@0 113 require('sdk/test').run(exports);

mercurial