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

Unified Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2604453002: Fix WindowTreeClient::RequestClose(window_id). (Closed)
Patch Set: test Created 3 years, 11 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
« ui/aura/mus/window_tree_client.cc ('K') | « ui/aura/mus/window_tree_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/window_tree_client_unittest.cc
diff --git a/ui/aura/mus/window_tree_client_unittest.cc b/ui/aura/mus/window_tree_client_unittest.cc
index f3aeeed972f4202db40f6807baf71101df9974d6..1c22711191116bd2636adc2b0c0684f0863e5518 100644
--- a/ui/aura/mus/window_tree_client_unittest.cc
+++ b/ui/aura/mus/window_tree_client_unittest.cc
@@ -32,6 +32,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/aura/window_tracker.h"
+#include "ui/aura/window_tree_host_observer.h"
#include "ui/compositor/compositor.h"
#include "ui/display/display_switches.h"
#include "ui/events/event.h"
@@ -1131,6 +1132,75 @@ TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsProperties) {
properties2[kUnknownPropertyKey]));
}
+namespace {
+
+class CloseWindowTestWindowDelegate : public test::TestWindowDelegate {
+ public:
+ CloseWindowTestWindowDelegate() {}
+ ~CloseWindowTestWindowDelegate() override {}
+
+ bool window_closed() const { return window_closed_; }
+
+ // TestWindowDelegate::
+ void OnRequestClose() override { window_closed_ = true; }
+
+ private:
+ bool window_closed_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(CloseWindowTestWindowDelegate);
+};
+
+class CloseWindowWindowTreeHostObserver : public aura::WindowTreeHostObserver {
+ public:
+ CloseWindowWindowTreeHostObserver() {}
+ ~CloseWindowWindowTreeHostObserver() override {}
+
+ bool root_destroyed() const { return root_destroyed_; }
+
+ // aura::WindowTreeHostObserver::
+ void OnHostCloseRequested(const aura::WindowTreeHost* host) override {
+ root_destroyed_ = true;
+ }
+
+ private:
+ bool root_destroyed_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(CloseWindowWindowTreeHostObserver);
+};
+
+} // namespace
+
+TEST_F(WindowTreeClientClientTest, CloseWindow) {
+ WindowTreeHostMus window_tree_host(window_tree_client_impl());
+ window_tree_host.InitHost();
+ CloseWindowWindowTreeHostObserver observer;
+ window_tree_host.AddObserver(&observer);
+ Window* top_level = window_tree_host.window();
+
+ CloseWindowTestWindowDelegate window_delegate1;
+ Window child1(&window_delegate1);
+ child1.Init(ui::LAYER_NOT_DRAWN);
+ top_level->AddChild(&child1);
+ CloseWindowTestWindowDelegate window_delegate2;
+ Window child2(&window_delegate2);
+ child2.Init(ui::LAYER_NOT_DRAWN);
+ top_level->AddChild(&child2);
+
+ // Close a child window should only trigger its window delegate to close
+ // that window.
+ EXPECT_FALSE(window_delegate1.window_closed());
+ window_tree_client()->RequestClose(server_id(&child1));
+ EXPECT_TRUE(window_delegate1.window_closed());
+ EXPECT_FALSE(window_delegate2.window_closed());
+ EXPECT_FALSE(observer.root_destroyed());
+
+ // Close a root window should send close request to the observer of its
+ // WindowTreeHost.
+ window_tree_client()->RequestClose(server_id(top_level));
+ EXPECT_TRUE(observer.root_destroyed());
+ EXPECT_FALSE(window_delegate2.window_closed());
+}
+
// Tests both SetCapture and ReleaseCapture, to ensure that Window is properly
// updated on failures.
TEST_F(WindowTreeClientWmTest, ExplicitCapture) {
« ui/aura/mus/window_tree_client.cc ('K') | « ui/aura/mus/window_tree_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698