-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
200 lines (172 loc) · 5.27 KB
/
util.js
File metadata and controls
200 lines (172 loc) · 5.27 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Fake utils for testing.
*/
goog.module('firebaseui.auth.testing.FakeUtil');
goog.module.declareLegacyNamespace();
goog.setTestOnly();
var Disposable = goog.require('goog.Disposable');
var PropertyReplacer = goog.require('goog.testing.PropertyReplacer');
var util = goog.require('firebaseui.auth.util');
/**
* Fake utils class.
* @constructor
* @extends {Disposable}
*/
var FakeUtil = function() {
FakeUtil.base(this, 'constructor');
this.hasOpener_ = false;
this.goToUrl_ = null;
this.openerGoToUrl_ = null;
this.closedWindow_ = null;
this.popupUrl_ = null;
this.openUrl_ = null;
this.windowName_ = null;
this.lastHistoryState_ = null;
this.lastHistoryTitle_ = null;
this.lastHistoryUrl_ = null;
};
goog.inherits(FakeUtil, Disposable);
/**
* Installs the fake utils.
* @return {!FakeUtil} The fake util.
*/
FakeUtil.prototype.install = function() {
var r = this.replacer_ = new PropertyReplacer();
var self = this;
r.set(util, 'goTo', function(url) {
self.goToUrl_ = url;
});
r.set(util, 'openerGoTo', function(url) {
self.openerGoToUrl_ = url;
});
r.set(util, 'hasOpener', function() {
return !!self.hasOpener_;
});
r.set(util, 'close', function(window) {
self.closedWindow_ = window;
});
r.set(util, 'popup', function(url) {
self.popupUrl_ = url;
});
r.set(util, 'open', function(url, windowName) {
self.openUrl_ = url;
self.windowName_ = windowName;
});
r.set(util, 'replaceHistoryState', function(state, title, url) {
self.lastHistoryState_ = state;
self.lastHistoryTitle_ = title;
self.lastHistoryUrl_ = url;
});
return this;
};
/** Removes the fake utils hooks. */
FakeUtil.prototype.uninstall = function() {
assertNull('unexpected goTo', this.goToUrl_);
assertNull('unexpected openerGoTo', this.openerGoToUrl_);
assertNull('unexpected window close', this.closedWindow_);
assertNull('unexpected popup window', this.popupUrl_);
assertNull('unexpected replaceHistoryState', this.lastHistoryUrl_);
this.hasOpener_ = null;
this.goToUrl_ = null;
this.openerGoToUrl_ = null;
this.closedWindow_ = null;
this.popupUrl_ = null;
if (this.replacer_) {
this.replacer_.reset();
this.replacer_ = null;
}
this.lastHistoryState_ = null;
this.lastHistoryTitle_ = null;
this.lastHistoryUrl_ = null;
};
/** @override */
FakeUtil.prototype.disposeInternal = function() {
this.uninstall();
FakeUtil.base(this, 'disposeInternal');
};
/**
* @param {boolean} hasOpener Whether the current window has an opener.
*/
FakeUtil.prototype.setHasOpener = function(hasOpener) {
this.hasOpener_ = hasOpener;
};
/**
* Asserts the window location is set to the given URL.
* @param {string} url The current location URL.
*/
FakeUtil.prototype.assertGoTo = function(url) {
assertEquals(url, this.goToUrl_);
this.goToUrl_ = null;
};
/**
* Asserts the opener window location is set to the given URL.
* @param {string} url The current location URL.
*/
FakeUtil.prototype.assertOpenerGoTo = function(url) {
assertEquals(url, this.openerGoToUrl_);
this.openerGoToUrl_ = null;
};
/**
* Asserts the given URL is loaded in the given window.
* @param {string} url The URL to be loaded.
* @param {string} windowName The window name to be loaded into.
*/
FakeUtil.prototype.assertOpen = function(url, windowName) {
assertEquals(url, this.openUrl_);
assertEquals(windowName, this.windowName_);
this.openUrl_ = null;
this.windowName_ = null;
};
/**
* Asserts a window is closed.
* @param {!Window} window The closed window.
*/
FakeUtil.prototype.assertWindowClosed =
function(window) {
assertEquals(window, this.closedWindow_);
this.closedWindow_ = null;
};
/**
* Asserts a window is not closed.
* @param {!Window} window The still open window.
*/
FakeUtil.prototype.assertWindowNotClosed =
function(window) {
assertNotEquals(window, this.closedWindow_);
};
/**
* Asserts a popup window is opened, and the location is set to the URL.
* @param {string} url The URL of the popup window.
*/
FakeUtil.prototype.assertPopupWindow = function(url) {
assertEquals(url, this.popupUrl_);
this.popupUrl_ = null;
};
/**
* Asserts replaceHistoryState is called with provided history state.
* @param {!Object} state The last history state to assert.
* @param {string} title The associated document title.
* @param {string} url The associated URL.
*/
FakeUtil.prototype.assertReplaceHistoryState = function(state, title, url) {
assertObjectEquals(state, this.lastHistoryState_);
assertEquals(title, this.lastHistoryTitle_);
assertEquals(url, this.lastHistoryUrl_);
this.lastHistoryState_ = null;
this.lastHistoryTitle_ = null;
this.lastHistoryUrl_ = null;
};
exports = FakeUtil;