Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / mojo / services / public / cpp / view_manager / tests / view_manager_unittest.cc
index 1e07b92..620307e 100644 (file)
@@ -13,6 +13,7 @@
 #include "mojo/public/cpp/application/application_impl.h"
 #include "mojo/public/cpp/application/service_provider_impl.h"
 #include "mojo/public/interfaces/application/service_provider.mojom.h"
+#include "mojo/services/public/cpp/geometry/geometry_util.h"
 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
 #include "mojo/services/public/cpp/view_manager/lib/view_private.h"
 #include "mojo/services/public/cpp/view_manager/util.h"
@@ -23,6 +24,7 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace mojo {
+
 namespace {
 
 const char kWindowManagerURL[] = "mojo:window_manager";
@@ -49,19 +51,19 @@ class ConnectApplicationLoader : public ApplicationLoader,
 
   explicit ConnectApplicationLoader(const LoadedCallback& callback)
       : callback_(callback) {}
-  virtual ~ConnectApplicationLoader() {}
+  ~ConnectApplicationLoader() override {}
 
  private:
   // Overridden from ApplicationDelegate:
-  virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+  void Initialize(ApplicationImpl* app) override {
     view_manager_client_factory_.reset(
         new ViewManagerClientFactory(app->shell(), this));
   }
 
   // Overridden from ApplicationLoader:
-  virtual void Load(ApplicationManager* manager,
-                    const GURL& url,
-                    scoped_refptr<LoadCallbacks> callbacks) OVERRIDE {
+  void Load(ApplicationManager* manager,
+            const GURL& url,
+            scoped_refptr<LoadCallbacks> callbacks) override {
     ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
     if (!shell_handle.is_valid())
       return;
@@ -70,23 +72,22 @@ class ConnectApplicationLoader : public ApplicationLoader,
     apps_.push_back(app.release());
   }
 
-  virtual void OnApplicationError(ApplicationManager* manager,
-                                  const GURL& url) OVERRIDE {}
+  void OnApplicationError(ApplicationManager* manager,
+                          const GURL& url) override {}
 
-  virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
-      OVERRIDE {
+  bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
     connection->AddService(view_manager_client_factory_.get());
     return true;
   }
 
   // Overridden from ViewManagerDelegate:
-  virtual void OnEmbed(ViewManager* view_manager,
-                       View* root,
-                       ServiceProviderImpl* exported_services,
-                       scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
+  void OnEmbed(ViewManager* view_manager,
+               View* root,
+               ServiceProviderImpl* exported_services,
+               scoped_ptr<ServiceProvider> imported_services) override {
     callback_.Run(view_manager, root);
   }
-  virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {}
+  void OnViewManagerDisconnected(ViewManager* view_manager) override {}
 
   ScopedVector<ApplicationImpl> apps_;
   LoadedCallback callback_;
@@ -98,13 +99,13 @@ class ConnectApplicationLoader : public ApplicationLoader,
 class BoundsChangeObserver : public ViewObserver {
  public:
   explicit BoundsChangeObserver(View* view) : view_(view) {}
-  virtual ~BoundsChangeObserver() {}
+  ~BoundsChangeObserver() override {}
 
  private:
   // Overridden from ViewObserver:
-  virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) OVERRIDE {
+  void OnViewBoundsChanged(View* view,
+                           const Rect& old_bounds,
+                           const Rect& new_bounds) override {
     DCHECK_EQ(view, view_);
     QuitRunLoop();
   }
@@ -129,7 +130,7 @@ class TreeSizeMatchesObserver : public ViewObserver {
   TreeSizeMatchesObserver(View* tree, size_t tree_size)
       : tree_(tree),
         tree_size_(tree_size) {}
-  virtual ~TreeSizeMatchesObserver() {}
+  ~TreeSizeMatchesObserver() override {}
 
   bool IsTreeCorrectSize() {
     return CountViews(tree_) == tree_size_;
@@ -137,7 +138,7 @@ class TreeSizeMatchesObserver : public ViewObserver {
 
  private:
   // Overridden from ViewObserver:
-  virtual void OnTreeChanged(const TreeChangeParams& params) OVERRIDE {
+  void OnTreeChanged(const TreeChangeParams& params) override {
     if (IsTreeCorrectSize())
       QuitRunLoop();
   }
@@ -174,7 +175,7 @@ class DestructionObserver : public ViewObserver {
 
  private:
   // Overridden from ViewObserver:
-  virtual void OnViewDestroyed(View* view) OVERRIDE {
+  void OnViewDestroyed(View* view) override {
     std::set<Id>::iterator it = views_->find(view->id());
     if (it != views_->end())
       views_->erase(it);
@@ -208,15 +209,13 @@ class OrderChangeObserver : public ViewObserver {
   OrderChangeObserver(View* view) : view_(view) {
     view_->AddObserver(this);
   }
-  virtual ~OrderChangeObserver() {
-    view_->RemoveObserver(this);
-  }
+  ~OrderChangeObserver() override { view_->RemoveObserver(this); }
 
  private:
   // Overridden from ViewObserver:
-  virtual void OnViewReordered(View* view,
-                               View* relative_view,
-                               OrderDirection direction) OVERRIDE {
+  void OnViewReordered(View* view,
+                       View* relative_view,
+                       OrderDirection direction) override {
     DCHECK_EQ(view, view_);
     QuitRunLoop();
   }
@@ -237,7 +236,7 @@ class ViewTracker : public ViewObserver {
   explicit ViewTracker(View* view) : view_(view) {
     view_->AddObserver(this);
   }
-  virtual ~ViewTracker() {
+  ~ViewTracker() override {
     if (view_)
       view_->RemoveObserver(this);
   }
@@ -246,7 +245,7 @@ class ViewTracker : public ViewObserver {
 
  private:
   // Overridden from ViewObserver:
-  virtual void OnViewDestroyed(View* view) OVERRIDE {
+  void OnViewDestroyed(View* view) override {
     DCHECK_EQ(view, view_);
     view_ = NULL;
   }
@@ -302,7 +301,7 @@ class ViewManagerTest : public testing::Test {
 
  private:
   // Overridden from testing::Test:
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     ConnectApplicationLoader::LoadedCallback ready_callback = base::Bind(
         &ViewManagerTest::OnViewManagerLoaded, base::Unretained(this));
     test_helper_.Init();
@@ -315,27 +314,7 @@ class ViewManagerTest : public testing::Test {
             new ConnectApplicationLoader(ready_callback)),
         GURL(kEmbeddedApp1URL));
 
-    test_helper_.application_manager()->ConnectToService(
-        GURL("mojo:mojo_view_manager"), &view_manager_init_);
-    ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kWindowManagerURL));
-  }
-
-  void EmbedRootCallback(bool* result_cache, bool result) {
-    *result_cache = result;
-  }
-
-  bool EmbedRoot(ViewManagerInitService* view_manager_init,
-                 const std::string& url) {
-    bool result = false;
-    ServiceProviderPtr sp;
-    BindToProxy(new ServiceProviderImpl, &sp);
-    view_manager_init->Embed(
-        url, sp.Pass(),
-        base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this),
-                   &result));
-    RunRunLoop();
-    window_manager_ = GetLoadedViewManager();
-    return result;
+    // TODO(sky): resolve this. Need to establish initial connection.
   }
 
   void OnViewManagerLoaded(ViewManager* view_manager, View* root) {
@@ -352,7 +331,6 @@ class ViewManagerTest : public testing::Test {
 
   base::RunLoop* connect_loop_;
   shell::ShellTestHelper test_helper_;
-  ViewManagerInitServicePtr view_manager_init_;
   // Used to receive the most recent view manager loaded by an embed action.
   ViewManager* loaded_view_manager_;
   // The View Manager connection held by the window manager (app running at the
@@ -363,9 +341,12 @@ class ViewManagerTest : public testing::Test {
   DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
 };
 
-TEST_F(ViewManagerTest, SetUp) {}
+// TODO(sky): all of these tests are disabled as each test triggers running
+// ViewsInit, which tries to register the same set of paths with the
+// PathService, triggering a DCHECK.
+TEST_F(ViewManagerTest, DISABLED_SetUp) {}
 
-TEST_F(ViewManagerTest, Embed) {
+TEST_F(ViewManagerTest, DISABLED_Embed) {
   View* view = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
@@ -423,7 +404,7 @@ TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupView) {
 
 // Verifies that bounds changes applied to a view hierarchy in one connection
 // are reflected to another.
-TEST_F(ViewManagerTest, SetBounds) {
+TEST_F(ViewManagerTest, DISABLED_SetBounds) {
   View* view = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
@@ -431,7 +412,9 @@ TEST_F(ViewManagerTest, SetBounds) {
   View* view_in_embedded = embedded->GetViewById(view->id());
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
 
-  view->SetBounds(gfx::Rect(100, 100));
+  Rect rect;
+  rect.width = rect.height = 100;
+  view->SetBounds(rect);
   EXPECT_NE(view->bounds(), view_in_embedded->bounds());
   WaitForBoundsToChange(view_in_embedded);
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
@@ -439,22 +422,27 @@ TEST_F(ViewManagerTest, SetBounds) {
 
 // Verifies that bounds changes applied to a view owned by a different
 // connection are refused.
-TEST_F(ViewManagerTest, SetBoundsSecurity) {
+TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) {
   View* view = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
 
   View* view_in_embedded = embedded->GetViewById(view->id());
-  view->SetBounds(gfx::Rect(800, 600));
+  Rect rect;
+  rect.width = 800;
+  rect.height = 600;
+  view->SetBounds(rect);
   WaitForBoundsToChange(view_in_embedded);
 
-  view_in_embedded->SetBounds(gfx::Rect(1024, 768));
+  rect.width = 1024;
+  rect.height = 768;
+  view_in_embedded->SetBounds(rect);
   // Bounds change should have been rejected.
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
 }
 
 // Verifies that a view can only be destroyed by the connection that created it.
-TEST_F(ViewManagerTest, DestroySecurity) {
+TEST_F(ViewManagerTest, DISABLED_DestroySecurity) {
   View* view = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
@@ -471,7 +459,7 @@ TEST_F(ViewManagerTest, DestroySecurity) {
   EXPECT_FALSE(tracker1.is_valid());
 }
 
-TEST_F(ViewManagerTest, MultiRoots) {
+TEST_F(ViewManagerTest, DISABLED_MultiRoots) {
   View* view1 = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view1);
   View* view2 = View::Create(window_manager());
@@ -481,14 +469,14 @@ TEST_F(ViewManagerTest, MultiRoots) {
   EXPECT_EQ(embedded1, embedded2);
 }
 
-TEST_F(ViewManagerTest, EmbeddingIdentity) {
+TEST_F(ViewManagerTest, DISABLED_EmbeddingIdentity) {
   View* view = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
   EXPECT_EQ(kWindowManagerURL, embedded->GetEmbedderURL());
 }
 
-TEST_F(ViewManagerTest, Reorder) {
+TEST_F(ViewManagerTest, DISABLED_Reorder) {
   View* view1 = View::Create(window_manager());
   window_manager()->GetRoots().front()->AddChild(view1);
 
@@ -525,6 +513,117 @@ TEST_F(ViewManagerTest, Reorder) {
   }
 }
 
+namespace {
+
+class VisibilityChangeObserver : public ViewObserver {
+ public:
+  explicit VisibilityChangeObserver(View* view) : view_(view) {
+    view_->AddObserver(this);
+  }
+  ~VisibilityChangeObserver() override { view_->RemoveObserver(this); }
+
+ private:
+  // Overridden from ViewObserver:
+  void OnViewVisibilityChanged(View* view) override {
+    EXPECT_EQ(view, view_);
+    QuitRunLoop();
+  }
+
+  View* view_;
+
+  DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
+};
+
+}  // namespace
+
+TEST_F(ViewManagerTest, DISABLED_Visible) {
+  View* view1 = View::Create(window_manager());
+  window_manager()->GetRoots().front()->AddChild(view1);
+
+  // Embed another app and verify initial state.
+  ViewManager* embedded = Embed(window_manager(), view1);
+  ASSERT_EQ(1u, embedded->GetRoots().size());
+  View* embedded_root = embedded->GetRoots().front();
+  EXPECT_TRUE(embedded_root->visible());
+  EXPECT_TRUE(embedded_root->IsDrawn());
+
+  // Change the visible state from the first connection and verify its mirrored
+  // correctly to the embedded app.
+  {
+    VisibilityChangeObserver observer(embedded_root);
+    view1->SetVisible(false);
+    DoRunLoop();
+  }
+
+  EXPECT_FALSE(view1->visible());
+  EXPECT_FALSE(view1->IsDrawn());
+
+  EXPECT_FALSE(embedded_root->visible());
+  EXPECT_FALSE(embedded_root->IsDrawn());
+
+  // Make the node visible again.
+  {
+    VisibilityChangeObserver observer(embedded_root);
+    view1->SetVisible(true);
+    DoRunLoop();
+  }
+
+  EXPECT_TRUE(view1->visible());
+  EXPECT_TRUE(view1->IsDrawn());
+
+  EXPECT_TRUE(embedded_root->visible());
+  EXPECT_TRUE(embedded_root->IsDrawn());
+}
+
+namespace {
+
+class DrawnChangeObserver : public ViewObserver {
+ public:
+  explicit DrawnChangeObserver(View* view) : view_(view) {
+    view_->AddObserver(this);
+  }
+  ~DrawnChangeObserver() override { view_->RemoveObserver(this); }
+
+ private:
+  // Overridden from ViewObserver:
+  void OnViewDrawnChanged(View* view) override {
+    EXPECT_EQ(view, view_);
+    QuitRunLoop();
+  }
+
+  View* view_;
+
+  DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver);
+};
+
+}  // namespace
+
+TEST_F(ViewManagerTest, DISABLED_Drawn) {
+  View* view1 = View::Create(window_manager());
+  window_manager()->GetRoots().front()->AddChild(view1);
+
+  // Embed another app and verify initial state.
+  ViewManager* embedded = Embed(window_manager(), view1);
+  ASSERT_EQ(1u, embedded->GetRoots().size());
+  View* embedded_root = embedded->GetRoots().front();
+  EXPECT_TRUE(embedded_root->visible());
+  EXPECT_TRUE(embedded_root->IsDrawn());
+
+  // Change the visibility of the root, this should propagate a drawn state
+  // change to |embedded|.
+  {
+    DrawnChangeObserver observer(embedded_root);
+    window_manager()->GetRoots().front()->SetVisible(false);
+    DoRunLoop();
+  }
+
+  EXPECT_TRUE(view1->visible());
+  EXPECT_FALSE(view1->IsDrawn());
+
+  EXPECT_TRUE(embedded_root->visible());
+  EXPECT_FALSE(embedded_root->IsDrawn());
+}
+
 // TODO(beng): tests for view event dispatcher.
 // - verify that we see events for all views.