| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/views/html_dialog_view.h" | 10 #include "chrome/browser/ui/views/html_dialog_view.h" |
| 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 11 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_view.h" | 15 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
| 20 | 20 |
| 21 using testing::Eq; | 21 using testing::Eq; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Window non-client-area means that the minimum size for the window | 25 // Window non-client-area means that the minimum size for the window |
| 26 // won't be the actual minimum size - our layout and resizing code | 26 // won't be the actual minimum size - our layout and resizing code |
| 27 // makes sure the chrome is always visible. | 27 // makes sure the chrome is always visible. |
| 28 const int kMinimumWidthToTestFor = 20; | 28 const int kMinimumWidthToTestFor = 20; |
| 29 const int kMinimumHeightToTestFor = 30; | 29 const int kMinimumHeightToTestFor = 30; |
| 30 | 30 |
| 31 class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { | 31 // Initial size of HTMLDialog for SizeWindow test case. They must be different |
| 32 // from the above kMinimumWidthToTestFor/kMinimumHeightToTestFor. |
| 33 const int kInitialWidth = 40; |
| 34 const int kInitialHeight = 40; |
| 35 |
| 36 class TestHtmlDialogView: public HtmlDialogView { |
| 32 public: | 37 public: |
| 33 TestHtmlDialogUIDelegate() {} | 38 TestHtmlDialogView(Profile* profile, HtmlDialogUIDelegate* delegate) |
| 34 virtual ~TestHtmlDialogUIDelegate() {} | 39 : HtmlDialogView(profile, delegate), |
| 40 painted_(false) { |
| 41 } |
| 35 | 42 |
| 36 // HTMLDialogUIDelegate implementation: | 43 bool painted() const { |
| 37 virtual bool IsDialogModal() const OVERRIDE { | 44 return painted_; |
| 38 return true; | |
| 39 } | 45 } |
| 40 virtual string16 GetDialogTitle() const OVERRIDE { | 46 |
| 41 return ASCIIToUTF16("Test"); | 47 protected: |
| 48 virtual void OnTabMainFrameFirstRender() OVERRIDE { |
| 49 HtmlDialogView::OnTabMainFrameFirstRender(); |
| 50 painted_ = true; |
| 51 MessageLoop::current()->Quit(); |
| 42 } | 52 } |
| 43 virtual GURL GetDialogContentURL() const OVERRIDE { | 53 |
| 44 return GURL(chrome::kChromeUIChromeURLsURL); | 54 private: |
| 45 } | 55 bool painted_; |
| 46 virtual void GetWebUIMessageHandlers( | 56 |
| 47 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { } | 57 DISALLOW_COPY_AND_ASSIGN(TestHtmlDialogView); |
| 48 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { | |
| 49 size->set_width(40); | |
| 50 size->set_height(40); | |
| 51 } | |
| 52 virtual std::string GetDialogArgs() const OVERRIDE { | |
| 53 return std::string(); | |
| 54 } | |
| 55 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { } | |
| 56 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) | |
| 57 OVERRIDE { | |
| 58 if (out_close_dialog) | |
| 59 *out_close_dialog = true; | |
| 60 } | |
| 61 virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } | |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 } // namespace | 60 } // namespace |
| 65 | 61 |
| 66 class HtmlDialogBrowserTest : public InProcessBrowserTest { | 62 class HtmlDialogBrowserTest : public InProcessBrowserTest { |
| 67 public: | 63 public: |
| 68 HtmlDialogBrowserTest() {} | 64 HtmlDialogBrowserTest() {} |
| 69 | 65 |
| 70 class WindowChangedObserver : public MessageLoopForUI::Observer { | 66 class WindowChangedObserver : public MessageLoopForUI::Observer { |
| 71 public: | 67 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 #else | 121 #else |
| 126 // http://code.google.com/p/chromium/issues/detail?id=52602 | 122 // http://code.google.com/p/chromium/issues/detail?id=52602 |
| 127 // Windows has some issues resizing windows- an off by one problem, | 123 // Windows has some issues resizing windows- an off by one problem, |
| 128 // and a minimum size that seems too big. This file isn't included in | 124 // and a minimum size that seems too big. This file isn't included in |
| 129 // Mac builds yet. On Chrome OS, this test doesn't apply since ChromeOS | 125 // Mac builds yet. On Chrome OS, this test doesn't apply since ChromeOS |
| 130 // doesn't allow resizing of windows. | 126 // doesn't allow resizing of windows. |
| 131 #define MAYBE_SizeWindow DISABLED_SizeWindow | 127 #define MAYBE_SizeWindow DISABLED_SizeWindow |
| 132 #endif | 128 #endif |
| 133 | 129 |
| 134 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { | 130 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { |
| 135 HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); | 131 test::TestHtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( |
| 132 GURL(chrome::kChromeUIChromeURLsURL)); |
| 133 delegate->set_size(kInitialWidth, kInitialHeight); |
| 136 | 134 |
| 137 HtmlDialogView* html_view = | 135 HtmlDialogView* html_view = |
| 138 new HtmlDialogView(browser()->profile(), delegate); | 136 new HtmlDialogView(browser()->profile(), delegate); |
| 139 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 137 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 140 ASSERT_TRUE(tab_contents != NULL); | 138 ASSERT_TRUE(tab_contents != NULL); |
| 141 views::Widget::CreateWindowWithParent(html_view, | 139 views::Widget::CreateWindowWithParent(html_view, |
| 142 tab_contents->GetDialogRootWindow()); | 140 tab_contents->GetDialogRootWindow()); |
| 143 html_view->InitDialog(); | 141 html_view->InitDialog(); |
| 144 html_view->GetWidget()->Show(); | 142 html_view->GetWidget()->Show(); |
| 145 | 143 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 ui_test_utils::RunMessageLoop(); | 205 ui_test_utils::RunMessageLoop(); |
| 208 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 206 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 209 EXPECT_LT(0, actual_bounds.width()); | 207 EXPECT_LT(0, actual_bounds.width()); |
| 210 EXPECT_LT(0, actual_bounds.height()); | 208 EXPECT_LT(0, actual_bounds.height()); |
| 211 | 209 |
| 212 MessageLoopForUI::current()->RemoveObserver( | 210 MessageLoopForUI::current()->RemoveObserver( |
| 213 WindowChangedObserver::GetInstance()); | 211 WindowChangedObserver::GetInstance()); |
| 214 } | 212 } |
| 215 | 213 |
| 216 // This is timing out about 5~10% of runs. See crbug.com/86059. | 214 // This is timing out about 5~10% of runs. See crbug.com/86059. |
| 217 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_TestStateTransition) { | 215 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_WebContentRendered) { |
| 218 HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); | 216 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( |
| 217 GURL(chrome::kChromeUIChromeURLsURL)); |
| 219 | 218 |
| 220 HtmlDialogView* html_view = | 219 TestHtmlDialogView* html_view = |
| 221 new HtmlDialogView(browser()->profile(), delegate); | 220 new TestHtmlDialogView(browser()->profile(), delegate); |
| 222 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 221 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 223 ASSERT_TRUE(tab_contents != NULL); | 222 ASSERT_TRUE(tab_contents != NULL); |
| 224 views::Widget::CreateWindowWithParent(html_view, | 223 views::Widget::CreateWindowWithParent(html_view, |
| 225 tab_contents->GetDialogRootWindow()); | 224 tab_contents->GetDialogRootWindow()); |
| 226 // Test if the state transitions from INITIALIZED to -> PAINTED | 225 EXPECT_TRUE(html_view->initialized_); |
| 227 EXPECT_EQ(HtmlDialogView::INITIALIZED, html_view->state_); | |
| 228 | 226 |
| 229 html_view->InitDialog(); | 227 html_view->InitDialog(); |
| 230 html_view->GetWidget()->Show(); | 228 html_view->GetWidget()->Show(); |
| 231 | 229 |
| 232 MessageLoopForUI::current()->AddObserver( | 230 // TestHtmlDialogView::OnTabMainFrameFirstRender() will Quit(). |
| 233 WindowChangedObserver::GetInstance()); | 231 MessageLoopForUI::current()->Run(); |
| 234 // We use busy loop because the state is updated in notifications. | |
| 235 while (html_view->state_ != HtmlDialogView::PAINTED) | |
| 236 MessageLoop::current()->RunAllPending(); | |
| 237 | 232 |
| 238 EXPECT_EQ(HtmlDialogView::PAINTED, html_view->state_); | 233 EXPECT_TRUE(html_view->painted()); |
| 239 | 234 |
| 240 MessageLoopForUI::current()->RemoveObserver( | 235 html_view->GetWidget()->Close(); |
| 241 WindowChangedObserver::GetInstance()); | |
| 242 } | 236 } |
| OLD | NEW |