<commit_before>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/wm/solo_window_tracker.h"

#include "ash/ash_constants.h"
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/screen.h"

namespace ash {

namespace {

class WindowRepaintChecker : public aura::WindowObserver {
 public:
  explicit WindowRepaintChecker(aura::Window* window)
      : is_paint_scheduled_(false) {
    window->AddObserver(this);
  }
  virtual ~WindowRepaintChecker() {
  }

  bool IsPaintScheduledAndReset() {
    bool result = is_paint_scheduled_;
    is_paint_scheduled_ = false;
    return result;
  }

 private:
  // aura::WindowObserver overrides:
  virtual void OnWindowPaintScheduled(aura::Window* window,
                                      const gfx::Rect& region) OVERRIDE {
    is_paint_scheduled_ = true;
  }
  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
    window->RemoveObserver(this);
  }

  bool is_paint_scheduled_;

  DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker);
};

}  // namespace

class SoloWindowTrackerTest : public test::AshTestBase {
 public:
  SoloWindowTrackerTest() {
  }
  virtual ~SoloWindowTrackerTest() {
  }

  // Helpers methods to create test windows in the primary root window.
  aura::Window* CreateWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_NORMAL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }
  aura::Window* CreateAlwaysOnTopWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_NORMAL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    window->SetProperty(aura::client::kAlwaysOnTopKey, true);
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }
  aura::Window* CreatePanelWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_PANEL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }

  // Drag |window| to the dock.
  void DockWindow(aura::Window* window) {
    // Because the tests use windows without delegates,
    // aura::test::EventGenerator cannot be used.
    gfx::Point drag_to =
        ash::ScreenAsh::GetDisplayBoundsInParent(window).top_right();
    scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
        window,
        window->bounds().origin(),
        HTCAPTION,
        aura::client::WINDOW_MOVE_SOURCE_MOUSE));
    resizer->Drag(drag_to, 0);
    resizer->CompleteDrag(0);
    EXPECT_EQ(internal::kShellWindowId_DockedContainer,
              window->parent()->id());
  }

  // Drag |window| out of the dock.
  void UndockWindow(aura::Window* window) {
    gfx::Point drag_to =
        ash::ScreenAsh::GetDisplayWorkAreaBoundsInParent(window).top_right() -
        gfx::Vector2d(10, 0);
    scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
        window,
        window->bounds().origin(),
        HTCAPTION,
        aura::client::WINDOW_MOVE_SOURCE_MOUSE));
    resizer->Drag(drag_to, 0);
    resizer->CompleteDrag(0);
    EXPECT_NE(internal::kShellWindowId_DockedContainer,
              window->parent()->id());
  }

  // Returns the primary display.
  gfx::Display GetPrimaryDisplay() {
    return ash::Shell::GetInstance()->GetScreen()->GetPrimaryDisplay();
  }

  // Returns the secondary display.
  gfx::Display GetSecondaryDisplay() {
    return ScreenAsh::GetSecondaryDisplay();
  }

  // Returns the window which uses the solo header, if any, on the primary
  // display.
  aura::Window* GetWindowWithSoloHeaderInPrimary() {
    return GetWindowWithSoloHeader(Shell::GetPrimaryRootWindow());
  }

  // Returns the window which uses the solo header, if any, in |root|.
  aura::Window* GetWindowWithSoloHeader(aura::Window* root) {
    SoloWindowTracker* solo_window_tracker =
        internal::GetRootWindowController(root)->solo_window_tracker();
    return solo_window_tracker ?
        solo_window_tracker->GetWindowWithSoloHeader() : NULL;
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(SoloWindowTrackerTest);
};

TEST_F(SoloWindowTrackerTest, Basic) {
  scoped_ptr<aura::Window> w1(CreateWindowInPrimary());
  w1->Show();

  // We only have one window, so it should use a solo header.
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  // Create a second window.
  scoped_ptr<aura::Window> w2(CreateWindowInPrimary());
  w2->Show();

  // Now there are two windows, so we should not use solo headers.
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Hide one window.  Solo should be enabled.
  w2->Hide();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  // Show that window.  Solo should be disabled.
  w2->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Minimize the first window.  Solo should be enabled.
  wm::GetWindowState(w1.get())->Minimize();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());

  // Close the minimized window.
  w1.reset();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());

  // Open an always-on-top window (which lives in a different container).
  scoped_ptr<aura::Window> w3(CreateAlwaysOnTopWindowInPrimary());
  w3->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Close the always-on-top window.
  w3.reset();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());
}

// Test that docked windows never use the solo header and that the presence of a
// docked window prevents all other windows from the using the solo window
// header.
TEST_F(SoloWindowTrackerTest, DockedWindow) {
  if (!switches::UseDockedWindows())
    return;

  scoped_ptr<aura::Window> w1(CreateWindowInPrimary());
  w1->Show();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  DockWindow(w1.get());
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  UndockWindow(w1.get());
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  scoped_ptr<aura::Window> w2(CreateWindowInPrimary());
  w2->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  DockWindow(w2.get());
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  wm::GetWindowState(w2.get())->Minimize();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());
}
<commit_msg>Disable SoloWindowTrackerTest.DockedWindow on Win8 Aura<commit_after>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/wm/solo_window_tracker.h"

#include "ash/ash_constants.h"
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/screen.h"

namespace ash {

namespace {

class WindowRepaintChecker : public aura::WindowObserver {
 public:
  explicit WindowRepaintChecker(aura::Window* window)
      : is_paint_scheduled_(false) {
    window->AddObserver(this);
  }
  virtual ~WindowRepaintChecker() {
  }

  bool IsPaintScheduledAndReset() {
    bool result = is_paint_scheduled_;
    is_paint_scheduled_ = false;
    return result;
  }

