diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 15:35:36 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 15:35:36 +0000 |
commit | 8a08fa1fbc6c430e15af07ebec5843be6e97cb4d (patch) | |
tree | 94f004f28635d362ea09e202ec4ccedbc6025b33 /ash | |
parent | b016fc8f57b48c81b2985aac394dbc71fd60396c (diff) | |
download | chromium_src-8a08fa1fbc6c430e15af07ebec5843be6e97cb4d.zip chromium_src-8a08fa1fbc6c430e15af07ebec5843be6e97cb4d.tar.gz chromium_src-8a08fa1fbc6c430e15af07ebec5843be6e97cb4d.tar.bz2 |
Second try for
https://chromiumcodereview.appspot.com/9689047/
with fix to allow for special conditions under test
BUG=115650
TEST=LauncherUpdaterTest.*
TBR=sky
Review URL: https://chromiumcodereview.appspot.com/9702072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126917 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/launcher/launcher.cc | 4 | ||||
-rw-r--r-- | ash/launcher/launcher.h | 3 | ||||
-rw-r--r-- | ash/launcher/launcher_unittest.cc | 59 | ||||
-rw-r--r-- | ash/wm/activation_controller_unittest.cc | 6 | ||||
-rw-r--r-- | ash/wm/window_util.cc | 15 |
5 files changed, 69 insertions, 18 deletions
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc index 516c036..3c1543f 100644 --- a/ash/launcher/launcher.cc +++ b/ash/launcher/launcher.cc @@ -157,4 +157,8 @@ gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) { bounds.height()); } +internal::LauncherView* Launcher::GetLauncherViewForTest() { + return static_cast<internal::LauncherView*>( + widget_->GetContentsView()->child_at(0)); +} } // namespace ash diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h index 4005137..6825771 100644 --- a/ash/launcher/launcher.h +++ b/ash/launcher/launcher.h @@ -47,6 +47,8 @@ class ASH_EXPORT Launcher { // Returns the screen bounds of the item for the specified window. If there is // no item for the specified window an empty rect is returned. gfx::Rect GetScreenBoundsOfItemIconForWindow(aura::Window* window); + // Only to be called for testing. Retrieves the LauncherView. + internal::LauncherView* GetLauncherViewForTest(); LauncherDelegate* delegate() { return delegate_.get(); } @@ -68,6 +70,7 @@ class ASH_EXPORT Launcher { // Contents view of the widget. Houses the LauncherView. DelegateView* delegate_view_; + // LauncherView used to display icons. internal::LauncherView* launcher_view_; scoped_ptr<LauncherDelegate> delegate_; diff --git a/ash/launcher/launcher_unittest.cc b/ash/launcher/launcher_unittest.cc index 86b2af5..dbb0c12 100644 --- a/ash/launcher/launcher_unittest.cc +++ b/ash/launcher/launcher_unittest.cc @@ -22,10 +22,7 @@ namespace ash { // LauncherView. TEST_F(LauncherTest, SetStatusWidth) { Launcher* launcher = Shell::GetInstance()->launcher(); - ASSERT_TRUE(launcher); - views::View* launcher_view = launcher->widget()->GetContentsView(); - ASSERT_EQ(1, launcher_view->child_count()); - launcher_view = launcher_view->child_at(0); + LauncherView* launcher_view = launcher->GetLauncherViewForTest(); int total_width = launcher->widget()->GetWindowScreenBounds().width(); ASSERT_GT(total_width, 0); @@ -33,13 +30,12 @@ TEST_F(LauncherTest, SetStatusWidth) { EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); } +// Confirm that launching an app gets the appropriate state reflected in +// its button. TEST_F(LauncherTest, LaunchApp) { Launcher* launcher = Shell::GetInstance()->launcher(); ASSERT_TRUE(launcher); - views::View* contents_view = launcher->widget()->GetContentsView(); - ASSERT_EQ(1, contents_view->child_count()); - LauncherView* launcher_view = - static_cast<LauncherView*>(contents_view->child_at(0)); + LauncherView* launcher_view = launcher->GetLauncherViewForTest(); LauncherView::TestAPI test(launcher_view); LauncherModel* model = launcher->model(); @@ -72,13 +68,12 @@ TEST_F(LauncherTest, LaunchApp) { ASSERT_EQ(--button_count, test.GetButtonCount()); } +// Confirm that launching a browser gets the appropriate state reflected in +// its button. TEST_F(LauncherTest, OpenBrowser) { Launcher* launcher = Shell::GetInstance()->launcher(); ASSERT_TRUE(launcher); - views::View* contents_view = launcher->widget()->GetContentsView(); - ASSERT_EQ(1, contents_view->child_count()); - LauncherView* launcher_view = - static_cast<LauncherView*>(contents_view->child_at(0)); + LauncherView* launcher_view = launcher->GetLauncherViewForTest(); LauncherView::TestAPI test(launcher_view); LauncherModel* model = launcher->model(); @@ -100,4 +95,44 @@ TEST_F(LauncherTest, OpenBrowser) { ASSERT_EQ(--button_count, test.GetButtonCount()); } +// Confirm that opening two different browsers and changing their activation +// causes the appropriate state changes in the launcher buttons. +TEST_F(LauncherTest, OpenTwoBrowsers) { + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + LauncherView* launcher_view = launcher->GetLauncherViewForTest(); + LauncherView::TestAPI test(launcher_view); + LauncherModel* model = launcher->model(); + + // Initially we have the app list and chrome icon. + int button_count = test.GetButtonCount(); + int item_count = model->item_count(); + int button1 = button_count, button2 = button_count + 1; + int item1 = item_count; + + // Add active tab. + { + LauncherItem item; + item.type = TYPE_TABBED; + item.status = STATUS_ACTIVE; + model->Add(item_count, item); + } + ASSERT_EQ(++button_count, test.GetButtonCount()); + EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button1)->state()); + + // Add new active tab and deactivate other. + { + LauncherItem item; + item.type = TYPE_TABBED; + model->Add(item_count, item); + LauncherItem last_item = model->items()[item1]; + last_item.status = STATUS_RUNNING; + model->Set(item1, last_item); + } + + ASSERT_EQ(++button_count, test.GetButtonCount()); + EXPECT_EQ(LauncherButton::STATE_RUNNING, test.GetButton(button1)->state()); + EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button2)->state()); +} + } // namespace ash diff --git a/ash/wm/activation_controller_unittest.cc b/ash/wm/activation_controller_unittest.cc index 32e12b1..68ce950 100644 --- a/ash/wm/activation_controller_unittest.cc +++ b/ash/wm/activation_controller_unittest.cc @@ -191,7 +191,7 @@ TEST_F(ActivationControllerTest, ClickOnMenu) { scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( &wd, 1, gfx::Rect(100, 100), NULL)); ad1.SetWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(NULL)); + EXPECT_EQ(NULL, wm::GetActiveWindow()); // Clicking on an activatable window activtes the window. aura::test::EventGenerator generator(Shell::GetRootWindow(), w1.get()); @@ -259,8 +259,8 @@ TEST_F(ActivationControllerTest, NotActiveInLostActive) { // Should not have gotten a OnLostActive yet. EXPECT_EQ(0, ad1.lost_active_count()); - // ActivateWindow(NULL) should deactivate the active window. - wm::ActivateWindow(NULL); + // Deactivate the active window. + wm::DeactivateWindow(w1.get()); EXPECT_FALSE(wm::IsActiveWindow(w1.get())); EXPECT_EQ(1, ad1.lost_active_count()); EXPECT_FALSE(ad1.window_was_active()); diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc index accafd9..d45c061 100644 --- a/ash/wm/window_util.cc +++ b/ash/wm/window_util.cc @@ -22,17 +22,26 @@ DEFINE_WINDOW_PROPERTY_KEY(bool, kOpenWindowSplitKey, false); namespace wm { void ActivateWindow(aura::Window* window) { - aura::client::GetActivationClient(Shell::GetRootWindow())->ActivateWindow( + DCHECK(window); + DCHECK(window->GetRootWindow()); + aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( window); } void DeactivateWindow(aura::Window* window) { - aura::client::GetActivationClient(Shell::GetRootWindow())->DeactivateWindow( + DCHECK(window); + DCHECK(window->GetRootWindow()); + aura::client::GetActivationClient(window->GetRootWindow())->DeactivateWindow( window); } bool IsActiveWindow(aura::Window* window) { - return GetActiveWindow() == window; + DCHECK(window); + if (!window->GetRootWindow()) + return false; + + return aura::client::GetActivationClient(window->GetRootWindow())-> + GetActiveWindow() == window; } aura::Window* GetActiveWindow() { |