forked from firebase/firebaseui-web
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil_test.js
More file actions
101 lines (89 loc) · 2.76 KB
/
Copy pathutil_test.js
File metadata and controls
101 lines (89 loc) · 2.76 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
/*
* 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 Tests for util.js.
*/
goog.provide('firebaseui.auth.utilTest');
goog.require('firebaseui.auth.util');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.testing.MockClock');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.recordFunction');
goog.setTestOnly('firebaseui.auth.utilTest');
var stubs = new goog.testing.PropertyReplacer();
var clock;
var BROWSER_URL = 'http://localhost';
function redirectCallback() {
firebaseui.auth.util.goTo(BROWSER_URL);
}
function setUp() {
clock = new goog.testing.MockClock();
clock.install();
stubs.set(firebaseui.auth.util, 'goTo', goog.testing.recordFunction());
}
function tearDown() {
stubs.reset();
clock.uninstall();
}
function testGetElement() {
// Test that the element is correctly retrieved.
var element = goog.dom.createDom(goog.dom.TagName.DIV);
element.setAttribute('id', 'myElement');
document.body.appendChild(element);
assertEquals(element, firebaseui.auth.util.getElement('#myElement'));
goog.dom.removeNode(element);
// Test getElement default error description.
try {
firebaseui.auth.util.getElement('#notFound');
fail('Should have thrown an error!');
} catch (e) {
assertEquals(e.message, 'Cannot find element.');
}
// Test getElement custom error description.
try {
firebaseui.auth.util.getElement('#notFound',
'Element requested was not found!');
fail('Should have thrown an error!');
} catch (e) {
assertEquals(e.message, 'Element requested was not found!');
}
}
function testIsHttpOrHttps() {
// HTTP scheme.
stubs.replace(
firebaseui.auth.util,
'getScheme',
function() {
return 'http:';
});
assertTrue(firebaseui.auth.util.isHttpOrHttps());
// HTTPS scheme.
stubs.replace(
firebaseui.auth.util,
'getScheme',
function() {
return 'https:';
});
assertTrue(firebaseui.auth.util.isHttpOrHttps());
// FILE scheme.
stubs.replace(
firebaseui.auth.util,
'getScheme',
function() {
return 'file:';
});
assertFalse(firebaseui.auth.util.isHttpOrHttps());
}