3 function createAndNavigateIFrame(url
)
5 var iframe
= document
.createElement("iframe");
7 iframe
.name
= "frame" + ++framesCount
;
8 iframe
.id
= iframe
.name
;
9 document
.body
.appendChild(iframe
);
12 function removeIFrame(name
)
14 var iframe
= document
.querySelector("#" + name
);
15 iframe
.parentElement
.removeChild(iframe
);
18 function navigateIFrame(name
, url
)
20 var iframe
= document
.querySelector("#" + name
);
24 function swapFrameCache(name
)
26 var iframe
= document
.querySelector("#" + name
);
27 iframe
.contentWindow
.applicationCache
.swapCache();
30 var initialize_ApplicationCacheTest = function() {
32 InspectorTest
.createAndNavigateIFrame = function(url
, callback
)
34 InspectorTest
.addSniffer(WebInspector
.ResourceTreeModel
.prototype, "_frameNavigated", frameNavigated
);
35 InspectorTest
.evaluateInPage("createAndNavigateIFrame(unescape('" + escape(url
) + "'))");
37 function frameNavigated(frame
)
43 InspectorTest
.navigateIFrame = function(frameId
, url
, callback
)
45 var frame
= InspectorTest
.resourceTreeModel
.frameForId(frameId
)
46 InspectorTest
.evaluateInPage("navigateIFrame(unescape('" + escape(frame
.name
) +"'), unescape('" + escape(url
) + "'))");
47 InspectorTest
.addSniffer(WebInspector
.ResourceTreeModel
.prototype, "_frameNavigated", frameNavigated
);
49 function frameNavigated(frame
)
55 InspectorTest
.removeIFrame = function(frameId
, callback
)
57 var frame
= InspectorTest
.resourceTreeModel
.frameForId(frameId
)
58 InspectorTest
.evaluateInPage("removeIFrame(unescape('" + escape(frame
.name
) +"'))");
59 InspectorTest
.addSniffer(WebInspector
.ResourceTreeModel
.prototype, "_frameDetached", frameDetached
);
61 function frameDetached(frame
)
67 InspectorTest
.swapFrameCache = function(frameId
)
69 var frame
= InspectorTest
.resourceTreeModel
.frameForId(frameId
);
70 InspectorTest
.evaluateInPage("swapFrameCache(unescape('" + escape(frame
.name
) +"'))");
74 InspectorTest
.dumpApplicationCache = function()
76 InspectorTest
.dumpApplicationCacheTree();
77 InspectorTest
.dumpApplicationCacheModel();
78 InspectorTest
.addResult("");
81 InspectorTest
.dumpApplicationCacheTree = function()
83 InspectorTest
.addResult("Dumping application cache tree:");
84 var applicationCacheTreeElement
= WebInspector
.panels
.resources
.applicationCacheListTreeElement
;
85 if (!applicationCacheTreeElement
.childCount()) {
86 InspectorTest
.addResult(" (empty)");
89 for (var i
= 0; i
< applicationCacheTreeElement
.childCount(); ++i
) {
90 var manifestTreeElement
= applicationCacheTreeElement
.childAt(i
);
91 InspectorTest
.addResult(" Manifest URL: " + manifestTreeElement
.manifestURL
);
92 if (!manifestTreeElement
.childCount()) {
93 InspectorTest
.addResult(" (no frames)");
96 for (var j
= 0; j
< manifestTreeElement
.childCount(); ++j
) {
97 var frameTreeElement
= manifestTreeElement
.childAt(j
);
98 InspectorTest
.addResult(" Frame: " + frameTreeElement
.displayName
);
103 InspectorTest
.frameIdToString = function(frameId
)
105 if (!InspectorTest
.framesByFrameId
)
106 InspectorTest
.framesByFrameId
= {};
107 var frame
= InspectorTest
.resourceTreeModel
.frameForId(frameId
);
109 frame
= InspectorTest
.framesByFrameId
[frameId
];
110 InspectorTest
.framesByFrameId
[frameId
] = frame
;
115 InspectorTest
.applicationCacheStatusToString = function(status
)
117 var statusInformation
= {};
118 statusInformation
[applicationCache
.UNCACHED
] = "UNCACHED";
119 statusInformation
[applicationCache
.IDLE
] = "IDLE";
120 statusInformation
[applicationCache
.CHECKING
] = "CHECKING";
121 statusInformation
[applicationCache
.DOWNLOADING
] = "DOWNLOADING";
122 statusInformation
[applicationCache
.UPDATEREADY
] = "UPDATEREADY";
123 statusInformation
[applicationCache
.OBSOLETE
] = "OBSOLETE";
124 return statusInformation
[status
] || statusInformation
[applicationCache
.UNCACHED
];
127 InspectorTest
.dumpApplicationCacheModel = function()
129 InspectorTest
.addResult("Dumping application cache model:");
130 var model
= WebInspector
.panels
.resources
._applicationCacheModel
;
133 for (var frameId
in model
._manifestURLsByFrame
)
134 frameIds
.push(frameId
);
136 function compareFunc(a
, b
) {
137 return InspectorTest
.frameIdToString(a
).localeCompare(InspectorTest
.frameIdToString(b
));
139 frameIds
.sort(compareFunc
);
141 if (!frameIds
.length
) {
142 InspectorTest
.addResult(" (empty)");
145 for (var i
= 0; i
< frameIds
.length
; ++i
) {
146 var frameId
= frameIds
[i
];
147 var manifestURL
= model
.frameManifestURL(frameId
);
148 var status
= model
.frameManifestStatus(frameId
);
149 InspectorTest
.addResult(" Frame: " + InspectorTest
.frameIdToString(frameId
));
150 InspectorTest
.addResult(" manifest url: " + manifestURL
);
151 InspectorTest
.addResult(" status: " + InspectorTest
.applicationCacheStatusToString(status
));
155 InspectorTest
.waitForFrameManifestURLAndStatus = function(frameId
, manifestURL
, status
, callback
)
157 var frameManifestStatus
= WebInspector
.panels
.resources
._applicationCacheModel
.frameManifestStatus(frameId
);
158 var frameManifestURL
= WebInspector
.panels
.resources
._applicationCacheModel
.frameManifestURL(frameId
);
159 if (frameManifestStatus
=== status
&& frameManifestURL
.indexOf(manifestURL
) !== -1) {
164 var handler
= InspectorTest
.waitForFrameManifestURLAndStatus
.bind(this, frameId
, manifestURL
, status
, callback
);
165 InspectorTest
.addSniffer(WebInspector
.ApplicationCacheModel
.prototype, "_frameManifestUpdated", handler
);
168 InspectorTest
.startApplicationCacheStatusesRecording = function()
170 if (InspectorTest
.applicationCacheStatusesRecords
) {
171 InspectorTest
.applicationCacheStatusesRecords
= {};
175 InspectorTest
.applicationCacheStatusesRecords
= {};
176 function addRecord(frameId
, manifestURL
, status
) {
178 record
.manifestURL
= manifestURL
;
179 record
.status
= status
;
180 if (!InspectorTest
.applicationCacheStatusesRecords
[frameId
])
181 InspectorTest
.applicationCacheStatusesRecords
[frameId
] = [];
182 InspectorTest
.applicationCacheStatusesRecords
[frameId
].push(record
);
184 if (InspectorTest
.awaitedFrameStatusEventsCount
&& InspectorTest
.awaitedFrameStatusEventsCount
[frameId
]) {
185 InspectorTest
.awaitedFrameStatusEventsCount
[frameId
].count
--;
186 if (!InspectorTest
.awaitedFrameStatusEventsCount
[frameId
].count
)
187 InspectorTest
.awaitedFrameStatusEventsCount
[frameId
].callback();
191 InspectorTest
.addSniffer(WebInspector
.ApplicationCacheModel
.prototype, "_frameManifestUpdated", addRecord
, true);
194 InspectorTest
.ensureFrameStatusEventsReceived = function(frameId
, count
, callback
)
196 var records
= InspectorTest
.applicationCacheStatusesRecords
[frameId
] || [];
197 var eventsLeft
= count
- records
.length
;
204 if (!InspectorTest
.awaitedFrameStatusEventsCount
)
205 InspectorTest
.awaitedFrameStatusEventsCount
= {};
206 InspectorTest
.awaitedFrameStatusEventsCount
[frameId
] = { count
: eventsLeft
, callback
: callback
};