OLD | NEW |
---|---|
(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 | |
OLD | NEW |