Chromium Code Reviews| 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 "base/timer/mock_timer.h" | |
| 8 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 11 #include "chrome/browser/ui/test/test_browser_dialog.h" | |
| 12 #include "chrome/browser/ui/views/profiles/force_signout_dialog.h" | |
|
sky
2017/06/05 23:43:19
This should be your first include, then newline, t
zmin
2017/06/06 21:00:44
Done.
| |
| 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() {} | |
|
sky
2017/06/05 23:43:19
use base::DoNothing() (in bind_helpers).
zmin
2017/06/06 21:00:44
Done.
| |
| 19 } // namespace | |
| 20 | |
| 21 class ForceSignoutDialogBrowserTest : public DialogBrowserTest { | |
| 22 public: | |
| 23 ForceSignoutDialogBrowserTest() {} | |
| 24 | |
| 25 void SetUp() override { | |
| 26 timer_ = base::MakeUnique<base::MockTimer>(false, false); | |
| 27 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(1), | |
| 28 base::Bind(&FakeFunction)); | |
| 29 DialogBrowserTest::SetUp(); | |
| 30 } | |
| 31 | |
| 32 void TearDown() override { | |
| 33 timer_->Stop(); | |
| 34 DialogBrowserTest::TearDown(); | |
| 35 } | |
| 36 | |
| 37 // override DialogBrowserTest | |
| 38 void ShowDialog(const std::string& name) override { | |
| 39 Profile* profile = browser()->profile(); | |
| 40 SigninManager* manager = SigninManagerFactory::GetForProfile(profile); | |
| 41 manager->SetAuthenticatedAccountInfo("test1", "test@xyz.com"); | |
| 42 ForceSignoutDialog::ShowDialog(profile, manager, timer_.get()); | |
| 43 } | |
| 44 | |
| 45 std::unique_ptr<base::MockTimer> timer_; | |
| 46 | |
| 47 // An integer represents the buttons of dialog. | |
| 48 | |
| 49 private: | |
| 50 DISALLOW_COPY_AND_ASSIGN(ForceSignoutDialogBrowserTest); | |
| 51 }; | |
| 52 | |
| 53 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_default) { | |
| 54 RunDialog(); | |
| 55 ASSERT_TRUE(timer_->IsRunning()); | |
| 56 } | |
| 57 | |
| 58 // Dialog will not be display if there is no valid browser window. | |
| 59 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, | |
| 60 NotOpenDialogDueToNoBrowser) { | |
| 61 Profile* profile = browser()->profile(); | |
| 62 CloseBrowserSynchronously(browser()); | |
| 63 EXPECT_EQ(nullptr, ForceSignoutDialog::ShowDialog( | |
| 64 profile, SigninManagerFactory::GetForProfile(profile), | |
| 65 timer_.get())); | |
| 66 ASSERT_FALSE(timer_->IsRunning()); | |
| 67 } | |
| 68 | |
| 69 IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, | |
| 70 NotOpenDialogDueToNoTabs) { | |
| 71 Profile* profile = browser()->profile(); | |
| 72 TabStripModel* model = browser()->tab_strip_model(); | |
| 73 ASSERT_EQ(1, model->count()); | |
| 74 model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | |
| 75 ASSERT_TRUE(model->empty()); | |
| 76 EXPECT_EQ(nullptr, ForceSignoutDialog::ShowDialog( | |
| 77 profile, SigninManagerFactory::GetForProfile(profile), | |
| 78 timer_.get())); | |
| 79 ASSERT_FALSE(timer_->IsRunning()); | |
| 80 } | |
| OLD | NEW |