Chromium Code Reviews| Index: chrome/browser/ui/views/profiles/force_signout_dialog_browsertest.cc |
| diff --git a/chrome/browser/ui/views/profiles/force_signout_dialog_browsertest.cc b/chrome/browser/ui/views/profiles/force_signout_dialog_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..05f465bc8ed9971318cf053d9474d5c4b5938070 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/profiles/force_signout_dialog_browsertest.cc |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2017 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 "base/bind.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/test/test_browser_dialog.h" |
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog.h" |
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog_view.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "components/signin/core/browser/signin_manager.h" |
| +#include "ui/base/ui_base_types.h" |
| + |
| +namespace { |
| +void FakeFunction() {} |
| +} // namespace |
| + |
| +class ForceSignoutDialogBrowserTest : public DialogBrowserTest { |
| + public: |
| + void SetUp() override { |
| + DialogBrowserTest::SetUp(); |
| + buttons = -1; |
| + } |
| + |
| + // DialogBrowserTest |
| + void ShowDialog(const std::string& name) override { |
| + Profile* profile = browser()->profile(); |
| + SigninManager* manager = SigninManagerFactory::GetForProfile(profile); |
| + manager->SetAuthenticatedAccountInfo("test1", "test@xyz.com"); |
| + base::Closure callback = base::Bind(&FakeFunction); |
| + if (name == "nodelay") |
| + callback = base::Closure(); |
| + ForceSignoutDialog* dialog = |
| + ForceSignoutDialog::ShowDialog(profile, manager, callback); |
| + buttons = dialog->GetDialogViewForTesting()->GetDialogButtons(); |
| + } |
| + |
| + int buttons; |
|
sky
2017/05/17 18:03:18
buttons_ (and document what it is).
zmin
2017/05/18 03:31:18
Done.
|
| +}; |
|
sky
2017/05/17 18:03:18
DISALLOW...
zmin
2017/05/18 03:31:18
Done.
|
| + |
| +IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_default) { |
| + RunDialog(); |
| + ASSERT_EQ(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, buttons); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_nodelay) { |
| + RunDialog(); |
| + ASSERT_EQ(ui::DIALOG_BUTTON_OK, buttons); |
| +} |
| + |
| +// Dialog will not be display if there is no valid browser window. |
| + |
| +IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
| + NotOpenDialogDueToNoBrowser) { |
| + ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| + Profile* profile = browser()->profile(); |
| + CloseBrowserSynchronously(browser()); |
| + ForceSignoutDialog::ShowDialog( |
| + profile, SigninManagerFactory::GetForProfile(profile), base::Closure()); |
| + ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
| + NotOpenDialogDueToNoTabs) { |
| + ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| + Profile* profile = browser()->profile(); |
| + TabStripModel* model = browser()->tab_strip_model(); |
| + ASSERT_EQ(1, model->count()); |
| + model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| + ASSERT_TRUE(model->empty()); |
| + ForceSignoutDialog::ShowDialog( |
| + profile, SigninManagerFactory::GetForProfile(profile), base::Closure()); |
| + ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| +} |