 private:
  // aura::WindowObserver overrides:
  virtual void OnWindowPaintScheduled(aura::Window* window,
                                      const gfx::Rect& region) OVERRIDE {
    is_paint_scheduled_ = true;
  }
  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
    window->RemoveObserver(this);
  }

  bool is_paint_scheduled_;

  DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker);
};

}  // namespace

class SoloWindowTrackerTest : public test::AshTestBase {
 public:
  SoloWindowTrackerTest() {
  }
  virtual ~SoloWindowTrackerTest() {
  }

  // Helpers methods to create test windows in the primary root window.
  aura::Window* CreateWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_NORMAL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }
  aura::Window* CreateAlwaysOnTopWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_NORMAL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    window->SetProperty(aura::client::kAlwaysOnTopKey, true);
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }
  aura::Window* CreatePanelWindowInPrimary() {
    aura::Window* window = new aura::Window(NULL);
    window->SetType(aura::client::WINDOW_TYPE_PANEL);
    window->Init(ui::LAYER_TEXTURED);
    window->SetBounds(gfx::Rect(100, 100));
    ParentWindowInPrimaryRootWindow(window);
    return window;
  }

  // Drag |window| to the dock.
  void DockWindow(aura::Window* window) {
    // Because the tests use windows without delegates,
    // aura::test::EventGenerator cannot be used.
    gfx::Point drag_to =
        ash::ScreenAsh::GetDisplayBoundsInParent(window).top_right();
    scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
        window,
        window->bounds().origin(),
        HTCAPTION,
        aura::client::WINDOW_MOVE_SOURCE_MOUSE));
    resizer->Drag(drag_to, 0);
    resizer->CompleteDrag(0);
    EXPECT_EQ(internal::kShellWindowId_DockedContainer,
              window->parent()->id());
  }

  // Drag |window| out of the dock.
  void UndockWindow(aura::Window* window) {
    gfx::Point drag_to =
        ash::ScreenAsh::GetDisplayWorkAreaBoundsInParent(window).top_right() -
        gfx::Vector2d(10, 0);
    scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
        window,
        window->bounds().origin(),
        HTCAPTION,
        aura::client::WINDOW_MOVE_SOURCE_MOUSE));
    resizer->Drag(drag_to, 0);
    resizer->CompleteDrag(0);
    EXPECT_NE(internal::kShellWindowId_DockedContainer,
              window->parent()->id());
  }

  // Returns the primary display.
  gfx::Display GetPrimaryDisplay() {
    return ash::Shell::GetInstance()->GetScreen()->GetPrimaryDisplay();
  }

  // Returns the secondary display.
  gfx::Display GetSecondaryDisplay() {
    return ScreenAsh::GetSecondaryDisplay();
  }

  // Returns the window which uses the solo header, if any, on the primary
  // display.
  aura::Window* GetWindowWithSoloHeaderInPrimary() {
    return GetWindowWithSoloHeader(Shell::GetPrimaryRootWindow());
  }

  // Returns the window which uses the solo header, if any, in |root|.
  aura::Window* GetWindowWithSoloHeader(aura::Window* root) {
    SoloWindowTracker* solo_window_tracker =
        internal::GetRootWindowController(root)->solo_window_tracker();
    return solo_window_tracker ?
        solo_window_tracker->GetWindowWithSoloHeader() : NULL;
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(SoloWindowTrackerTest);
};

TEST_F(SoloWindowTrackerTest, Basic) {
  scoped_ptr<aura::Window> w1(CreateWindowInPrimary());
  w1->Show();

  // We only have one window, so it should use a solo header.
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  // Create a second window.
  scoped_ptr<aura::Window> w2(CreateWindowInPrimary());
  w2->Show();

  // Now there are two windows, so we should not use solo headers.
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Hide one window.  Solo should be enabled.
  w2->Hide();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  // Show that window.  Solo should be disabled.
  w2->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Minimize the first window.  Solo should be enabled.
  wm::GetWindowState(w1.get())->Minimize();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());

  // Close the minimized window.
  w1.reset();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());

  // Open an always-on-top window (which lives in a different container).
  scoped_ptr<aura::Window> w3(CreateAlwaysOnTopWindowInPrimary());
  w3->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  // Close the always-on-top window.
  w3.reset();
  EXPECT_EQ(w2.get(), GetWindowWithSoloHeaderInPrimary());
}

// Test that docked windows never use the solo header and that the presence of a
// docked window prevents all other windows from the using the solo window
// header.
#if defined(USE_AURA) && defined(OS_WIN)
// Failing on Win8 Aura. http://crbug.com/319135
#define MAYBE_DockedWindow DISABLED_DockedWindow
#else
#define MAYBE_DockedWindow DockedWindow
#endif
TEST_F(SoloWindowTrackerTest, MAYBE_DockedWindow) {
  if (!switches::UseDockedWindows())
    return;

  scoped_ptr<aura::Window> w1(CreateWindowInPrimary());
  w1->Show();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  DockWindow(w1.get());
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  UndockWindow(w1.get());
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());

  scoped_ptr<aura::Window> w2(CreateWindowInPrimary());
  w2->Show();
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  DockWindow(w2.get());
  EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());

  wm::GetWindowState(w2.get())->Minimize();
  EXPECT_EQ(w1.get(), GetWindowWithSoloHeaderInPrimary());
}

{'fraction_non_alphanumeric': 0.12957785854067655, 'fraction_numerical': 0.008526698350573106, 'mean_word_length': 4.522578155152451, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4108977', 'n_tokens_mistral': 4800, 'n_tokens_neox': 4648, 'n_words': 906}