| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/views/html_dialog_view.h" | 12 #include "chrome/browser/ui/views/html_dialog_view.h" |
| 13 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" | 13 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view.h" | 17 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents_view.h" |
| 19 #include "content/public/browser/web_contents.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 | 23 |
| 24 using content::WebContents; |
| 23 using testing::Eq; | 25 using testing::Eq; |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 // Initial size of HTMLDialog for SizeWindow test case. | 29 // Initial size of HTMLDialog for SizeWindow test case. |
| 28 const int kInitialWidth = 40; | 30 const int kInitialWidth = 40; |
| 29 const int kInitialHeight = 40; | 31 const int kInitialHeight = 40; |
| 30 | 32 |
| 31 class TestHtmlDialogView: public HtmlDialogView { | 33 class TestHtmlDialogView: public HtmlDialogView { |
| 32 public: | 34 public: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 #define MAYBE_SizeWindow DISABLED_SizeWindow | 101 #define MAYBE_SizeWindow DISABLED_SizeWindow |
| 100 #endif | 102 #endif |
| 101 | 103 |
| 102 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { | 104 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { |
| 103 test::TestHtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( | 105 test::TestHtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( |
| 104 GURL(chrome::kChromeUIChromeURLsURL)); | 106 GURL(chrome::kChromeUIChromeURLsURL)); |
| 105 delegate->set_size(kInitialWidth, kInitialHeight); | 107 delegate->set_size(kInitialWidth, kInitialHeight); |
| 106 | 108 |
| 107 TestHtmlDialogView* html_view = | 109 TestHtmlDialogView* html_view = |
| 108 new TestHtmlDialogView(browser()->profile(), delegate); | 110 new TestHtmlDialogView(browser()->profile(), delegate); |
| 109 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 111 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 110 ASSERT_TRUE(tab_contents != NULL); | 112 ASSERT_TRUE(web_contents != NULL); |
| 111 views::Widget::CreateWindowWithParent(html_view, | 113 views::Widget::CreateWindowWithParent( |
| 112 tab_contents->GetDialogRootWindow()); | 114 html_view, web_contents->GetView()->GetTopLevelNativeWindow()); |
| 113 html_view->InitDialog(); | 115 html_view->InitDialog(); |
| 114 html_view->GetWidget()->Show(); | 116 html_view->GetWidget()->Show(); |
| 115 | 117 |
| 116 // TestHtmlDialogView should quit current message loop on size change. | 118 // TestHtmlDialogView should quit current message loop on size change. |
| 117 html_view->set_should_quit_on_size_change(true); | 119 html_view->set_should_quit_on_size_change(true); |
| 118 | 120 |
| 119 gfx::Rect bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 121 gfx::Rect bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 120 | 122 |
| 121 gfx::Rect set_bounds = bounds; | 123 gfx::Rect set_bounds = bounds; |
| 122 gfx::Rect actual_bounds, rwhv_bounds; | 124 gfx::Rect actual_bounds, rwhv_bounds; |
| 123 | 125 |
| 124 // Bigger than the default in both dimensions. | 126 // Bigger than the default in both dimensions. |
| 125 set_bounds.set_width(400); | 127 set_bounds.set_width(400); |
| 126 set_bounds.set_height(300); | 128 set_bounds.set_height(300); |
| 127 | 129 |
| 128 html_view->MoveContents(tab_contents, set_bounds); | 130 html_view->MoveContents(web_contents, set_bounds); |
| 129 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. | 131 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. |
| 130 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 132 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 131 EXPECT_EQ(set_bounds, actual_bounds); | 133 EXPECT_EQ(set_bounds, actual_bounds); |
| 132 | 134 |
| 133 rwhv_bounds = html_view->dom_contents()->tab_contents()-> | 135 rwhv_bounds = html_view->dom_contents()->web_contents()-> |
| 134 GetRenderWidgetHostView()->GetViewBounds(); | 136 GetRenderWidgetHostView()->GetViewBounds(); |
| 135 EXPECT_LT(0, rwhv_bounds.width()); | 137 EXPECT_LT(0, rwhv_bounds.width()); |
| 136 EXPECT_LT(0, rwhv_bounds.height()); | 138 EXPECT_LT(0, rwhv_bounds.height()); |
| 137 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); | 139 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); |
| 138 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); | 140 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); |
| 139 | 141 |
| 140 // Larger in one dimension and smaller in the other. | 142 // Larger in one dimension and smaller in the other. |
| 141 set_bounds.set_width(550); | 143 set_bounds.set_width(550); |
| 142 set_bounds.set_height(250); | 144 set_bounds.set_height(250); |
| 143 | 145 |
| 144 html_view->MoveContents(tab_contents, set_bounds); | 146 html_view->MoveContents(web_contents, set_bounds); |
| 145 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. | 147 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. |
| 146 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 148 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 147 EXPECT_EQ(set_bounds, actual_bounds); | 149 EXPECT_EQ(set_bounds, actual_bounds); |
| 148 | 150 |
| 149 rwhv_bounds = html_view->dom_contents()->tab_contents()-> | 151 rwhv_bounds = html_view->dom_contents()->web_contents()-> |
| 150 GetRenderWidgetHostView()->GetViewBounds(); | 152 GetRenderWidgetHostView()->GetViewBounds(); |
| 151 EXPECT_LT(0, rwhv_bounds.width()); | 153 EXPECT_LT(0, rwhv_bounds.width()); |
| 152 EXPECT_LT(0, rwhv_bounds.height()); | 154 EXPECT_LT(0, rwhv_bounds.height()); |
| 153 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); | 155 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); |
| 154 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); | 156 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); |
| 155 | 157 |
| 156 // Get very small. | 158 // Get very small. |
| 157 gfx::Size min_size = html_view->GetWidget()->GetMinimumSize(); | 159 gfx::Size min_size = html_view->GetWidget()->GetMinimumSize(); |
| 158 set_bounds.set_size(min_size); | 160 set_bounds.set_size(min_size); |
| 159 | 161 |
| 160 html_view->MoveContents(tab_contents, set_bounds); | 162 html_view->MoveContents(web_contents, set_bounds); |
| 161 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. | 163 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. |
| 162 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 164 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 163 EXPECT_EQ(set_bounds, actual_bounds); | 165 EXPECT_EQ(set_bounds, actual_bounds); |
| 164 | 166 |
| 165 rwhv_bounds = html_view->dom_contents()->tab_contents()-> | 167 rwhv_bounds = html_view->dom_contents()->web_contents()-> |
| 166 GetRenderWidgetHostView()->GetViewBounds(); | 168 GetRenderWidgetHostView()->GetViewBounds(); |
| 167 EXPECT_LT(0, rwhv_bounds.width()); | 169 EXPECT_LT(0, rwhv_bounds.width()); |
| 168 EXPECT_LT(0, rwhv_bounds.height()); | 170 EXPECT_LT(0, rwhv_bounds.height()); |
| 169 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); | 171 EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); |
| 170 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); | 172 EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); |
| 171 | 173 |
| 172 // Check to make sure we can't get to 0x0 | 174 // Check to make sure we can't get to 0x0 |
| 173 set_bounds.set_width(0); | 175 set_bounds.set_width(0); |
| 174 set_bounds.set_height(0); | 176 set_bounds.set_height(0); |
| 175 | 177 |
| 176 html_view->MoveContents(tab_contents, set_bounds); | 178 html_view->MoveContents(web_contents, set_bounds); |
| 177 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. | 179 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit. |
| 178 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); | 180 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds(); |
| 179 EXPECT_LT(0, actual_bounds.width()); | 181 EXPECT_LT(0, actual_bounds.width()); |
| 180 EXPECT_LT(0, actual_bounds.height()); | 182 EXPECT_LT(0, actual_bounds.height()); |
| 181 } | 183 } |
| 182 | 184 |
| 183 // This is timing out about 5~10% of runs. See crbug.com/86059. | 185 // This is timing out about 5~10% of runs. See crbug.com/86059. |
| 184 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_WebContentRendered) { | 186 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_WebContentRendered) { |
| 185 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( | 187 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate( |
| 186 GURL(chrome::kChromeUIChromeURLsURL)); | 188 GURL(chrome::kChromeUIChromeURLsURL)); |
| 187 | 189 |
| 188 TestHtmlDialogView* html_view = | 190 TestHtmlDialogView* html_view = |
| 189 new TestHtmlDialogView(browser()->profile(), delegate); | 191 new TestHtmlDialogView(browser()->profile(), delegate); |
| 190 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 192 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 191 ASSERT_TRUE(tab_contents != NULL); | 193 ASSERT_TRUE(web_contents != NULL); |
| 192 views::Widget::CreateWindowWithParent(html_view, | 194 views::Widget::CreateWindowWithParent( |
| 193 tab_contents->GetDialogRootWindow()); | 195 html_view, web_contents->GetView()->GetTopLevelNativeWindow()); |
| 194 EXPECT_TRUE(html_view->initialized_); | 196 EXPECT_TRUE(html_view->initialized_); |
| 195 | 197 |
| 196 html_view->InitDialog(); | 198 html_view->InitDialog(); |
| 197 html_view->GetWidget()->Show(); | 199 html_view->GetWidget()->Show(); |
| 198 | 200 |
| 199 // TestHtmlDialogView::OnTabMainFrameFirstRender() will Quit(). | 201 // TestHtmlDialogView::OnTabMainFrameFirstRender() will Quit(). |
| 200 MessageLoopForUI::current()->Run(); | 202 MessageLoopForUI::current()->Run(); |
| 201 | 203 |
| 202 EXPECT_TRUE(html_view->painted()); | 204 EXPECT_TRUE(html_view->painted()); |
| 203 | 205 |
| 204 html_view->GetWidget()->Close(); | 206 html_view->GetWidget()->Close(); |
| 205 } | 207 } |
| OLD | NEW |