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

Unified Diff: chrome/browser/ui/webui/constrained_html_ui_browsertest.cc

Issue 8220026: Add new methods to create constrained windows for print preview and release the internal TabConte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/constrained_html_ui.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/constrained_html_ui_browsertest.cc
===================================================================
--- chrome/browser/ui/webui/constrained_html_ui_browsertest.cc (revision 104824)
+++ chrome/browser/ui/webui/constrained_html_ui_browsertest.cc (working copy)
@@ -4,8 +4,6 @@
#include "chrome/test/ui/ui_test.h"
-#include "base/file_path.h"
-#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
@@ -15,18 +13,28 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
-#include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/tab_contents.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "content/browser/tab_contents/tab_contents_observer.h"
-using testing::Eq;
-
namespace {
+class ConstrainedHtmlDialogBrowserTestHandler : public WebUIMessageHandler {
+ public:
+ ConstrainedHtmlDialogBrowserTestHandler() {}
+ virtual ~ConstrainedHtmlDialogBrowserTestHandler() {}
+
+ ConstrainedHtmlUI* constrained_ui() {
+ return static_cast<ConstrainedHtmlUI*>(web_ui());
+ }
+ private:
+ virtual void RegisterMessages() {}
+};
+
class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate {
public:
- TestHtmlDialogUIDelegate() {}
+ TestHtmlDialogUIDelegate() {
+ test_handler_.reset(new ConstrainedHtmlDialogBrowserTestHandler);
+ }
virtual ~TestHtmlDialogUIDelegate() {}
// HTMLDialogUIDelegate implementation:
@@ -40,7 +48,9 @@
return GURL(chrome::kChromeUIConstrainedHTMLTestURL);
}
virtual void GetWebUIMessageHandlers(
- std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {}
+ std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {
+ handlers->push_back(test_handler_.get());
+ }
virtual void GetDialogSize(gfx::Size* size) const OVERRIDE {
size->set_width(400);
size->set_height(400);
@@ -55,13 +65,43 @@
*out_close_dialog = true;
}
virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; }
+
+ ConstrainedHtmlDialogBrowserTestHandler* test_handler() {
+ return test_handler_.get();
+ }
+
+ private:
+ scoped_ptr<ConstrainedHtmlDialogBrowserTestHandler> test_handler_;
};
+class ConstrainedHtmlDialogBrowserTestObserver : public TabContentsObserver {
+ public:
+ explicit ConstrainedHtmlDialogBrowserTestObserver(TabContents* contents)
+ : TabContentsObserver(contents),
+ tab_destroyed_(false) {
+ }
+ virtual ~ConstrainedHtmlDialogBrowserTestObserver() {}
+
+ bool tab_destroyed() { return tab_destroyed_; }
+
+ private:
+ virtual void TabContentsDestroyed(TabContents* tab) {
+ tab_destroyed_ = true;
+ }
+
+ bool tab_destroyed_;
+};
+
} // namespace
class ConstrainedHtmlDialogBrowserTest : public InProcessBrowserTest {
public:
ConstrainedHtmlDialogBrowserTest() {}
+
+ protected:
+ size_t GetConstrainedWindowCount(TabContentsWrapper* wrapper) const {
+ return wrapper->constrained_window_tab_helper()->constrained_window_count();
+ }
};
// Tests that opening/closing the constrained window won't crash it.
@@ -69,12 +109,44 @@
// The delegate deletes itself.
HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate();
TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper();
- ASSERT_TRUE(wrapper != NULL);
+ ASSERT_TRUE(wrapper);
- ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(),
- delegate,
- wrapper);
+ ConstrainedWindow* window =
+ ConstrainedHtmlUI::CreateConstrainedHtmlDialog(browser()->profile(),
+ delegate,
+ wrapper);
+ EXPECT_TRUE(window);
+ EXPECT_EQ(1U, GetConstrainedWindowCount(wrapper));
+}
- ASSERT_EQ(1U, wrapper->constrained_window_tab_helper()->
- constrained_window_count());
+// Tests that ReleaseTabContentsOnDialogClose() works.
+IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest,
+ ReleaseTabContentsOnDialogClose) {
+ // The delegate deletes itself.
+ TestHtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate();
+ TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper();
+ ASSERT_TRUE(wrapper);
+
+ TabContentsWrapper* new_tab =
+ ConstrainedHtmlUI::CreateConstrainedPrintPreviewHtmlUI(
+ browser()->profile(),
+ delegate,
+ wrapper);
+ ASSERT_TRUE(new_tab);
+ ASSERT_EQ(1U, GetConstrainedWindowCount(wrapper));
+
+ ConstrainedHtmlDialogBrowserTestObserver observer(new_tab->tab_contents());
+ ConstrainedHtmlDialogBrowserTestHandler* handler = delegate->test_handler();
+ ConstrainedHtmlUI* constrained_ui = handler->constrained_ui();
+ ASSERT_TRUE(constrained_ui);
+ ConstrainedHtmlUIDelegate* constrained_delegate =
+ constrained_ui->GetConstrainedDelegate();
+ ASSERT_TRUE(constrained_delegate);
+ constrained_delegate->ReleaseTabContentsOnDialogClose();
+ constrained_delegate->OnDialogCloseFromWebUI();
+
+ ASSERT_FALSE(observer.tab_destroyed());
+ EXPECT_EQ(0U, GetConstrainedWindowCount(wrapper));
+ delete new_tab;
Paweł Hajdan Jr. 2011/10/11 22:16:48 Why not scoped_ptr? Otherwise if any of ASSERTs fa
Lei Zhang 2011/10/11 23:41:25 Done.
+ EXPECT_TRUE(observer.tab_destroyed());
}
« no previous file with comments | « chrome/browser/ui/webui/constrained_html_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698