OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/memory/ptr_util.h" |
| 7 #include "chrome/browser/signin/signin_manager_factory.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 11 #include "chrome/browser/ui/views/profiles/force_signout_dialog.h" |
| 12 #include "chrome/browser/ui/views/profiles/force_signout_dialog_view.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "components/signin/core/browser/signin_manager.h" |
| 15 #include "ui/base/ui_base_types.h" |
| 16 |
| 17 namespace { |
| 18 void FakeFunction() {} |
| 19 } // namespace |
| 20 |
| 21 class ForceSignoutDialogBrowserTest : public DialogBrowserTest { |
| 22 public: |
| 23 void SetUp() override { |
| 24 DialogBrowserTest::SetUp(); |
| 25 buttons = -1; |
| 26 } |
| 27 |
| 28 // DialogBrowserTest |
| 29 void ShowDialog(const std::string& name) override { |
| 30 Profile* profile = browser()->profile(); |
| 31 SigninManager* manager = SigninManagerFactory::GetForProfile(profile); |
| 32 manager->SetAuthenticatedAccountInfo("test1", "test@xyz.com"); |
| 33 base::Closure callback = base::Bind(&FakeFunction); |
| 34 if (name == "nodelay") |
| 35 callback = base::Closure(); |
| 36 ForceSignoutDialog::ShowDialog(profile, manager, callback); |
| 37 buttons = ForceSignoutDialog::GetDialogViewForTesting()->GetDialogButtons(); |
| 38 } |
| 39 |
| 40 int buttons; |
| 41 }; |
| 42 |
| 43 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_default) { |
| 44 RunDialog(); |
| 45 ASSERT_EQ(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, buttons); |
| 46 } |
| 47 |
| 48 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_nodelay) { |
| 49 RunDialog(); |
| 50 ASSERT_EQ(ui::DIALOG_BUTTON_OK, buttons); |
| 51 } |
| 52 |
| 53 // Dialog will not be display if there is no valid browser window. |
| 54 |
| 55 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
| 56 NotOpenDialogDueToNoBrowser) { |
| 57 ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| 58 Profile* profile = browser()->profile(); |
| 59 CloseBrowserSynchronously(browser()); |
| 60 ForceSignoutDialog::ShowDialog( |
| 61 profile, SigninManagerFactory::GetForProfile(profile), base::Closure()); |
| 62 ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| 63 } |
| 64 |
| 65 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
| 66 NotOpenDialogDueToNoTabs) { |
| 67 ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| 68 Profile* profile = browser()->profile(); |
| 69 TabStripModel* model = browser()->tab_strip_model(); |
| 70 ASSERT_EQ(1, model->count()); |
| 71 model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 72 ASSERT_TRUE(model->empty()); |
| 73 ForceSignoutDialog::ShowDialog( |
| 74 profile, SigninManagerFactory::GetForProfile(profile), base::Closure()); |
| 75 ASSERT_FALSE(BrowserModalDialogList::GetInstance()->IsShowing()); |
| 76 } |
OLD | NEW |