- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / webui / sandboxstatus_browsertest.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 /**
6  * TestFixture for SUID Sandbox testing.
7  * @extends {testing.Test}
8  * @constructor
9  */
10 function SandboxStatusUITest() {}
11
12 SandboxStatusUITest.prototype = {
13   __proto__: testing.Test.prototype,
14   /**
15    * Browse to the options page & call our preLoad().
16    */
17   browsePreload: 'chrome://sandbox',
18
19 };
20
21 // This test is for Linux only.
22 // PLEASE READ:
23 // - If failures of this test are a problem on a bot under your care,
24 //   the proper way to address such failures is to install the SUID
25 //   sandbox. See:
26 //     http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
27 // - PLEASE DO NOT GLOBALLY DISABLE THIS TEST.
28 // SUID sandbox is currently incompatible with AddressSanitizer,
29 // see http://crbug.com/137653.
30 GEN('#if defined(OS_LINUX) && !defined(ADDRESS_SANITIZER)');
31 GEN('# define MAYBE_testSUIDSandboxEnabled \\');
32 GEN('     testSUIDSandboxEnabled');
33 GEN('#else');
34 GEN('# define MAYBE_testSUIDSandboxEnabled \\');
35 GEN('     DISABLED_testSUIDSandboxEnabled');
36 GEN('#endif');
37
38 /**
39  * Test if the SUID sandbox is enabled.
40  */
41 TEST_F('SandboxStatusUITest', 'MAYBE_testSUIDSandboxEnabled', function() {
42   var suidyesstring = 'SUID Sandbox\tYes';
43   var suidnostring = 'SUID Sandbox\tNo';
44   var suidyes = document.body.innerText.match(suidyesstring);
45   var suidno = document.body.innerText.match(suidnostring);
46
47   expectEquals(null, suidno);
48   assertFalse(suidyes === null);
49   expectEquals(suidyesstring, suidyes[0]);
50 });
51
52 // The seccomp-bpf sandbox is also not compatible with ASAN.
53 GEN('#if !defined(OS_LINUX) || defined(ADDRESS_SANITIZER)');
54 GEN('# define MAYBE_testBPFSandboxEnabled \\');
55 GEN('     DISABLED_testBPFSandboxEnabled');
56 GEN('#elif !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)');
57 // Not yet available on the ARM linux bots: http://crbug.com/243478
58 GEN('# define MAYBE_testBPFSandboxEnabled \\');
59 GEN('     DISABLED_testBPFSandboxEnabled');
60 GEN('#else');
61 GEN('# define MAYBE_testBPFSandboxEnabled \\');
62 GEN('     testBPFSandboxEnabled');
63 GEN('#endif');
64
65 /**
66  * Test if the seccomp-bpf sandbox is enabled.
67  */
68 TEST_F('SandboxStatusUITest', 'MAYBE_testBPFSandboxEnabled', function() {
69   var bpfyesstring = 'Seccomp-BPF sandbox\tYes';
70   var bpfnostring = 'Seccomp-BPF sandbox\tNo';
71   var bpfyes = document.body.innerText.match(bpfyesstring);
72   var bpfno = document.body.innerText.match(bpfnostring);
73
74   expectEquals(null, bpfno);
75   assertFalse(bpfyes === null);
76   expectEquals(bpfyesstring, bpfyes[0]);
77 });
78
79 /**
80  * TestFixture for GPU Sandbox testing.
81  * @extends {testing.Test}
82  * @constructor
83  */
84 function GPUSandboxStatusUITest() {}
85
86 GPUSandboxStatusUITest.prototype = {
87   __proto__: testing.Test.prototype,
88   /**
89    * Browse to the options page & call our preLoad().
90    */
91   browsePreload: 'chrome://gpu',
92   isAsync: true,
93 };
94
95 // This test is disabled because it can only pass on real hardware. We
96 // arrange for it to run on real hardware in specific configurations
97 // (such as Chrome OS hardware, via Autotest), then run it with
98 // --gtest_also_run_disabled_tests on those configurations.
99
100 /**
101  * Test if the GPU sandbox is enabled.
102  */
103 TEST_F('GPUSandboxStatusUITest', 'DISABLED_testGPUSandboxEnabled', function() {
104   var gpuyesstring = 'Sandboxed\ttrue';
105   var gpunostring = 'Sandboxed\tfalse';
106
107   var observer = new MutationObserver(function(mutations) {
108     mutations.forEach(function(mutation) {
109       for (var i = 0; i < mutation.addedNodes.length; i++) {
110         // Here we can inspect each of the added nodes. We expect
111         // to find one that contains one of the GPU status strings.
112         var addedNode = mutation.addedNodes[i];
113         // Check for both. If it contains neither, it's an unrelated
114         // mutation event we don't care about. But if it contains one,
115         // pass or fail accordingly.
116         var gpuyes = addedNode.innerText.match(gpuyesstring);
117         var gpuno = addedNode.innerText.match(gpunostring);
118         if (gpuyes || gpuno) {
119           expectEquals(null, gpuno);
120           expectTrue(gpuyes && (gpuyes[0] == gpuyesstring));
121           testDone();
122         }
123       }
124     })
125   });
126   observer.observe(document.getElementById('basic-info'), {childList: true});
127 });