- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / window_open / spanning / background.js
1 // Copyright (c) 2011 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.
4
5 var nextTest = null;
6 openFromNormalShouldOpenInNormal();
7
8 function openFromNormalShouldOpenInNormal() {
9   nextTest = openFromExtensionHostInIncognitoBrowserShouldOpenInNormalBrowser;
10   chrome.windows.getAll({populate: true}, function(windows) {
11     chrome.test.assertEq(1, windows.length);
12     chrome.test.assertFalse(windows[0].incognito);
13     chrome.test.assertEq(1, windows[0].tabs.length);
14     chrome.test.assertFalse(windows[0].tabs[0].incognito);
15
16     // The rest of the test continues in infobar.html.
17     chrome.infobars.show({tabId: windows[0].tabs[0].id, path: "infobar.html"});
18   });
19 }
20
21 function openFromExtensionHostInIncognitoBrowserShouldOpenInNormalBrowser() {
22   nextTest = null;
23   chrome.windows.getCurrent(function(normalWin) {
24     chrome.test.assertFalse(normalWin.incognito);
25     // Create an incognito window.
26     chrome.windows.create({ incognito: true }, function(incognitoWin) {
27       // Remove the normal window. We keep running because of the incognito
28       // window.
29       chrome.windows.remove(normalWin.id, function() {
30         chrome.tabs.getAllInWindow(incognitoWin.id, function(tabs) {
31           chrome.test.assertEq(1, tabs.length);
32           // The rest of the test continues in infobar.html.
33           chrome.infobars.show({tabId: tabs[0].id, path: "infobar.html"});
34         });
35       });
36     });
37   });
38 }
39
40 function verifyCreatedTab(tab) {
41   // The new tab should be a normal tab, and it should be in a normal
42   // window.
43   chrome.test.assertFalse(tab.incognito);
44   chrome.windows.get(tab.windowId, function(win) {
45     chrome.test.assertFalse(win.incognito);
46     if (nextTest) {
47       nextTest();
48     } else {
49       chrome.test.notifyPass();
50     }
51   });
52 }