Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1013)

Side by Side Diff: chrome/renderer/extensions/json_js_unittest.cc

Issue 12287011: Move the chromeHidden.toJSON paranoia out of event.js and into json.js, a new (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fixup Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/dispatcher.cc ('k') | chrome/renderer/resources/extensions/event.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/test/base/module_system_test.h"
6 #include "grit/renderer_resources.h"
7
8 namespace extensions {
9 namespace {
10
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);
16 }
17
18 protected:
19 std::string requires() {
20 return
21 "var assert = requireNative('assert');\n"
22 "var json = require('json');\n";
23 }
24
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";
34 }
35 };
36
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");
41 }
42
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");
61 }
62
63 } // namespace
64 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.cc ('k') | chrome/renderer/resources/extensions/event.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698