blob: 38910a2c5df5cdac8b6283b671de58a9a1ea73da [file] [log] [blame]
[email protected]582f6e92014-07-16 23:39:151// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]53229732013-06-21 02:56:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]582f6e92014-07-16 23:39:155#include "extensions/renderer/module_system_test.h"
[email protected]53229732013-06-21 02:56:026
[email protected]53229732013-06-21 02:56:027namespace extensions {
8namespace {
9
[email protected]582f6e92014-07-16 23:39:1510class SafeBuiltinsUnittest : public ModuleSystemTest {};
[email protected]53229732013-06-21 02:56:0211
12TEST_F(SafeBuiltinsUnittest, TestNotOriginalObject) {
[email protected]2a356872014-02-21 23:18:5213 ModuleSystem::NativesEnabledScope natives_enabled_scope(
[email protected]d9f51dad2014-07-09 05:39:3814 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");
[email protected]53229732013-06-21 02:56:0220}
21
22TEST_F(SafeBuiltinsUnittest, TestSelf) {
[email protected]2a356872014-02-21 23:18:5223 ModuleSystem::NativesEnabledScope natives_enabled_scope(
[email protected]d9f51dad2014-07-09 05:39:3824 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");
[email protected]53229732013-06-21 02:56:0233}
34
35TEST_F(SafeBuiltinsUnittest, TestStaticFunction) {
[email protected]2a356872014-02-21 23:18:5236 ModuleSystem::NativesEnabledScope natives_enabled_scope(
[email protected]d9f51dad2014-07-09 05:39:3837 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");
[email protected]53229732013-06-21 02:56:0246}
47
48TEST_F(SafeBuiltinsUnittest, TestInstanceMethod) {
[email protected]2a356872014-02-21 23:18:5249 ModuleSystem::NativesEnabledScope natives_enabled_scope(
[email protected]d9f51dad2014-07-09 05:39:3850 env()->module_system());
51 env()->RegisterModule(
52 "test",
[email protected]53229732013-06-21 02:56:0253 "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"
[email protected]d9f51dad2014-07-09 05:39:3858 "assert.AssertTrue(arr[0] == 1);\n");
59 env()->module_system()->Require("test");
[email protected]53229732013-06-21 02:56:0260}
61
62// NOTE: JSON is already tested in ExtensionApiTest.Messaging, via
63// chrome/test/data/extensions/api_test/messaging/connect/page.js.
64
65} // namespace
66} // namespace extensions