diff options
author | scr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 06:28:50 +0000 |
---|---|---|
committer | scr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 06:28:50 +0000 |
commit | 1582387e898ffc722d7f34768e257d1d25b9cde8 (patch) | |
tree | 1d0d81267afeac63c95d03dd4f9d1fd0fe1bd25b | |
parent | b945425ee28d986f665f9a51ceadbc787ddef0e2 (diff) | |
download | chromium_src-1582387e898ffc722d7f34768e257d1d25b9cde8.zip chromium_src-1582387e898ffc722d7f34768e257d1d25b9cde8.tar.gz chromium_src-1582387e898ffc722d7f34768e257d1d25b9cde8.tar.bz2 |
Allow WebUI Tests to use preLoad in HtmlDialogUI.
- Refactor JsInjectionReadyObserver to its own header/impl files.
- Call JsInjectionReadyObserver::OnJsInjectionReady when the dialog
is shown.
- Move preamble generation to after the AddLibrary calls & generate setting
of preload_* variables rather than passing in browsePreload and
browsePrintPreload.
- Modify tests that show HtmlDialogUI to show the dialogs using preamble
rather than SetUpOnMainThread so AddLibrary & set_preload_* calls precede
showing the dialog (so preload is called against the appropriate fixture).
R=flackr@chromium.org, jhawkins@chromium.org
BUG=104371
TEST=browser_tests --gtest_filter=Hung*.* -AND- CertificateViewerUITest*.*
Review URL: http://codereview.chromium.org/8586009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112146 0039d316-1c4b-4281-b951-d872f2087c98
26 files changed, 227 insertions, 130 deletions
diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc index a1cc91b..b2829be 100644 --- a/chrome/browser/errorpage_browsertest.cc +++ b/chrome/browser/errorpage_browsertest.cc @@ -8,8 +8,8 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/test_navigation_observer.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/test_navigation_observer.h" #include "content/browser/net/url_request_failed_dns_job.h" #include "content/browser/net/url_request_mock_http_job.h" diff --git a/chrome/browser/ui/webui/html_dialog_ui.cc b/chrome/browser/ui/webui/html_dialog_ui.cc index 788ee23..05d9fec 100644 --- a/chrome/browser/ui/webui/html_dialog_ui.cc +++ b/chrome/browser/ui/webui/html_dialog_ui.cc @@ -73,7 +73,7 @@ void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { content::NotificationService::current()->Notify( chrome::NOTIFICATION_HTML_DIALOG_SHOWN, content::Source<WebUI>(this), - content::NotificationService::NoDetails()); + content::Details<RenderViewHost>(render_view_host)); } void HtmlDialogUI::OnDialogClosed(const ListValue* args) { diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc index 9049fd8..d960cc1 100644 --- a/chrome/browser/ui/webui/web_ui_browsertest.cc +++ b/chrome/browser/ui/webui/web_ui_browsertest.cc @@ -175,13 +175,7 @@ void WebUIBrowserTest::PreLoadJavascriptLibraries( libraries_preloaded_ = true; } -void WebUIBrowserTest::BrowsePreload(const GURL& browse_to, - const std::string& preload_test_fixture, - const std::string& preload_test_name) { - // Remember for callback OnJsInjectionReady(). - preload_test_fixture_ = preload_test_fixture; - preload_test_name_ = preload_test_name; - +void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { TestNavigationObserver navigation_observer( content::Source<NavigationController>( &browser()->GetSelectedTabContentsWrapper()->controller()), @@ -193,14 +187,7 @@ void WebUIBrowserTest::BrowsePreload(const GURL& browse_to, navigation_observer.WaitForObservation(); } -void WebUIBrowserTest::BrowsePrintPreload( - const GURL& browse_to, - const std::string& preload_test_fixture, - const std::string& preload_test_name) { - // Remember for callback OnJsInjectionReady(). - preload_test_fixture_ = preload_test_fixture; - preload_test_name_ = preload_test_name; - +void WebUIBrowserTest::BrowsePrintPreload(const GURL& browse_to) { ui_test_utils::NavigateToURL(browser(), browse_to); TestTabStripModelObserver tabstrip_observer( @@ -223,6 +210,16 @@ WebUIBrowserTest::WebUIBrowserTest() libraries_preloaded_(false), override_selected_web_ui_(NULL) {} +void WebUIBrowserTest::set_preload_test_fixture( + const std::string& preload_test_fixture) { + preload_test_fixture_ = preload_test_fixture; +} + +void WebUIBrowserTest::set_preload_test_name( + const std::string& preload_test_name) { + preload_test_name_ = preload_test_name; +} + namespace { class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { diff --git a/chrome/browser/ui/webui/web_ui_browsertest.h b/chrome/browser/ui/webui/web_ui_browsertest.h index 99f086a..59895da 100644 --- a/chrome/browser/ui/webui/web_ui_browsertest.h +++ b/chrome/browser/ui/webui/web_ui_browsertest.h @@ -12,7 +12,8 @@ #include "base/string16.h" #include "chrome/browser/ui/webui/web_ui_test_handler.h" #include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/test_navigation_observer.h" +#include "chrome/test/base/js_injection_ready_observer.h" +#include "chrome/test/base/test_navigation_observer.h" class RenderViewHost; class WebUIMessageHandler; @@ -37,7 +38,7 @@ class Value; // and the lone test within this class. class WebUIBrowserTest : public InProcessBrowserTest, - public TestNavigationObserver::JsInjectionReadyObserver { + public JsInjectionReadyObserver { public: typedef std::vector<const base::Value*> ConstValueVector; virtual ~WebUIBrowserTest(); @@ -101,17 +102,13 @@ class WebUIBrowserTest // the javascript for the given |preload_test_fixture| and // |preload_test_name|. chrome.send will be overridden to allow javascript // handler mocking. - void BrowsePreload(const GURL& browse_to, - const std::string& preload_test_fixture, - const std::string& preload_test_name); + void BrowsePreload(const GURL& browse_to); // Called by javascript-generated test bodies to browse to a page and preload // the javascript for the given |preload_test_fixture| and // |preload_test_name|. chrome.send will be overridden to allow javascript // handler mocking. - void BrowsePrintPreload(const GURL& browse_to, - const std::string& preload_test_fixture, - const std::string& preload_test_name); + void BrowsePrintPreload(const GURL& browse_to); protected: // URL to dummy WebUI page for testing framework. @@ -119,6 +116,10 @@ class WebUIBrowserTest WebUIBrowserTest(); + // Accessors for preload test fixture and name. + void set_preload_test_fixture(const std::string& preload_test_fixture); + void set_preload_test_name(const std::string& preload_test_name); + // Set up & tear down console error catching. virtual void SetUpOnMainThread() OVERRIDE; virtual void CleanUpOnMainThread() OVERRIDE; @@ -140,7 +141,7 @@ class WebUIBrowserTest static GURL WebUITestDataPathToURL(const FilePath::StringType& path); private: - // TestNavigationObserver::JsInjectionReadyObserver implementation. + // JsInjectionReadyObserver implementation. virtual void OnJsInjectionReady(RenderViewHost* render_view_host) OVERRIDE; // Builds a string containing all added javascript libraries. diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index b5caf61..174b03a 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -201,6 +201,7 @@ 'test/base/chrome_test_suite.h', 'test/base/in_process_browser_test.cc', 'test/base/in_process_browser_test.h', + 'test/base/js_injection_ready_observer.h', 'test/base/model_test_utils.cc', 'test/base/model_test_utils.h', 'test/base/profile_mock.cc', @@ -213,6 +214,8 @@ 'test/base/test_launcher_utils.h', 'test/base/test_location_bar.cc', 'test/base/test_location_bar.h', + 'test/base/test_navigation_observer.cc', + 'test/base/test_navigation_observer.h', 'test/base/test_switches.cc', 'test/base/test_switches.h', 'test/base/test_tab_strip_model_observer.cc', @@ -238,8 +241,6 @@ 'test/base/ui_test_utils_win.cc', 'test/base/values_test_util.cc', 'test/base/values_test_util.h', - 'test/test_navigation_observer.cc', - 'test/test_navigation_observer.h', # TODO: these should live here but are currently used by # production code code in libbrowser (in chrome.gyp). #'../content/browser/net/url_request_mock_http_job.cc', @@ -2710,7 +2711,8 @@ 'test/base/chrome_render_view_test.h', 'test/base/chrome_test_launcher.cc', 'test/data/webui/assertions.js', - 'test/data/webui/async_gen-inl.h', + 'test/data/webui/async_gen.cc', + 'test/data/webui/async_gen.h', 'test/data/webui/async_gen.js', 'test/data/webui/certificate_viewer_dialog_test.js', 'test/data/webui/certificate_viewer_ui_test-inl.h', @@ -2721,6 +2723,8 @@ 'test/data/webui/hung_renderer_dialog_ui_test-inl.h', 'test/data/webui/mock4js_browsertest.js', 'test/data/webui/ntp4.js', + 'test/data/webui/print_preview.h', + 'test/data/webui/print_preview.cc', 'test/data/webui/print_preview.js', 'test/gpu/gpu_feature_browsertest.cc', # TODO(craig): Rename this and run from base_unittests when the test diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h index 5e96ad8..e411445 100644 --- a/chrome/common/chrome_notification_types.h +++ b/chrome/common/chrome_notification_types.h @@ -71,7 +71,9 @@ enum NotificationType { // traversal. The source is the browser, there are no details. NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, - // Sent after an HtmlDialog dialog has been shown. The source is the dialog. + // Sent after an HtmlDialog dialog has been shown. The source is the + // dialog. The details is a Details<RenderViewHost> with a pointer to the RVH + // for the shown dialog. NOTIFICATION_HTML_DIALOG_SHOWN, // Application-modal dialogs ----------------------------------------------- diff --git a/chrome/test/base/js2gtest.js b/chrome/test/base/js2gtest.js index bfabc07..70a31c4 100644 --- a/chrome/test/base/js2gtest.js +++ b/chrome/test/base/js2gtest.js @@ -66,6 +66,14 @@ var typedeffedCppFixtures = {}; */ var genIncludes = []; +/** + * When true, add calls to set_preload_test_(fixture|name). This is needed when + * |testType| === 'browser' to send an injection message before the page loads, + * but is not required or supported for |testType| === 'unit'. + * @type {boolean} + */ +var addSetPreloadInfo; + // Generate the file to stdout. print('// GENERATED FILE'); print('// ' + arguments.join(' ')); @@ -81,10 +89,12 @@ if (testType === 'unit') { print('#include "chrome/test/base/v8_unit_test.h"'); testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; testF = 'TEST_F'; + addSetPreloadInfo = false; } else { print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; testF = 'IN_PROC_BROWSER_TEST_F'; + addSetPreloadInfo = true; } print('#include "googleurl/src/gurl.h"'); print('#include "testing/gtest/include/gtest/gtest.h"'); @@ -156,22 +166,23 @@ function TEST_F(testFixture, testFunction, testBody) { } print(testF + '(' + testFixture + ', ' + testFunction + ') {'); - if (testGenPreamble) - testGenPreamble(testFixture, testFunction); for (var i = 0; i < extraLibraries.length; i++) { print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + extraLibraries[i].replace(/\\/g, '/') + '")));'); } print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + jsFileBase.replace(/\\/g, '/') + '")));'); - if (browsePreload) { - print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + - '", "' + testFunction + '");'); - } + if (addSetPreloadInfo) { + print(' set_preload_test_fixture("' + testFixture + '");'); + print(' set_preload_test_name("' + testFunction + '");'); + } + if (testGenPreamble) + testGenPreamble(testFixture, testFunction); + if (browsePreload) + print(' BrowsePreload(GURL("' + browsePreload + '"));'); if (browsePrintPreload) { print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + - ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + - ' "' + testFixture + '", "' + testFunction + '");'); + ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))));'); } print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + '"' + testFixture + '", ' + diff --git a/chrome/test/base/js_injection_ready_observer.h b/chrome/test/base/js_injection_ready_observer.h new file mode 100644 index 0000000..9c3029c --- /dev/null +++ b/chrome/test/base/js_injection_ready_observer.h @@ -0,0 +1,23 @@ +// 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. + +#ifndef CHROME_TEST_BASE_JS_INJECTION_READY_OBSERVER_H_ +#define CHROME_TEST_BASE_JS_INJECTION_READY_OBSERVER_H_ +#pragma once + +class RenderViewHost; + +// Interface to notify when JavaScript injection is possible. +class JsInjectionReadyObserver { + public: + // Called to indicate page entry committed and ready for JavaScript + // injection. |render_view_host| may be used to route injection messages to + // the appropriate RenderView. + virtual void OnJsInjectionReady(RenderViewHost* render_view_host) = 0; + + protected: + virtual ~JsInjectionReadyObserver() {} +}; + +#endif // CHROME_TEST_BASE_JS_INJECTION_READY_OBSERVER_H_ diff --git a/chrome/test/base/test_html_dialog_observer.cc b/chrome/test/base/test_html_dialog_observer.cc index 6f51eb7..e6d14cb 100644 --- a/chrome/test/base/test_html_dialog_observer.cc +++ b/chrome/test/base/test_html_dialog_observer.cc @@ -5,6 +5,8 @@ #include "chrome/test/base/test_html_dialog_observer.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/test/base/js_injection_ready_observer.h" +#include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/tab_contents.h" @@ -12,10 +14,11 @@ #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" -#include "chrome/test/base/ui_test_utils.h" -TestHtmlDialogObserver::TestHtmlDialogObserver() - : web_ui_(NULL), done_(false), running_(false) { +TestHtmlDialogObserver::TestHtmlDialogObserver( + JsInjectionReadyObserver* js_injection_ready_observer) + : js_injection_ready_observer_(js_injection_ready_observer), + web_ui_(NULL), done_(false), running_(false) { registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, content::NotificationService::AllSources()); } @@ -29,6 +32,10 @@ void TestHtmlDialogObserver::Observe( const content::NotificationDetails& details) { switch (type) { case chrome::NOTIFICATION_HTML_DIALOG_SHOWN: + if (js_injection_ready_observer_) { + js_injection_ready_observer_->OnJsInjectionReady( + content::Details<RenderViewHost>(details).ptr()); + } web_ui_ = content::Source<WebUI>(source).ptr(); registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, content::NotificationService::AllSources()); diff --git a/chrome/test/base/test_html_dialog_observer.h b/chrome/test/base/test_html_dialog_observer.h index 7959234..a5897ad 100644 --- a/chrome/test/base/test_html_dialog_observer.h +++ b/chrome/test/base/test_html_dialog_observer.h @@ -10,6 +10,7 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +class JsInjectionReadyObserver; class WebUI; // For browser_tests, which run on the UI thread, run a second message @@ -17,8 +18,11 @@ class WebUI; // WebUI instance is captured and ready. class TestHtmlDialogObserver : public content::NotificationObserver { public: - // Create and register a new TestHtmlDialogObserver. - TestHtmlDialogObserver(); + // Create and register a new TestHtmlDialogObserver. If + // |js_injection_ready_observer| is non-NULL, notify it as soon as the RVH is + // available. + explicit TestHtmlDialogObserver( + JsInjectionReadyObserver* js_injection_ready_observer); virtual ~TestHtmlDialogObserver(); // Waits for an HtmlDialog to be created. The WebUI instance is captured @@ -32,6 +36,9 @@ class TestHtmlDialogObserver : public content::NotificationObserver { content::NotificationRegistrar registrar_; + // Observer to take some action when the dialog is ready for JavaScript + // injection. + JsInjectionReadyObserver* js_injection_ready_observer_; WebUI* web_ui_; bool done_; bool running_; diff --git a/chrome/test/test_navigation_observer.cc b/chrome/test/base/test_navigation_observer.cc index 0e9f6bb..2a57df7 100644 --- a/chrome/test/test_navigation_observer.cc +++ b/chrome/test/base/test_navigation_observer.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/test_navigation_observer.h" +#include "chrome/test/base/test_navigation_observer.h" +#include "chrome/test/base/js_injection_ready_observer.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" @@ -34,16 +35,9 @@ class TestNavigationObserver::RVHOSendJS DISALLOW_COPY_AND_ASSIGN(RVHOSendJS); }; -TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() { -} - -TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() { -} - TestNavigationObserver::TestNavigationObserver( const content::NotificationSource& source, - TestNavigationObserver::JsInjectionReadyObserver* - js_injection_ready_observer, + JsInjectionReadyObserver* js_injection_ready_observer, int number_of_navigations) : navigation_started_(false), navigations_completed_(0), @@ -71,7 +65,7 @@ void TestNavigationObserver::WaitForObservation() { } TestNavigationObserver::TestNavigationObserver( - TestNavigationObserver::JsInjectionReadyObserver* + JsInjectionReadyObserver* js_injection_ready_observer, int number_of_navigations) : navigation_started_(false), diff --git a/chrome/test/test_navigation_observer.h b/chrome/test/base/test_navigation_observer.h index 401b4c0..510e56f 100644 --- a/chrome/test/test_navigation_observer.h +++ b/chrome/test/base/test_navigation_observer.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 CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ -#define CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ +#ifndef CHROME_TEST_BASE_TEST_NAVIGATION_OBSERVER_H_ +#define CHROME_TEST_BASE_TEST_NAVIGATION_OBSERVER_H_ #pragma once #include "base/compiler_specific.h" @@ -11,6 +11,7 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +class JsInjectionReadyObserver; class NavigationController; class RenderViewHost; @@ -23,17 +24,6 @@ class TestNavigationObserver : public content::NotificationObserver { public: class RVHOSendJS; - // Interface to notify when JavaScript injection is possible. - class JsInjectionReadyObserver { - public: - JsInjectionReadyObserver(); - virtual ~JsInjectionReadyObserver(); - - // Called to indicate page entry committed and ready for JavaScript - // injection. - virtual void OnJsInjectionReady(RenderViewHost* render_view_host) = 0; - }; - // Create and register a new TestNavigationObserver against the // |controller|. When |js_injection_ready_observer| is non-null, notify with // OnEntryCommitted() after |number_of_navigations| navigations. @@ -92,4 +82,4 @@ class TestNavigationObserver : public content::NotificationObserver { DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); }; -#endif // CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_ +#endif // CHROME_TEST_BASE_TEST_NAVIGATION_OBSERVER_H_ diff --git a/chrome/test/base/test_tab_strip_model_observer.cc b/chrome/test/base/test_tab_strip_model_observer.cc index c2307b7..0716a78 100644 --- a/chrome/test/base/test_tab_strip_model_observer.cc +++ b/chrome/test/base/test_tab_strip_model_observer.cc @@ -12,8 +12,7 @@ TestTabStripModelObserver::TestTabStripModelObserver( TabStripModel* tab_strip_model, - TestTabStripModelObserver::JsInjectionReadyObserver* - js_injection_ready_observer) + JsInjectionReadyObserver* js_injection_ready_observer) : TestNavigationObserver(js_injection_ready_observer, 1), tab_strip_model_(tab_strip_model) { tab_strip_model_->AddObserver(this); diff --git a/chrome/test/base/test_tab_strip_model_observer.h b/chrome/test/base/test_tab_strip_model_observer.h index 37cb147..473d1b7 100644 --- a/chrome/test/base/test_tab_strip_model_observer.h +++ b/chrome/test/base/test_tab_strip_model_observer.h @@ -8,7 +8,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/tabs/tab_strip_model_observer.h" -#include "chrome/test/test_navigation_observer.h" +#include "chrome/test/base/test_navigation_observer.h" class TabStripModel; diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index 0261133..75531f2 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -43,7 +43,7 @@ #include "chrome/common/extensions/extension_action.h" #include "chrome/test/automation/javascript_execution_controller.h" #include "chrome/test/base/bookmark_load_observer.h" -#include "chrome/test/test_navigation_observer.h" +#include "chrome/test/base/test_navigation_observer.h" #include "content/browser/download/download_item.h" #include "content/browser/download/download_manager.h" #include "content/browser/renderer_host/render_view_host.h" diff --git a/chrome/test/data/webui/async_gen.cc b/chrome/test/data/webui/async_gen.cc new file mode 100644 index 0000000..1291bbd --- /dev/null +++ b/chrome/test/data/webui/async_gen.cc @@ -0,0 +1,35 @@ +// 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. + +#include "chrome/test/data/webui/async_gen.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/values.h" + +WebUIBrowserAsyncGenTest::WebUIBrowserAsyncGenTest() {} + +WebUIBrowserAsyncGenTest::~WebUIBrowserAsyncGenTest() {} + +WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler:: + AsyncWebUIMessageHandler() {} + +WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler:: + ~AsyncWebUIMessageHandler() {} + +void WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::HandleCallJS( + const base::ListValue* list_value) { + std::string call_js; + ASSERT_TRUE(list_value->GetString(0, &call_js)); + web_ui_->CallJavascriptFunction(call_js); +} + +void WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::RegisterMessages() { + web_ui_->RegisterMessageCallback( + "callJS", base::Bind(&AsyncWebUIMessageHandler::HandleCallJS, + base::Unretained(this))); + web_ui_->RegisterMessageCallback( + "tearDown", base::Bind(&AsyncWebUIMessageHandler::HandleTearDown, + base::Unretained(this))); +} diff --git a/chrome/test/data/webui/async_gen-inl.h b/chrome/test/data/webui/async_gen.h index fae1af4..4bc70df 100644 --- a/chrome/test/data/webui/async_gen-inl.h +++ b/chrome/test/data/webui/async_gen.h @@ -1,13 +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. +#ifndef CHROME_TEST_DATA_WEBUI_ASYNC_GEN_H_ +#define CHROME_TEST_DATA_WEBUI_ASYNC_GEN_H_ +#pragma once -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/values.h" #include "chrome/browser/ui/webui/web_ui_browsertest.h" #include "testing/gmock/include/gmock/gmock.h" +namespace base { +class ListValue; +} // namespace base + // C++ support class for javascript-generated asynchronous tests. class WebUIBrowserAsyncGenTest : public WebUIBrowserTest { public: @@ -20,23 +24,13 @@ class WebUIBrowserAsyncGenTest : public WebUIBrowserTest { AsyncWebUIMessageHandler(); ~AsyncWebUIMessageHandler(); - MOCK_METHOD1(HandleTornDown, void(const base::ListValue*)); + MOCK_METHOD1(HandleTearDown, void(const base::ListValue*)); private: - void HandleCallJS(const base::ListValue* list_value) { - std::string call_js; - ASSERT_TRUE(list_value->GetString(0, &call_js)); - web_ui_->CallJavascriptFunction(call_js); - } - - virtual void RegisterMessages() OVERRIDE { - web_ui_->RegisterMessageCallback( - "callJS", base::Bind(&AsyncWebUIMessageHandler::HandleCallJS, - base::Unretained(this))); - web_ui_->RegisterMessageCallback( - "tornDown", base::Bind(&AsyncWebUIMessageHandler::HandleTornDown, - base::Unretained(this))); - } + void HandleCallJS(const base::ListValue* list_value); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; }; // Handler for this test fixture. @@ -50,8 +44,10 @@ class WebUIBrowserAsyncGenTest : public WebUIBrowserTest { virtual void SetUpOnMainThread() OVERRIDE { WebUIBrowserTest::SetUpOnMainThread(); - EXPECT_CALL(message_handler_, HandleTornDown(::testing::_)); + EXPECT_CALL(message_handler_, HandleTearDown(::testing::_)); } DISALLOW_COPY_AND_ASSIGN(WebUIBrowserAsyncGenTest); }; + +#endif // CHROME_TEST_DATA_WEBUI_ASYNC_GEN_H_ diff --git a/chrome/test/data/webui/async_gen.js b/chrome/test/data/webui/async_gen.js index 13929b8..8b8078f 100644 --- a/chrome/test/data/webui/async_gen.js +++ b/chrome/test/data/webui/async_gen.js @@ -23,7 +23,7 @@ WebUIBrowserAsyncGenTest.prototype = { expectFalse(this.tornDown); expectFalse(this.running); this.tornDown = true; - chrome.send('tornDown'); + chrome.send('tearDown'); testing.Test.prototype.tearDown.call(this); }, @@ -46,18 +46,8 @@ WebUIBrowserAsyncGenTest.prototype = { running: false, }; -// Include the bulk of c++ code. -GEN('#include "chrome/test/data/webui/async_gen-inl.h"'); -GEN(''); - -// Constructors and destructors must be provided in .cc to prevent clang errors. -GEN('WebUIBrowserAsyncGenTest::WebUIBrowserAsyncGenTest() {}'); -GEN('WebUIBrowserAsyncGenTest::~WebUIBrowserAsyncGenTest() {}'); -GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); -GEN(' AsyncWebUIMessageHandler() {}'); -GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); -GEN(' ~AsyncWebUIMessageHandler() {}'); -GEN(''); +// Include the c++ test fixture. +GEN('#include "chrome/test/data/webui/async_gen.h"'); /** * Will be set to continuation test #1. diff --git a/chrome/test/data/webui/certificate_viewer_dialog_test.js b/chrome/test/data/webui/certificate_viewer_dialog_test.js index 13cac46..fc22d6d 100644 --- a/chrome/test/data/webui/certificate_viewer_dialog_test.js +++ b/chrome/test/data/webui/certificate_viewer_dialog_test.js @@ -17,6 +17,14 @@ CertificateViewerUITest.prototype = { * @override */ typedefCppFixture: 'CertificateViewerUITest', + + /** + * Show the certificate viewer dialog. + */ + testGenPreamble: function() { + GEN('ShowCertificateViewer();'); + }, + }; /** 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 0e5ef75..8ec38cc 100644 --- a/chrome/test/data/webui/certificate_viewer_ui_test-inl.h +++ b/chrome/test/data/webui/certificate_viewer_ui_test-inl.h @@ -22,11 +22,11 @@ class CertificateViewerUITest : public WebUIBrowserTest { CertificateViewerUITest(); virtual ~CertificateViewerUITest(); - private: - virtual void SetUpOnMainThread() OVERRIDE; + protected: + void ShowCertificateViewer(); }; -void CertificateViewerUITest::SetUpOnMainThread() { +void CertificateViewerUITest::ShowCertificateViewer() { // Enable more WebUI to use WebUI certificate viewer. ChromeWebUI::OverrideMoreWebUI(true); @@ -37,8 +37,8 @@ void CertificateViewerUITest::SetUpOnMainThread() { ASSERT_TRUE(browser()); ASSERT_TRUE(browser()->window()); - TestHtmlDialogObserver dialog_observer; - ShowCertificateViewer(browser()->window()->GetNativeHandle(), google_cert); + TestHtmlDialogObserver dialog_observer(this); + ::ShowCertificateViewer(browser()->window()->GetNativeHandle(), google_cert); WebUI* webui = dialog_observer.GetWebUI(); webui->tab_contents()->render_view_host()->SetWebUIProperty( "expectedUrl", chrome::kChromeUICertificateViewerURL); diff --git a/chrome/test/data/webui/hung_renderer_dialog_test.js b/chrome/test/data/webui/hung_renderer_dialog_test.js index 6fdb211..5e75ee3 100644 --- a/chrome/test/data/webui/hung_renderer_dialog_test.js +++ b/chrome/test/data/webui/hung_renderer_dialog_test.js @@ -17,6 +17,13 @@ HungRendererDialogUITest.prototype = { * @override */ typedefCppFixture: 'HungRendererDialogUITest', + + /** + * Show the hung renderer dialog. + */ + testGenPreamble: function() { + GEN('ShowHungRendererDialogInternal();'); + }, }; // Include the bulk of c++ code. diff --git a/chrome/test/data/webui/hung_renderer_dialog_ui_test-inl.h b/chrome/test/data/webui/hung_renderer_dialog_ui_test-inl.h index 6811805..d78ac873 100644 --- a/chrome/test/data/webui/hung_renderer_dialog_ui_test-inl.h +++ b/chrome/test/data/webui/hung_renderer_dialog_ui_test-inl.h @@ -18,21 +18,21 @@ class HungRendererDialogUITest : public WebUIBrowserTest { HungRendererDialogUITest(); virtual ~HungRendererDialogUITest(); - private: - virtual void SetUpOnMainThread() OVERRIDE; + protected: + void ShowHungRendererDialogInternal(); }; -void HungRendererDialogUITest::SetUpOnMainThread() { +void HungRendererDialogUITest::ShowHungRendererDialogInternal() { // Force the flag so that we will use the WebUI version of the Dialog. ChromeWebUI::OverrideMoreWebUI(true); // Choose which tab contents to report as hung. In this case, the default // tab contents will be about:blank. - ASSERT_TRUE(browser() != NULL); + ASSERT_TRUE(browser()); TabContents* tab_contents = browser()->GetSelectedTabContents(); // The TestHtmlDialogObserver will catch our dialog when it gets created. - TestHtmlDialogObserver dialog_observer; + TestHtmlDialogObserver dialog_observer(this); // Show a disabled Hung Renderer Dialog that won't kill processes or restart // hang timers. @@ -49,5 +49,4 @@ void HungRendererDialogUITest::SetUpOnMainThread() { // Tell the test which WebUI instance we are dealing with and complete // initialization of this test. SetWebUIInstance(webui); - WebUIBrowserTest::SetUpOnMainThread(); } diff --git a/chrome/test/data/webui/print_preview.cc b/chrome/test/data/webui/print_preview.cc new file mode 100644 index 0000000..becc763 --- /dev/null +++ b/chrome/test/data/webui/print_preview.cc @@ -0,0 +1,15 @@ +// 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. + +#include "chrome/test/data/webui/print_preview.h" + +PrintPreviewWebUITest::PrintPreviewWebUITest() {} + +PrintPreviewWebUITest::~PrintPreviewWebUITest() {} + +// Always print preview for testing. +void PrintPreviewWebUITest::SetUpCommandLine(CommandLine* command_line) { + WebUIBrowserTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kEnablePrintPreview); +} diff --git a/chrome/test/data/webui/print_preview.h b/chrome/test/data/webui/print_preview.h new file mode 100644 index 0000000..2bc4600 --- /dev/null +++ b/chrome/test/data/webui/print_preview.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef CHROME_TEST_DATA_WEBUI_PRINT_PREVIEW_H_ +#define CHROME_TEST_DATA_WEBUI_PRINT_PREVIEW_H_ +#pragma once + +#include "base/command_line.h" +#include "chrome/browser/ui/webui/web_ui_browsertest.h" +#include "chrome/common/chrome_switches.h" + +class PrintPreviewWebUITest : public WebUIBrowserTest { + public: + PrintPreviewWebUITest(); + virtual ~PrintPreviewWebUITest(); + + private: + // WebUIBrowserTest implementation. + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebUITest); +}; + +#endif // CHROME_TEST_DATA_WEBUI_PRINT_PREVIEW_H_ diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js index 530211e..690dfc1 100644 --- a/chrome/test/data/webui/print_preview.js +++ b/chrome/test/data/webui/print_preview.js @@ -163,21 +163,7 @@ PrintPreviewWebUITest.prototype = { }, }; -GEN('#include "base/command_line.h"'); -GEN('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); -GEN('#include "chrome/common/chrome_switches.h"'); -GEN(''); -GEN('class PrintPreviewWebUITest'); -GEN(' : public WebUIBrowserTest {'); -GEN(' protected:'); -GEN(' // WebUIBrowserTest override.'); -GEN(' virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {'); -GEN(' WebUIBrowserTest::SetUpCommandLine(command_line);'); -GEN(' command_line->AppendSwitch(switches::kEnablePrintPreview);'); -GEN(' }'); -GEN(''); -GEN('};'); -GEN(''); +GEN('#include "chrome/test/data/webui/print_preview.h"'); /** * The expected length of the |printer-list| element. diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js index f5dbee4..8717ebe 100644 --- a/chrome/test/data/webui/test_api.js +++ b/chrome/test/data/webui/test_api.js @@ -69,7 +69,8 @@ var testing = {}; /** * When set to a function, will be called in the context of the test - * generation inside the function, and before any generated C++. + * generation inside the function, after AddLibrary calls and before + * generated C++. * @type {function(string,string)} */ testGenPreamble: null, |