Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / renderer / extensions / json_js_unittest.cc
blob130c03bc4a2616b6be09c1a91c5e55d868733eb0
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"
6 #include "grit/renderer_resources.h"
8 namespace extensions {
9 namespace {
11 // Tests chrome/renderer/resources/json.js.
12 class JsonJsTest : public ModuleSystemTest {
13 virtual void SetUp() OVERRIDE {
14 ModuleSystemTest::SetUp();
15 RegisterModule("json", IDR_JSON_JS);
18 protected:
19 std::string requires() {
20 return
21 "var assert = requireNative('assert');\n"
22 "var json = require('json');\n";
25 std::string test_body() {
26 return
27 "var str = '{\"a\":1,\"b\":true,\"c\":[\"hi\"]}';\n"
28 "var obj = json.parse(str);\n"
29 "assert.AssertTrue(json.stringify(obj) === str);\n"
30 "assert.AssertTrue(obj.a === 1);\n"
31 "assert.AssertTrue(obj.b === true);\n"
32 "assert.AssertTrue(obj.c.length === 1);\n"
33 "assert.AssertTrue(obj.c[0] === 'hi');\n";
37 TEST_F(JsonJsTest, NoOverrides) {
38 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
39 RegisterModule("test", requires() + test_body());
40 module_system_->Require("test");
43 TEST_F(JsonJsTest, EverythingOverridden) {
44 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
45 std::string test =
46 requires() +
47 "function fakeToJSON() { throw '42'; }\n"
48 "Object.prototype.toJSON = fakeToJSON;\n"
49 "Array.prototype.toJSON = fakeToJSON;\n"
50 "Number.prototype.toJSON = fakeToJSON;\n"
51 "Boolean.prototype.toJSON = fakeToJSON;\n"
52 "String.prototype.toJSON = fakeToJSON;\n" +
53 test_body() +
54 "assert.AssertTrue(Object.prototype.toJSON == fakeToJSON);\n"
55 "assert.AssertTrue(Array.prototype.toJSON == fakeToJSON);\n"
56 "assert.AssertTrue(Number.prototype.toJSON == fakeToJSON);\n"
57 "assert.AssertTrue(Boolean.prototype.toJSON == fakeToJSON);\n"
58 "assert.AssertTrue(String.prototype.toJSON == fakeToJSON);\n";
59 RegisterModule("test", test);
60 module_system_->Require("test");
63 } // namespace
64 } // namespace extensions