This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
activity_window_test.js
130 lines (116 loc) · 4.03 KB
/
activity_window_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* global AppWindow, ActivityWindow, MocksHelper */
'use strict';
requireApp('system/test/unit/mock_orientation_manager.js');
requireApp('system/shared/test/unit/mocks/mock_manifest_helper.js');
requireApp('system/shared/test/unit/mocks/mock_settings_listener.js');
requireApp('system/test/unit/mock_applications.js');
requireApp('system/test/unit/mock_attention_screen.js');
requireApp('system/shared/test/unit/mocks/mock_screen_layout.js');
var mocksForActivityWindow = new MocksHelper([
'OrientationManager', 'Applications', 'SettingsListener',
'ManifestHelper', 'AttentionScreen'
]).init();
suite('system/ActivityWindow', function() {
mocksForActivityWindow.attachTestHelpers();
var activityWindow;
var stubById;
var fakeConfig = {
'url': 'app://fakeact.gaiamobile.org/pick.html',
'oop': true,
'name': 'Fake Activity',
'manifestURL': 'app://fakeact.gaiamobile.org/manifest.webapp',
'origin': 'app://fakeact.gaiamobile.org',
'manifest': {
'name': 'Fake Activity'
}
};
setup(function(done) {
stubById = this.sinon.stub(document, 'getElementById');
stubById.returns(document.createElement('div'));
requireApp('system/js/system.js');
requireApp('system/js/browser_config_helper.js');
requireApp('system/js/browser_frame.js');
requireApp('system/js/app_window.js');
requireApp('system/js/browser_mixin.js');
requireApp('system/js/activity_window.js', done);
});
teardown(function() {
stubById.restore();
});
suite('activity window instance.', function() {
var app, appF, appOrientationUndefined;
setup(function() {
app = new AppWindow({
iframe: document.createElement('iframe'),
frame: document.createElement('div'),
origin: 'http://fake',
url: 'http://fakeurl/index.html',
manifestURL: 'http://fakemanifesturl',
name: 'fake',
manifest: {
orientation: 'default'
}
});
appF = new AppWindow({
iframe: document.createElement('iframe'),
frame: document.createElement('div'),
origin: 'http://fake',
url: 'http://fakeurl/index.html',
manifestURL: 'http://fakemanifesturl',
name: 'fake',
manifest: {
orientation: 'default',
fullscreen: true
}
});
appOrientationUndefined = new AppWindow({
iframe: document.createElement('iframe'),
frame: document.createElement('div'),
origin: 'http://fake',
url: 'http://fakeurl/index.html',
manifestURL: 'http://fakemanifesturl',
name: 'fake',
manifest: {
}
});
});
teardown(function() {
});
test('Render activity inside its caller', function() {
var activity = new ActivityWindow(fakeConfig, app);
assert.deepEqual(activity.containerElement, app.element);
});
test('requestOpen', function() {
var activity = new ActivityWindow(fakeConfig, app);
var stubRequestOpen = this.sinon.stub(app, 'requestOpen');
activity.requestOpen();
assert.isTrue(stubRequestOpen.calledOnce);
});
test('copy fullscreen from caller', function() {
var activity = new ActivityWindow(fakeConfig, appF);
assert.isTrue(activity.element.classList.contains('fullscreen-app'));
});
test('Activity created', function() {
var created = false;
window.addEventListener('activitycreated', function oncreated() {
window.removeEventListener('activitycreated', oncreated);
created = true;
});
activityWindow = new ActivityWindow(fakeConfig);
assert.equal(
activityWindow.browser.element.getAttribute('mozbrowser'),
'true');
assert.isTrue(created);
});
test('Activity should stop event propagation', function() {
var activity = new ActivityWindow(fakeConfig, appOrientationUndefined);
var spy = this.sinon.spy();
activity.handleEvent({
type: 'mozbrowserloadend',
stopPropagation: spy,
detail: {}
});
assert.isTrue(spy.called);
});
});
});