<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.

#import "chrome/browser/ui/app_list/app_list_service_mac.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"

namespace {

const int kScreenWidth = 800;
const int kScreenHeight = 600;

const int kWindowWidth = 100;
const int kWindowHeight = 200;

// Size of the normal (non-hidden) dock.
const int kDockSize = 30;
// Size of the hidden dock.
const int kHiddenDockSize = 4;

// Distance to move during the opening animation.
const int kAnimationOffset = 20;

// The assumed size of the hidden dock.
const int kExtraDistance = 50;

// A cursor position that is within the dock. This must be < kDockSize.
const int kCursorOnDock = kDockSize / 2;
// A cursor position that is within 50 pixels of the dock.
const int kCursorNearDock = kDockSize + 50;
// A cursor position that is more than 50 pixels away from the dock.
const int kCursorAwayFromDock = kCursorNearDock + 1;

// A position for the center of the window that causes the window to overlap the
// edge of the screen. This must be < kWindowWidth / 2 and < kWindowHeight / 2.
const int kWindowNearEdge = kWindowWidth / 4;
// A position for the center of the window that places the window away from all
// edges of the screen. This must be > kWindowWidth / 2, > kWindowHeight / 2, <
// kScreenWidth - kWindowWidth / 2 and < kScreenHeight - kWindowHeight / 2.
const int kWindowAwayFromEdge = 158;

enum DockLocation {
  DOCK_LOCATION_BOTTOM,
  DOCK_LOCATION_LEFT,
  DOCK_LOCATION_RIGHT,
};

// Returns |point| offset by (|x_offset|, |y_offset|).
NSPoint OffsetPoint(const NSPoint& point, CGFloat x_offset, CGFloat y_offset) {
  return NSMakePoint(point.x + x_offset, point.y + y_offset);
}

}  // namespace

class AppListServiceMacUnitTest : public testing::Test {
 public:
  virtual void SetUp() OVERRIDE {
    display_.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
    display_.set_work_area(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
    window_size_ = gfx::Size(kWindowWidth, kWindowHeight);
    cursor_is_visible_ = true;
    cursor_ = gfx::Point();
  }

  // Sets up the test environment with the dock in a given location.
  void PlaceDock(DockLocation location, bool hidden) {
    int dock_size = hidden ? kHiddenDockSize : kDockSize;
    switch (location) {
      case DOCK_LOCATION_BOTTOM:
        display_.set_work_area(
            gfx::Rect(0, 0, kScreenWidth, kScreenHeight - dock_size));
        break;
      case DOCK_LOCATION_LEFT:
        display_.set_work_area(
            gfx::Rect(dock_size, 0, kScreenWidth - dock_size, kScreenHeight));
        break;
      case DOCK_LOCATION_RIGHT:
        display_.set_work_area(
            gfx::Rect(0, 0, kScreenWidth - dock_size, kScreenHeight));
        break;
    }
  }

  // Set whether the test mouse cursor is visible.
  void SetCursorVisible(bool visible) {
    cursor_is_visible_ = visible;
  }

  // Set up the test mouse cursor in a given location.
  void PlaceCursor(int x, int y) {
    cursor_ = gfx::Point(x, y);
  }

  void DoFindAnchorPoint(NSPoint* target_origin,
                         NSPoint* start_origin) {
    AppListServiceMac::FindAnchorPoint(window_size_,
                                       display_,
                                       kScreenHeight,
                                       cursor_is_visible_,
                                       cursor_,
                                       target_origin,
                                       start_origin);
  }
<commit_msg>App List tests now assume the existence of the menu bar.<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.

#import "chrome/browser/ui/app_list/app_list_service_mac.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"

namespace {

const int kScreenWidth = 800;
const int kScreenHeight = 600;

const int kWindowWidth = 100;
const int kWindowHeight = 200;

// Size of the menu bar along the top of the screen.
const int kMenuBarSize = 22;
// Size of the normal (non-hidden) dock.
const int kDockSize = 30;
// Size of the hidden dock.
const int kHiddenDockSize = 4;

// Distance to move during the opening animation.
const int kAnimationOffset = 20;

// The assumed size of the hidden dock.
const int kExtraDistance = 50;

// A cursor position that is within the dock. This must be < kDockSize.
const int kCursorOnDock = kDockSize / 2;
// A cursor position that is within 50 pixels of the dock.
const int kCursorNearDock = kDockSize + 50;
// A cursor position that is more than 50 pixels away from the dock.
const int kCursorAwayFromDock = kCursorNearDock + 1;

// A position for the center of the window that causes the window to overlap the
// edge of the screen. This must be < kWindowWidth / 2 and < kWindowHeight / 2.
const int kWindowNearEdge = kWindowWidth / 4;
// A position for the center of the window that places the window away from all
// edges of the screen. This must be > kWindowWidth / 2, > kWindowHeight / 2, <
// kScreenWidth - kWindowWidth / 2 and < kScreenHeight - kWindowHeight / 2.
const int kWindowAwayFromEdge = 158;

enum DockLocation {
  DOCK_LOCATION_BOTTOM,
  DOCK_LOCATION_LEFT,
  DOCK_LOCATION_RIGHT,
};

// Returns |point| offset by (|x_offset|, |y_offset|).
NSPoint OffsetPoint(const NSPoint& point, CGFloat x_offset, CGFloat y_offset) {
  return NSMakePoint(point.x + x_offset, point.y + y_offset);
}

}  // namespace

class AppListServiceMacUnitTest : public testing::Test {
 public:
  virtual void SetUp() OVERRIDE {
    display_.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
    display_.set_work_area(
        gfx::Rect(0, kMenuBarSize, kScreenWidth, kScreenHeight - kMenuBarSize));
    window_size_ = gfx::Size(kWindowWidth, kWindowHeight);
    cursor_is_visible_ = true;
    cursor_ = gfx::Point();
  }

  // Sets up the test environment with the dock in a given location.
  void PlaceDock(DockLocation location, bool hidden) {
    int dock_size = hidden ? kHiddenDockSize : kDockSize;
    switch (location) {
      case DOCK_LOCATION_BOTTOM:
        display_.set_work_area(
            gfx::Rect(0,
                      kMenuBarSize,
                      kScreenWidth,
                      kScreenHeight - kMenuBarSize - dock_size));
        break;
      case DOCK_LOCATION_LEFT:
        display_.set_work_area(gfx::Rect(dock_size,
                                         kMenuBarSize,
                                         kScreenWidth - dock_size,
                                         kScreenHeight - kMenuBarSize));
        break;
      case DOCK_LOCATION_RIGHT:
        display_.set_work_area(gfx::Rect(0,
                                         kMenuBarSize,
                                         kScreenWidth - dock_size,
                                         kScreenHeight - kMenuBarSize));
        break;
    }
  }

  // Set whether the test mouse cursor is visible.
  void SetCursorVisible(bool visible) {
    cursor_is_visible_ = visible;
  }

  // Set up the test mouse cursor in a given location.
  void PlaceCursor(int x, int y) {
    cursor_ = gfx::Point(x, y);
  }

  void DoFindAnchorPoint(NSPoint* target_origin,
                         NSPoint* start_origin) {
    AppListServiceMac::FindAnchorPoint(window_size_,
                                       display_,
                                       kScreenHeight,
                                       cursor_is_visible_,
                                       cursor_,
                                       target_origin,
                                       start_origin);
  }

{'fraction_non_alphanumeric': 0.08191382765531062, 'fraction_numerical': 0.012274549098196393, 'mean_word_length': 2.3935401614959626, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5934057', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2336, 'n_words': 750}