- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / runtime / privileged / test.js
1 // Copyright (c) 2012 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 assertEq = chrome.test.assertEq;
6 var assertTrue = chrome.test.assertTrue;
7 var fail = chrome.test.fail;
8 var succeed = chrome.test.succeed;
9
10 function checkIsDefined(prop) {
11   if (!chrome.runtime) {
12     fail('chrome.runtime is not defined');
13     return false;
14   }
15   if (!chrome.runtime[prop]) {
16     fail('chrome.runtime.' + prop + ' is not undefined');
17     return false;
18   }
19   return true;
20 }
21
22 chrome.test.runTests([
23
24   function testGetURL() {
25     if (!checkIsDefined('getURL'))
26       return;
27     var url = chrome.runtime.getURL('_generated_background_page.html');
28     assertEq(url, window.location.href);
29     succeed();
30   },
31
32   function testGetManifest() {
33     if (!checkIsDefined('getManifest'))
34       return;
35     var manifest = chrome.runtime.getManifest();
36     if (!manifest || !manifest.background || !manifest.background.scripts) {
37       fail();
38       return;
39     }
40     assertEq(manifest.name, 'chrome.runtime API Test');
41     assertEq(manifest.version, '1');
42     assertEq(manifest.manifest_version, 2);
43     assertEq(manifest.background.scripts, ['test.js']);
44     succeed();
45   },
46
47   function testID() {
48     if (!checkIsDefined('id'))
49       return;
50     // We *could* get the browser to tell the test what the extension ID is,
51     // and compare against that. It's a pain. Testing for a non-empty ID should
52     // be good enough.
53     assertTrue(chrome.runtime.id != '', 'chrome.runtime.id is empty-string.');
54     succeed();
55   }
56
57 ]);