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
parent 6f38c134
......@@ -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',
......
# 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)',
],
},
],
},
],
}
......@@ -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() {
......
#!/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()
......@@ -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;
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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_
......@@ -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"
......
......@@ -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"
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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
......
......@@ -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"
......
......@@ -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)',
],
......
......@@ -60,7 +60,6 @@
'<(gypv8sh)',
'<(PRODUCT_DIR)/d8<(EXECUTABLE_SUFFIX)',
'<(mock_js)',
'<(accessibility_audit_js)',
'<(test_api_js)',
'<(js2gtest)',
],
......
......@@ -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);
}
......@@ -34,17 +35,23 @@ 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 + ';');
......
// 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_
// 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"));
}
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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;
......
......@@ -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:
......
......@@ -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:
......
......@@ -121,6 +121,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}
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment