addon-sdk/source/test/test-windows-common.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 const { Loader } = require('sdk/test/loader');
michael@0 7 const { browserWindows } = require('sdk/windows');
michael@0 8 const { viewFor } = require('sdk/view/core');
michael@0 9 const { modelFor } = require('sdk/model/core');
michael@0 10 const { Ci } = require("chrome");
michael@0 11 const { isBrowser, getWindowTitle } = require("sdk/window/utils");
michael@0 12
michael@0 13 // TEST: browserWindows Iterator
michael@0 14 exports.testBrowserWindowsIterator = function(assert) {
michael@0 15 let activeWindowCount = 0;
michael@0 16 let windows = [];
michael@0 17 let i = 0;
michael@0 18 for each (let window in browserWindows) {
michael@0 19 if (window === browserWindows.activeWindow)
michael@0 20 activeWindowCount++;
michael@0 21
michael@0 22 assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
michael@0 23 assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
michael@0 24 windows.push(window);
michael@0 25 }
michael@0 26 assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
michael@0 27
michael@0 28 i = 0;
michael@0 29 for (let j in browserWindows) {
michael@0 30 assert.equal(j, i++, 'for (x in browserWindows) works');
michael@0 31 }
michael@0 32 };
michael@0 33
michael@0 34
michael@0 35 exports.testWindowTabsObject_alt = function(assert, done) {
michael@0 36 let window = browserWindows.activeWindow;
michael@0 37 window.tabs.open({
michael@0 38 url: 'data:text/html;charset=utf-8,<title>tab 2</title>',
michael@0 39 inBackground: true,
michael@0 40 onReady: function onReady(tab) {
michael@0 41 assert.equal(tab.title, 'tab 2', 'Correct new tab title');
michael@0 42 assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
michael@0 43
michael@0 44 // end test
michael@0 45 tab.close(done);
michael@0 46 }
michael@0 47 });
michael@0 48 };
michael@0 49
michael@0 50 // TEST: browserWindows.activeWindow
michael@0 51 exports.testWindowActivateMethod_simple = function(assert) {
michael@0 52 let window = browserWindows.activeWindow;
michael@0 53 let tab = window.tabs.activeTab;
michael@0 54
michael@0 55 window.activate();
michael@0 56
michael@0 57 assert.equal(browserWindows.activeWindow, window,
michael@0 58 'Active window is active after window.activate() call');
michael@0 59 assert.equal(window.tabs.activeTab, tab,
michael@0 60 'Active tab is active after window.activate() call');
michael@0 61 };
michael@0 62
michael@0 63
michael@0 64 exports["test getView(window)"] = function(assert, done) {
michael@0 65 browserWindows.once("open", window => {
michael@0 66 const view = viewFor(window);
michael@0 67
michael@0 68 assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
michael@0 69 assert.ok(isBrowser(view), "view is a browser window");
michael@0 70 assert.equal(getWindowTitle(view), window.title,
michael@0 71 "window has a right title");
michael@0 72
michael@0 73 window.close(done);
michael@0 74 });
michael@0 75
michael@0 76
michael@0 77 browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
michael@0 78 };
michael@0 79
michael@0 80
michael@0 81 exports["test modelFor(window)"] = function(assert, done) {
michael@0 82 browserWindows.once("open", window => {
michael@0 83 const view = viewFor(window);
michael@0 84
michael@0 85 assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
michael@0 86 assert.ok(isBrowser(view), "view is a browser window");
michael@0 87 assert.ok(modelFor(view) === window, "modelFor(browserWindow) is SDK window");
michael@0 88
michael@0 89 window.close(done);
michael@0 90 });
michael@0 91
michael@0 92
michael@0 93 browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
michael@0 94 };
michael@0 95
michael@0 96 require('sdk/test').run(exports);

mercurial