summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 07:07:18 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-14 07:07:18 +0000
commit1b6cdc850d7eb2b4a19f5a51dca2ad57c9a9622f (patch)
tree2a26d85ad15485ccf6a7e48c1def21803e9710a2 /chrome/test
parent83c249924ea14cc9b9c6628c2e93a5d09c474c75 (diff)
downloadchromium_src-1b6cdc850d7eb2b4a19f5a51dca2ad57c9a9622f.zip
chromium_src-1b6cdc850d7eb2b4a19f5a51dca2ad57c9a9622f.tar.gz
chromium_src-1b6cdc850d7eb2b4a19f5a51dca2ad57c9a9622f.tar.bz2
Revert "Add JsonSchema-based validation for the tab APIs."
This reverts commit 4f47758f5238f2e5b05d9de18f390bfe2aeb6980. Revert "TBR: Fix unit tests, line endings." This reverts commit 257fa01e20c46c68dce1c5992b75c64686cb1a66. Review URL: http://codereview.chromium.org/67122 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13652 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rwxr-xr-xchrome/test/data/extensions/json_schema_test.js314
-rwxr-xr-xchrome/test/data/js_test_runner.html53
-rw-r--r--chrome/test/render_view_test.cc89
-rw-r--r--chrome/test/render_view_test.h47
-rw-r--r--chrome/test/unit/unittests.vcproj24
5 files changed, 2 insertions, 525 deletions
diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js
deleted file mode 100755
index 497c344..0000000
--- a/chrome/test/data/extensions/json_schema_test.js
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright (c) 2009 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.
-
-function assert(truth) {
- if (!truth)
- throw new Error("Assertion failed.");
-}
-
-function assertValid(type, instance, schema) {
- var validator = new chromium.JSONSchemaValidator();
- validator["validate" + type](instance, schema, "");
- if (validator.errors.length != 0) {
- console.log("Got unexpected errors");
- console.log(validator.errors);
- assert(false);
- }
-}
-
-function assertNotValid(type, instance, schema, errors) {
- var validator = new chromium.JSONSchemaValidator();
- validator["validate" + type](instance, schema, "");
- assert(validator.errors.length === errors.length);
- for (var i = 0; i < errors.length; i++) {
- if (validator.errors[i].message == errors[i]) {
- log("Got expected error: " + validator.errors[i].message + " for path: " +
- validator.errors[i].path);
- } else {
- log("Missed expected error: " + errors[i] + ". Got: " +
- validator.errors[i].message + " instead.");
- assert(false);
- }
- }
-}
-
-function formatError(key, replacements) {
- return chromium.JSONSchemaValidator.formatError(key, replacements);
-}
-
-function testFormatError() {
- assert(formatError("propertyRequired") == "Property is required.");
- assert(formatError("invalidEnum", ["foo, bar"]) ==
- "Value must be one of: [foo, bar].");
- assert(formatError("invalidType", ["foo", "bar"]) ==
- "Expected 'foo' but got 'bar'.");
-}
-
-function testComplex() {
- var schema = {
- type: "array",
- items: [
- {
- type: "object",
- properties: {
- id: {
- type: "integer",
- minimum: 1
- },
- url: {
- type: "string",
- pattern: /^https?\:/,
- optional: true
- },
- index: {
- type: "integer",
- minimum: 0,
- optional: true
- },
- selected: {
- type: "boolean",
- optional: true
- }
- }
- },
- { type: "function", optional: true },
- { type: "function", optional: true }
- ]
- };
-
- var instance = [
- {
- id: 42,
- url: "http://www.google.com/",
- index: 2,
- selected: true
- },
- function(){},
- function(){}
- ];
-
- assertValid("", instance, schema);
- instance.length = 2;
- assertValid("", instance, schema);
- instance.length = 1;
- instance.push({});
- assertNotValid("", instance, schema,
- [formatError("invalidType", ["function", "object"])]);
- instance[1] = function(){};
-
- instance[0].url = "foo";
- assertNotValid("", instance, schema,
- [formatError("stringPattern",
- [schema.items[0].properties.url.pattern])]);
- delete instance[0].url;
- assertValid("", instance, schema);
-
- instance[0].id = 0;
- assertNotValid("", instance, schema,
- [formatError("numberMinValue",
- [schema.items[0].properties.id.minimum])]);
-}
-
-function testEnum() {
- var schema = {
- enum: ["foo", 42, false]
- };
-
- assertValid("", "foo", schema);
- assertValid("", 42, schema);
- assertValid("", false, schema);
- assertNotValid("", "42", schema, [formatError("invalidEnum",
- [schema.enum.join(", ")])]);
- assertNotValid("", null, schema, [formatError("invalidEnum",
- [schema.enum.join(", ")])]);
-}
-
-function testExtends() {
- var parent = {
- type: "number"
- }
- var schema = {
- extends: parent
- };
-
- assertValid("", 42, schema);
- assertNotValid("", "42", schema,
- [formatError("invalidType", ["number", "string"])]);
-
- // Make the derived schema more restrictive
- parent.minimum = 43;
- assertNotValid("", 42, schema, [formatError("numberMinValue", [43])]);
- assertValid("", 43, schema);
-}
-
-function testObject() {
- var schema = {
- properties: {
- "foo": {
- type: "string"
- },
- "bar": {
- type: "integer"
- }
- }
- };
-
- assertValid("Object", {foo:"foo",bar:42}, schema);
- assertValid("Object", {foo:"foo",bar:42,"extra":true}, schema);
- assertNotValid("Object", {foo:"foo"}, schema,
- [formatError("propertyRequired")]);
- assertNotValid("Object", {foo:"foo", bar:"42"}, schema,
- [formatError("invalidType", ["integer", "string"])]);
-
- schema.additionalProperties = false;
- assertNotValid("Object", {foo:"foo",bar:42,"extra":true}, schema,
- [formatError("unexpectedProperty")]);
-
- schema.additionalProperties = {
- type: "boolean"
- };
- assertValid("Object", {foo:"foo",bar:42,"extra":true}, schema);
-
- schema.properties.bar.optional = true;
- assertValid("Object", {foo:"foo",bar:42}, schema);
- assertValid("Object", {foo:"foo"}, schema);
- assertNotValid("Object", {foo:"foo", bar:"42"}, schema,
- [formatError("invalidType", ["integer", "string"])]);
-}
-
-function testArrayTuple() {
- var schema = {
- items: [
- {
- type: "string"
- },
- {
- type: "integer"
- }
- ]
- };
-
- assertValid("Array", ["42", 42], schema);
- assertValid("Array", ["42", 42, "anything"], schema);
- assertNotValid("Array", ["42"], schema, [formatError("itemRequired")]);
- assertNotValid("Array", [42, 42], schema,
- [formatError("invalidType", ["string", "integer"])]);
-
- schema.additionalProperties = false;
- assertNotValid("Array", ["42", 42, "anything"], schema,
- [formatError("arrayMaxItems", [schema.items.length])]);
-
- schema.additionalProperties = {
- type: "boolean"
- };
- assertNotValid("Array", ["42", 42, "anything"], schema,
- [formatError("invalidType", ["boolean", "string"])]);
- assertValid("Array", ["42", 42, false], schema);
-
- schema.items[0].optional = true;
- assertValid("Array", ["42", 42], schema);
- assertValid("Array", [, 42], schema);
- assertNotValid("Array", [42, 42], schema,
- [formatError("invalidType", ["string", "integer"])]);
-}
-
-function testArrayNonTuple() {
- var schema = {
- items: {
- type: "string"
- },
- minItems: 2,
- maxItems: 3
- };
-
- assertValid("Array", ["x", "x"], schema);
- assertValid("Array", ["x", "x", "x"], schema);
-
- assertNotValid("Array", ["x"], schema,
- [formatError("arrayMinItems", [schema.minItems])]);
- assertNotValid("Array", ["x", "x", "x", "x"], schema,
- [formatError("arrayMaxItems", [schema.maxItems])]);
- assertNotValid("Array", [42], schema,
- [formatError("arrayMinItems", [schema.minItems]),
- formatError("invalidType", ["string", "integer"])]);
-}
-
-function testString() {
- var schema = {
- minLength: 1,
- maxLength: 10,
- pattern: /^x/
- };
-
- assertValid("String", "x", schema);
- assertValid("String", "xxxxxxxxxx", schema);
-
- assertNotValid("String", "y", schema,
- [formatError("stringPattern", [schema.pattern])]);
- assertNotValid("String", "xxxxxxxxxxx", schema,
- [formatError("stringMaxLength", [schema.maxLength])]);
- assertNotValid("String", "", schema,
- [formatError("stringMinLength", [schema.minLength]),
- formatError("stringPattern", [schema.pattern])]);
-}
-
-function testNumber() {
- var schema = {
- minimum: 1,
- maximum: 100,
- maxDecimal: 2
- };
-
- assertValid("Number", 1, schema);
- assertValid("Number", 50, schema);
- assertValid("Number", 100, schema);
- assertValid("Number", 88.88, schema);
-
- assertNotValid("Number", 0.5, schema,
- [formatError("numberMinValue", [schema.minimum])]);
- assertNotValid("Number", 100.1, schema,
- [formatError("numberMaxValue", [schema.maximum])]);
- assertNotValid("Number", 100.111, schema,
- [formatError("numberMaxValue", [schema.maximum]),
- formatError("numberMaxDecimal", [schema.maxDecimal])]);
-}
-
-function testType() {
- // valid
- assertValid("Type", {}, {type:"object"});
- assertValid("Type", [], {type:"array"});
- assertValid("Type", function(){}, {type:"function"});
- assertValid("Type", "foobar", {type:"string"});
- assertValid("Type", "", {type:"string"});
- assertValid("Type", 88.8, {type:"number"});
- assertValid("Type", 42, {type:"number"});
- assertValid("Type", 0, {type:"number"});
- assertValid("Type", 42, {type:"integer"});
- assertValid("Type", 0, {type:"integer"});
- assertValid("Type", true, {type:"boolean"});
- assertValid("Type", false, {type:"boolean"});
- assertValid("Type", null, {type:"null"});
-
- // not valid
- assertNotValid("Type", [], {type: "object"},
- [formatError("invalidType", ["object", "array"])]);
- assertNotValid("Type", null, {type: "object"},
- [formatError("invalidType", ["object", "null"])]);
- assertNotValid("Type", function(){}, {type: "object"},
- [formatError("invalidType", ["object", "function"])]);
- assertNotValid("Type", 42, {type: "array"},
- [formatError("invalidType", ["array", "integer"])]);
- assertNotValid("Type", 42, {type: "string"},
- [formatError("invalidType", ["string", "integer"])]);
- assertNotValid("Type", "42", {type: "number"},
- [formatError("invalidType", ["number", "string"])]);
- assertNotValid("Type", 88.8, {type: "integer"},
- [formatError("invalidType", ["integer", "number"])]);
- assertNotValid("Type", 1, {type: "boolean"},
- [formatError("invalidType", ["boolean", "integer"])]);
- assertNotValid("Type", false, {type: "null"},
- [formatError("invalidType", ["null", "boolean"])]);
- assertNotValid("Type", {}, {type: "function"},
- [formatError("invalidType", ["function", "object"])]);
-}
diff --git a/chrome/test/data/js_test_runner.html b/chrome/test/data/js_test_runner.html
deleted file mode 100755
index 55d0448..0000000
--- a/chrome/test/data/js_test_runner.html
+++ /dev/null
@@ -1,53 +0,0 @@
-<!--
-Copyright (c) 2009 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.
-
-This file is a manual test runner for JavaScript unit tests. It finds all the
-global functions starting with "test" and runs them. It is useful for developing
-and debugging JavaScript unit tests.
-
-See: chrome/test/data/extensions/schema_test.js for an example.
--->
-<textarea style="position:absolute; left:5px; top:5px; right:5px; bottom:5px;">
-</textarea>
-
-<!-- Add a reference to the script and the script test files here. -->
-<script src="../../../renderer/resources/schema.js"></script>
-<script src="schema_test.js"></script>
-
-<script>
-function log() {
- console.log.apply(console, arguments);
-}
-
-function runAllTests() {
- for (var p in window) {
- if (p.substring(0, 4) == "test") {
- runTest(p);
- }
- }
- window.setTimeout(function() {
- log("DONE");
- }, 0);
-}
-
-function runTest(p) {
- window.setTimeout(function() {
- var success = false;
- try {
- window[p]();
- success = true;
- } finally {
- print((success ? "PASS" : "FAIL") + " " + p);
- }
- }, 0);
-}
-
-function print(msg) {
- document.getElementsByTagName("textarea")[0].value += msg + "\n";
-}
-
-runAllTests();
-
-</script>
diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc
deleted file mode 100644
index 49d4c63..0000000
--- a/chrome/test/render_view_test.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (c) 2009 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/render_view_test.h"
-
-#include "chrome/common/render_messages.h"
-#include "chrome/browser/extensions/extension_function_dispatcher.h"
-#include "chrome/renderer/extensions/event_bindings.h"
-#include "chrome/renderer/extensions/extension_process_bindings.h"
-#include "chrome/renderer/extensions/renderer_extension_bindings.h"
-#include "chrome/renderer/js_only_v8_extensions.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
-#include "webkit/glue/weburlrequest.h"
-#include "webkit/glue/webview.h"
-
-using WebKit::WebScriptSource;
-using WebKit::WebString;
-
-namespace {
-
-const int32 kRouteId = 5;
-const int32 kOpenerId = 7;
-
-};
-
-void RenderViewTest::ProcessPendingMessages() {
- msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask());
- msg_loop_.Run();
-}
-
-WebFrame* RenderViewTest::GetMainFrame() {
- return view_->webview()->GetMainFrame();
-}
-
-void RenderViewTest::ExecuteJavaScript(const char* js) {
- GetMainFrame()->ExecuteScript(WebScriptSource(WebString::fromUTF8(js)));
-}
-
-void RenderViewTest::LoadHTML(const char* html) {
- std::string url_str = "data:text/html;charset=utf-8,";
- url_str.append(html);
- GURL url(url_str);
-
- scoped_ptr<WebRequest> request(WebRequest::Create(url));
- GetMainFrame()->LoadRequest(request.get());
-
- // The load actually happens asynchronously, so we pump messages to process
- // the pending continuation.
- ProcessPendingMessages();
-}
-
-void RenderViewTest::SetUp() {
- WebKit::initialize(&webkitclient_);
- WebKit::registerExtension(BaseJsV8Extension::Get());
- WebKit::registerExtension(JsonJsV8Extension::Get());
- WebKit::registerExtension(JsonSchemaJsV8Extension::Get());
- WebKit::registerExtension(EventBindings::Get());
- WebKit::registerExtension(ExtensionProcessBindings::Get());
- WebKit::registerExtension(RendererExtensionBindings::Get(&render_thread_));
-
- // TODO(aa): Should some of this go to some other inheriting class?
- std::vector<std::string> names;
- ExtensionFunctionDispatcher::GetAllFunctionNames(&names);
- ExtensionProcessBindings::SetFunctionNames(names);
-
- mock_process_.reset(new MockProcess());
-
- render_thread_.set_routing_id(kRouteId);
-
- // This needs to pass the mock render thread to the view.
- view_ = RenderView::Create(&render_thread_, NULL, NULL, kOpenerId,
- WebPreferences(),
- new SharedRenderViewCounter(0), kRouteId);
-}
-void RenderViewTest::TearDown() {
- render_thread_.SendCloseMessage();
-
- // Run the loop so the release task from the renderwidget executes.
- ProcessPendingMessages();
-
- view_ = NULL;
-
- mock_process_.reset();
- WebKit::shutdown();
-
- msg_loop_.RunAllPending();
-}
diff --git a/chrome/test/render_view_test.h b/chrome/test/render_view_test.h
deleted file mode 100644
index abda898..0000000
--- a/chrome/test/render_view_test.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2009 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.
-
-#ifndef CHROME_TEST_RENDER_VIEW_TEST_H_
-#define CHROME_TEST_RENDER_VIEW_TEST_H_
-
-#include "base/scoped_ptr.h"
-#include "chrome/renderer/mock_render_process.h"
-#include "chrome/renderer/mock_render_thread.h"
-#include "chrome/renderer/render_view.h"
-#include "chrome/renderer/renderer_webkitclient_impl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/webframe.h"
-
-class RenderViewTest : public testing::Test {
- public:
- RenderViewTest() {}
- ~RenderViewTest() {}
-
- protected:
- // Spins the message loop to process all messages that are currently pending.
- void ProcessPendingMessages();
-
- // Returns a pointer to the main frame.
- WebFrame* GetMainFrame();
-
- // Executes the given JavaScript in the context of the main frame. The input
- // is a NULL-terminated UTF-8 string.
- void ExecuteJavaScript(const char* js);
-
- // Loads the given HTML into the main frame as a data: URL.
- void LoadHTML(const char* html);
-
- // testing::Test
- virtual void SetUp();
-
- virtual void TearDown();
-
- MessageLoop msg_loop_;
- MockRenderThread render_thread_;
- scoped_ptr<MockProcess> mock_process_;
- scoped_refptr<RenderView> view_;
- RendererWebKitClientImpl webkitclient_;
-};
-
-#endif // CHROME_TEST_RENDER_VIEW_TEST_H_
diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj
index 7750528..4711923f 100644
--- a/chrome/test/unit/unittests.vcproj
+++ b/chrome/test/unit/unittests.vcproj
@@ -192,14 +192,6 @@
>
</File>
<File
- RelativePath="..\render_view_test.cc"
- >
- </File>
- <File
- RelativePath="..\render_view_test.h"
- >
- </File>
- <File
RelativePath=".\run_all_unittests.cc"
>
</File>
@@ -496,15 +488,11 @@
>
</File>
<File
- RelativePath="..\..\browser\extensions\extension_content_script_inject_unittest.cc"
- >
- </File>
- <File
- RelativePath="..\..\browser\extensions\extension_messages_unittest.cc"
+ RelativePath="..\..\browser\extensions\extension_process_manager_unittest.cc"
>
</File>
<File
- RelativePath="..\..\browser\extensions\extension_process_manager_unittest.cc"
+ RelativePath="..\..\browser\extensions\extension_content_script_inject_unittest.cc"
>
</File>
<File
@@ -868,18 +856,10 @@
Name="renderer"
>
<File
- RelativePath="..\..\renderer\extensions\extension_api_client_unittest.cc"
- >
- </File>
- <File
RelativePath="..\..\renderer\extensions\greasemonkey_api_unittest.cc"
>
</File>
<File
- RelativePath="..\..\renderer\extensions\json_schema_unittest.cc"
- >
- </File>
- <File
RelativePath="..\..\renderer\net\render_dns_master_unittest.cc"
>
</File>