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

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

Issue 11358027: Move constrained web dialog code back to chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros fix2 Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_tabstrip.h" 9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/constrained_window_tab_helper.h" 10 #include "chrome/browser/ui/constrained_window_tab_helper.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
12 #include "chrome/browser/ui/webui/test_web_dialog_delegate.h" 13 #include "chrome/browser/ui/webui/test_web_dialog_delegate.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "ui/web_dialogs/constrained_web_dialog_ui.h"
19 19
20 using content::WebContents; 20 using content::WebContents;
21 using ui::ConstrainedWebDialogDelegate;
22 using ui::WebDialogDelegate; 21 using ui::WebDialogDelegate;
23 22
24 namespace { 23 namespace {
25 24
26 class ConstrainedWebDialogBrowserTestObserver 25 class ConstrainedWebDialogBrowserTestObserver
27 : public content::WebContentsObserver { 26 : public content::WebContentsObserver {
28 public: 27 public:
29 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) 28 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents)
30 : content::WebContentsObserver(contents), 29 : content::WebContentsObserver(contents),
31 tab_destroyed_(false) { 30 tab_destroyed_(false) {
(...skipping 10 matching lines...) Expand all
42 bool tab_destroyed_; 41 bool tab_destroyed_;
43 }; 42 };
44 43
45 } // namespace 44 } // namespace
46 45
47 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { 46 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest {
48 public: 47 public:
49 ConstrainedWebDialogBrowserTest() {} 48 ConstrainedWebDialogBrowserTest() {}
50 49
51 protected: 50 protected:
52 size_t GetConstrainedWindowCount(TabContents* tab_contents) const { 51 size_t GetConstrainedWindowCount(WebContents* web_contents) const {
53 ConstrainedWindowTabHelper* constrained_window_tab_helper = 52 ConstrainedWindowTabHelper* constrained_window_tab_helper =
54 ConstrainedWindowTabHelper::FromWebContents 53 ConstrainedWindowTabHelper::FromWebContents(web_contents);
55 (tab_contents->web_contents());
56 return constrained_window_tab_helper->constrained_window_count(); 54 return constrained_window_tab_helper->constrained_window_count();
57 } 55 }
58 }; 56 };
59 57
60 // Tests that opening/closing the constrained window won't crash it. 58 // Tests that opening/closing the constrained window won't crash it.
61 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { 59 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) {
62 // The delegate deletes itself. 60 // The delegate deletes itself.
63 WebDialogDelegate* delegate = new test::TestWebDialogDelegate( 61 WebDialogDelegate* delegate = new test::TestWebDialogDelegate(
64 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); 62 GURL(chrome::kChromeUIConstrainedHTMLTestURL));
65 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); 63 WebContents* web_contents = chrome::GetActiveWebContents(browser());
66 ASSERT_TRUE(tab_contents); 64 ASSERT_TRUE(web_contents);
67 65
68 ConstrainedWebDialogDelegate* dialog_delegate = 66 ConstrainedWebDialogDelegate* dialog_delegate =
69 ui::CreateConstrainedWebDialog(browser()->profile(), 67 CreateConstrainedWebDialog(browser()->profile(),
70 delegate, 68 delegate,
71 NULL, 69 NULL,
72 tab_contents); 70 web_contents);
73 ASSERT_TRUE(dialog_delegate); 71 ASSERT_TRUE(dialog_delegate);
74 EXPECT_TRUE(dialog_delegate->window()); 72 EXPECT_TRUE(dialog_delegate->window());
75 EXPECT_EQ(1U, GetConstrainedWindowCount(tab_contents)); 73 EXPECT_EQ(1U, GetConstrainedWindowCount(web_contents));
76 } 74 }
77 75
78 // Tests that ReleaseTabContentsOnDialogClose() works. 76 // Tests that ReleaseTabContentsOnDialogClose() works.
79 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, 77 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
80 ReleaseTabContentsOnDialogClose) { 78 ReleaseTabContentsOnDialogClose) {
81 // The delegate deletes itself. 79 // The delegate deletes itself.
82 WebDialogDelegate* delegate = new test::TestWebDialogDelegate( 80 WebDialogDelegate* delegate = new test::TestWebDialogDelegate(
83 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); 81 GURL(chrome::kChromeUIConstrainedHTMLTestURL));
84 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); 82 WebContents* web_contents = chrome::GetActiveWebContents(browser());
85 ASSERT_TRUE(tab_contents); 83 ASSERT_TRUE(web_contents);
86 84
87 ConstrainedWebDialogDelegate* dialog_delegate = 85 ConstrainedWebDialogDelegate* dialog_delegate =
88 ui::CreateConstrainedWebDialog(browser()->profile(), 86 CreateConstrainedWebDialog(browser()->profile(),
89 delegate, 87 delegate,
90 NULL, 88 NULL,
91 tab_contents); 89 web_contents);
92 ASSERT_TRUE(dialog_delegate); 90 ASSERT_TRUE(dialog_delegate);
93 scoped_ptr<TabContents> new_tab(dialog_delegate->tab()); 91 scoped_ptr<TabContents> new_tab(dialog_delegate->tab());
94 ASSERT_TRUE(new_tab.get()); 92 ASSERT_TRUE(new_tab.get());
95 ASSERT_EQ(1U, GetConstrainedWindowCount(tab_contents)); 93 ASSERT_EQ(1U, GetConstrainedWindowCount(web_contents));
96 94
97 ConstrainedWebDialogBrowserTestObserver observer(new_tab->web_contents()); 95 ConstrainedWebDialogBrowserTestObserver observer(new_tab->web_contents());
98 dialog_delegate->ReleaseTabContentsOnDialogClose(); 96 dialog_delegate->ReleaseTabContentsOnDialogClose();
99 dialog_delegate->OnDialogCloseFromWebUI(); 97 dialog_delegate->OnDialogCloseFromWebUI();
100 98
101 ASSERT_FALSE(observer.tab_destroyed()); 99 ASSERT_FALSE(observer.tab_destroyed());
102 EXPECT_EQ(0U, GetConstrainedWindowCount(tab_contents)); 100 EXPECT_EQ(0U, GetConstrainedWindowCount(web_contents));
103 new_tab.reset(); 101 new_tab.reset();
104 EXPECT_TRUE(observer.tab_destroyed()); 102 EXPECT_TRUE(observer.tab_destroyed());
105 } 103 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_ui.cc ('k') | chrome/browser/ui/webui/print_preview/print_preview_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698