summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--chrome/browser/ui/webui/web_ui_browsertest.cc48
-rw-r--r--chrome/browser/ui/webui/web_ui_browsertest.h6
-rw-r--r--chrome/chrome_tests.gypi21
-rw-r--r--chrome/test/data/webui/sample_pass.js17
-rw-r--r--tools/gypv8sh.py74
6 files changed, 161 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 1091306..1175f5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,7 @@ v8.log
/chrome/app/theme/google_chrome
/chrome/browser/autofill/internal
/chrome/browser/extensions/default_extensions/chromeos
+/chrome/browser/ui/webui/web_ui_browsertest-inl.h
/chrome/installer/linux
/chrome/installer/mac/internal
/chrome/installer/mac/third_party/xz/xz
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc
index 66815d0..4e8e959 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/web_ui_browsertest.cc
@@ -11,6 +11,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/ui_test_utils.h"
@@ -21,9 +22,8 @@
namespace {
-const FilePath::StringType kWebUILibraryJS =
- FILE_PATH_LITERAL("test_api.js");
-const FilePath::StringType kWebUITestFolder = FILE_PATH_LITERAL("webui");
+const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js");
+const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui");
base::LazyInstance<std::vector<std::string> > error_messages_(
base::LINKER_INITIALIZED);
@@ -244,3 +244,45 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) {
EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"),
"WebUITestHandler::Observe");
}
+
+
+// This test framework is used in the generated tests, which are included
+// below. WebUIBrowserTest requires being on a page which is a WebUI page. Using
+// the TestChromeWebUIFactory, we use a dummy URL |kChromeTestBrowserTestPass|,
+// which we force to be a WebUI page.
+class WebUIBrowserTestPass
+ : public WebUIBrowserTest,
+ public TestChromeWebUIFactory::WebUIProvider {
+ private:
+ // TestChromeWebUIFactory::WebUIProvider:
+ virtual WebUI* NewWebUI(TabContents* tab_contents,
+ const GURL& url) OVERRIDE {
+ return new WebUI(tab_contents);
+ }
+
+ // InProcessBrowserTest:
+ virtual void SetUpOnMainThread() OVERRIDE {
+ WebUIBrowserTest::SetUpOnMainThread();
+ ui_test_utils::NavigateToURL(browser(),
+ GURL(kChromeTestBrowserTestPass));
+ }
+
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ WebUIBrowserTest::SetUpInProcessBrowserTestFixture();
+ TestChromeWebUIFactory::AddFactoryOverride(
+ GURL(kChromeTestBrowserTestPass).host(), this);
+ }
+
+ virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
+ WebUIBrowserTest::TearDownInProcessBrowserTestFixture();
+ TestChromeWebUIFactory::RemoveFactoryOverride(
+ GURL(kChromeTestBrowserTestPass).host());
+ }
+
+ static const char kChromeTestBrowserTestPass[];
+};
+
+const char WebUIBrowserTestPass::kChromeTestBrowserTestPass[] =
+ "chrome://WebUIBrowserTestPass";
+
+#include "chrome/browser/ui/webui/web_ui_browsertest-inl.h"
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.h b/chrome/browser/ui/webui/web_ui_browsertest.h
index 001ae7a..a8e9f96 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.h
+++ b/chrome/browser/ui/webui/web_ui_browsertest.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_BROWSER_WEBUI_WEB_UI_BROWSERTEST_H_
-#define CONTENT_BROWSER_WEBUI_WEB_UI_BROWSERTEST_H_
+#ifndef CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_
+#define CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_
#pragma once
#include <string>
@@ -98,4 +98,4 @@ class WebUIBrowserTest : public InProcessBrowserTest {
std::vector<FilePath> user_libraries;
};
-#endif // CONTENT_BROWSER_WEBUI_WEB_UI_BROWSERTEST_H_
+#endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index cf87f75..cc751b1 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2292,6 +2292,7 @@
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
'../v8/tools/gyp/v8.gyp:v8',
+ '../v8/tools/gyp/v8.gyp:v8_shell',
'../webkit/webkit.gyp:test_shell_test_support',
# Runtime dependencies
'../third_party/mesa/mesa.gyp:osmesa',
@@ -2556,6 +2557,26 @@
'../content/renderer/render_widget_browsertest.h',
'../content/renderer/v8_value_converter_browsertest.cc',
],
+ 'actions': [
+ {
+ 'action_name': 'js2webui',
+ 'variables': {
+ 'gypv8sh': '../tools/gypv8sh.py',
+ 'js2webui': 'browser/ui/webui/javascript2webui.js',
+ },
+ 'inputs': [
+ '<(gypv8sh)',
+ '<(js2webui)',
+ '<!@(python <(gypv8sh) -i)',
+ ],
+ 'outputs': [
+ '<!@(python <(gypv8sh) -o)',
+ ],
+ 'action': [
+ 'python', '<(gypv8sh)', '-p', '<(PRODUCT_DIR)', '<(js2webui)',
+ ],
+ },
+ ],
'conditions': [
['chromeos==0', {
'sources/': [
diff --git a/chrome/test/data/webui/sample_pass.js b/chrome/test/data/webui/sample_pass.js
new file mode 100644
index 0000000..ca9b88c4
--- /dev/null
+++ b/chrome/test/data/webui/sample_pass.js
@@ -0,0 +1,17 @@
+// Copyright (c) 2011 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.
+
+// Sample tests that exercise the test JS library and show how this framework
+// could be used to test the downloads page.
+function testAssertFalse() {
+ assertFalse(false);
+}
+
+function testAssertTrue() {
+ assertTrue(true);
+}
+
+function testAssertEquals() {
+ assertEquals(5, 5, "fives");
+}
diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py
new file mode 100644
index 0000000..fddd6b2
--- /dev/null
+++ b/tools/gypv8sh.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+# Copyright (c) 2011 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 script is used by chrome_tests.gypi's js2webui action to maintain the
+argument lists and to generate inlinable tests.
+
+Usage:
+ python tools/gypv8sh.py -p product_dir path/to/javascript2webui.js
+ python tools/gypv8sh.py -t # print test_harnesses
+ python tools/gypv8sh.py -i # print inputs
+ python tools/gypv8sh.py -o # print outputs
+"""
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+import optparse
+import os
+import subprocess
+import sys
+
+# Please adjust the following to edit or add new javascript webui tests.
+rules = [
+ [
+ 'WebUIBrowserTestPass',
+ 'test/data/webui/sample_pass.js',
+ 'browser/ui/webui/web_ui_browsertest-inl.h',
+ ],
+]
+
+def main ():
+ """Run the program"""
+ # For options -t, -i, & -o, we print the "column" of the |rules|. We keep a
+ # set of indices to print in |print_rule_indices| and print them in sorted
+ # order if non-empty.
+ parser = optparse.OptionParser()
+ parser.set_usage(
+ "%prog [-v][-n] --product_dir PRODUCT_DIR -or- "
+ "%prog [-v][-n] (-i|-t|-o)")
+ parser.add_option('-v', '--verbose', action='store_true')
+ parser.add_option('-n', '--impotent', action='store_true',
+ help="don't execute; just print (as if verbose)")
+ parser.add_option(
+ '-p', '--product_dir',
+ help='for gyp to set the <(PRODUCT_DIR) for running v8_shell')
+ parser.add_option('-t', '--test_fixture', action='store_const', const=0,
+ dest='print_rule_index', help='print test_fixtures')
+ parser.add_option('-i', '--in', action='store_const', const=1,
+ dest='print_rule_index', help='print inputs')
+ parser.add_option('-o', '--out', action='store_const', const=2,
+ dest='print_rule_index', help='print outputs')
+ (opts, args) = parser.parse_args()
+
+ if (opts.print_rule_index != None):
+ for rule in rules:
+ print rule[opts.print_rule_index]
+ else:
+ if not opts.product_dir:
+ parser.error("--product_dir option is required")
+ v8_shell = os.path.join(opts.product_dir, 'v8_shell')
+ jsfilename = args[0]
+ for rule in rules:
+ arguments = [jsfilename, rule[0], rule[1], os.path.basename(rule[1])]
+ cmd = [v8_shell, '-e', "arguments=" + json.dumps(arguments), jsfilename]
+ if opts.verbose or opts.impotent:
+ print cmd
+ if not opts.impotent:
+ sys.exit(subprocess.call(cmd, stdout=open(rule[2],'w+')))
+
+if __name__ == '__main__':
+ sys.exit(main())