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

Unified Diff: mojo/services/view_manager/view_manager_connection_unittest.cc

Issue 287053004: SetBounds for ViewTreeNode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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
Index: mojo/services/view_manager/view_manager_connection_unittest.cc
diff --git a/mojo/services/view_manager/view_manager_connection_unittest.cc b/mojo/services/view_manager/view_manager_connection_unittest.cc
index 063a740e2eb07da72c487f8f552939bc3d86d8a6..013be5cc9f017387cf94e5a70012e5c5a1288b71 100644
--- a/mojo/services/view_manager/view_manager_connection_unittest.cc
+++ b/mojo/services/view_manager/view_manager_connection_unittest.cc
@@ -11,6 +11,7 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "mojo/common/common_type_converters.h"
+#include "mojo/geometry/geometry_type_converters.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/shell/connect.h"
@@ -19,6 +20,7 @@
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "mojo/shell/shell_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/rect.h"
namespace mojo {
@@ -60,6 +62,15 @@ std::string NodeIdToString(TransportNodeId id) {
base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
}
+// Converts |rect| into a string.
+std::string RectToString(const Rect& rect) {
+ return base::StringPrintf("%d,%d %dx%d",
+ rect.position().x(),
+ rect.position().y(),
+ rect.size().width(),
+ rect.size().height());
+}
+
// Boolean callback. Sets |result_cache| to the value of |result| and quits
// the run loop.
void BooleanCallback(bool* result_cache, bool result) {
@@ -139,6 +150,16 @@ bool DeleteView(IViewManager* view_manager, TransportViewId view_id) {
return result;
}
+bool SetNodeBounds(IViewManager* view_manager,
+ TransportNodeId node_id,
+ const gfx::Rect& bounds) {
+ bool result = false;
+ view_manager->SetNodeBounds(node_id, bounds,
+ base::Bind(&BooleanCallback, &result));
+ DoRunLoop();
+ return result;
+}
+
// Adds a node, blocking until done.
bool AddNode(IViewManager* view_manager,
TransportNodeId parent,
@@ -270,6 +291,17 @@ class ViewManagerClientImpl : public IViewManagerClient {
static_cast<int>(next_server_change_id)));
QuitIfNecessary();
}
+ virtual void OnNodeBoundsChanged(TransportNodeId node_id,
+ const Rect& old_bounds,
+ const Rect& new_bounds) {
+ changes_.push_back(
+ base::StringPrintf(
+ "BoundsChanged node=%s old_bounds=%s new_bounds=%s",
+ NodeIdToString(node_id).c_str(),
+ RectToString(old_bounds).c_str(),
+ RectToString(new_bounds).c_str()));
+ QuitIfNecessary();
+ }
virtual void OnNodeHierarchyChanged(
TransportNodeId node,
TransportNodeId new_parent,
@@ -1128,6 +1160,26 @@ TEST_F(ViewManagerConnectionTest, GetNodeTree) {
}
}
+TEST_F(ViewManagerConnectionTest, SetNodeBounds) {
+ ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1));
+ ASSERT_TRUE(AddNode(view_manager_.get(),
+ CreateNodeId(0, 1),
+ CreateNodeId(1, 1),
+ 1));
+ EstablishSecondConnection();
+
+ AllocationScope scope;
+ ASSERT_TRUE(SetNodeBounds(view_manager_.get(),
+ CreateNodeId(1, 1),
+ gfx::Rect(0, 0, 100, 100)));
+
+ client2_.DoRunLoopUntilChangesCount(1);
+ Changes changes(client2_.GetAndClearChanges());
+ ASSERT_EQ(1u, changes.size());
+ EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100",
+ changes[0]);
+}
+
TEST_F(ViewManagerConnectionTest, SetRoots) {
// Create 1, 2, and 3 in the first connection.
ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1));

Powered by Google App Engine
This is Rietveld 408576698