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..ccd6f30f75ee1d7a449f4f567f66ded7515ec3ee |
--- /dev/null |
+++ b/chrome/browser/ui/views/profiles/force_signout_dialog_browsertest.cc |
@@ -0,0 +1,80 @@ |
+// 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 "base/timer/mock_timer.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" |
sky
2017/06/05 23:43:19
This should be your first include, then newline, t
zmin
2017/06/06 21:00:44
Done.
|
+#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() {} |
sky
2017/06/05 23:43:19
use base::DoNothing() (in bind_helpers).
zmin
2017/06/06 21:00:44
Done.
|
+} // namespace |
+ |
+class ForceSignoutDialogBrowserTest : public DialogBrowserTest { |
+ public: |
+ ForceSignoutDialogBrowserTest() {} |
+ |
+ void SetUp() override { |
+ timer_ = base::MakeUnique<base::MockTimer>(false, false); |
+ timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(1), |
+ base::Bind(&FakeFunction)); |
+ DialogBrowserTest::SetUp(); |
+ } |
+ |
+ void TearDown() override { |
+ timer_->Stop(); |
+ DialogBrowserTest::TearDown(); |
+ } |
+ |
+ // override DialogBrowserTest |
+ void ShowDialog(const std::string& name) override { |
+ Profile* profile = browser()->profile(); |
+ SigninManager* manager = SigninManagerFactory::GetForProfile(profile); |
+ manager->SetAuthenticatedAccountInfo("test1", "test@xyz.com"); |
+ ForceSignoutDialog::ShowDialog(profile, manager, timer_.get()); |
+ } |
+ |
+ std::unique_ptr<base::MockTimer> timer_; |
+ |
+ // An integer represents the buttons of dialog. |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ForceSignoutDialogBrowserTest); |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, InvokeDialog_default) { |
+ RunDialog(); |
+ ASSERT_TRUE(timer_->IsRunning()); |
+} |
+ |
+// Dialog will not be display if there is no valid browser window. |
+IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
+ NotOpenDialogDueToNoBrowser) { |
+ Profile* profile = browser()->profile(); |
+ CloseBrowserSynchronously(browser()); |
+ EXPECT_EQ(nullptr, ForceSignoutDialog::ShowDialog( |
+ profile, SigninManagerFactory::GetForProfile(profile), |
+ timer_.get())); |
+ ASSERT_FALSE(timer_->IsRunning()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ForceSignoutDialogBrowserTest, |
+ NotOpenDialogDueToNoTabs) { |
+ 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()); |
+ EXPECT_EQ(nullptr, ForceSignoutDialog::ShowDialog( |
+ profile, SigninManagerFactory::GetForProfile(profile), |
+ timer_.get())); |
+ ASSERT_FALSE(timer_->IsRunning()); |
+} |