Hide wallet checkbox when there's no wallet data
[chromium-blink-merge.git] / extensions / renderer / safe_builtins_unittest.cc
blob38910a2c5df5cdac8b6283b671de58a9a1ea73da
1 // Copyright 2014 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 #include "extensions/renderer/module_system_test.h"
7 namespace extensions {
8 namespace {
10 class SafeBuiltinsUnittest : public ModuleSystemTest {};
12 TEST_F(SafeBuiltinsUnittest, TestNotOriginalObject) {
13 ModuleSystem::NativesEnabledScope natives_enabled_scope(
14 env()->module_system());
15 env()->RegisterModule("test",
16 "var assert = requireNative('assert');\n"
17 "Array.foo = 10;\n"
18 "assert.AssertTrue(!$Array.hasOwnProperty('foo'));\n");
19 env()->module_system()->Require("test");
22 TEST_F(SafeBuiltinsUnittest, TestSelf) {
23 ModuleSystem::NativesEnabledScope natives_enabled_scope(
24 env()->module_system());
25 env()->RegisterModule("test",
26 "var assert = requireNative('assert');\n"
27 "Array.foo = 10;\n"
28 "assert.AssertTrue($Array.self.foo == 10);\n"
29 "var arr = $Array.self(1);\n"
30 "assert.AssertTrue(arr.length == 1);\n"
31 "assert.AssertTrue(arr[0] === undefined);\n");
32 env()->module_system()->Require("test");
35 TEST_F(SafeBuiltinsUnittest, TestStaticFunction) {
36 ModuleSystem::NativesEnabledScope natives_enabled_scope(
37 env()->module_system());
38 env()->RegisterModule("test",
39 "var assert = requireNative('assert');\n"
40 "Object.keys = function() {throw new Error()};\n"
41 "var obj = {a: 10};\n"
42 "var keys = $Object.keys(obj);\n"
43 "assert.AssertTrue(keys.length == 1);\n"
44 "assert.AssertTrue(keys[0] == 'a');\n");
45 env()->module_system()->Require("test");
48 TEST_F(SafeBuiltinsUnittest, TestInstanceMethod) {
49 ModuleSystem::NativesEnabledScope natives_enabled_scope(
50 env()->module_system());
51 env()->RegisterModule(
52 "test",
53 "var assert = requireNative('assert');\n"
54 "Array.prototype.push = function() {throw new Error();}\n"
55 "var arr = []\n"
56 "$Array.push(arr, 1);\n"
57 "assert.AssertTrue(arr.length == 1);\n"
58 "assert.AssertTrue(arr[0] == 1);\n");
59 env()->module_system()->Require("test");
62 // NOTE: JSON is already tested in ExtensionApiTest.Messaging, via
63 // chrome/test/data/extensions/api_test/messaging/connect/page.js.
65 } // namespace
66 } // namespace extensions