Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4174)

Unified Diff: ash/system/toast/toast_manager_unittest.cc

Issue 1782793002: Ash: Implement Toasts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/toast/toast_manager_unittest.cc
diff --git a/ash/system/toast/toast_manager_unittest.cc b/ash/system/toast/toast_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0765579308eb5ed465d35134db316a1923a54707
--- /dev/null
+++ b/ash/system/toast/toast_manager_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2016 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 "ash/shell.h"
+#include "ash/system/toast/toast_manager.h"
+#include "ash/test/ash_test_base.h"
+#include "base/run_loop.h"
+
+namespace ash {
+
+// Long duration so the timeout doesn't occur.
+const int64_t kLongLongDuration = INT64_MAX;
+
+class DummyEvent : public ui::Event {
+ public:
+ DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {}
+ ~DummyEvent() override {}
+};
+
+class ToastManagerTest : public test::AshTestBase {
+ public:
+ ToastManagerTest() {}
+ ~ToastManagerTest() override {}
+
+ private:
+ void SetUp() override {
+ test::AshTestBase::SetUp();
+
+ manager_ = Shell::GetInstance()->toast_manager();
+
+ manager_->ResetToastIdForTesting();
+ EXPECT_EQ(0, GetToastId());
+ }
+
+ void TearDown() override { test::AshTestBase::TearDown(); }
oshima 2016/03/11 09:40:24 this isn't necessary
yoshiki 2016/03/11 14:30:35 Done.
+
+ protected:
+ ToastManager* manager() const { return manager_; }
+
+ int GetToastId() const { return manager_->toast_id_for_testing(); }
oshima 2016/03/11 09:40:24 new line
yoshiki 2016/03/11 14:30:35 Done.
+ ToastOverlay* GetCurrentOverlay() const {
+ return manager_->GetCurrentOverlayForTesting();
+ }
oshima 2016/03/11 09:40:24 new line
yoshiki 2016/03/11 14:30:34 Done.
+ void ClickDismissButton() {
+ GetCurrentOverlay()->ClickDismissButtonForTesting(DummyEvent());
+ }
+
+ private:
+ ToastManager* manager_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(ToastManagerTest);
+};
+
+TEST_F(ToastManagerTest, ShowAndCloseAutomatically) {
+ manager()->Show("DUMMY", 10);
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_EQ(1, GetToastId());
+
+ while (GetCurrentOverlay() != nullptr)
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(ToastManagerTest, ShowAndCloseManually) {
+ manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_EQ(1, GetToastId());
+
+ ClickDismissButton();
+
+ while (GetCurrentOverlay() != nullptr)
+ base::RunLoop().RunUntilIdle();
+}
oshima 2016/03/11 09:40:24 can you also add the cases where messages are queu
yoshiki 2016/03/11 14:30:34 Done.
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698