diff options
author | glotov@google.com <glotov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 14:41:33 +0000 |
---|---|---|
committer | glotov@google.com <glotov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 14:41:33 +0000 |
commit | 70cb3412e93862ca0ed1a980a8e4ba9004e9f264 (patch) | |
tree | 55c290e2bf065a03cf829ef051595b903b5de7ba /chrome | |
parent | 3838ca1b5303b0228514d61990d1ae3dab96704a (diff) | |
download | chromium_src-70cb3412e93862ca0ed1a980a8e4ba9004e9f264.zip chromium_src-70cb3412e93862ca0ed1a980a8e4ba9004e9f264.tar.gz chromium_src-70cb3412e93862ca0ed1a980a8e4ba9004e9f264.tar.bz2 |
Revert 108276 - Revert 108206 - Share TabFirstRenderWatcher with HtmlDialogView.
- Move TabFirstRenderWatcher out of chromeos and combine the logic with HTMLDialgoView.
- Update HtmlDialogBrowserTest.TestStateTransition and move state transition test into TabFirstRenderWatcherTest.TestStateTransition;
- HtmlDialogBrowserTest.TestStateTransition -> WebContentRendered as it only tests OnTabMainFrameFirstRender is callled now;
- Conslidate two TestHtmlDialogUIDelegate into one;
Will share it with the auro app list window to avoid initial jankiness.
BUG=98308,86059
TEST=Hold until all app list changes are in.
Review URL: http://codereview.chromium.org/8417005
TBR=xiyuan@chromium.org
Review URL: http://codereview.chromium.org/8351070
TBR=glotov@google.com
Review URL: http://codereview.chromium.org/8437052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/login/webui_login_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_first_render_watcher.cc (renamed from chrome/browser/chromeos/tab_first_render_watcher.cc) | 6 | ||||
-rw-r--r-- | chrome/browser/tab_first_render_watcher.h (renamed from chrome/browser/chromeos/tab_first_render_watcher.h) | 11 | ||||
-rw-r--r-- | chrome/browser/tab_first_render_watcher_browsertest.cc | 88 | ||||
-rw-r--r-- | chrome/browser/ui/views/html_dialog_view.cc | 60 | ||||
-rw-r--r-- | chrome/browser/ui/views/html_dialog_view.h | 41 | ||||
-rw-r--r-- | chrome/browser/ui/views/html_dialog_view_browsertest.cc | 80 | ||||
-rw-r--r-- | chrome/browser/ui/webui/constrained_html_ui_browsertest.cc | 41 | ||||
-rw-r--r-- | chrome/browser/ui/webui/test_html_dialog_ui_delegate.cc | 56 | ||||
-rw-r--r-- | chrome/browser/ui/webui/test_html_dialog_ui_delegate.h | 48 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 4 |
12 files changed, 281 insertions, 161 deletions
diff --git a/chrome/browser/chromeos/login/webui_login_view.h b/chrome/browser/chromeos/login/webui_login_view.h index 3dd3fa1..d822f0b 100644 --- a/chrome/browser/chromeos/login/webui_login_view.h +++ b/chrome/browser/chromeos/login/webui_login_view.h @@ -8,7 +8,7 @@ #include "chrome/browser/chromeos/login/login_html_dialog.h" #include "chrome/browser/chromeos/status/status_area_host.h" -#include "chrome/browser/chromeos/tab_first_render_watcher.h" +#include "chrome/browser/tab_first_render_watcher.h" #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" #include "content/browser/tab_contents/tab_contents_delegate.h" #include "views/widget/widget_delegate.h" @@ -26,7 +26,6 @@ class Widget; namespace chromeos { class StatusAreaView; -class TabFirstRenderWatcher; // View used to render a WebUI supporting Widget. This widget is used for the // WebUI based start up and lock screens. It contains a StatusAreaView and diff --git a/chrome/browser/chromeos/tab_first_render_watcher.cc b/chrome/browser/tab_first_render_watcher.cc index 66344a4..3d0d53d 100644 --- a/chrome/browser/chromeos/tab_first_render_watcher.cc +++ b/chrome/browser/tab_first_render_watcher.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/tab_first_render_watcher.h" +#include "chrome/browser/tab_first_render_watcher.h" #include "content/browser/renderer_host/render_widget_host.h" #include "content/browser/renderer_host/render_view_host.h" @@ -10,8 +10,6 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" -namespace chromeos { - TabFirstRenderWatcher::TabFirstRenderWatcher(TabContents* tab, Delegate* delegate) : state_(NONE), @@ -54,5 +52,3 @@ void TabFirstRenderWatcher::Observe(int type, NOTREACHED() << "unknown type" << type; } } - -} // namespace chromeos diff --git a/chrome/browser/chromeos/tab_first_render_watcher.h b/chrome/browser/tab_first_render_watcher.h index 22218c2..d09f3b8 100644 --- a/chrome/browser/chromeos/tab_first_render_watcher.h +++ b/chrome/browser/tab_first_render_watcher.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_BROWSER_CHROMEOS_TAB_FIRST_RENDER_WATCHER_H_ -#define CHROME_BROWSER_CHROMEOS_TAB_FIRST_RENDER_WATCHER_H_ +#ifndef CHROME_BROWSER_TAB_FIRST_RENDER_WATCHER_H_ +#define CHROME_BROWSER_TAB_FIRST_RENDER_WATCHER_H_ #pragma once #include "base/compiler_specific.h" @@ -13,10 +13,7 @@ class RenderViewHost; class TabContents; -namespace chromeos { - // This class watches given TabContent's loading and rendering state change. -// TODO(xiyuan): Move this to a proper place and share with HTMLDialogView. class TabFirstRenderWatcher : public content::NotificationObserver { public: class Delegate { @@ -52,6 +49,4 @@ class TabFirstRenderWatcher : public content::NotificationObserver { DISALLOW_COPY_AND_ASSIGN(TabFirstRenderWatcher); }; -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_TAB_FIRST_RENDER_WATCHER_H_ +#endif // CHROME_BROWSER_TAB_FIRST_RENDER_WATCHER_H_ diff --git a/chrome/browser/tab_first_render_watcher_browsertest.cc b/chrome/browser/tab_first_render_watcher_browsertest.cc new file mode 100644 index 0000000..a5c94af --- /dev/null +++ b/chrome/browser/tab_first_render_watcher_browsertest.cc @@ -0,0 +1,88 @@ +// 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 "base/message_loop.h" +#include "chrome/browser/tab_first_render_watcher.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/views/dom_view.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "views/widget/widget.h" + +namespace { + +views::Widget* CreateWindowForContents(views::View* contents) { + views::Widget::InitParams widget_params( + views::Widget::InitParams::TYPE_WINDOW); + + views::Widget* widget = new views::Widget; + widget->Init(widget_params); + widget->SetContentsView(contents); + + return widget; +} + +} // namespace + +class TabFirstRenderWatcherTest : public InProcessBrowserTest, + public TabFirstRenderWatcher::Delegate { + public: + TabFirstRenderWatcherTest() + : host_created_(false), + main_frame_loaded_(false), + main_frame_rendered_(false) { + } + + // TabFirstRenderWatcher::Delegate implementation. + virtual void OnRenderHostCreated(RenderViewHost* host) OVERRIDE { + host_created_ = true; + } + + virtual void OnTabMainFrameLoaded() OVERRIDE { + main_frame_loaded_ = true; + MessageLoop::current()->Quit(); + } + + virtual void OnTabMainFrameFirstRender() OVERRIDE { + main_frame_rendered_ = true; + MessageLoop::current()->Quit(); + } + + protected: + bool host_created_; + bool main_frame_loaded_; + bool main_frame_rendered_; +}; + +// Migrated from HtmlDialogBrowserTest.TestStateTransition, which times out +// about 5~10% of runs. See crbug.com/86059. +IN_PROC_BROWSER_TEST_F(TabFirstRenderWatcherTest, + DISABLED_TestStateTransition) { + DOMView* dom_view = new DOMView; + dom_view->Init(browser()->profile(), NULL); + CreateWindowForContents(dom_view); + dom_view->GetWidget()->Show(); + + scoped_ptr<TabFirstRenderWatcher> watcher( + new TabFirstRenderWatcher(dom_view->dom_contents()->tab_contents(), + this)); + + EXPECT_FALSE(host_created_); + EXPECT_FALSE(main_frame_loaded_); + EXPECT_FALSE(main_frame_rendered_); + + dom_view->LoadURL(GURL(chrome::kChromeUIChromeURLsURL)); + EXPECT_TRUE(host_created_); + + // OnTabMainFrameLoaded() will Quit(). + MessageLoopForUI::current()->Run(); + EXPECT_TRUE(main_frame_loaded_); + + // OnTabMainFrameFirstRender() will Quit(). + MessageLoopForUI::current()->Run(); + EXPECT_TRUE(main_frame_rendered_); + + dom_view->GetWidget()->Close(); +} diff --git a/chrome/browser/ui/views/html_dialog_view.cc b/chrome/browser/ui/views/html_dialog_view.cc index 5c21639..a9ce20f 100644 --- a/chrome/browser/ui/views/html_dialog_view.cc +++ b/chrome/browser/ui/views/html_dialog_view.cc @@ -52,7 +52,7 @@ HtmlDialogView::HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate) : DOMView(), HtmlDialogTabContentsDelegate(profile), - state_(NONE), + initialized_(false), delegate_(delegate) { } @@ -79,8 +79,8 @@ bool HtmlDialogView::AcceleratorPressed(const views::Accelerator& accelerator) { void HtmlDialogView::ViewHierarchyChanged( bool is_add, View* parent, View* child) { DOMView::ViewHierarchyChanged(is_add, parent, child); - if (is_add && GetWidget() && state_ == NONE) { - state_ = INITIALIZED; + if (is_add && GetWidget() && !initialized_) { + initialized_ = true; #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) CHECK( static_cast<views::NativeWidgetGtk*>( @@ -250,49 +250,27 @@ void HtmlDialogView::InitDialog() { // the comment above HtmlDialogUI in its header file for why. HtmlDialogUI::GetPropertyAccessor().SetProperty( tab_contents->property_bag(), this); - notification_registrar_.Add( - this, - content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, - content::Source<TabContents>(tab_contents)); - notification_registrar_.Add( - this, - content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, - content::Source<TabContents>(tab_contents)); + tab_watcher_.reset(new TabFirstRenderWatcher(tab_contents, this)); DOMView::LoadURL(GetDialogContentURL()); } -void HtmlDialogView::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { - RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr(); - notification_registrar_.Add( - this, - content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, - content::Source<RenderWidgetHost>(rwh)); - break; - } - case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: - if (state_ == INITIALIZED) - state_ = LOADED; - break; - case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: - if (state_ == LOADED) { - state_ = PAINTED; -#if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) - views::NativeWidgetGtk::UpdateFreezeUpdatesProperty( - GTK_WINDOW(GetWidget()->GetNativeView()), false); -#endif - } - break; - default: - NOTREACHED() << "unknown type" << type; - } -} - void HtmlDialogView::RegisterDialogAccelerators() { // Pressing the ESC key will close the dialog. AddAccelerator(views::Accelerator(ui::VKEY_ESCAPE, false, false, false)); } + +void HtmlDialogView::OnRenderHostCreated(RenderViewHost* host) { +} + +void HtmlDialogView::OnTabMainFrameLoaded() { +} + +void HtmlDialogView::OnTabMainFrameFirstRender() { +#if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) + if (initialized_) { + views::NativeWidgetGtk::UpdateFreezeUpdatesProperty( + GTK_WINDOW(GetWidget()->GetNativeView()), false); + } +#endif +} diff --git a/chrome/browser/ui/views/html_dialog_view.h b/chrome/browser/ui/views/html_dialog_view.h index da8c3ad..5877c72 100644 --- a/chrome/browser/ui/views/html_dialog_view.h +++ b/chrome/browser/ui/views/html_dialog_view.h @@ -10,11 +10,11 @@ #include <vector> #include "base/gtest_prod_util.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/tab_first_render_watcher.h" #include "chrome/browser/ui/views/dom_view.h" #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/gfx/size.h" #include "views/widget/widget_delegate.h" @@ -38,7 +38,7 @@ class HtmlDialogView public HtmlDialogTabContentsDelegate, public HtmlDialogUIDelegate, public views::WidgetDelegate, - public content::NotificationObserver { + public TabFirstRenderWatcher::Delegate { public: HtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate); virtual ~HtmlDialogView(); @@ -84,30 +84,25 @@ class HtmlDialogView OVERRIDE; virtual void CloseContents(TabContents* source) OVERRIDE; - // Overridden from content::NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - protected: // Register accelerators for this dialog. virtual void RegisterDialogAccelerators(); + // TabFirstRenderWatcher::Delegate implementation. + virtual void OnRenderHostCreated(RenderViewHost* host) OVERRIDE; + virtual void OnTabMainFrameLoaded() OVERRIDE; + virtual void OnTabMainFrameFirstRender() OVERRIDE; + private: - FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, TestStateTransition); - - // A state used to ensure that we show the window only after the - // renderer painted the full page. - enum DialogState { - NONE, - INITIALIZED, // FreezeUpdates property is set to prevent WM from showing - // the window until the property is remoevd. - LOADED, // Renderer loaded the page. - PAINTED, // 1st paint event after the page is loaded. - // FreezeUpdates property is removed to tell WM to shows - // the window. - }; - DialogState state_; + FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); + + // Whether the view is initialized. That is, dialog acceleartors is registered + // and FreezeUpdates property is set to prevent WM from showing the window + // until the property is removed. + bool initialized_; + + // Watches for TabContents rendering. + scoped_ptr<TabFirstRenderWatcher> tab_watcher_; // This view is a delegate to the HTML content since it needs to get notified // about when the dialog is closing. For all other actions (besides dialog @@ -115,8 +110,6 @@ class HtmlDialogView // using this variable. HtmlDialogUIDelegate* delegate_; - content::NotificationRegistrar notification_registrar_; - DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); }; diff --git a/chrome/browser/ui/views/html_dialog_view_browsertest.cc b/chrome/browser/ui/views/html_dialog_view_browsertest.cc index ab27321..7fc77bd 100644 --- a/chrome/browser/ui/views/html_dialog_view_browsertest.cc +++ b/chrome/browser/ui/views/html_dialog_view_browsertest.cc @@ -8,7 +8,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/views/html_dialog_view.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" +#include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" @@ -28,37 +28,33 @@ namespace { const int kMinimumWidthToTestFor = 20; const int kMinimumHeightToTestFor = 30; -class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { - public: - TestHtmlDialogUIDelegate() {} - virtual ~TestHtmlDialogUIDelegate() {} +// Initial size of HTMLDialog for SizeWindow test case. They must be different +// from the above kMinimumWidthToTestFor/kMinimumHeightToTestFor. +const int kInitialWidth = 40; +const int kInitialHeight = 40; - // HTMLDialogUIDelegate implementation: - virtual bool IsDialogModal() const OVERRIDE { - return true; - } - virtual string16 GetDialogTitle() const OVERRIDE { - return ASCIIToUTF16("Test"); - } - virtual GURL GetDialogContentURL() const OVERRIDE { - return GURL(chrome::kChromeUIChromeURLsURL); - } - virtual void GetWebUIMessageHandlers( - std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { } - virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { - size->set_width(40); - size->set_height(40); +class TestHtmlDialogView: public HtmlDialogView { + public: + TestHtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate) + : HtmlDialogView(profile, delegate), + painted_(false) { } - virtual std::string GetDialogArgs() const OVERRIDE { - return std::string(); + + bool painted() const { + return painted_; } - virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { } - virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) - OVERRIDE { - if (out_close_dialog) - *out_close_dialog = true; + + protected: + virtual void OnTabMainFrameFirstRender() OVERRIDE { + HtmlDialogView::OnTabMainFrameFirstRender(); + painted_ = true; + MessageLoop::current()->Quit(); } - virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } + + private: + bool painted_; + + DISALLOW_COPY_AND_ASSIGN(TestHtmlDialogView); }; } // namespace @@ -132,7 +128,9 @@ class HtmlDialogBrowserTest : public InProcessBrowserTest { #endif IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { - HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); + test::TestHtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( + GURL(chrome::kChromeUIChromeURLsURL)); + delegate->set_size(kInitialWidth, kInitialHeight); HtmlDialogView* html_view = new HtmlDialogView(browser()->profile(), delegate); @@ -214,29 +212,25 @@ IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { } // This is timing out about 5~10% of runs. See crbug.com/86059. -IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_TestStateTransition) { - HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); +IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_WebContentRendered) { + HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( + GURL(chrome::kChromeUIChromeURLsURL)); - HtmlDialogView* html_view = - new HtmlDialogView(browser()->profile(), delegate); + TestHtmlDialogView* html_view = + new TestHtmlDialogView(browser()->profile(), delegate); TabContents* tab_contents = browser()->GetSelectedTabContents(); ASSERT_TRUE(tab_contents != NULL); views::Widget::CreateWindowWithParent(html_view, tab_contents->GetDialogRootWindow()); - // Test if the state transitions from INITIALIZED to -> PAINTED - EXPECT_EQ(HtmlDialogView::INITIALIZED, html_view->state_); + EXPECT_TRUE(html_view->initialized_); html_view->InitDialog(); html_view->GetWidget()->Show(); - MessageLoopForUI::current()->AddObserver( - WindowChangedObserver::GetInstance()); - // We use busy loop because the state is updated in notifications. - while (html_view->state_ != HtmlDialogView::PAINTED) - MessageLoop::current()->RunAllPending(); + // TestHtmlDialogView::OnTabMainFrameFirstRender() will Quit(). + MessageLoopForUI::current()->Run(); - EXPECT_EQ(HtmlDialogView::PAINTED, html_view->state_); + EXPECT_TRUE(html_view->painted()); - MessageLoopForUI::current()->RemoveObserver( - WindowChangedObserver::GetInstance()); + html_view->GetWidget()->Close(); } diff --git a/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc b/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc index c70ad0a..e70534a 100644 --- a/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc +++ b/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc @@ -9,7 +9,7 @@ #include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/constrained_html_ui.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" +#include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" @@ -18,39 +18,6 @@ namespace { -class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { - public: - TestHtmlDialogUIDelegate() {} - virtual ~TestHtmlDialogUIDelegate() {} - - // HTMLDialogUIDelegate implementation: - virtual bool IsDialogModal() const OVERRIDE { - return true; - } - virtual string16 GetDialogTitle() const OVERRIDE { - return UTF8ToUTF16("Test"); - } - virtual GURL GetDialogContentURL() const OVERRIDE { - return GURL(chrome::kChromeUIConstrainedHTMLTestURL); - } - virtual void GetWebUIMessageHandlers( - std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {} - virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { - size->set_width(400); - size->set_height(400); - } - virtual std::string GetDialogArgs() const OVERRIDE { - return std::string(); - } - virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { } - virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) - OVERRIDE { - if (out_close_dialog) - *out_close_dialog = true; - } - virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } -}; - class ConstrainedHtmlDialogBrowserTestObserver : public TabContentsObserver { public: explicit ConstrainedHtmlDialogBrowserTestObserver(TabContents* contents) @@ -84,7 +51,8 @@ class ConstrainedHtmlDialogBrowserTest : public InProcessBrowserTest { // Tests that opening/closing the constrained window won't crash it. IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) { // The delegate deletes itself. - HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); + HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( + GURL(chrome::kChromeUIConstrainedHTMLTestURL)); TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); ASSERT_TRUE(wrapper); @@ -101,7 +69,8 @@ IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) { IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, ReleaseTabContentsOnDialogClose) { // The delegate deletes itself. - TestHtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); + HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( + GURL(chrome::kChromeUIConstrainedHTMLTestURL)); TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); ASSERT_TRUE(wrapper); diff --git a/chrome/browser/ui/webui/test_html_dialog_ui_delegate.cc b/chrome/browser/ui/webui/test_html_dialog_ui_delegate.cc new file mode 100644 index 0000000..11eb078 --- /dev/null +++ b/chrome/browser/ui/webui/test_html_dialog_ui_delegate.cc @@ -0,0 +1,56 @@ +// 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/browser/ui/webui/test_html_dialog_ui_delegate.h" + +#include "base/utf_string_conversions.h" + +namespace test { + +TestHtmlDialogUIDelegate::TestHtmlDialogUIDelegate(const GURL& url) + : url_(url), + size_(400, 400) { +} + +TestHtmlDialogUIDelegate::~TestHtmlDialogUIDelegate() { +} + +bool TestHtmlDialogUIDelegate::IsDialogModal() const { + return true; +} + +string16 TestHtmlDialogUIDelegate::GetDialogTitle() const { + return UTF8ToUTF16("Test"); +} + +GURL TestHtmlDialogUIDelegate::GetDialogContentURL() const { + return url_; +} + +void TestHtmlDialogUIDelegate::GetWebUIMessageHandlers( + std::vector<WebUIMessageHandler*>* handlers) const { +} + +void TestHtmlDialogUIDelegate::GetDialogSize(gfx::Size* size) const { + *size = size_; +} + +std::string TestHtmlDialogUIDelegate::GetDialogArgs() const { + return std::string(); +} + +void TestHtmlDialogUIDelegate::OnDialogClosed(const std::string& json_retval) { +} + +void TestHtmlDialogUIDelegate::OnCloseContents(TabContents* source, + bool* out_close_dialog) { + if (out_close_dialog) + *out_close_dialog = true; +} + +bool TestHtmlDialogUIDelegate::ShouldShowDialogTitle() const { + return true; +} + +} // namespace test diff --git a/chrome/browser/ui/webui/test_html_dialog_ui_delegate.h b/chrome/browser/ui/webui/test_html_dialog_ui_delegate.h new file mode 100644 index 0000000..d9fdf0f --- /dev/null +++ b/chrome/browser/ui/webui/test_html_dialog_ui_delegate.h @@ -0,0 +1,48 @@ +// 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_BROWSER_UI_WEBUI_TEST_HTML_DIALOG_UI_DELEGATE_H_ +#define CHROME_BROWSER_UI_WEBUI_TEST_HTML_DIALOG_UI_DELEGATE_H_ +#pragma once + +#include <string> + +#include "base/compiler_specific.h" +#include "chrome/browser/ui/webui/html_dialog_ui.h" +#include "ui/gfx/size.h" + +namespace test { + +class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { + public: + explicit TestHtmlDialogUIDelegate(const GURL& url); + virtual ~TestHtmlDialogUIDelegate(); + + void set_size(int width, int height) { + size_.SetSize(width, height); + } + + // HTMLDialogUIDelegate implementation: + virtual bool IsDialogModal() const OVERRIDE; + virtual string16 GetDialogTitle() const OVERRIDE; + virtual GURL GetDialogContentURL() const OVERRIDE; + virtual void GetWebUIMessageHandlers( + std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; + virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; + virtual std::string GetDialogArgs() const OVERRIDE; + virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; + virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) + OVERRIDE; + virtual bool ShouldShowDialogTitle() const OVERRIDE; + + protected: + const GURL url_; + gfx::Size size_; + + DISALLOW_COPY_AND_ASSIGN(TestHtmlDialogUIDelegate); +}; + +} // namespace test + +#endif // CHROME_BROWSER_UI_WEBUI_TEST_HTML_DIALOG_UI_DELEGATE_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index fe945f2..28c03f9 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -812,8 +812,6 @@ 'browser/chromeos/system_key_event_listener.h', 'browser/chromeos/tab_closeable_state_watcher.cc', 'browser/chromeos/tab_closeable_state_watcher.h', - 'browser/chromeos/tab_first_render_watcher.cc', - 'browser/chromeos/tab_first_render_watcher.h', 'browser/chromeos/upgrade_detector_chromeos.cc', 'browser/chromeos/upgrade_detector_chromeos.h', 'browser/chromeos/user_cros_settings_provider.cc', @@ -2296,6 +2294,8 @@ 'browser/sync/sync_ui_util_mac.mm', 'browser/tab_closeable_state_watcher.cc', 'browser/tab_closeable_state_watcher.h', + 'browser/tab_first_render_watcher.cc', + 'browser/tab_first_render_watcher.h', 'browser/tab_contents/background_contents.cc', 'browser/tab_contents/background_contents.h', 'browser/tab_contents/chrome_interstitial_page.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index df1d107..ec435cb 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2520,6 +2520,7 @@ 'browser/speech/speech_input_bubble_browsertest.cc', 'browser/spellchecker/spellcheck_host_browsertest.cc', 'browser/ssl/ssl_browser_tests.cc', + 'browser/tab_first_render_watcher_browsertest.cc', 'browser/task_manager/task_manager_browsertest.cc', 'browser/task_manager/task_manager_browsertest_util.cc', 'browser/task_manager/task_manager_browsertest_util.h', @@ -2565,6 +2566,8 @@ 'browser/ui/webui/options/password_manager_browsertest.js', 'browser/ui/webui/options/personal_options_browsertest.js', 'browser/ui/webui/options/search_engine_manager_browsertest.js', + 'browser/ui/webui/test_html_dialog_ui_delegate.cc', + 'browser/ui/webui/test_html_dialog_ui_delegate.h', 'browser/ui/webui/web_ui_browsertest.cc', 'browser/ui/webui/web_ui_browsertest.h', 'browser/ui/webui/web_ui_test_handler.cc', @@ -2849,6 +2852,7 @@ }, { # else: toolkit_views == 0 'sources!': [ 'browser/extensions/browser_action_test_util_views.cc', + 'browser/tab_first_render_watcher_browsertest.cc', 'browser/ui/panels/panel_browser_view_browsertest.cc', 'browser/ui/views/browser_actions_container_browsertest.cc', 'browser/ui/views/dom_view_browsertest.cc', |