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

Unified Diff: chrome/browser/ui/webui/web_ui_browsertest.h

Issue 7087014: Support automatic javascript test registry in gtest when creating WebUI tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added example of helper functions which aren't included as tests. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/web_ui_browsertest.h
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.h b/chrome/browser/ui/webui/web_ui_browsertest.h
index 001ae7a8483efa43a75b6f7e4f3cd27f52e372d2..0d31b181f074a31af58d8db59ecb2ca02ee8713c 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>
@@ -23,6 +23,54 @@ class WebUIMessageHandler;
ASSERT_TRUE(RunJavascriptTest(#y)); \
}
+#define WEB_UI_BROWSER_TEST_JS_(test_case_name, test_name, parent_class, \
+ parent_id, assertion, jsfile) \
+class GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
+ : public parent_class, public ::testing::WithParamInterface<std::string> {\
+ public:\
+ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
+ protected:\
+ virtual void PrepForJSOnMainThread();\
+ virtual void RunTestOnMainThread() {\
+ AddLibrary(FilePath(jsfile));\
+ PrepForJSOnMainThread();\
+ assertion(RunJavascriptTest(GetParam()));\
+ }\
+ private:\
+ static ::testing::internal::TestMetaFactory< \
+ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)> meta_factory_; \
+ virtual void TestBody() {}\
+ static int const gtest_registering_dummy_;\
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(\
+ GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
+};\
+\
+::testing::internal::TestMetaFactory< \
+ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>\
+ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::meta_factory_; \
+int const GTEST_TEST_CLASS_NAME_(test_case_name, \
+ test_name)::gtest_registering_dummy_ = \
+ ::parent_class::AddJSToRegistry(\
+ FilePath(jsfile),\
+ #test_case_name, #test_name, "", "",\
David Tseng 2011/05/30 20:44:49 Do we need the |test_name| parameter? It is alrea
Sheridan Rawlins 2011/05/31 23:15:00 I include the test_name after the slash so that it
+ (parent_id),\
+ parent_class::SetUpTestCase,\
+ parent_class::TearDownTestCase,\
+ &meta_factory_);\
+void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::PrepForJSOnMainThread()
+
+#define WEB_UI_BROWSER_TEST_JS_TRUE(test_fixture, test_name, jsfile) \
+ WEB_UI_BROWSER_TEST_JS_(test_fixture, test_name, test_fixture, \
+ ::testing::internal::GetTypeId<test_fixture>(), \
+ ASSERT_TRUE, jsfile)
+
+#define WEB_UI_BROWSER_TEST_JS_FALSE(test_fixture, test_name, jsfile) \
+ WEB_UI_BROWSER_TEST_JS_(test_fixture, test_name, test_fixture, \
+ ::testing::internal::GetTypeId<test_fixture>(), \
+ ASSERT_FALSE, jsfile)
+
+#define WEB_UI_BROWSER_TEST_JS WEB_UI_BROWSER_TEST_JS_TRUE
+
// The runner of WebUI javascript based tests.
// See chrome/test/data/webui/test_api.js for the javascript side test API's.
//
@@ -69,9 +117,19 @@ class WebUIBrowserTest : public InProcessBrowserTest {
// Returns a mock WebUI object under test (if any).
virtual WebUIMessageHandler* GetMockMessageHandler();
+ static int AddJSToRegistry(
+ const FilePath& library_path,
+ const char* test_case_name, const char* name,
+ const char* type_param,
+ const char* value_param,
+ ::testing::internal::TypeId fixture_class_id,
+ ::testing::internal::SetUpTestCaseFunc set_up_tc,
+ ::testing::internal::TearDownTestCaseFunc tear_down_tc,
+ ::testing::internal::TestMetaFactoryBase<std::string>* meta_factory);
+
private:
// Builds a string containing all added javascript libraries.
- void BuildJavascriptLibraries(std::string* content);
+ void BuildJavascriptLibraries(std::string* content) const;
// Builds a string with a call to the runTest JS function, passing the
// given test and its arguments.
@@ -95,7 +153,7 @@ class WebUIBrowserTest : public InProcessBrowserTest {
FilePath test_data_directory_;
// User added libraries
- std::vector<FilePath> user_libraries;
+ std::vector<FilePath> user_libraries_;
};
-#endif // CONTENT_BROWSER_WEBUI_WEB_UI_BROWSERTEST_H_
+#endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_

Powered by Google App Engine
This is Rietveld 408576698