Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / aura / window_unittest.cc
index f1a7abf..2972507 100644 (file)
@@ -36,7 +36,7 @@
 #include "ui/compositor/test/test_layers.h"
 #include "ui/events/event.h"
 #include "ui/events/event_utils.h"
-#include "ui/events/gestures/gesture_configuration.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
 #include "ui/events/keycodes/keyboard_codes.h"
 #include "ui/events/test/event_generator.h"
 #include "ui/gfx/canvas.h"
@@ -55,23 +55,23 @@ class WindowTest : public AuraTestBase {
   WindowTest() : max_separation_(0) {
   }
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     AuraTestBase::SetUp();
     // TODO: there needs to be an easier way to do this.
-    max_separation_ = ui::GestureConfiguration::
-        max_separation_for_gesture_touches_in_pixels();
-    ui::GestureConfiguration::
-        set_max_separation_for_gesture_touches_in_pixels(0);
+    max_separation_ = ui::GestureConfiguration::GetInstance()
+                          ->max_separation_for_gesture_touches_in_pixels();
+    ui::GestureConfiguration::GetInstance()
+        ->set_max_separation_for_gesture_touches_in_pixels(0);
   }
 
-  virtual void TearDown() OVERRIDE {
+  void TearDown() override {
     AuraTestBase::TearDown();
-    ui::GestureConfiguration::
-        set_max_separation_for_gesture_touches_in_pixels(max_separation_);
+    ui::GestureConfiguration::GetInstance()
+        ->set_max_separation_for_gesture_touches_in_pixels(max_separation_);
   }
 
  private:
-  int max_separation_;
+  float max_separation_;
 
   DISALLOW_COPY_AND_ASSIGN(WindowTest);
 };
