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