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

Unified Diff: ui/arc/notification/arc_custom_notification_view_unittest.cc

Issue 2723143002: Add unittests of ArcCustomNotificationView (Closed)
Patch Set: wip Created 3 years, 7 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
« no previous file with comments | « ui/arc/BUILD.gn ('k') | ui/arc/notification/arc_notification_content_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/arc/notification/arc_custom_notification_view_unittest.cc
diff --git a/ui/arc/notification/arc_custom_notification_view_unittest.cc b/ui/arc/notification/arc_custom_notification_view_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c99ec92bc29e789d118548b19b0ea7c50c99766
--- /dev/null
+++ b/ui/arc/notification/arc_custom_notification_view_unittest.cc
@@ -0,0 +1,247 @@
+// 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 <memory>
+
+#include "base/strings/utf_string_conversions.h"
+#include "ui/arc/notification/arc_notification_content_view.h"
+#include "ui/arc/notification/arc_notification_delegate.h"
+#include "ui/arc/notification/arc_notification_item.h"
+#include "ui/arc/notification/arc_notification_surface.h"
+#include "ui/arc/notification/arc_notification_view.h"
+#include "ui/message_center/notification.h"
+#include "ui/message_center/views/message_center_controller.h"
+#include "ui/message_center/views/message_view_factory.h"
+#include "ui/views/controls/button/image_button.h"
+#include "ui/views/test/views_test_base.h"
+
+namespace arc {
+
+namespace {
+
+class MockNotificationSurface : public ArcNotificationSurface {
+ public:
+ MockNotificationSurface(const std::string& notification_id,
+ aura::Window* window)
+ : notification_id_(notification_id), window_(window) {}
+
+ gfx::Size GetSize() const override { return gfx::Size(100, 200); }
+
+ void AttachWindow(views::NativeViewHost* nvh) override {}
+
+ aura::Window* GetWindow() const override { return window_; }
+
+ const std::string& GetNotificationId() const override {
+ return notification_id_;
+ }
+
+ private:
+ std::string notification_id_;
+ aura::Window* window_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockNotificationSurface);
+};
+
+} // anonymous namespace
+
+class MockArcNotificationItem : public ArcNotificationItem {
+ public:
+ MockArcNotificationItem(const std::string& notification_id)
+ : notification_id_(notification_id), weak_factory_(this) {}
+
+ void OnUpdatedFromAndroid(mojom::ArcNotificationDataPtr data) override {}
+
+ void OnClosedFromAndroid() override {}
+
+ void Close(bool by_user) override { count_close_++; }
+ size_t count_close() { return count_close_; }
+
+ void Click() override {}
+ void ToggleExpansion() override {}
+ bool IsOpeningSettingsSupported() const override { return true; }
+ mojom::ArcNotificationExpandState GetExpandState() const override {
+ return mojom::ArcNotificationExpandState::FIXED_SIZE;
+ }
+ mojom::ArcNotificationShownContents GetShownContents() const override {
+ return mojom::ArcNotificationShownContents::CONTENTS_SHOWN;
+ }
+
+ const base::string16& GetAccessibleName() const override {
+ return base::EmptyString16();
+ };
+ void OpenSettings() override {}
+
+ void AddObserver(Observer* observer) override {}
+ void RemoveObserver(Observer* observer) override {}
+
+ void IncrementWindowRefCount() override {}
+ void DecrementWindowRefCount() override {}
+ bool GetPinned() const override { return false; }
+ const gfx::ImageSkia& GetSnapshot() const override { return snapshot_; }
+
+ const std::string& GetNotificationKey() const override {
+ return notification_key_;
+ }
+ const std::string& GetNotificationId() const override {
+ return notification_id_;
+ }
+
+ base::WeakPtr<MockArcNotificationItem> GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+ }
+
+ private:
+ std::string notification_id_;
+ std::string notification_key_;
+ gfx::ImageSkia snapshot_;
+ size_t count_close_ = 0;
+
+ base::WeakPtrFactory<MockArcNotificationItem> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockArcNotificationItem);
+};
+
+class TestMessageCenterController
+ : public message_center::MessageCenterController {
+ public:
+ TestMessageCenterController() {}
+
+ // MessageCenterController
+ void ClickOnNotification(const std::string& notification_id) override {
+ // For this test, this method should not be invoked.
+ NOTREACHED();
+ }
+
+ void RemoveNotification(const std::string& notification_id,
+ bool by_user) override {
+ removed_ids_.insert(notification_id);
+ }
+
+ std::unique_ptr<ui::MenuModel> CreateMenuModel(
+ const message_center::NotifierId& notifier_id,
+ const base::string16& display_source) override {
+ // For this test, this method should not be invoked.
+ NOTREACHED();
+ return nullptr;
+ }
+
+ bool HasClickedListener(const std::string& notification_id) override {
+ return false;
+ }
+
+ void ClickOnNotificationButton(const std::string& notification_id,
+ int button_index) override {
+ // For this test, this method should not be invoked.
+ NOTREACHED();
+ }
+
+ void ClickOnSettingsButton(const std::string& notification_id) override {
+ // For this test, this method should not be invoked.
+ NOTREACHED();
+ }
+
+ void UpdateNotificationSize(const std::string& notification_id) override {}
+
+ bool IsRemoved(const std::string& notification_id) const {
+ return (removed_ids_.find(notification_id) != removed_ids_.end());
+ }
+
+ private:
+ std::set<std::string> removed_ids_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestMessageCenterController);
+};
+
+class DummyEvent : public ui::Event {
+ public:
+ DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {}
+ ~DummyEvent() override {}
+};
+
+class ArcNotificationContentViewTest : public views::ViewsTestBase {
+ public:
+ ArcNotificationContentViewTest() {}
+ ~ArcNotificationContentViewTest() override {}
+
+ void SetUp() override {
+ std::string notification_id("notification id");
+
+ views::ViewsTestBase::SetUp();
+ notification_item_.reset(new MockArcNotificationItem(notification_id));
+
+ notification_delegate_ =
+ new ArcNotificationDelegate(notification_item_->GetWeakPtr());
+
+ notification_.reset(new message_center::Notification(
+ message_center::NOTIFICATION_TYPE_CUSTOM, notification_id,
+ base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message"), gfx::Image(),
+ base::UTF8ToUTF16("display source"), GURL(),
+ message_center::NotifierId(message_center::NotifierId::APPLICATION,
+ "extension_id"),
+ message_center::RichNotificationData(), notification_delegate_.get()));
+
+ notification_view_.reset(static_cast<ArcNotificationView*>(
+ message_center::MessageViewFactory::Create(controller(), *notification_,
+ true)));
+ notification_view_->set_owned_by_client();
+
+ views::Widget::InitParams init_params(
+ CreateParams(views::Widget::InitParams::TYPE_POPUP));
+ views::Widget* widget = new views::Widget();
+ widget->Init(init_params);
+
+ surface_ =
+ new MockNotificationSurface(notification_id, widget->GetNativeWindow());
+ GetArcNotificationContentView()->OnNotificationSurfaceAdded(surface_);
+
+ widget->SetContentsView(notification_view_.get());
+ widget->SetSize(notification_view_->GetPreferredSize());
+ }
+
+ void TearDown() override {
+ GetArcNotificationContentView()->OnNotificationSurfaceRemoved(surface_);
+ widget()->Close();
+ notification_view_.reset();
+ views::ViewsTestBase::TearDown();
+ }
+
+ void PressCloseButton() {
+ DummyEvent dummy_event;
+ views::ImageButton* close_button =
+ GetArcNotificationContentView()->close_button_.get();
+ ASSERT_NE(nullptr, close_button);
+ GetArcNotificationContentView()->ButtonPressed(close_button, dummy_event);
+ }
+
+ TestMessageCenterController* controller() { return &controller_; }
+ views::Widget* widget() { return notification_view_->GetWidget(); }
+
+ ArcNotificationContentView* GetArcNotificationContentView() {
+ views::View* view = notification_view_->contents_view_;
+ EXPECT_EQ(ArcNotificationContentView::kViewClassName, view->GetClassName());
+ return static_cast<ArcNotificationContentView*>(view);
+ }
+
+ MockArcNotificationItem* notification_item() const {
+ return notification_item_.get();
+ }
+
+ private:
+ MockNotificationSurface* surface_;
+ TestMessageCenterController controller_;
+ scoped_refptr<ArcNotificationDelegate> notification_delegate_;
+ std::unique_ptr<message_center::Notification> notification_;
+ std::unique_ptr<ArcNotificationView> notification_view_;
+ std::unique_ptr<MockArcNotificationItem> notification_item_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcNotificationContentViewTest);
+};
+
+TEST_F(ArcNotificationContentViewTest, CloseButton) {
+ EXPECT_EQ(0u, notification_item()->count_close());
+ PressCloseButton();
+ EXPECT_EQ(1u, notification_item()->count_close());
+}
+
+} // namespace arc
« no previous file with comments | « ui/arc/BUILD.gn ('k') | ui/arc/notification/arc_notification_content_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698