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

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: add to dispatcher.cc 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');"
koz (OOO until 15th September) 2013/02/19 23:19:08 Nit: if you add \n to your lines you get line numb
not at google - send to devlin 2013/02/19 23:52:13 Done.
22 "var json = require('json');";
23 }
24
25 std::string test_body() {
26 return
27 "var str = '{\"a\":1,\"b\":true,\"c\":[\"hi\"]}';"
28 "var obj = json.parse(str);"
29 "assert.AssertTrue(json.stringify(obj) === str);"
30 "assert.AssertTrue(obj.a === 1);"
31 "assert.AssertTrue(obj.b === true);"
32 "assert.AssertTrue(obj.c.length === 1);"
33 "assert.AssertTrue(obj.c[0] === 'hi');";
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 overrides =
46 "function fakeToJSON() { throw '42'; }"
47 "Object.prototype.toJSON = fakeToJSON;"
48 "Array.prototype.toJSON = fakeToJSON;"
49 "Number.prototype.toJSON = fakeToJSON;"
50 "Boolean.prototype.toJSON = fakeToJSON;"
51 "String.prototype.toJSON = fakeToJSON;";
52 RegisterModule("test", requires() + overrides + test_body());
koz (OOO until 15th September) 2013/02/19 23:19:08 Cool test :-) You may want to test that after the
not at google - send to devlin 2013/02/19 23:52:13 Done.
not at google - send to devlin 2013/02/19 23:52:13 Done.
53 module_system_->Require("test");
54 }
55
56 } // namespace
57 } // 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