This repository was archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtest.mock-hangout.selenium.js
179 lines (163 loc) · 6.93 KB
/
test.mock-hangout.selenium.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var expect = require('expect.js'),
_ = require("underscore"),
common = require('./common');
describe("MOCK HANGOUT", function() {
var browser = null,
event = null,
session = null;
if (process.env.SKIP_SELENIUM_TESTS) {
return;
}
this.timeout(60000); // Extra long timeout for selenium :(
before(function(done) {
this.timeout(240000);
common.stopSeleniumServer().then(function() {
common.getSeleniumBrowser(function (theBrowser) {
browser = theBrowser;
common.standardSetup(function() {
event = common.server.db.events.findWhere({shortName: "writers-at-work"});
event.set("open", true);
session = event.get("sessions").at(0);
done();
});
});
});
});
after(function(done) {
browser.quit().then(function() {
common.standardShutdown(done);
});
});
afterEach(function(done) {
// Get a URL that won't throw modals at us.
browser.get(common.URL + "/public/html/test.html").then(function() {
done();
});
});
it("Communicates the hangout's URL on connction.", function(done) {
var u1 = common.server.db.users.at(0);
browser.mockAuthenticate(u1.get("sock-key"));
// At first, there's no hangout url..
expect(session.get("hangout-url")).to.be(null);
// but after we connect ...
var url = common.URL + "/test/hangout/" + session.id + "/";
browser.get(url);
browser.waitForFunc(function() {
return session.getNumConnectedParticipants() == 1 && session.get("hangout-url") !== null;
}).then(function() {;
expect(session.get("hangout-url")).to.eql(url);
expect(session.get("hangout-id")).to.eql(url + "-id");
done();
});
});
it("Updates connected participants who don't load app.", function(done) {
var u1 = common.server.db.users.at(0);
var u2 = common.server.db.users.at(1);
var u3 = common.server.db.users.at(2);
var u4 = common.server.db.users.at(3);
var baseUrl = common.URL + "/test/hangout/" + session.id + "/";
var queryUrl = baseUrl + "?mockUserIds=" + [u1.id, u2.id, u3.id].join(",");
browser.mockAuthenticate(u1.get("sock-key"));
// First, load the hangout without extra users.
browser.get(queryUrl);
// Wait for iframe to load. Would be cleaner to introspect, but.. ugh.
browser.waitForFunc(function() {
return session.getNumConnectedParticipants() == 1;
}).then(function() {
expect(session.getNumConnectedParticipants()).to.be(1);
});
// Next, load the hangout with u2 and u3 as non-app users
browser.get(queryUrl)
browser.waitForFunc(function() {
return session.getNumConnectedParticipants() == 3;
}).then(function() {
expect(_.pluck(session.get("connectedParticipants"), "id")).to.eql([
u1.id, u2.id, u3.id
]);
session.set("hangout-url", baseUrl);
done();
});
});
function hangoutShowsNoAuthError() {
var frame = "document.querySelector('iframe').contentWindow.";
return browser.wait(function() {
return browser.executeScript("try { return " +
frame + frame + "document.querySelector('.alert-error').innerHTML;" +
"} catch (e) { return ''; }"
).then(function(html) {;
return html.indexOf("We could not log you in to Unhangout.") != -1;
});
});
}
function hangoutShowsAboutActivity() {
var frame = "document.querySelector('iframe').contentWindow.";
return browser.wait(function() {
return browser.executeScript("try { " +
"return " + frame + frame +
"document.querySelector('.about-activity p').innerHTML;" +
"} catch (e) { return ''; }"
).then(function(html) {
return html.indexOf("helps the Unhangout Permalink service") != -1;
});
});
}
it("Shows an auth error when not authenticated.", function(done) {
// Clear any latent auth
session.set("connectedParticipants", []);
browser.unMockAuthenticate();
browser.get(common.FAST_URL);
browser.executeScript("return localStorage.removeItem('UNHANGOUT_AUTH');");
browser.get(common.URL + "/test/hangout/" + session.id + "/");
hangoutShowsNoAuthError().then(function() {
expect(session.getNumConnectedParticipants()).to.be(0);
done();
});
});
/*
* No longer using local-storage -- just do cookie or URL params. Most
* browsers that have 3rd-party cookies disabled also disable 3rd-party
* local storage.
it("Authenticates with local storage.", function(done) {
// Set the mock cookie.
session.set("connectedParticipants", []);
browser.then(function() { console.log("a1"); });
browser.get(common.URL);
browser.then(function() { console.log("a2"); });
browser.mockAuthenticate("regular1");
browser.then(function() { console.log("a3"); });
// Now visit a page again, which should trigger setting local storage.
browser.get(common.URL);
browser.then(function() { console.log("a4"); });
// Remove auth cookie (but not localStorage).
browser.unMockAuthenticate();
browser.then(function() { console.log("a5"); });
browser.get(common.URL + "/test/hangout/" + session.id + "/");
var frame = "document.querySelector('iframe').contentWindow.";
// Now visit the hangout. We should be authed by local storage.
browser.then(function() { console.log("a6"); });
hangoutShowsAboutActivity().then(function() {
browser.then(function() { console.log("a7"); });
return common.await(function() {
return session.getNumConnectedParticipants() == 1;
});
}).then(function() {
done();
});
});
*/
it("Gets sock key from URL param if localStorage/cookie fail", function(done) {
var user = common.server.db.users.findWhere({"sock-key": "regular1"});
session.set("connectedParticipants", []);
session.set("hangout-url", null);
// Make sure we're logged out.
browser.unMockAuthenticate();
browser.executeScript("return localStorage.removeItem('UNHANGOUT_AUTH');");
browser.get(common.URL + "/test/hangout/" + session.id + "/" +
"?sockKey=" + user.get("sock-key") +
"&userId=" + user.id);
browser.waitForHangoutReady(session, user.get("sock-key"));
hangoutShowsAboutActivity().then(function() {
done();
});
});
});