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

Unified Diff: ui/message_center/views/notifier_settings_view_unittest.cc

Issue 2574583005: Remove stl_util's deletion function use from message center notifier settings. (Closed)
Patch Set: nits Created 4 years 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/message_center/views/notifier_settings_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/notifier_settings_view_unittest.cc
diff --git a/ui/message_center/views/notifier_settings_view_unittest.cc b/ui/message_center/views/notifier_settings_view_unittest.cc
index 9be54ac5ac11446130320924b509140584d74d9b..0fdd487582094dacdf77f3527d4653ed973f04f3 100644
--- a/ui/message_center/views/notifier_settings_view_unittest.cc
+++ b/ui/message_center/views/notifier_settings_view_unittest.cc
@@ -5,9 +5,10 @@
#include <stddef.h>
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/message_center/fake_notifier_settings_provider.h"
+#include "ui/message_center/notifier_settings.h"
#include "ui/message_center/views/notifier_settings_view.h"
#include "ui/views/test/views_test_base.h"
@@ -15,28 +16,57 @@ namespace message_center {
namespace {
-Notifier* NewNotifier(const std::string& id,
- const std::string& title,
- bool enabled) {
- NotifierId notifier_id(NotifierId::APPLICATION, id);
- return new Notifier(notifier_id, base::UTF8ToUTF16(title), enabled);
-}
-
// A class used by NotifierSettingsView to integrate with a setting system
// for the clients of this module.
-class TestingNotifierSettingsProvider
- : public FakeNotifierSettingsProvider {
+class TestingNotifierSettingsProvider : public NotifierSettingsProvider {
public:
- TestingNotifierSettingsProvider(const std::vector<Notifier*>& notifiers,
- const NotifierId& settings_handler_id)
- : FakeNotifierSettingsProvider(notifiers),
- settings_handler_id_(settings_handler_id),
- request_count_(0u) {}
- ~TestingNotifierSettingsProvider() override {}
+ ~TestingNotifierSettingsProvider() override = default;
+
+ size_t request_count() const { return request_count_; }
+ const NotifierId* last_requested_notifier_id() const {
+ return last_notifier_id_settings_requested_.get();
+ }
+
+ // NotifierSettingsProvider
+
+ void AddObserver(NotifierSettingsObserver* observer) override {}
+ void RemoveObserver(NotifierSettingsObserver* observer) override {}
+
+ size_t GetNotifierGroupCount() const override { return 1; }
+
+ const message_center::NotifierGroup& GetNotifierGroupAt(
+ size_t index) const override {
+ DCHECK_EQ(0u, index);
+ return GetActiveNotifierGroup();
+ }
+
+ bool IsNotifierGroupActiveAt(size_t index) const override {
+ return index == 0;
+ }
+
+ void SwitchToNotifierGroup(size_t index) override { NOTREACHED(); }
+
+ const message_center::NotifierGroup& GetActiveNotifierGroup() const override {
+ static NotifierGroup group{base::UTF8ToUTF16("Fake name"),
+ base::UTF8ToUTF16("fake@email.com")};
+ return group;
+ }
+
+ void GetNotifierList(
+ std::vector<std::unique_ptr<Notifier>>* notifiers) override {
+ notifiers->clear();
+ notifiers->push_back(NewNotifier("id", "title", /*enabled=*/true));
+ notifiers->push_back(NewNotifier("id2", "other title", /*enabled=*/false));
+ }
+
+ void SetNotifierEnabled(const Notifier& notifier, bool enabled) override {}
+
+ // Called when the settings window is closed.
+ void OnNotifierSettingsClosing() override {}
bool NotifierHasAdvancedSettings(
const NotifierId& notifier_id) const override {
- return notifier_id == settings_handler_id_;
+ return notifier_id == NotifierId(NotifierId::APPLICATION, "id");
}
void OnNotifierAdvancedSettingsRequested(
@@ -46,14 +76,16 @@ class TestingNotifierSettingsProvider
last_notifier_id_settings_requested_.reset(new NotifierId(notifier_id));
}
- size_t request_count() const { return request_count_; }
- const NotifierId* last_requested_notifier_id() const {
- return last_notifier_id_settings_requested_.get();
+ private:
+ std::unique_ptr<Notifier> NewNotifier(const std::string& id,
+ const std::string& title,
+ bool enabled) {
+ NotifierId notifier_id(NotifierId::APPLICATION, id);
+ return base::MakeUnique<Notifier>(notifier_id, base::UTF8ToUTF16(title),
+ enabled);
}
- private:
- NotifierId settings_handler_id_;
- size_t request_count_;
+ size_t request_count_ = 0u;
std::unique_ptr<NotifierId> last_notifier_id_settings_requested_;
};
@@ -68,35 +100,29 @@ class NotifierSettingsViewTest : public views::ViewsTestBase {
void TearDown() override;
NotifierSettingsView* GetView() const;
- TestingNotifierSettingsProvider* settings_provider() const {
- return settings_provider_.get();
+ const TestingNotifierSettingsProvider* settings_provider() const {
+ return &settings_provider_;
}
private:
- std::unique_ptr<TestingNotifierSettingsProvider> settings_provider_;
+ TestingNotifierSettingsProvider settings_provider_;
std::unique_ptr<NotifierSettingsView> notifier_settings_view_;
DISALLOW_COPY_AND_ASSIGN(NotifierSettingsViewTest);
};
-NotifierSettingsViewTest::NotifierSettingsViewTest() {}
+NotifierSettingsViewTest::NotifierSettingsViewTest() = default;
-NotifierSettingsViewTest::~NotifierSettingsViewTest() {}
+NotifierSettingsViewTest::~NotifierSettingsViewTest() = default;
void NotifierSettingsViewTest::SetUp() {
views::ViewsTestBase::SetUp();
- std::vector<Notifier*> notifiers;
- notifiers.push_back(NewNotifier("id", "title", /*enabled=*/true));
- notifiers.push_back(NewNotifier("id2", "other title", /*enabled=*/false));
- settings_provider_.reset(new TestingNotifierSettingsProvider(
- notifiers, NotifierId(NotifierId::APPLICATION, "id")));
- notifier_settings_view_.reset(
- new NotifierSettingsView(settings_provider_.get()));
+ notifier_settings_view_ =
+ base::MakeUnique<NotifierSettingsView>(&settings_provider_);
}
void NotifierSettingsViewTest::TearDown() {
notifier_settings_view_.reset();
- settings_provider_.reset();
views::ViewsTestBase::TearDown();
}
@@ -105,16 +131,14 @@ NotifierSettingsView* NotifierSettingsViewTest::GetView() const {
}
TEST_F(NotifierSettingsViewTest, TestLearnMoreButton) {
- const std::set<NotifierSettingsView::NotifierButton*> buttons =
+ const std::set<NotifierSettingsView::NotifierButton*>& buttons =
GetView()->buttons_;
EXPECT_EQ(2u, buttons.size());
size_t number_of_settings_buttons = 0;
- std::set<NotifierSettingsView::NotifierButton*>::iterator iter =
- buttons.begin();
- for (; iter != buttons.end(); ++iter) {
- if ((*iter)->has_learn_more()) {
+ for (auto* button : buttons) {
+ if (button->has_learn_more()) {
++number_of_settings_buttons;
- (*iter)->SendLearnMorePressedForTest();
+ button->SendLearnMorePressedForTest();
}
}
@@ -122,7 +146,7 @@ TEST_F(NotifierSettingsViewTest, TestLearnMoreButton) {
EXPECT_EQ(1u, settings_provider()->request_count());
const NotifierId* last_settings_button_id =
settings_provider()->last_requested_notifier_id();
- ASSERT_FALSE(last_settings_button_id == NULL);
+ ASSERT_FALSE(last_settings_button_id == nullptr);
EXPECT_EQ(NotifierId(NotifierId::APPLICATION, "id"),
*last_settings_button_id);
}
« no previous file with comments | « ui/message_center/views/notifier_settings_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698