This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
browser.js
78 lines (66 loc) · 1.68 KB
/
browser.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
/**
* Abstraction around browser app.
* @constructor
* @param {Marionette.Client} client for operations.
*/
function Browser(client) {
this.client = client;
}
/**
* @type {string} Origin of browser app.
*/
Browser.URL = 'app://browser.gaiamobile.org';
Browser.Selectors = {
'searchBar': '#url-input',
'searchButton': '#url-button',
'mozbrowser': 'iframe[mozbrowser]',
'bookmarkButton': '#bookmark-button',
'addToHomeButton': '#bookmark-menu-add-home'
};
/**
* @private
* @param {Marionette.Client} client for selector.
* @param {String} name of selector [its a key in Browser.Selectors].
*/
function findElement(client, name) {
return client.findElement(Browser.Selectors[name]);
}
Browser.prototype = {
get searchBar() {
return findElement(this.client, 'searchBar');
},
get searchButton() {
return findElement(this.client, 'searchButton');
},
get bookmarkButton() {
return findElement(this.client, 'bookmarkButton');
},
get addToHomeButton() {
return findElement(this.client, 'addToHomeButton');
},
/**
* Finds iframe of current running tab.
*/
currentTabFrame: function() {
// being really lazy right now and just finding first mozbrowser
return this.client.findElement(Browser.Selectors.mozbrowser);
},
/**
* Launches browser app and focuses on frame.
*/
launch: function() {
this.client.apps.launch(Browser.URL);
this.client.apps.switchToApp(Browser.URL);
},
close: function() {
this.client.apps.close(Browser.URL);
},
/**
* Back to Browser app frame
*/
backToApp: function() {
this.client.switchToFrame();
this.client.apps.switchToApp(Browser.URL);
}
};
module.exports = Browser;