diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 01:52:42 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 01:52:42 +0000 |
commit | e2dced44d39c58376c2cc5fdd85e78fb6cafec8d (patch) | |
tree | b2a4757e4511d9aec2e0e87345ece0feb6c8f280 /ash/launcher/launcher_view_unittest.cc | |
parent | 150f339aee07be3bc9ea10f35c4d1b7e03459155 (diff) | |
download | chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.zip chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.tar.gz chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.tar.bz2 |
Implement LauncherIconObserver.
This will be used to listen for changes in the launcher view so that panels can be correctly drawn over the corresponding launcher icon.
BUG=124115
TEST=aura_shell_unittests
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=133089
Review URL: https://chromiumcodereview.appspot.com/10116011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133120 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/launcher/launcher_view_unittest.cc')
-rw-r--r-- | ash/launcher/launcher_view_unittest.cc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc new file mode 100644 index 0000000..78836f6 --- /dev/null +++ b/ash/launcher/launcher_view_unittest.cc @@ -0,0 +1,104 @@ +// 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 "ash/launcher/launcher_view.h" + +#include "ash/ash_switches.h" +#include "ash/launcher/launcher.h" +#include "ash/launcher/launcher_icon_observer.h" +#include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" +#include "ash/test/test_launcher_delegate.h" +#include "base/basictypes.h" +#include "base/command_line.h" +#include "base/compiler_specific.h" +#include "ui/aura/window.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" + +namespace ash { + +namespace { + +class TestLauncherIconObserver : public LauncherIconObserver { + public: + TestLauncherIconObserver() : count_(0) { + Shell::GetInstance()->launcher()->AddIconObserver(this); + } + + virtual ~TestLauncherIconObserver() { + Shell::GetInstance()->launcher()->RemoveIconObserver(this); + } + + // LauncherIconObserver implementation. + void OnLauncherIconPositionsChanged() OVERRIDE { + count_++; + } + + int count() const { return count_; } + void Reset() { count_ = 0; } + + private: + int count_; + + DISALLOW_COPY_AND_ASSIGN(TestLauncherIconObserver); +}; + +class LauncherViewTest : public ash::test::AshTestBase { + public: + LauncherViewTest() {} + virtual ~LauncherViewTest() {} + + virtual void SetUp() OVERRIDE { + AshTestBase::SetUp(); + observer_.reset(new TestLauncherIconObserver); + } + + virtual void TearDown() OVERRIDE { + observer_.reset(); + AshTestBase::TearDown(); + } + + TestLauncherIconObserver* observer() { return observer_.get(); } + + private: + scoped_ptr<TestLauncherIconObserver> observer_; + + DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); +}; + +TEST_F(LauncherViewTest, AddRemove) { + ash::test::TestLauncherDelegate* launcher_delegate = + ash::test::TestLauncherDelegate::instance(); + ASSERT_TRUE(launcher_delegate); + + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(0, 0, 200, 200); + + scoped_ptr<views::Widget> widget(new views::Widget()); + widget->Init(params); + launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); + EXPECT_EQ(1, observer()->count()); + observer()->Reset(); + + widget->Show(); + widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); + EXPECT_EQ(1, observer()->count()); + observer()->Reset(); +} + +TEST_F(LauncherViewTest, BoundsChanged) { + Launcher* launcher = Shell::GetInstance()->launcher(); + int total_width = launcher->widget()->GetWindowScreenBounds().width(); + ASSERT_GT(total_width, 0); + launcher->SetStatusWidth(total_width / 2); + EXPECT_EQ(1, observer()->count()); + observer()->Reset(); +} + +} // namespace + +} // namespace ash |