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
|
<!DOCTYPE html>
<html>
<!--
Copyright 2008 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.net.IframeLoadMonitor</title>
<script src="../base.js"></script>
<script>
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.net.IframeLoadMonitor');
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<div id="frame_parent"></div>
<script>
var TEST_FRAME_SRCS = ['iframeloadmonitor_test_frame.html',
'iframeloadmonitor_test_frame2.html',
'iframeloadmonitor_test_frame3.html'];
// Create a new test case.
var iframeLoaderTestCase = new goog.testing.AsyncTestCase(document.title);
iframeLoaderTestCase.stepTimeout = 4 * 1000;
// Array holding all iframe load monitors.
iframeLoaderTestCase.iframeLoadMonitors_ = [];
// How many single frames finished loading
iframeLoaderTestCase.singleComplete_ = 0;
/** Sets up the test environment, adds tests and sets up the worker pools. */
iframeLoaderTestCase.setUpPage = function() {
this.log('Setting tests up');
iframeLoaderTestCase.waitForAsync('loading iframes');
var dom = goog.dom.getDomHelper();
// Load single frame
var frame = dom.createDom('iframe');
this.iframeLoadMonitors_.push(new goog.net.IframeLoadMonitor(frame));
goog.events.listen(this.iframeLoadMonitors_[0],
goog.net.IframeLoadMonitor.LOAD_EVENT, this);
var frameParent = dom.getElement('frame_parent');
dom.appendChild(frameParent, frame);
this.log('Loading frame at: ' + TEST_FRAME_SRCS[0]);
frame.src = TEST_FRAME_SRCS[0];
// Load single frame with content check
var frame1 = dom.createDom('iframe');
this.iframeLoadMonitors_.push(new goog.net.IframeLoadMonitor(frame1, true));
goog.events.listen(this.iframeLoadMonitors_[1],
goog.net.IframeLoadMonitor.LOAD_EVENT, this);
var frameParent = dom.getElement('frame_parent');
dom.appendChild(frameParent, frame1);
this.log('Loading frame with content check at: ' + TEST_FRAME_SRCS[0]);
frame1.src = TEST_FRAME_SRCS[0];
this.add(new goog.testing.TestCase.Test(
'test results', this.testResults, this));
};
/** Handles any events fired */
iframeLoaderTestCase.handleEvent = function(e) {
this.log('handleEvent, type: ' + e.type);
if (e.type == goog.net.IframeLoadMonitor.LOAD_EVENT) {
this.singleComplete_++;
this.callbacksComplete();
}
};
/** Checks if all the load callbacks are done*/
iframeLoaderTestCase.callbacksComplete = function() {
if (this.singleComplete_ == 2) {
iframeLoaderTestCase.continueTesting();
}
}
/** Tests the results. */
iframeLoaderTestCase.testResults = function() {
this.log('getting test results');
for (var i = 0; i < this.iframeLoadMonitors_.length; i++) {
assertTrue(this.iframeLoadMonitors_[i].isLoaded());
}
};
/** Used by the JsUnit test runner. */
function testResults() {
iframeLoaderTestCase.testResults();
}
/** Used by the JsUnit test runner. */
function setUpPage() {
iframeLoaderTestCase.runTests();
}
/** Standalone Closure Test Runner. */
if (typeof G_testRunner != 'undefined') {
G_testRunner.initialize(iframeLoaderTestCase);
}
</script>
</body>
</html>
|