summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/slider_unittest.cc
blob: 27c1c20eb0904652c9d16bfd26af4a75c11b80da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2012 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 "ui/views/controls/slider.h"

#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/view.h"

namespace {

void ClickAt(views::View* view, int x, int y) {
  views::MouseEvent press(ui::ET_MOUSE_PRESSED, x, y, ui::EF_LEFT_MOUSE_BUTTON);
  view->OnMousePressed(press);
  views::MouseEvent release(ui::ET_MOUSE_RELEASED, x, y,
      ui::EF_LEFT_MOUSE_BUTTON);
  view->OnMouseReleased(release);
}

}

namespace views {

TEST(SliderTest, UpdateFromClick) {
  scoped_ptr<Slider> slider(new Slider(NULL, Slider::HORIZONTAL));
  View* view = slider.get();
  gfx::Size size = view->GetPreferredSize();
  view->SetSize(size);

  ClickAt(view, 0, 0);
  EXPECT_EQ(0.0f, slider->value());

  ClickAt(view, view->width(), 0);
  EXPECT_EQ(1.0f, slider->value());
}

TEST(SliderTest, UpdateFromClickRTL) {
  std::string locale = l10n_util::GetApplicationLocale("");
  base::i18n::SetICUDefaultLocale("he");

  scoped_ptr<Slider> slider(new Slider(NULL, Slider::HORIZONTAL));
  View* view = slider.get();
  gfx::Size size = view->GetPreferredSize();
  view->SetSize(size);

  ClickAt(view, 0, 0);
  EXPECT_EQ(1.0f, slider->value());

  ClickAt(view, view->width(), 0);
  EXPECT_EQ(0.0f, slider->value());

  // Reset locale.
  base::i18n::SetICUDefaultLocale(locale);
}

}  // namespace views