@@ -94,13 +94,13 @@ class DestroyTrackingDelegateImpl : public TestWindowDelegate {
 
   bool in_destroying() const { return in_destroying_; }
 
-  virtual void OnWindowDestroying(Window* window) OVERRIDE {
+  void OnWindowDestroying(Window* window) override {
     EXPECT_FALSE(in_destroying_);
     in_destroying_ = true;
     destroying_count_++;
   }
 
-  virtual void OnWindowDestroyed(Window* window) OVERRIDE {
+  void OnWindowDestroyed(Window* window) override {
     EXPECT_TRUE(in_destroying_);
     in_destroying_ = false;
     destroyed_count_++;
@@ -123,7 +123,7 @@ class ChildWindowDelegateImpl : public DestroyTrackingDelegateImpl {
       : parent_delegate_(parent_delegate) {
   }
 
-  virtual void OnWindowDestroying(Window* window) OVERRIDE {
+  void OnWindowDestroying(Window* window) override {
     EXPECT_TRUE(parent_delegate_->in_destroying());
     DestroyTrackingDelegateImpl::OnWindowDestroying(window);
   }
@@ -143,7 +143,7 @@ class DestroyOrphanDelegate : public TestWindowDelegate {
 
   void set_window(Window* window) { window_ = window; }
 
-  virtual void OnWindowDestroyed(Window* window) OVERRIDE {
+  void OnWindowDestroyed(Window* window) override {
     EXPECT_FALSE(window_->parent());
   }
 
@@ -175,20 +175,16 @@ class CaptureWindowDelegateImpl : public TestWindowDelegate {
   int touch_event_count() const { return touch_event_count_; }
   int gesture_event_count() const { return gesture_event_count_; }
 
-  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+  void OnMouseEvent(ui::MouseEvent* event) override {
     if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED)
       capture_changed_event_count_++;
     mouse_event_count_++;
   }
-  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
-    touch_event_count_++;
-  }
-  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+  void OnTouchEvent(ui::TouchEvent* event) override { touch_event_count_++; }
+  void OnGestureEvent(ui::GestureEvent* event) override {
     gesture_event_count_++;
   }
-  virtual void OnCaptureLost() OVERRIDE {
-    capture_lost_count_++;
-  }
+  void OnCaptureLost() override { capture_lost_count_++; }
 
  private:
   int capture_changed_event_count_;
@@ -205,7 +201,7 @@ class GestureTrackPositionDelegate : public TestWindowDelegate {
  public:
   GestureTrackPositionDelegate() {}
 
-  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+  void OnGestureEvent(ui::GestureEvent* event) override {
     position_ = event->location();
     event->StopPropagation();
   }
@@ -226,9 +222,9 @@ class SelfEventHandlingWindowDelegate : public TestWindowDelegate {
  public:
   SelfEventHandlingWindowDelegate() {}
 
-  virtual bool ShouldDescendIntoChildForEventHandling(
+  bool ShouldDescendIntoChildForEventHandling(
       Window* child,
-      const gfx::Point& location) OVERRIDE {
+      const gfx::Point& location) override {
     return false;
   }
 
@@ -242,12 +238,10 @@ class DestroyWindowDelegate : public TestWindowDelegate {
   DestroyWindowDelegate() {}
 
  private:
-  virtual ~DestroyWindowDelegate() {}
+  ~DestroyWindowDelegate() override {}
 
   // Overridden from WindowDelegate.
-  virtual void OnWindowDestroyed(Window* window) OVERRIDE {
-    delete this;
-  }
+  void OnWindowDestroyed(Window* window) override { delete this; }
 
   DISALLOW_COPY_AND_ASSIGN(DestroyWindowDelegate);
 };
@@ -576,9 +570,7 @@ class AddedToRootWindowObserver : public WindowObserver {
  public:
   AddedToRootWindowObserver() : called_(false) {}
 
-  virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE {
-    called_ = true;
-  }
+  void OnWindowAddedToRootWindow(Window* window) override { called_ = true; }
 
   bool called() const { return called_; }
 
@@ -1087,7 +1079,7 @@ class MouseEnterExitWindowDelegate : public TestWindowDelegate {
  public:
   MouseEnterExitWindowDelegate() : entered_(false), exited_(false) {}
 
-  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+  void OnMouseEvent(ui::MouseEvent* event) override {
     switch (event->type()) {
       case ui::ET_MOUSE_ENTERED:
         EXPECT_TRUE(event->flags() & ui::EF_IS_SYNTHESIZED);
@@ -1372,7 +1364,7 @@ class VisibilityWindowDelegate : public TestWindowDelegate {
     hidden_ = 0;
   }
 
-  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
+  void OnWindowTargetVisibilityChanged(bool visible) override {
     if (visible)
       shown_++;
     else
@@ -1665,6 +1657,7 @@ class WindowObserverTest : public WindowTest,
   struct VisibilityInfo {
     bool window_visible;
     bool visible_param;
+    int changed_count;
   };
 
   WindowObserverTest()
@@ -1674,7 +1667,7 @@ class WindowObserverTest : public WindowTest,
         old_property_value_(-3) {
   }
 
-  virtual ~WindowObserverTest() {}
+  ~WindowObserverTest() override {}
 
   const VisibilityInfo* GetVisibilityInfo() const {
     return visibility_info_.get();
@@ -1720,35 +1713,33 @@ class WindowObserverTest : public WindowTest,
   }
 
  private:
-  virtual void OnWindowAdded(Window* new_window) OVERRIDE {
-    added_count_++;
-  }
+  void OnWindowAdded(Window* new_window) override { added_count_++; }
 
-  virtual void OnWillRemoveWindow(Window* window) OVERRIDE {
-    removed_count_++;
-  }
+  void OnWillRemoveWindow(Window* window) override { removed_count_++; }
 
-  virtual void OnWindowVisibilityChanged(Window* window,
-                                         bool visible) OVERRIDE {
-    visibility_info_.reset(new VisibilityInfo);
+  void OnWindowVisibilityChanged(Window* window, bool visible) override {
+    if (!visibility_info_) {
+      visibility_info_.reset(new VisibilityInfo);
+      visibility_info_->changed_count = 0;
+    }
     visibility_info_->window_visible = window->IsVisible();
     visibility_info_->visible_param = visible;
+    visibility_info_->changed_count++;
   }
 
-  virtual void OnWindowDestroyed(Window* window) OVERRIDE {
+  void OnWindowDestroyed(Window* window) override {
     EXPECT_FALSE(window->parent());
     destroyed_count_++;
   }
 
-  virtual void OnWindowPropertyChanged(Window* window,
-                                       const void* key,
-                                       intptr_t old) OVERRIDE {
+  void OnWindowPropertyChanged(Window* window,
+                               const void* key,
+                               intptr_t old) override {
     property_key_ = key;
     old_property_value_ = old;
   }
 
-  virtual void OnAncestorWindowTransformed(Window* source,
-                                           Window* window) OVERRIDE {
+  void OnAncestorWindowTransformed(Window* source, Window* window) override {
     transform_notifications_.push_back(
         std::make_pair(source->id(), window->id()));
   }
@@ -1804,6 +1795,7 @@ TEST_F(WindowObserverTest, WindowVisibility) {
     return;
   EXPECT_FALSE(GetVisibilityInfo()->window_visible);
   EXPECT_FALSE(GetVisibilityInfo()->visible_param);
+  EXPECT_EQ(1, GetVisibilityInfo()->changed_count);
 
   // If parent isn't visible, showing window won't make the window visible, but
   // passed visible value must be true.
@@ -1816,6 +1808,7 @@ TEST_F(WindowObserverTest, WindowVisibility) {
     return;
   EXPECT_FALSE(GetVisibilityInfo()->window_visible);
   EXPECT_TRUE(GetVisibilityInfo()->visible_param);
+  EXPECT_EQ(1, GetVisibilityInfo()->changed_count);
 
   // If parent is visible, showing window will make the window
   // visible and the passed visible value is true.
@@ -1828,6 +1821,15 @@ TEST_F(WindowObserverTest, WindowVisibility) {
     return;
   EXPECT_TRUE(GetVisibilityInfo()->window_visible);
   EXPECT_TRUE(GetVisibilityInfo()->visible_param);
+  EXPECT_EQ(1, GetVisibilityInfo()->changed_count);
+
+  // Verify that the OnWindowVisibilityChanged only once
+  // per visibility change.
+  w2->Hide();
+  EXPECT_EQ(2, GetVisibilityInfo()->changed_count);
+
+  w2->Hide();
+  EXPECT_EQ(2, GetVisibilityInfo()->changed_count);
 }
 
 // Test if OnWindowDestroyed is invoked as expected.
@@ -2018,16 +2020,14 @@ class TestVisibilityClient : public client::VisibilityClient {
       : ignore_visibility_changes_(false) {
     client::SetVisibilityClient(root_window, this);
   }
-  virtual ~TestVisibilityClient() {
-  }
+  ~TestVisibilityClient() override {}
 
   void set_ignore_visibility_changes(bool ignore_visibility_changes) {
     ignore_visibility_changes_ = ignore_visibility_changes;
   }
 
   // Overridden from client::VisibilityClient:
-  virtual void UpdateLayerVisibility(aura::Window* window,
-                                     bool visible) OVERRIDE {
+  void UpdateLayerVisibility(aura::Window* window, bool visible) override {
     if (!ignore_visibility_changes_)
       window->layer()->SetVisible(visible);
   }
@@ -2152,7 +2152,7 @@ TEST_F(WindowTest, MouseEventsOnWindowChange) {
 class RootWindowAttachmentObserver : public WindowObserver {
  public:
   RootWindowAttachmentObserver() : added_count_(0), removed_count_(0) {}
-  virtual ~RootWindowAttachmentObserver() {}
+  ~RootWindowAttachmentObserver() override {}
 
   int added_count() const { return added_count_; }
   int removed_count() const { return removed_count_; }
@@ -2163,11 +2163,9 @@ class RootWindowAttachmentObserver : public WindowObserver {
   }
 
   // Overridden from WindowObserver:
-  virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE {
-    ++added_count_;
-  }
-  virtual void OnWindowRemovingFromRootWindow(Window* window,
-                                              Window* new_root) OVERRIDE {
+  void OnWindowAddedToRootWindow(Window* window) override { ++added_count_; }
+  void OnWindowRemovingFromRootWindow(Window* window,
+                                      Window* new_root) override {
     ++removed_count_;
   }
 
@@ -2247,9 +2245,9 @@ class BoundsChangedWindowObserver : public WindowObserver {
  public:
   BoundsChangedWindowObserver() : root_set_(false) {}
 
-  virtual void OnWindowBoundsChanged(Window* window,
-                                     const gfx::Rect& old_bounds,
-                                     const gfx::Rect& new_bounds) OVERRIDE {
+  void OnWindowBoundsChanged(Window* window,
+                             const gfx::Rect& old_bounds,
+                             const gfx::Rect& new_bounds) override {
     root_set_ = window->GetRootWindow() != NULL;
   }
 
@@ -2328,9 +2326,7 @@ class OwningWindowDelegate : public TestWindowDelegate {
     owned_window_.reset(window);
   }
 
-  virtual void OnWindowDestroyed(Window* window) OVERRIDE {
-    owned_window_.reset(NULL);
-  }
+  void OnWindowDestroyed(Window* window) override { owned_window_.reset(NULL); }
 
  private:
   scoped_ptr<Window> owned_window_;
@@ -2373,8 +2369,8 @@ class BoundsChangeDelegate : public TestWindowDelegate {
   }
 
   // Window
-  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
-                               const gfx::Rect& new_bounds) OVERRIDE {
+  void OnBoundsChanged(const gfx::Rect& old_bounds,
+                       const gfx::Rect& new_bounds) override {
     bounds_changed_ = true;
   }
 
@@ -2482,11 +2478,9 @@ class AddChildNotificationsObserver : public WindowObserver {
   }
 
   // WindowObserver overrides:
-  virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE {
-    added_count_++;
-  }
-  virtual void OnWindowRemovingFromRootWindow(Window* window,
-                                              Window* new_root) OVERRIDE {
+  void OnWindowAddedToRootWindow(Window* window) override { added_count_++; }
+  void OnWindowRemovingFromRootWindow(Window* window,
+                                      Window* new_root) override {
     removed_count_++;
   }
 
@@ -2531,9 +2525,7 @@ class HierarchyObserver : public WindowObserver {
   HierarchyObserver(Window* target) : target_(target) {
     target_->AddObserver(this);
   }
-  virtual ~HierarchyObserver() {
-    target_->RemoveObserver(this);
-  }
+  ~HierarchyObserver() override { target_->RemoveObserver(this); }
 
   void ValidateState(
       int index,
@@ -2547,12 +2539,10 @@ class HierarchyObserver : public WindowObserver {
 
  private:
   // Overridden from WindowObserver:
-  virtual void OnWindowHierarchyChanging(
-      const HierarchyChangeParams& params) OVERRIDE {
+  void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override {
     params_.push_back(params);
   }
-  virtual void OnWindowHierarchyChanged(
-      const HierarchyChangeParams& params) OVERRIDE {
+  void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
     params_.push_back(params);
   }
 
@@ -2919,7 +2909,7 @@ namespace {
 class PaintWindowDelegate : public TestWindowDelegate {
  public:
   PaintWindowDelegate() : paint_count_(0) {}
-  virtual ~PaintWindowDelegate() {}
+  ~PaintWindowDelegate() override {}
 
   const gfx::Rect& most_recent_paint_clip_bounds() const {
     return most_recent_paint_clip_bounds_;
@@ -2933,7 +2923,7 @@ class PaintWindowDelegate : public TestWindowDelegate {
   int paint_count() const { return paint_count_; }
 
   // TestWindowDelegate::
-  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+  void OnPaint(gfx::Canvas* canvas) override {
     paint_count_++;
     canvas->GetClipBounds(&most_recent_paint_clip_bounds_);
     const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix();
@@ -3349,7 +3339,7 @@ TEST_F(WindowTest, StackChildAtLayerless) {
       "21 11 12",
     },
   };
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
+  for (size_t i = 0; i < arraysize(data); ++i) {
     test::TestWindowDelegate delegate;
     Window root(NULL);
     root.Init(WINDOW_LAYER_NOT_DRAWN);
@@ -3396,7 +3386,7 @@ class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
   TestLayerAnimationObserver()
       : animation_completed_(false),
         animation_aborted_(false) {}
-  virtual ~TestLayerAnimationObserver() {}
+  ~TestLayerAnimationObserver() override {}
 
   bool animation_completed() const { return animation_completed_; }
   bool animation_aborted() const { return animation_aborted_; }
@@ -3408,19 +3398,16 @@ class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
 
  private:
   // ui::LayerAnimationObserver:
-  virtual void OnLayerAnimationEnded(
-      ui::LayerAnimationSequence* sequence) OVERRIDE {
+  void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override {
     animation_completed_ = true;
   }
 
-  virtual void OnLayerAnimationAborted(
-      ui::LayerAnimationSequence* sequence) OVERRIDE {
+  void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {
     animation_aborted_ = true;
   }
 
-  virtual void OnLayerAnimationScheduled(
-      ui::LayerAnimationSequence* sequence) OVERRIDE {
-  }
+  void OnLayerAnimationScheduled(
+      ui::LayerAnimationSequence* sequence) override {}
 
   bool animation_completed_;
   bool animation_aborted_;