diff options
author | plundblad@chromium.org <plundblad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 22:16:59 +0000 |
---|---|---|
committer | plundblad@chromium.org <plundblad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 22:16:59 +0000 |
commit | b5664184022f0172b1218f3d04a6e768626532cc (patch) | |
tree | 3de4834485edb57d28cee262a0507f4886929942 | |
parent | 6f38c134527081792dadb98037ce5b1c99ae1071 (diff) | |
download | chromium_src-b5664184022f0172b1218f3d04a6e768626532cc.zip chromium_src-b5664184022f0172b1218f3d04a6e768626532cc.tar.gz chromium_src-b5664184022f0172b1218f3d04a6e768626532cc.tar.bz2 |
Support automatically resolving dependencies in javascript tests.
BUG=371692
Review URL: https://codereview.chromium.org/304793002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275260 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 561 insertions, 290 deletions
diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox.gyp b/chrome/browser/resources/chromeos/chromevox/chromevox.gyp index 591fa22..6355356 100644 --- a/chrome/browser/resources/chromeos/chromevox/chromevox.gyp +++ b/chrome/browser/resources/chromeos/chromevox/chromevox.gyp @@ -5,7 +5,6 @@ { 'conditions': [ ['chromeos==1', { - 'includes': ['common.gypi'], 'variables': { # Whether to compress the 4 main ChromeVox scripts. Applicable if # use_migrated_chromevox is true. @@ -15,6 +14,10 @@ 'options_script_loader_file': 'chromevox/background/options_loader.js', 'kbexplorer_loader_file': 'chromevox/background/kbexplorer_loader.js', }, + 'includes': [ + 'chromevox_tests.gypi', + 'common.gypi', + ], 'targets': [ { 'target_name': 'chromevox', diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi b/chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi new file mode 100644 index 0000000..3683db6 --- /dev/null +++ b/chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi @@ -0,0 +1,121 @@ +# Copyright 2014 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. + +{ + 'includes': [ + '../../../../js_unittest_vars.gypi', + ], + 'variables': { + 'chromevox_test_deps_js_file': '<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/chromeos/chromevox/test_deps.js', + }, + 'targets': [ + { + 'target_name': 'chromevox_tests', + 'type': 'executable', + 'dependencies': [ + '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/base/base.gyp:base_i18n', + '<(DEPTH)/base/base.gyp:test_support_base', + '<(DEPTH)/chrome/chrome.gyp:browser', + '<(DEPTH)/chrome/chrome.gyp:renderer', + '<(DEPTH)/chrome/chrome.gyp:test_support_common', + '<(DEPTH)/chrome/chrome_resources.gyp:chrome_resources', + '<(DEPTH)/chrome/chrome_resources.gyp:chrome_strings', + '<(DEPTH)/chrome/chrome_resources.gyp:packed_extra_resources', + '<(DEPTH)/chrome/chrome_resources.gyp:packed_resources', + '<(DEPTH)/testing/gmock.gyp:gmock', + '<(DEPTH)/testing/gtest.gyp:gtest', + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + 'chromevox_test_deps_js', + ], + 'defines': [ + 'HAS_OUT_OF_PROC_TEST_RUNNER', + ], + 'include_dirs': [ + '<(DEPTH)', + '<(SHARED_INTERMEDIATE_DIR)', + ], + 'rules': [ + { + # A JavaScript test that runs in an environment similar to a webui + # browser test. + 'rule_name': 'js2webui', + 'extension': 'js', + 'msvs_external_rule': 1, + 'inputs': [ + '<(gypv8sh)', + '<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)', + '<(mock_js)', + '<(test_api_js)', + '<(js2gtest)', + '<(chromevox_test_deps_js_file)', + 'testing/chromevox_unittest_base.js', + ], + 'outputs': [ + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT)-gen.cc', + '<(PRODUCT_DIR)/test_data/chrome/browser/resources/chromeos/chromevox/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js', + ], + 'process_outputs_as_sources': 1, + 'action': [ + 'python', + '<(gypv8sh)', + '<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)', + '--deps_js', '<(chromevox_test_deps_js_file)', + '<(mock_js)', + '<(test_api_js)', + '<(js2gtest)', + 'webui', + '<(RULE_INPUT_PATH)', + 'chrome/browser/resources/chromeos/chromevox/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js', + '<@(_outputs)', + ], + }, + ], + 'sources': [ + '<(DEPTH)/chrome/browser/ui/webui/web_ui_test_handler.cc', + '<(DEPTH)/chrome/browser/ui/webui/web_ui_test_handler.h', + '<(DEPTH)/chrome/test/base/browser_tests_main.cc', + '<(DEPTH)/chrome/test/base/test_chrome_web_ui_controller_factory.cc', + '<(DEPTH)/chrome/test/base/test_chrome_web_ui_controller_factory.h', + '<(DEPTH)/chrome/test/base/web_ui_browser_test.cc', + '<(DEPTH)/chrome/test/base/web_ui_browser_test.h', + + 'common/aria_util_test.js', + ], + }, # target chromevox_tests + { + 'target_name': 'chromevox_test_deps_js', + 'type': 'none', + 'actions': [ + { + 'action_name': 'deps_js', + 'message': 'Generate <(_target_name)', + 'variables': { + # Closure library directory relative to source tree root. + 'closure_dir': 'chrome/third_party/chromevox/third_party/closure-library/closure/goog', + 'depswriter_path': 'tools/generate_deps.py', + 'js_files': [ + '<!@(python tools/find_js_files.py . <(DEPTH)/<(closure_dir))', + ], + }, + 'inputs': [ + '<@(js_files)', + '<(depswriter_path)', + ], + 'outputs': [ + '<(chromevox_test_deps_js_file)', + ], + 'action': [ + 'python', + '<(depswriter_path)', + '-w', '<(DEPTH)/<(closure_dir):<(closure_dir)', + '-w', ':chrome/browser/resources/chromeos/chromevox', + '-o', '<(chromevox_test_deps_js_file)', + '<@(js_files)', + ], + }, + ], + }, + ], +} diff --git a/chrome/browser/resources/chromeos/chromevox/common/aria_util_test.js b/chrome/browser/resources/chromeos/chromevox/common/aria_util_test.js index e6f1a26..0206ef9 100644 --- a/chrome/browser/resources/chromeos/chromevox/common/aria_util_test.js +++ b/chrome/browser/resources/chromeos/chromevox/common/aria_util_test.js @@ -16,12 +16,10 @@ CvoxAriaUtilUnitTest.prototype = { __proto__: ChromeVoxUnitTestBase.prototype, /** @override */ - extraLibraries: [ - 'aria_util.js', - 'dom_util.js', - 'node_state.js', - 'chromevox.js', - '../host/interface/abstract_earcons.js'] + closureModuleDeps: [ + 'cvox.AriaUtil', + 'cvox.ChromeVox', + 'cvox.DomUtil',] }; TEST_F('CvoxAriaUtilUnitTest', 'GetStateGridWithActiveCell', function() { diff --git a/chrome/browser/resources/chromeos/chromevox/tools/find_js_files.py b/chrome/browser/resources/chromeos/chromevox/tools/find_js_files.py new file mode 100755 index 0000000..6d459a3 --- /dev/null +++ b/chrome/browser/resources/chromeos/chromevox/tools/find_js_files.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +# Copyright 2014 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. + +'''Scans one or more directory trees for .js files, printing filenames, +relative to the current directory on stdout. +''' + +import optparse +import os +import sys + +_SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) +_CHROME_SOURCE = os.path.realpath( + os.path.join(_SCRIPT_DIR, *[os.path.pardir] * 6)) +sys.path.insert( + 0, os.path.join( + _CHROME_SOURCE, ('chrome/third_party/chromevox/third_party/' + + 'closure-library/closure/bin/build'))) +import treescan + + +def main(): + parser = optparse.OptionParser(description=__doc__) + parser.usage = '%prog <tree_root>...' + _, args = parser.parse_args() + for root in args: + print '\n'.join(treescan.ScanTreeForJsFiles(root)) + + +if __name__ == '__main__': + main() diff --git a/chrome/browser/ui/webui/bidi_checker_web_ui_test.h b/chrome/browser/ui/webui/bidi_checker_web_ui_test.h index 0082e10..8a302b4 100644 --- a/chrome/browser/ui/webui/bidi_checker_web_ui_test.h +++ b/chrome/browser/ui/webui/bidi_checker_web_ui_test.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_UI_WEBUI_BIDI_CHECKER_WEB_UI_TEST_H_ #include "base/command_line.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" namespace base { class WaitableEvent; diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.h b/chrome/browser/ui/webui/downloads_ui_browsertest.h index 6272e87..4d35321 100644 --- a/chrome/browser/ui/webui/downloads_ui_browsertest.h +++ b/chrome/browser/ui/webui/downloads_ui_browsertest.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_BROWSERTEST_H_ #define CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_BROWSERTEST_H_ -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" // This is a helper class used by downloads_ui_browsertest.js. class DownloadsUIBrowserTest : public WebUIBrowserTest { diff --git a/chrome/browser/ui/webui/extensions/extension_settings_browsertest.h b/chrome/browser/ui/webui/extensions/extension_settings_browsertest.h index dcbead3..09caa3e 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_browsertest.h +++ b/chrome/browser/ui/webui/extensions/extension_settings_browsertest.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_BROWSERTEST_H_ #include "chrome/browser/extensions/extension_test_notification_observer.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "extensions/common/extension.h" class Profile; diff --git a/chrome/browser/ui/webui/identity_internals_ui_browsertest.h b/chrome/browser/ui/webui/identity_internals_ui_browsertest.h index db19737..d2abf18 100644 --- a/chrome/browser/ui/webui/identity_internals_ui_browsertest.h +++ b/chrome/browser/ui/webui/identity_internals_ui_browsertest.h @@ -8,7 +8,7 @@ #include <string> #include <vector> -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" class IdentityInternalsUIBrowserTest : public WebUIBrowserTest { public: @@ -30,4 +30,3 @@ class IdentityInternalsUIBrowserTest : public WebUIBrowserTest { }; #endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ - diff --git a/chrome/browser/ui/webui/inspect_ui_browsertest.cc b/chrome/browser/ui/webui/inspect_ui_browsertest.cc index e9d9683..c887f50 100644 --- a/chrome/browser/ui/webui/inspect_ui_browsertest.cc +++ b/chrome/browser/ui/webui/inspect_ui_browsertest.cc @@ -9,7 +9,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/web_contents.h" #include "content/public/test/browser_test_utils.h" diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc index 44b5281..0b97eba 100644 --- a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc +++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc @@ -18,7 +18,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager_base.h" diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.h b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.h index 252a22c..e5e358c 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.h +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_UI_WEBUI_NET_INTERNALS_NET_INTERNALS_UI_BROWSERTEST_H_ #include "base/memory/scoped_ptr.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" class GURL; diff --git a/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc b/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc index f3a90c4..e12465e 100644 --- a/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc +++ b/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc @@ -5,7 +5,7 @@ #include "base/files/file_path.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "url/gurl.h" class MostVisitedWebUITest : public WebUIBrowserTest { diff --git a/chrome/browser/ui/webui/options/options_browsertest.h b/chrome/browser/ui/webui/options/options_browsertest.h index 674cc9e..af953c9 100644 --- a/chrome/browser/ui/webui/options/options_browsertest.h +++ b/chrome/browser/ui/webui/options/options_browsertest.h @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "content/public/browser/web_ui_message_handler.h" // This is a helper class used by options_browsertest.js to feed the navigation diff --git a/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui_browsertest.cc b/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui_browsertest.cc index b424ac1..ff6d812 100644 --- a/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui_browsertest.cc +++ b/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui_browsertest.cc @@ -9,7 +9,7 @@ #include "chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "components/password_manager/content/browser/password_manager_internals_service_factory.h" #include "components/password_manager/core/browser/password_manager_internals_service.h" #include "components/password_manager/core/common/password_manager_switches.h" diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1955969..3d05761 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1329,7 +1329,6 @@ 'browser/renderer_host/render_process_host_chrome_browsertest.cc', 'browser/renderer_host/web_cache_manager_browsertest.cc', 'browser/repost_form_warning_browsertest.cc', - 'browser/resources/chromeos/chromevox/common/aria_util_test.js', 'browser/safe_browsing/local_safebrowsing_test_server.cc', 'browser/safe_browsing/safe_browsing_blocking_page_test.cc', 'browser/safe_browsing/safe_browsing_service_browsertest.cc', @@ -1537,8 +1536,9 @@ 'test/base/browser_tests_main.cc', 'test/base/chrome_render_view_test.cc', 'test/base/chrome_render_view_test.h', - 'test/base/web_ui_browsertest.cc', - 'test/base/web_ui_browsertest.h', + 'test/base/web_ui_browser_test.cc', + 'test/base/web_ui_browser_test.h', + 'test/base/web_ui_browser_test_browsertest.cc', 'test/base/in_process_browser_test_browsertest.cc', 'test/base/tracing_browsertest.cc', 'test/base/test_chrome_web_ui_controller_factory.cc', @@ -1610,7 +1610,6 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)', '<(mock_js)', - '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], @@ -2117,7 +2116,6 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)', '<(mock_js)', - '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], diff --git a/chrome/js_unittest_rules.gypi b/chrome/js_unittest_rules.gypi index 14de5b6..d877f16 100644 --- a/chrome/js_unittest_rules.gypi +++ b/chrome/js_unittest_rules.gypi @@ -60,7 +60,6 @@ '<(gypv8sh)', '<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)', '<(mock_js)', - '<(accessibility_audit_js)', '<(test_api_js)', '<(js2gtest)', ], diff --git a/chrome/test/base/js2gtest.js b/chrome/test/base/js2gtest.js index a13ad87..9cf8fef 100644 --- a/chrome/test/base/js2gtest.js +++ b/chrome/test/base/js2gtest.js @@ -15,9 +15,10 @@ // Arguments from rules in chrome_tests.gypi are passed in through // python script gypv8sh.py. -if (arguments.length < 4) { +if (arguments.length != 6) { print('usage: ' + - arguments[0] + ' path-to-testfile.js testfile.js output.cc test-type'); + arguments[0] + + ' path-to-testfile.js testfile.js path_to_deps.js output.cc test-type'); quit(-1); } @@ -35,16 +36,22 @@ var jsFile = arguments[1]; var jsFileBase = arguments[2]; /** + * Path to Closure library style deps.js file. + * @type {string?} + */ +var depsFile = arguments[3]; + +/** * Path to C++ file generation is outputting to. * @type {string} */ -var outputFile = arguments[3]; +var outputFile = arguments[4]; /** * Type of this test. * @type {string} ('unit'| 'webui') */ -var testType = arguments[4]; +var testType = arguments[5]; /** * C++ gtest macro to use for TEST_F depending on |testType|. @@ -91,7 +98,7 @@ if (testType === 'unit') { testF = 'TEST_F'; addSetPreloadInfo = false; } else { - print('#include "chrome/test/base/web_ui_browsertest.h"'); + print('#include "chrome/test/base/web_ui_browser_test.h"'); testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; testF = 'IN_PROC_BROWSER_TEST_F'; addSetPreloadInfo = true; @@ -114,6 +121,100 @@ function includeFileToPaths(includeFile) { }; } + +/** + * Maps object names to the path to the file that provides them. + * Populated from the |depsFile| if any. + * @type {Object.<string, string>} + */ +var dependencyProvidesToPaths = {}; + +/** + * Maps dependency path names to object names required by the file. + * Populated from the |depsFile| if any. + * @type {Object.<string, Array.<string>>} + */ +var dependencyPathsToRequires = {}; + +if (depsFile) { + var goog = goog || {}; + /** + * Called by the javascript in the deps file to add modules and their + * dependencies. + * @param {string} path Relative path to the file. + * @param Array.<string> provides Objects provided by this file. + * @param Array.<string> requires Objects required by this file. + */ + goog.addDependency = function(path, provides, requires) { + provides.forEach(function(provide) { + dependencyProvidesToPaths[provide] = path; + }); + dependencyPathsToRequires[path] = requires; + }; + + // Read and eval the deps file. It should only contain goog.addDependency + // calls. + eval(read(depsFile)); +} + +/** + * Resolves a list of libraries to an ordered list of paths to load by the + * generated C++. The input should contain object names provided + * by the deps file. Dependencies will be resolved and included in the + * correct order, meaning that the returned array may contain more entries + * than the input. + * @param {Array.<string>} deps List of dependencies. + * @return {Array.<string>} List of paths to load. + */ +function resolveClosureModuleDeps(deps) { + if (!depsFile && deps.length > 0) { + print('Can\'t have closure dependencies without a deps file.'); + quit(-1); + } + var resultPaths = []; + var addedPaths = {}; + + function addPath(path) { + addedPaths[path] = true; + resultPaths.push(path); + } + + function resolveAndAppend(path) { + if (addedPaths[path]) { + return; + } + // Set before recursing to catch cycles. + addedPaths[path] = true; + dependencyPathsToRequires[path].forEach(function(require) { + var providingPath = dependencyProvidesToPaths[require]; + if (!providingPath) { + print('Unknown object', require, 'required by', path); + quit(-1); + } + resolveAndAppend(providingPath); + }); + resultPaths.push(path); + } + + // Always add closure library's base.js if provided by deps. + var basePath = dependencyProvidesToPaths['goog']; + if (basePath) { + addPath(basePath); + } + + deps.forEach(function(dep) { + var providingPath = dependencyProvidesToPaths[dep]; + if (providingPath) { + resolveAndAppend(providingPath); + } else { + print('Unknown dependency:', dep); + quit(-1); + } + }); + + return resultPaths; +} + /** * Output |code| verbatim. * @param {string} code The code to output. @@ -158,7 +259,8 @@ function TEST_F(testFixture, testFunction, testBody) { this[testFixture].prototype.extraLibraries.map( function(includeFile) { return includeFileToPaths(includeFile).base; - })); + }), + resolveClosureModuleDeps(this[testFixture].prototype.closureModuleDeps)); if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); diff --git a/chrome/test/base/web_ui_browsertest.cc b/chrome/test/base/web_ui_browser_test.cc index 1f874e2..8e125ec 100644 --- a/chrome/test/base/web_ui_browsertest.cc +++ b/chrome/test/base/web_ui_browser_test.cc @@ -1,14 +1,12 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include <string> #include <vector> -#include "base/bind.h" -#include "base/bind_helpers.h" #include "base/lazy_instance.h" #include "base/memory/ref_counted_memory.h" #include "base/path_service.h" @@ -19,19 +17,12 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" -#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/browser/ui/webui/web_ui_test_handler.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" @@ -40,8 +31,6 @@ #include "content/public/test/browser_test_utils.h" #include "content/public/test/test_navigation_observer.h" #include "net/base/filename_util.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest-spi.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_handle.h" @@ -49,7 +38,6 @@ #include "chrome/browser/printing/print_preview_dialog_controller.h" #endif -using content::NavigationController; using content::RenderViewHost; using content::WebContents; using content::WebUIController; @@ -587,230 +575,3 @@ void WebUIBrowserTest::SetupHandlers() { GetMockMessageHandler()->RegisterMessages(); } } - -// According to the interface for EXPECT_FATAL_FAILURE -// (http://code.google.com/p/googletest/wiki/AdvancedGuide#Catching_Failures) -// the statement must be statically available. Therefore, we make a static -// global s_test_ which should point to |this| for the duration of the test run -// and be cleared afterward. -class WebUIBrowserExpectFailTest : public WebUIBrowserTest { - public: - WebUIBrowserExpectFailTest() { - EXPECT_FALSE(s_test_); - s_test_ = this; - } - - protected: - virtual ~WebUIBrowserExpectFailTest() { - EXPECT_TRUE(s_test_); - s_test_ = NULL; - } - - static void RunJavascriptTestNoReturn(const std::string& testname) { - EXPECT_TRUE(s_test_); - s_test_->RunJavascriptTest(testname); - } - - static void RunJavascriptAsyncTestNoReturn(const std::string& testname) { - EXPECT_TRUE(s_test_); - s_test_->RunJavascriptAsyncTest(testname); - } - - private: - static WebUIBrowserTest* s_test_; -}; - -WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; - -// Test that bogus javascript fails fast - no timeout waiting for result. -IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { - AddLibrary(base::FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); - EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("DISABLED_BogusFunctionName"), - "WebUITestHandler::JavaScriptComplete"); -} - -// Test that bogus javascript fails fast - no timeout waiting for result. -IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestRuntimeErrorFailsFast) { - AddLibrary(base::FilePath(FILE_PATH_LITERAL("runtime_error.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); - EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("TestRuntimeErrorFailsFast"), - "WebUITestHandler::JavaScriptComplete"); -} - -// Test that bogus javascript fails async test fast as well - no timeout waiting -// for result. -IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsAsyncFast) { - AddLibrary(base::FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); - EXPECT_FATAL_FAILURE( - RunJavascriptAsyncTestNoReturn("DISABLED_BogusFunctionName"), - "WebUITestHandler::JavaScriptComplete"); -} - -// Tests that the async framework works. -class WebUIBrowserAsyncTest : public WebUIBrowserTest { - public: - // Calls the testDone() function from test_api.js - void TestDone() { - RunJavascriptFunction("testDone"); - } - - // Starts a failing test. - void RunTestFailsAssert() { - RunJavascriptFunction("runAsync", new base::StringValue("testFailsAssert")); - } - - // Starts a passing test. - void RunTestPasses() { - RunJavascriptFunction("runAsync", new base::StringValue("testPasses")); - } - - protected: - WebUIBrowserAsyncTest() {} - - // Class to synchronize asynchronous javascript activity with the tests. - class AsyncWebUIMessageHandler : public WebUIMessageHandler { - public: - AsyncWebUIMessageHandler() {} - - MOCK_METHOD1(HandleTestContinues, void(const base::ListValue*)); - MOCK_METHOD1(HandleTestFails, void(const base::ListValue*)); - MOCK_METHOD1(HandleTestPasses, void(const base::ListValue*)); - - private: - virtual void RegisterMessages() OVERRIDE { - web_ui()->RegisterMessageCallback("startAsyncTest", - base::Bind(&AsyncWebUIMessageHandler::HandleStartAsyncTest, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("testContinues", - base::Bind(&AsyncWebUIMessageHandler::HandleTestContinues, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("testFails", - base::Bind(&AsyncWebUIMessageHandler::HandleTestFails, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("testPasses", - base::Bind(&AsyncWebUIMessageHandler::HandleTestPasses, - base::Unretained(this))); - } - - // Starts the test in |list_value|[0] with the runAsync wrapper. - void HandleStartAsyncTest(const base::ListValue* list_value) { - const base::Value* test_name; - ASSERT_TRUE(list_value->Get(0, &test_name)); - web_ui()->CallJavascriptFunction("runAsync", *test_name); - } - - DISALLOW_COPY_AND_ASSIGN(AsyncWebUIMessageHandler); - }; - - // Handler for this object. - ::testing::StrictMock<AsyncWebUIMessageHandler> message_handler_; - - private: - // Provide this object's handler. - virtual WebUIMessageHandler* GetMockMessageHandler() OVERRIDE { - return &message_handler_; - } - - // Set up and browse to kDummyURL for all tests. - virtual void SetUpOnMainThread() OVERRIDE { - WebUIBrowserTest::SetUpOnMainThread(); - AddLibrary(base::FilePath(FILE_PATH_LITERAL("async.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); - } - - DISALLOW_COPY_AND_ASSIGN(WebUIBrowserAsyncTest); -}; - -// Test that assertions fail immediately after assertion fails (no testContinues -// message). (Sync version). -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncOkTestFail) { - ASSERT_FALSE(RunJavascriptTest("testFailsAssert")); -} - -// Test that assertions fail immediately after assertion fails (no testContinues -// message). (Async version). -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsAssert) { - EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); - ASSERT_FALSE(RunJavascriptAsyncTest( - "startAsyncTest", new base::StringValue("testFailsAssert"))); -} - -// Test that expectations continue the function, but fail the test. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsExpect) { - ::testing::InSequence s; - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); - ASSERT_FALSE(RunJavascriptAsyncTest( - "startAsyncTest", new base::StringValue("testFailsExpect"))); -} - -// Test that test continues and passes. (Sync version). -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncPasses) { - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - ASSERT_TRUE(RunJavascriptTest("testPasses")); -} - -// Test that test continues and passes. (Async version). -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPasses) { - ::testing::InSequence s; - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) - .WillOnce(::testing::InvokeWithoutArgs( - this, &WebUIBrowserAsyncTest::TestDone)); - ASSERT_TRUE(RunJavascriptAsyncTest( - "startAsyncTest", new base::StringValue("testPasses"))); -} - -// Test that two tests pass. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassPass) { - ::testing::InSequence s; - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) - .WillOnce(::testing::InvokeWithoutArgs( - this, &WebUIBrowserAsyncTest::RunTestPasses)); - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) - .WillOnce(::testing::InvokeWithoutArgs( - this, &WebUIBrowserAsyncTest::TestDone)); - ASSERT_TRUE(RunJavascriptAsyncTest( - "startAsyncTest", new base::StringValue("testPasses"))); -} - -// Test that first test passes; second fails. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassThenFail) { - ::testing::InSequence s; - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) - .WillOnce(::testing::InvokeWithoutArgs( - this, &WebUIBrowserAsyncTest::RunTestFailsAssert)); - EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); - ASSERT_FALSE(RunJavascriptAsyncTest( - "startAsyncTest", new base::StringValue("testPasses"))); -} - -// Test that testDone() with failure first then sync pass still fails. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncDoneFailFirstSyncPass) { - ::testing::InSequence s; - EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); - EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); - - // Call runAsync directly instead of deferring through startAsyncTest. It will - // call testDone() on failure, then return. - ASSERT_FALSE(RunJavascriptAsyncTest( - "runAsync", new base::StringValue("testAsyncDoneFailFirstSyncPass"))); -} - -// Test that calling testDone during RunJavascriptAsyncTest still completes -// when waiting for async result. This is similar to the previous test, but call -// testDone directly and expect pass result. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { - ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); -} - -// Test that calling testDone during RunJavascriptTest still completes when -// waiting for async result. -IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { - ASSERT_TRUE(RunJavascriptTest("testDone")); -} diff --git a/chrome/test/base/web_ui_browsertest.h b/chrome/test/base/web_ui_browser_test.h index 3f35b56..8173cf7 100644 --- a/chrome/test/base/web_ui_browsertest.h +++ b/chrome/test/base/web_ui_browser_test.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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_BASE_WEB_UI_BROWSERTEST_H_ -#define CHROME_TEST_BASE_WEB_UI_BROWSERTEST_H_ +#ifndef CHROME_TEST_BASE_WEB_UI_BROWSER_TEST_H_ +#define CHROME_TEST_BASE_WEB_UI_BROWSER_TEST_H_ #include <string> #include <vector> @@ -188,4 +188,4 @@ class WebUIBrowserTest : public InProcessBrowserTest { scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; }; -#endif // CHROME_TEST_BASE_WEB_UI_BROWSERTEST_H_ +#endif // CHROME_TEST_BASE_WEB_UI_BROWSER_TEST_H_ diff --git a/chrome/test/base/web_ui_browser_test_browsertest.cc b/chrome/test/base/web_ui_browser_test_browsertest.cc new file mode 100644 index 0000000..5fe1392 --- /dev/null +++ b/chrome/test/base/web_ui_browser_test_browsertest.cc @@ -0,0 +1,245 @@ +// Copyright 2014 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 <string> + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/values.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/web_ui_browser_test.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_message_handler.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest-spi.h" + +using content::WebUIMessageHandler; + +// According to the interface for EXPECT_FATAL_FAILURE +// (http://code.google.com/p/googletest/wiki/AdvancedGuide#Catching_Failures) +// the statement must be statically available. Therefore, we make a static +// global s_test_ which should point to |this| for the duration of the test run +// and be cleared afterward. +class WebUIBrowserExpectFailTest : public WebUIBrowserTest { + public: + WebUIBrowserExpectFailTest() { + EXPECT_FALSE(s_test_); + s_test_ = this; + } + + protected: + virtual ~WebUIBrowserExpectFailTest() { + EXPECT_TRUE(s_test_); + s_test_ = NULL; + } + + static void RunJavascriptTestNoReturn(const std::string& testname) { + EXPECT_TRUE(s_test_); + s_test_->RunJavascriptTest(testname); + } + + static void RunJavascriptAsyncTestNoReturn(const std::string& testname) { + EXPECT_TRUE(s_test_); + s_test_->RunJavascriptAsyncTest(testname); + } + + private: + static WebUIBrowserTest* s_test_; +}; + +WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; + +// Test that bogus javascript fails fast - no timeout waiting for result. +IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { + AddLibrary(base::FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); + EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("DISABLED_BogusFunctionName"), + "WebUITestHandler::JavaScriptComplete"); +} + +// Test that bogus javascript fails fast - no timeout waiting for result. +IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestRuntimeErrorFailsFast) { + AddLibrary(base::FilePath(FILE_PATH_LITERAL("runtime_error.js"))); + ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); + EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("TestRuntimeErrorFailsFast"), + "WebUITestHandler::JavaScriptComplete"); +} + +// Test that bogus javascript fails async test fast as well - no timeout waiting +// for result. +IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsAsyncFast) { + AddLibrary(base::FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); + EXPECT_FATAL_FAILURE( + RunJavascriptAsyncTestNoReturn("DISABLED_BogusFunctionName"), + "WebUITestHandler::JavaScriptComplete"); +} + +// Tests that the async framework works. +class WebUIBrowserAsyncTest : public WebUIBrowserTest { + public: + // Calls the testDone() function from test_api.js + void TestDone() { + RunJavascriptFunction("testDone"); + } + + // Starts a failing test. + void RunTestFailsAssert() { + RunJavascriptFunction("runAsync", new base::StringValue("testFailsAssert")); + } + + // Starts a passing test. + void RunTestPasses() { + RunJavascriptFunction("runAsync", new base::StringValue("testPasses")); + } + + protected: + WebUIBrowserAsyncTest() {} + + // Class to synchronize asynchronous javascript activity with the tests. + class AsyncWebUIMessageHandler : public WebUIMessageHandler { + public: + AsyncWebUIMessageHandler() {} + + MOCK_METHOD1(HandleTestContinues, void(const base::ListValue*)); + MOCK_METHOD1(HandleTestFails, void(const base::ListValue*)); + MOCK_METHOD1(HandleTestPasses, void(const base::ListValue*)); + + private: + virtual void RegisterMessages() OVERRIDE { + web_ui()->RegisterMessageCallback("startAsyncTest", + base::Bind(&AsyncWebUIMessageHandler::HandleStartAsyncTest, + base::Unretained(this))); + web_ui()->RegisterMessageCallback("testContinues", + base::Bind(&AsyncWebUIMessageHandler::HandleTestContinues, + base::Unretained(this))); + web_ui()->RegisterMessageCallback("testFails", + base::Bind(&AsyncWebUIMessageHandler::HandleTestFails, + base::Unretained(this))); + web_ui()->RegisterMessageCallback("testPasses", + base::Bind(&AsyncWebUIMessageHandler::HandleTestPasses, + base::Unretained(this))); + } + + // Starts the test in |list_value|[0] with the runAsync wrapper. + void HandleStartAsyncTest(const base::ListValue* list_value) { + const base::Value* test_name; + ASSERT_TRUE(list_value->Get(0, &test_name)); + web_ui()->CallJavascriptFunction("runAsync", *test_name); + } + + DISALLOW_COPY_AND_ASSIGN(AsyncWebUIMessageHandler); + }; + + // Handler for this object. + ::testing::StrictMock<AsyncWebUIMessageHandler> message_handler_; + + private: + // Provide this object's handler. + virtual WebUIMessageHandler* GetMockMessageHandler() OVERRIDE { + return &message_handler_; + } + + // Set up and browse to kDummyURL for all tests. + virtual void SetUpOnMainThread() OVERRIDE { + WebUIBrowserTest::SetUpOnMainThread(); + AddLibrary(base::FilePath(FILE_PATH_LITERAL("async.js"))); + ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); + } + + DISALLOW_COPY_AND_ASSIGN(WebUIBrowserAsyncTest); +}; + +// Test that assertions fail immediately after assertion fails (no testContinues +// message). (Sync version). +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncOkTestFail) { + ASSERT_FALSE(RunJavascriptTest("testFailsAssert")); +} + +// Test that assertions fail immediately after assertion fails (no testContinues +// message). (Async version). +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsAssert) { + EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); + ASSERT_FALSE(RunJavascriptAsyncTest( + "startAsyncTest", new base::StringValue("testFailsAssert"))); +} + +// Test that expectations continue the function, but fail the test. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsExpect) { + ::testing::InSequence s; + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); + ASSERT_FALSE(RunJavascriptAsyncTest( + "startAsyncTest", new base::StringValue("testFailsExpect"))); +} + +// Test that test continues and passes. (Sync version). +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncPasses) { + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + ASSERT_TRUE(RunJavascriptTest("testPasses")); +} + +// Test that test continues and passes. (Async version). +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPasses) { + ::testing::InSequence s; + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) + .WillOnce(::testing::InvokeWithoutArgs( + this, &WebUIBrowserAsyncTest::TestDone)); + ASSERT_TRUE(RunJavascriptAsyncTest( + "startAsyncTest", new base::StringValue("testPasses"))); +} + +// Test that two tests pass. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassPass) { + ::testing::InSequence s; + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) + .WillOnce(::testing::InvokeWithoutArgs( + this, &WebUIBrowserAsyncTest::RunTestPasses)); + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) + .WillOnce(::testing::InvokeWithoutArgs( + this, &WebUIBrowserAsyncTest::TestDone)); + ASSERT_TRUE(RunJavascriptAsyncTest( + "startAsyncTest", new base::StringValue("testPasses"))); +} + +// Test that first test passes; second fails. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassThenFail) { + ::testing::InSequence s; + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) + .WillOnce(::testing::InvokeWithoutArgs( + this, &WebUIBrowserAsyncTest::RunTestFailsAssert)); + EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); + ASSERT_FALSE(RunJavascriptAsyncTest( + "startAsyncTest", new base::StringValue("testPasses"))); +} + +// Test that testDone() with failure first then sync pass still fails. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncDoneFailFirstSyncPass) { + ::testing::InSequence s; + EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); + EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); + + // Call runAsync directly instead of deferring through startAsyncTest. It will + // call testDone() on failure, then return. + ASSERT_FALSE(RunJavascriptAsyncTest( + "runAsync", new base::StringValue("testAsyncDoneFailFirstSyncPass"))); +} + +// Test that calling testDone during RunJavascriptAsyncTest still completes +// when waiting for async result. This is similar to the previous test, but call +// testDone directly and expect pass result. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { + ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); +} + +// Test that calling testDone during RunJavascriptTest still completes when +// waiting for async result. +IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { + ASSERT_TRUE(RunJavascriptTest("testDone")); +} diff --git a/chrome/test/data/webui/async_gen.h b/chrome/test/data/webui/async_gen.h index c86cc89..ef96cc3 100644 --- a/chrome/test/data/webui/async_gen.h +++ b/chrome/test/data/webui/async_gen.h @@ -4,7 +4,7 @@ #ifndef CHROME_TEST_DATA_WEBUI_ASYNC_GEN_H_ #define CHROME_TEST_DATA_WEBUI_ASYNC_GEN_H_ -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "content/public/browser/web_ui_message_handler.h" #include "testing/gmock/include/gmock/gmock.h" diff --git a/chrome/test/data/webui/certificate_viewer_ui_test-inl.h b/chrome/test/data/webui/certificate_viewer_ui_test-inl.h index 342db9f..4b5356b 100644 --- a/chrome/test/data/webui/certificate_viewer_ui_test-inl.h +++ b/chrome/test/data/webui/certificate_viewer_ui_test-inl.h @@ -10,7 +10,7 @@ #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" diff --git a/chrome/test/data/webui/chrome_send_browsertest.h b/chrome/test/data/webui/chrome_send_browsertest.h index b96dd85..e454765 100644 --- a/chrome/test/data/webui/chrome_send_browsertest.h +++ b/chrome/test/data/webui/chrome_send_browsertest.h @@ -5,7 +5,7 @@ #ifndef CHROME_TEST_DATA_WEBUI_CHROME_SEND_BROWSERTEST_H_ #define CHROME_TEST_DATA_WEBUI_CHROME_SEND_BROWSERTEST_H_ -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" #include "content/public/browser/web_ui_message_handler.h" #include "testing/gmock/include/gmock/gmock.h" diff --git a/chrome/test/data/webui/history_ui_browsertest.h b/chrome/test/data/webui/history_ui_browsertest.h index ef426b5..ded7fc4 100644 --- a/chrome/test/data/webui/history_ui_browsertest.h +++ b/chrome/test/data/webui/history_ui_browsertest.h @@ -7,7 +7,7 @@ #include "base/time/time.h" -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" class HistoryService; diff --git a/chrome/test/data/webui/ntp4_browsertest.h b/chrome/test/data/webui/ntp4_browsertest.h index 679d269..a38267b 100644 --- a/chrome/test/data/webui/ntp4_browsertest.h +++ b/chrome/test/data/webui/ntp4_browsertest.h @@ -5,7 +5,7 @@ #ifndef CHROME_TEST_DATA_WEBUI_NTP4_BROWSERTEST_H_ #define CHROME_TEST_DATA_WEBUI_NTP4_BROWSERTEST_H_ -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" class NTP4LoggedInWebUITest : public WebUIBrowserTest { public: diff --git a/chrome/test/data/webui/print_preview.h b/chrome/test/data/webui/print_preview.h index e3b1a58..2698563 100644 --- a/chrome/test/data/webui/print_preview.h +++ b/chrome/test/data/webui/print_preview.h @@ -5,7 +5,7 @@ #ifndef CHROME_TEST_DATA_WEBUI_PRINT_PREVIEW_H_ #define CHROME_TEST_DATA_WEBUI_PRINT_PREVIEW_H_ -#include "chrome/test/base/web_ui_browsertest.h" +#include "chrome/test/base/web_ui_browser_test.h" class PrintPreviewWebUITest : public WebUIBrowserTest { public: diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js index 07510ae..2696d2b 100644 --- a/chrome/test/data/webui/test_api.js +++ b/chrome/test/data/webui/test_api.js @@ -122,6 +122,17 @@ var testing = {}; extraLibraries: [], /** + * Extra libraries to add before loading this test file. + * This list is in the form of Closure library style object + * names. To support this, a closure deps.js file must + * be specified when generating the test C++ source. + * The specified libraries will be included with their transitive + * dependencies according to the deps file. + * @type {Array.<string>} + */ + closureModuleDeps: [], + + /** * Whether to run the accessibility checks. * @type {boolean} */ diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py index 5c93e51..b8bd406 100755 --- a/tools/gypv8sh.py +++ b/tools/gypv8sh.py @@ -5,10 +5,6 @@ """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 v8_shell mock.js test_api.js js2webui.js \ - inputfile inputrelfile cxxoutfile jsoutfile """ import json @@ -22,24 +18,28 @@ import shutil def main (): parser = optparse.OptionParser() parser.set_usage( - "%prog v8_shell mock.js axs_testing.js test_api.js js2webui.js " + "%prog v8_shell mock.js test_api.js js2webui.js " "testtype inputfile inputrelfile cxxoutfile jsoutfile") 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('--deps_js', action="store", + help=("Path to deps.js for dependency resolution, " + + "optional.")) (opts, args) = parser.parse_args() - if len(args) != 10: + if len(args) != 9: parser.error('all arguments are required.') - (v8_shell, mock_js, axs_testing_js, test_api, js2webui, test_type, + (v8_shell, mock_js, test_api, js2webui, test_type, inputfile, inputrelfile, cxxoutfile, jsoutfile) = args cmd = [v8_shell] icudatafile = os.path.join(os.path.dirname(v8_shell), 'icudtl.dat') if os.path.exists(icudatafile): cmd.extend(['--icu-data-file=%s' % icudatafile]) - arguments = [js2webui, inputfile, inputrelfile, cxxoutfile, test_type] + arguments = [js2webui, inputfile, inputrelfile, opts.deps_js, + cxxoutfile, test_type] cmd.extend(['-e', "arguments=" + json.dumps(arguments), mock_js, - axs_testing_js, test_api, js2webui]) + test_api, js2webui]) if opts.verbose or opts.impotent: print cmd if not opts.impotent: |