Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / renderer / extensions / safe_builtins_unittest.cc
blob262bb3d424b12fbcced344572d3f120f99524fd8
1 // Copyright 2013 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 "chrome/test/base/module_system_test.h"
7 #include "grit/renderer_resources.h"
9 namespace extensions {
10 namespace {
12 class SafeBuiltinsUnittest : public ModuleSystemTest {
15 TEST_F(SafeBuiltinsUnittest, TestNotOriginalObject) {
16 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
17 RegisterModule("test",
18 "var assert = requireNative('assert');\n"
19 "Array.foo = 10;\n"
20 "assert.AssertTrue(!$Array.hasOwnProperty('foo'));\n"
22 module_system_->Require("test");
25 TEST_F(SafeBuiltinsUnittest, TestSelf) {
26 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
27 RegisterModule("test",
28 "var assert = requireNative('assert');\n"
29 "Array.foo = 10;\n"
30 "assert.AssertTrue($Array.self.foo == 10);\n"
31 "var arr = $Array.self(1);\n"
32 "assert.AssertTrue(arr.length == 1);\n"
33 "assert.AssertTrue(arr[0] === undefined);\n"
35 module_system_->Require("test");
38 TEST_F(SafeBuiltinsUnittest, TestStaticFunction) {
39 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
40 RegisterModule("test",
41 "var assert = requireNative('assert');\n"
42 "Object.keys = function() {throw new Error()};\n"
43 "var obj = {a: 10};\n"
44 "var keys = $Object.keys(obj);\n"
45 "assert.AssertTrue(keys.length == 1);\n"
46 "assert.AssertTrue(keys[0] == 'a');\n"
48 module_system_->Require("test");
51 TEST_F(SafeBuiltinsUnittest, TestInstanceMethod) {
52 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
53 RegisterModule("test",
54 "var assert = requireNative('assert');\n"
55 "Array.prototype.push = function() {throw new Error();}\n"
56 "var arr = []\n"
57 "$Array.push(arr, 1);\n"
58 "assert.AssertTrue(arr.length == 1);\n"
59 "assert.AssertTrue(arr[0] == 1);\n"
61 module_system_->Require("test");
64 // NOTE: JSON is already tested in ExtensionApiTest.Messaging, via
65 // chrome/test/data/extensions/api_test/messaging/connect/page.js.
67 } // namespace
68 } // namespace extensions