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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/dispatcher.cc ('k') | chrome/renderer/resources/extensions/event.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/json_js_unittest.cc
diff --git a/chrome/renderer/extensions/json_js_unittest.cc b/chrome/renderer/extensions/json_js_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b90c3dcef4bd7a941a0224a1d3f3133a754473b7
--- /dev/null
+++ b/chrome/renderer/extensions/json_js_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/module_system_test.h"
+#include "grit/renderer_resources.h"
+
+namespace extensions {
+namespace {
+
+// Tests chrome/renderer/resources/json.js.
+class JsonJsTest : public ModuleSystemTest {
+ virtual void SetUp() OVERRIDE {
+ ModuleSystemTest::SetUp();
+ RegisterModule("json", IDR_JSON_JS);
+ }
+
+ protected:
+ std::string requires() {
+ return
+ "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.
+ "var json = require('json');";
+ }
+
+ std::string test_body() {
+ return
+ "var str = '{\"a\":1,\"b\":true,\"c\":[\"hi\"]}';"
+ "var obj = json.parse(str);"
+ "assert.AssertTrue(json.stringify(obj) === str);"
+ "assert.AssertTrue(obj.a === 1);"
+ "assert.AssertTrue(obj.b === true);"
+ "assert.AssertTrue(obj.c.length === 1);"
+ "assert.AssertTrue(obj.c[0] === 'hi');";
+ }
+};
+
+TEST_F(JsonJsTest, NoOverrides) {
+ ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
+ RegisterModule("test", requires() + test_body());
+ module_system_->Require("test");
+}
+
+TEST_F(JsonJsTest, EverythingOverridden) {
+ ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
+ std::string overrides =
+ "function fakeToJSON() { throw '42'; }"
+ "Object.prototype.toJSON = fakeToJSON;"
+ "Array.prototype.toJSON = fakeToJSON;"
+ "Number.prototype.toJSON = fakeToJSON;"
+ "Boolean.prototype.toJSON = fakeToJSON;"
+ "String.prototype.toJSON = fakeToJSON;";
+ 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.
+ module_system_->Require("test");
+}
+
+} // namespace
+} // namespace extensions
« 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