BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / tab_modal_confirm_dialog_browsertest.cc
blobdb18f70d1eaf91d9e84d0ca25da278ad93559d03
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/lifetime/application_lifetime.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/browser/page_navigator.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/window_open_disposition.h"
20 MockTabModalConfirmDialogDelegate::MockTabModalConfirmDialogDelegate(
21 content::WebContents* web_contents,
22 Delegate* delegate)
23 : TabModalConfirmDialogDelegate(web_contents),
24 delegate_(delegate) {
27 MockTabModalConfirmDialogDelegate::~MockTabModalConfirmDialogDelegate() {
30 base::string16 MockTabModalConfirmDialogDelegate::GetTitle() {
31 return base::string16();
34 base::string16 MockTabModalConfirmDialogDelegate::GetDialogMessage() {
35 return base::string16();
38 void MockTabModalConfirmDialogDelegate::OnAccepted() {
39 if (delegate_)
40 delegate_->OnAccepted();
43 void MockTabModalConfirmDialogDelegate::OnCanceled() {
44 if (delegate_)
45 delegate_->OnCanceled();
48 void MockTabModalConfirmDialogDelegate::OnClosed() {
49 if (delegate_)
50 delegate_->OnClosed();
53 TabModalConfirmDialogTest::TabModalConfirmDialogTest()
54 : delegate_(NULL),
55 dialog_(NULL),
56 accepted_count_(0),
57 canceled_count_(0),
58 closed_count_(0) {
61 void TabModalConfirmDialogTest::SetUpOnMainThread() {
62 delegate_ = new MockTabModalConfirmDialogDelegate(
63 browser()->tab_strip_model()->GetActiveWebContents(), this);
64 dialog_ = TabModalConfirmDialog::Create(
65 delegate_, browser()->tab_strip_model()->GetActiveWebContents());
66 content::RunAllPendingInMessageLoop();
69 void TabModalConfirmDialogTest::TearDownOnMainThread() {
70 content::RunAllPendingInMessageLoop();
73 void TabModalConfirmDialogTest::OnAccepted() {
74 ++accepted_count_;
77 void TabModalConfirmDialogTest::OnCanceled() {
78 ++canceled_count_;
81 void TabModalConfirmDialogTest::OnClosed() {
82 ++closed_count_;
85 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Accept) {
86 dialog_->AcceptTabModalDialog();
87 EXPECT_EQ(1, accepted_count_);
88 EXPECT_EQ(0, canceled_count_);
89 EXPECT_EQ(0, closed_count_);
92 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Cancel) {
93 dialog_->CancelTabModalDialog();
94 EXPECT_EQ(0, accepted_count_);
95 EXPECT_EQ(1, canceled_count_);
96 EXPECT_EQ(0, closed_count_);
99 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, CancelSelf) {
100 delegate_->Cancel();
101 EXPECT_EQ(0, accepted_count_);
102 EXPECT_EQ(1, canceled_count_);
103 EXPECT_EQ(0, closed_count_);
106 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Close) {
107 dialog_->CloseDialog();
108 EXPECT_EQ(0, accepted_count_);
109 EXPECT_EQ(0, canceled_count_);
110 EXPECT_EQ(1, closed_count_);
113 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, CloseSelf) {
114 delegate_->Close();
115 EXPECT_EQ(0, accepted_count_);
116 EXPECT_EQ(0, canceled_count_);
117 EXPECT_EQ(1, closed_count_);
120 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Navigate) {
121 content::OpenURLParams params(GURL("about:blank"),
122 content::Referrer(),
123 CURRENT_TAB,
124 ui::PAGE_TRANSITION_LINK,
125 false);
126 browser()->tab_strip_model()->GetActiveWebContents()->OpenURL(params);
128 EXPECT_EQ(0, accepted_count_);
129 EXPECT_EQ(0, canceled_count_);
130 EXPECT_EQ(1, closed_count_);
133 IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Quit) {
134 base::MessageLoop::current()->task_runner()->PostTask(
135 FROM_HERE, base::Bind(&chrome::AttemptExit));
136 content::RunMessageLoop();
137 EXPECT_EQ(0, accepted_count_);
138 EXPECT_EQ(0, canceled_count_);
139 EXPECT_EQ(1, closed_count_);