Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / crazy_extension / background.js
blob1a108dfea2757de0ce110621ddb2ae48758659f1
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This test is for bizarre things that extensions probably will do. We just
6 // need to ensure that behaviour is predictable.
8 chrome.test.runTests([
9 function accessNonexistentIframe() {
10 var iframe = document.createElement("iframe");
11 iframe.src = document.location;
12 var iteration = 0;
13 iframe.addEventListener('load', function() {
14 switch (iteration) {
15 case 0: {
16 // First test is that chrome.app doesn't even get defined if it was
17 // never accessed.
18 var iframeChrome = iframe.contentWindow.chrome;
19 document.body.removeChild(iframe);
20 chrome.test.assertEq(undefined, iframeChrome.app);
21 document.body.appendChild(iframe);
22 break;
24 case 1: {
25 // Second test is that it does if accessed before removal.
26 var iframeChrome = iframe.contentWindow.chrome;
27 var iframeChromeApp = iframeChrome.app;
28 chrome.test.assertTrue(typeof(iframeChromeApp) == 'object');
29 document.body.removeChild(iframe);
30 chrome.test.assertTrue(typeof(iframeChrome.app) == 'object');
31 document.body.appendChild(iframe);
32 break;
34 case 2: {
35 // Third test is that accessing API methods doesn't crash the
36 // renderer if the frame doesn't exist anymore.
37 var iframeChromeApp = iframe.contentWindow.chrome.app;
38 document.body.removeChild(iframe);
39 chrome.test.assertEq(undefined, iframeChromeApp.getDetails());
40 chrome.test.succeed();
41 break;
44 iteration++;
45 });
46 document.body.appendChild(iframe);
48 ]);