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 3 // found in the LICENSE file. 4 5 #include "chrome/test/ui/ui_test.h" 6 7 #include "base/file_path.h" 8 #include "base/message_loop.h" 9 #include "chrome/browser/ui/webui/constrained_html_ui.h" 10 #include "chrome/browser/ui/webui/html_dialog_ui.h" 11 #include "chrome/common/url_constants.h" 12 #include "chrome/test/in_process_browser_test.h" 13 #include "chrome/test/ui_test_utils.h" 14 #include "content/browser/renderer_host/render_widget_host_view.h" 15 #include "content/browser/tab_contents/tab_contents.h" 16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gtest/include/gtest/gtest.h" 18 19 using testing::Eq; 20 21 namespace { 22 23 class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { 24 public: TestHtmlDialogUIDelegate()25 TestHtmlDialogUIDelegate() {} ~TestHtmlDialogUIDelegate()26 virtual ~TestHtmlDialogUIDelegate() {} 27 28 // HTMLDialogUIDelegate implementation: IsDialogModal() const29 virtual bool IsDialogModal() const { 30 return true; 31 } GetDialogTitle() const32 virtual std::wstring GetDialogTitle() const { 33 return std::wstring(L"Test"); 34 } GetDialogContentURL() const35 virtual GURL GetDialogContentURL() const { 36 return GURL(chrome::kChromeUIConstrainedHTMLTestURL); 37 } GetWebUIMessageHandlers(std::vector<WebUIMessageHandler * > * handlers) const38 virtual void GetWebUIMessageHandlers( 39 std::vector<WebUIMessageHandler*>* handlers) const {} GetDialogSize(gfx::Size * size) const40 virtual void GetDialogSize(gfx::Size* size) const { 41 size->set_width(400); 42 size->set_height(400); 43 } GetDialogArgs() const44 virtual std::string GetDialogArgs() const { 45 return std::string(); 46 } OnDialogClosed(const std::string & json_retval)47 virtual void OnDialogClosed(const std::string& json_retval) { } OnCloseContents(TabContents * source,bool * out_close_dialog)48 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) { 49 if (out_close_dialog) 50 *out_close_dialog = true; 51 } ShouldShowDialogTitle() const52 virtual bool ShouldShowDialogTitle() const { return true; } 53 }; 54 55 } // namespace 56 57 class ConstrainedHtmlDialogBrowserTest : public InProcessBrowserTest { 58 public: ConstrainedHtmlDialogBrowserTest()59 ConstrainedHtmlDialogBrowserTest() {} 60 }; 61 62 // Tests that opening/closing the constrained window won't crash it. IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest,BasicTest)63IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) { 64 // The delegate deletes itself. 65 HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); 66 TabContents* tab_contents = browser()->GetSelectedTabContents(); 67 ASSERT_TRUE(tab_contents != NULL); 68 69 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(), 70 delegate, 71 tab_contents); 72 73 ASSERT_EQ(1U, tab_contents->constrained_window_count()); 74 } 75