1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
#include "base/bind.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
MockTabModalConfirmDialogDelegate::MockTabModalConfirmDialogDelegate(
content::WebContents* web_contents,
Delegate* delegate)
: TabModalConfirmDialogDelegate(web_contents),
delegate_(delegate) {
}
MockTabModalConfirmDialogDelegate::~MockTabModalConfirmDialogDelegate() {
}
string16 MockTabModalConfirmDialogDelegate::GetTitle() {
return string16();
}
string16 MockTabModalConfirmDialogDelegate::GetMessage() {
return string16();
}
void MockTabModalConfirmDialogDelegate::OnAccepted() {
if (delegate_)
delegate_->OnAccepted();
}
void MockTabModalConfirmDialogDelegate::OnCanceled() {
if (delegate_)
delegate_->OnCanceled();
}
TabModalConfirmDialogTest::TabModalConfirmDialogTest()
: delegate_(NULL),
dialog_(NULL),
accepted_count_(0),
canceled_count_(0) {
}
void TabModalConfirmDialogTest::SetUpOnMainThread() {
delegate_ = new MockTabModalConfirmDialogDelegate(
chrome::GetActiveWebContents(browser()), this);
dialog_ = TabModalConfirmDialog::Create(
delegate_, chrome::GetActiveWebContents(browser()));
content::RunAllPendingInMessageLoop();
}
void TabModalConfirmDialogTest::CleanUpOnMainThread() {
content::RunAllPendingInMessageLoop();
}
void TabModalConfirmDialogTest::OnAccepted() {
++accepted_count_;
}
void TabModalConfirmDialogTest::OnCanceled() {
++canceled_count_;
}
IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Accept) {
dialog_->AcceptTabModalDialog();
EXPECT_EQ(1, accepted_count_);
EXPECT_EQ(0, canceled_count_);
}
IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Cancel) {
dialog_->CancelTabModalDialog();
EXPECT_EQ(0, accepted_count_);
EXPECT_EQ(1, canceled_count_);
}
IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, CancelSelf) {
delegate_->Cancel();
EXPECT_EQ(0, accepted_count_);
EXPECT_EQ(1, canceled_count_);
}
IN_PROC_BROWSER_TEST_F(TabModalConfirmDialogTest, Quit) {
MessageLoopForUI::current()->PostTask(FROM_HERE,
base::Bind(&browser::AttemptExit));
content::RunMessageLoop();
EXPECT_EQ(0, accepted_count_);
EXPECT_EQ(1, canceled_count_);
}
|