Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/ui/webui/constrained_html_ui_browsertest.cc

Issue 8417005: Share TabFirstRenderWatcher with HtmlDialogView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/test/ui/ui_test.h" 5 #include "chrome/test/ui/ui_test.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/constrained_window_tab_helper.h" 9 #include "chrome/browser/ui/constrained_window_tab_helper.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/browser/ui/webui/constrained_html_ui.h" 11 #include "chrome/browser/ui/webui/constrained_html_ui.h"
12 #include "chrome/browser/ui/webui/html_dialog_ui.h" 12 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/browser/tab_contents/tab_contents.h" 16 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/browser/tab_contents/tab_contents_observer.h" 17 #include "content/browser/tab_contents/tab_contents_observer.h"
18 18
19 namespace { 19 namespace {
20 20
21 class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate {
22 public:
23 TestHtmlDialogUIDelegate() {}
24 virtual ~TestHtmlDialogUIDelegate() {}
25
26 // HTMLDialogUIDelegate implementation:
27 virtual bool IsDialogModal() const OVERRIDE {
28 return true;
29 }
30 virtual string16 GetDialogTitle() const OVERRIDE {
31 return UTF8ToUTF16("Test");
32 }
33 virtual GURL GetDialogContentURL() const OVERRIDE {
34 return GURL(chrome::kChromeUIConstrainedHTMLTestURL);
35 }
36 virtual void GetWebUIMessageHandlers(
37 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {}
38 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE {
39 size->set_width(400);
40 size->set_height(400);
41 }
42 virtual std::string GetDialogArgs() const OVERRIDE {
43 return std::string();
44 }
45 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { }
46 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog)
47 OVERRIDE {
48 if (out_close_dialog)
49 *out_close_dialog = true;
50 }
51 virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; }
52 };
53
54 class ConstrainedHtmlDialogBrowserTestObserver : public TabContentsObserver { 21 class ConstrainedHtmlDialogBrowserTestObserver : public TabContentsObserver {
55 public: 22 public:
56 explicit ConstrainedHtmlDialogBrowserTestObserver(TabContents* contents) 23 explicit ConstrainedHtmlDialogBrowserTestObserver(TabContents* contents)
57 : TabContentsObserver(contents), 24 : TabContentsObserver(contents),
58 tab_destroyed_(false) { 25 tab_destroyed_(false) {
59 } 26 }
60 virtual ~ConstrainedHtmlDialogBrowserTestObserver() {} 27 virtual ~ConstrainedHtmlDialogBrowserTestObserver() {}
61 28
62 bool tab_destroyed() { return tab_destroyed_; } 29 bool tab_destroyed() { return tab_destroyed_; }
63 30
(...skipping 13 matching lines...) Expand all
77 44
78 protected: 45 protected:
79 size_t GetConstrainedWindowCount(TabContentsWrapper* wrapper) const { 46 size_t GetConstrainedWindowCount(TabContentsWrapper* wrapper) const {
80 return wrapper->constrained_window_tab_helper()->constrained_window_count(); 47 return wrapper->constrained_window_tab_helper()->constrained_window_count();
81 } 48 }
82 }; 49 };
83 50
84 // Tests that opening/closing the constrained window won't crash it. 51 // Tests that opening/closing the constrained window won't crash it.
85 IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) { 52 IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) {
86 // The delegate deletes itself. 53 // The delegate deletes itself.
87 HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); 54 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate(
55 GURL(chrome::kChromeUIConstrainedHTMLTestURL));
88 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); 56 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper();
89 ASSERT_TRUE(wrapper); 57 ASSERT_TRUE(wrapper);
90 58
91 ConstrainedHtmlUIDelegate* html_ui_delegate = 59 ConstrainedHtmlUIDelegate* html_ui_delegate =
92 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(), 60 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(),
93 delegate, 61 delegate,
94 wrapper); 62 wrapper);
95 ASSERT_TRUE(html_ui_delegate); 63 ASSERT_TRUE(html_ui_delegate);
96 EXPECT_TRUE(html_ui_delegate->window()); 64 EXPECT_TRUE(html_ui_delegate->window());
97 EXPECT_EQ(1U, GetConstrainedWindowCount(wrapper)); 65 EXPECT_EQ(1U, GetConstrainedWindowCount(wrapper));
98 } 66 }
99 67
100 // Tests that ReleaseTabContentsOnDialogClose() works. 68 // Tests that ReleaseTabContentsOnDialogClose() works.
101 IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, 69 IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest,
102 ReleaseTabContentsOnDialogClose) { 70 ReleaseTabContentsOnDialogClose) {
103 // The delegate deletes itself. 71 // The delegate deletes itself.
104 TestHtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); 72 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate(
73 GURL(chrome::kChromeUIConstrainedHTMLTestURL));
105 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); 74 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper();
106 ASSERT_TRUE(wrapper); 75 ASSERT_TRUE(wrapper);
107 76
108 ConstrainedHtmlUIDelegate* html_ui_delegate = 77 ConstrainedHtmlUIDelegate* html_ui_delegate =
109 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(), 78 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(),
110 delegate, 79 delegate,
111 wrapper); 80 wrapper);
112 ASSERT_TRUE(html_ui_delegate); 81 ASSERT_TRUE(html_ui_delegate);
113 scoped_ptr<TabContentsWrapper> new_tab(html_ui_delegate->tab()); 82 scoped_ptr<TabContentsWrapper> new_tab(html_ui_delegate->tab());
114 ASSERT_TRUE(new_tab.get()); 83 ASSERT_TRUE(new_tab.get());
115 ASSERT_EQ(1U, GetConstrainedWindowCount(wrapper)); 84 ASSERT_EQ(1U, GetConstrainedWindowCount(wrapper));
116 85
117 ConstrainedHtmlDialogBrowserTestObserver observer(new_tab->tab_contents()); 86 ConstrainedHtmlDialogBrowserTestObserver observer(new_tab->tab_contents());
118 html_ui_delegate->ReleaseTabContentsOnDialogClose(); 87 html_ui_delegate->ReleaseTabContentsOnDialogClose();
119 html_ui_delegate->OnDialogCloseFromWebUI(); 88 html_ui_delegate->OnDialogCloseFromWebUI();
120 89
121 ASSERT_FALSE(observer.tab_destroyed()); 90 ASSERT_FALSE(observer.tab_destroyed());
122 EXPECT_EQ(0U, GetConstrainedWindowCount(wrapper)); 91 EXPECT_EQ(0U, GetConstrainedWindowCount(wrapper));
123 new_tab.reset(); 92 new_tab.reset();
124 EXPECT_TRUE(observer.tab_destroyed()); 93 EXPECT_TRUE(observer.tab_destroyed());
125 } 94 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/html_dialog_view_browsertest.cc ('k') | chrome/browser/ui/webui/test_html_dialog_ui_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698