- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / app_background_page / two_with_manifest / test.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 // This test runs through an expected use of a live background page:
6 // - A background page is opened via the manifest.
7 // - A live (web-extent) web page is loaded (a.html), which opens the background
8 //   page using a different name.
9 // - We wait for this background page to get loaded. If a visible tab appears
10 //   instead, the test fails, otherwise it succeeds as soon as the page is
11 //   loaded.
12
13 var pagePrefix =
14     'http://a.com:PORT/extensions/api_test/app_background_page/common';
15
16 // Dispatch "tunneled" functions from the live web pages to this testing page.
17 chrome.extension.onRequest.addListener(function(request) {
18   window[request.name](request.args);
19 });
20
21 // At no point should a window be created that contains the background page
22 // (bg.html).
23 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
24   if (tab.url.match("bg\.html$")) {
25     chrome.test.notifyFail("popup opened instead of background page");
26   }
27 });
28
29 // Start the test by opening the first page in the app. This will create a
30 // background page whose name is "bg", and this should replace the background
31 // page created by the manifest (named "background").
32 window.onload = function() {
33   // We wait for window.onload before getting the test config.  If the
34   // config is requested before onload, then sometimes onload has already
35   // fired by the time chrome.test.getConfig()'s callback runs.
36   chrome.test.getConfig(function(config) {
37     var a_url =
38         pagePrefix.replace(/PORT/, config.testServer.port) + '/a.html';
39     chrome.tabs.create({ 'url': a_url });
40   });
41 }
42
43 // Background page opened.
44 function onBackgroundPageLoaded() {
45   // If this gets called without failing the test (by opening a visible
46   // background page) we're done.
47   chrome.test.notifyPass();
48 }
49
50 // A second background page opened.
51 function onBackgroundPageResponded() {
52   chrome.test.notifyFail("onBackgroundPageResponded called unexpectedly");
53 }
54
55 // The background counter check found an unexpected value (most likely caused
56 // by an unwanted navigation).
57 function onCounterError() {
58   chrome.test.notifyFail("checkCounter found an unexpected value");
59 }