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

Unified Diff: components/mus/ws/focus_controller_unittest.cc

Issue 1465143004: Converts focusmanager from delegate to observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 1 month 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 | « components/mus/ws/focus_controller_observer.h ('k') | components/mus/ws/window_tree_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/focus_controller_unittest.cc
diff --git a/components/mus/ws/focus_controller_unittest.cc b/components/mus/ws/focus_controller_unittest.cc
index 5c97936b0513476ad1f5bf2c4ca6d8c714cc8e1a..7e9cdf800e4534583bcfe610209b415adba51d2d 100644
--- a/components/mus/ws/focus_controller_unittest.cc
+++ b/components/mus/ws/focus_controller_unittest.cc
@@ -4,7 +4,7 @@
#include "components/mus/ws/focus_controller.h"
-#include "components/mus/ws/focus_controller_delegate.h"
+#include "components/mus/ws/focus_controller_observer.h"
#include "components/mus/ws/server_window.h"
#include "components/mus/ws/test_server_window_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,9 +14,9 @@ namespace mus {
namespace ws {
namespace {
-class TestFocusControllerDelegate : public FocusControllerDelegate {
+class TestFocusControllerObserver : public FocusControllerObserver {
public:
- TestFocusControllerDelegate()
+ TestFocusControllerObserver()
: change_count_(0u),
old_focused_window_(nullptr),
new_focused_window_(nullptr) {}
@@ -31,9 +31,13 @@ class TestFocusControllerDelegate : public FocusControllerDelegate {
ServerWindow* new_focused_window() { return new_focused_window_; }
private:
- // FocusControllerDelegate:
- void OnFocusChanged(ServerWindow* old_focused_window,
+ // FocusControllerObserver:
+ void OnFocusChanged(FocusControllerChangeSource source,
+ ServerWindow* old_focused_window,
ServerWindow* new_focused_window) override {
+ if (source == FocusControllerChangeSource::EXPLICIT)
+ return;
+
change_count_++;
old_focused_window_ = old_focused_window;
new_focused_window_ = new_focused_window;
@@ -43,7 +47,7 @@ class TestFocusControllerDelegate : public FocusControllerDelegate {
ServerWindow* old_focused_window_;
ServerWindow* new_focused_window_;
- DISALLOW_COPY_AND_ASSIGN(TestFocusControllerDelegate);
+ DISALLOW_COPY_AND_ASSIGN(TestFocusControllerObserver);
};
} // namespace
@@ -60,50 +64,52 @@ TEST(FocusControllerTest, Basic) {
child_child.SetVisible(true);
child.Add(&child_child);
- TestFocusControllerDelegate focus_delegate;
- FocusController focus_controller(&focus_delegate);
+ TestFocusControllerObserver focus_observer;
+ FocusController focus_controller;
+ focus_controller.AddObserver(&focus_observer);
focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_delegate.change_count());
+ EXPECT_EQ(0u, focus_observer.change_count());
// Remove the ancestor of the focused window, focus should go to the |root|.
root.Remove(&child);
- EXPECT_EQ(1u, focus_delegate.change_count());
- EXPECT_EQ(&root, focus_delegate.new_focused_window());
- EXPECT_EQ(&child_child, focus_delegate.old_focused_window());
- focus_delegate.ClearAll();
+ EXPECT_EQ(1u, focus_observer.change_count());
+ EXPECT_EQ(&root, focus_observer.new_focused_window());
+ EXPECT_EQ(&child_child, focus_observer.old_focused_window());
+ focus_observer.ClearAll();
// Make the focused window invisible. Focus is lost in this case (as no one
// to give focus to).
root.SetVisible(false);
- EXPECT_EQ(1u, focus_delegate.change_count());
- EXPECT_EQ(nullptr, focus_delegate.new_focused_window());
- EXPECT_EQ(&root, focus_delegate.old_focused_window());
- focus_delegate.ClearAll();
+ EXPECT_EQ(1u, focus_observer.change_count());
+ EXPECT_EQ(nullptr, focus_observer.new_focused_window());
+ EXPECT_EQ(&root, focus_observer.old_focused_window());
+ focus_observer.ClearAll();
// Go back to initial state and focus |child_child|.
root.SetVisible(true);
root.Add(&child);
focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_delegate.change_count());
+ EXPECT_EQ(0u, focus_observer.change_count());
// Hide the focused window, focus should go to parent.
child_child.SetVisible(false);
- EXPECT_EQ(1u, focus_delegate.change_count());
- EXPECT_EQ(&child, focus_delegate.new_focused_window());
- EXPECT_EQ(&child_child, focus_delegate.old_focused_window());
- focus_delegate.ClearAll();
+ EXPECT_EQ(1u, focus_observer.change_count());
+ EXPECT_EQ(&child, focus_observer.new_focused_window());
+ EXPECT_EQ(&child_child, focus_observer.old_focused_window());
+ focus_observer.ClearAll();
child_child.SetVisible(true);
focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_delegate.change_count());
+ EXPECT_EQ(0u, focus_observer.change_count());
// Hide the parent of the focused window.
child.SetVisible(false);
- EXPECT_EQ(1u, focus_delegate.change_count());
- EXPECT_EQ(&root, focus_delegate.new_focused_window());
- EXPECT_EQ(&child_child, focus_delegate.old_focused_window());
- focus_delegate.ClearAll();
+ EXPECT_EQ(1u, focus_observer.change_count());
+ EXPECT_EQ(&root, focus_observer.new_focused_window());
+ EXPECT_EQ(&child_child, focus_observer.old_focused_window());
+ focus_observer.ClearAll();
+ focus_controller.RemoveObserver(&focus_observer);
}
} // namespace ws
« no previous file with comments | « components/mus/ws/focus_controller_observer.h ('k') | components/mus/ws/window_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698