Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: ash/launcher/launcher_view_unittest.cc

Issue 11801027: More work to make ash_unittests pass when we require context. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TableViewTest by making it a ViewsTestBase. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/launcher/launcher_tooltip_manager_unittest.cc ('k') | ash/shell/widgets.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/launcher/launcher.h" 10 #include "ash/launcher/launcher.h"
11 #include "ash/launcher/launcher_button.h" 11 #include "ash/launcher/launcher_button.h"
12 #include "ash/launcher/launcher_icon_observer.h" 12 #include "ash/launcher/launcher_icon_observer.h"
13 #include "ash/launcher/launcher_model.h" 13 #include "ash/launcher/launcher_model.h"
14 #include "ash/launcher/launcher_tooltip_manager.h" 14 #include "ash/launcher/launcher_tooltip_manager.h"
15 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell_window_ids.h"
17 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
18 #include "ash/test/launcher_view_test_api.h" 19 #include "ash/test/launcher_view_test_api.h"
19 #include "ash/test/test_launcher_delegate.h" 20 #include "ash/test/test_launcher_delegate.h"
20 #include "base/basictypes.h" 21 #include "base/basictypes.h"
21 #include "base/compiler_specific.h" 22 #include "base/compiler_specific.h"
22 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
25 #include "ui/aura/root_window.h"
24 #include "ui/aura/test/aura_test_base.h" 26 #include "ui/aura/test/aura_test_base.h"
25 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
26 #include "ui/base/events/event.h" 28 #include "ui/base/events/event.h"
27 #include "ui/base/events/event_constants.h" 29 #include "ui/base/events/event_constants.h"
28 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
29 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
30 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
31 33
32 namespace { 34 namespace {
33 const int kExpectedAppIndex = 1; 35 const int kExpectedAppIndex = 1;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 104 };
103 105
104 TEST_F(LauncherViewIconObserverTest, AddRemove) { 106 TEST_F(LauncherViewIconObserverTest, AddRemove) {
105 ash::test::TestLauncherDelegate* launcher_delegate = 107 ash::test::TestLauncherDelegate* launcher_delegate =
106 ash::test::TestLauncherDelegate::instance(); 108 ash::test::TestLauncherDelegate::instance();
107 ASSERT_TRUE(launcher_delegate); 109 ASSERT_TRUE(launcher_delegate);
108 110
109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 111 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
110 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 112 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
111 params.bounds = gfx::Rect(0, 0, 200, 200); 113 params.bounds = gfx::Rect(0, 0, 200, 200);
114 params.context = CurrentContext();
112 115
113 scoped_ptr<views::Widget> widget(new views::Widget()); 116 scoped_ptr<views::Widget> widget(new views::Widget());
114 widget->Init(params); 117 widget->Init(params);
115 launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); 118 launcher_delegate->AddLauncherItem(widget->GetNativeWindow());
116 launcher_view_test()->RunMessageLoopUntilAnimationsDone(); 119 launcher_view_test()->RunMessageLoopUntilAnimationsDone();
117 EXPECT_TRUE(observer()->change_notified()); 120 EXPECT_TRUE(observer()->change_notified());
118 observer()->Reset(); 121 observer()->Reset();
119 122
120 widget->Show(); 123 widget->Show();
121 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); 124 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 test_api_.reset(new LauncherViewTestAPI(launcher_view_.get())); 196 test_api_.reset(new LauncherViewTestAPI(launcher_view_.get()));
194 test_api_->SetAnimationDuration(1); // Speeds up animation for test. 197 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
195 } 198 }
196 199
197 virtual void TearDown() OVERRIDE { 200 virtual void TearDown() OVERRIDE {
198 launcher_view_.reset(); 201 launcher_view_.reset();
199 AshTestBase::TearDown(); 202 AshTestBase::TearDown();
200 } 203 }
201 204
202 protected: 205 protected:
206 void EnsureViewIsInWidget() {
207 widget_.reset(new views::Widget);
208 views::Widget::InitParams params(
209 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
210 params.transparent = true;
211 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
212 params.parent = Shell::GetContainer(
213 Shell::GetPrimaryRootWindow(),
214 ash::internal::kShellWindowId_LauncherContainer);
215
216 widget_->Init(params);
217 widget_->SetContentsView(launcher_view_.get());
218 }
219
203 LauncherID AddAppShortcut() { 220 LauncherID AddAppShortcut() {
204 LauncherItem item; 221 LauncherItem item;
205 item.type = TYPE_APP_SHORTCUT; 222 item.type = TYPE_APP_SHORTCUT;
206 item.status = STATUS_CLOSED; 223 item.status = STATUS_CLOSED;
207 224
208 LauncherID id = model_->next_id(); 225 LauncherID id = model_->next_id();
209 model_->Add(item); 226 model_->Add(item);
210 test_api_->RunMessageLoopUntilAnimationsDone(); 227 test_api_->RunMessageLoopUntilAnimationsDone();
211 return id; 228 return id;
212 } 229 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 views::View* GetTooltipAnchorView() { 351 views::View* GetTooltipAnchorView() {
335 return launcher_view_->tooltip_manager()->anchor_; 352 return launcher_view_->tooltip_manager()->anchor_;
336 } 353 }
337 354
338 void ShowTooltip() { 355 void ShowTooltip() {
339 launcher_view_->tooltip_manager()->ShowInternal(); 356 launcher_view_->tooltip_manager()->ShowInternal();
340 } 357 }
341 358
342 MockLauncherDelegate delegate_; 359 MockLauncherDelegate delegate_;
343 scoped_ptr<LauncherModel> model_; 360 scoped_ptr<LauncherModel> model_;
361 scoped_ptr<views::Widget> widget_;
344 scoped_ptr<internal::LauncherView> launcher_view_; 362 scoped_ptr<internal::LauncherView> launcher_view_;
345 scoped_ptr<LauncherViewTestAPI> test_api_; 363 scoped_ptr<LauncherViewTestAPI> test_api_;
346 364
347 private: 365 private:
348 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); 366 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
349 }; 367 };
350 368
351 // Adds browser button until overflow and verifies that the last added browser 369 // Adds browser button until overflow and verifies that the last added browser
352 // button is hidden. 370 // button is hidden.
353 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) { 371 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state()); 693 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state());
676 item.status = ash::STATUS_ACTIVE; 694 item.status = ash::STATUS_ACTIVE;
677 model_->Set(index, item); 695 model_->Set(index, item);
678 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state()); 696 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state());
679 item.status = ash::STATUS_ATTENTION; 697 item.status = ash::STATUS_ATTENTION;
680 model_->Set(index, item); 698 model_->Set(index, item);
681 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state()); 699 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state());
682 } 700 }
683 701
684 TEST_F(LauncherViewTest, LauncherTooltipTest) { 702 TEST_F(LauncherViewTest, LauncherTooltipTest) {
703 EnsureViewIsInWidget();
704
685 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 705 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
686 test_api_->GetButtonCount()); 706 test_api_->GetButtonCount());
687 707
688 // Prepare some items to the launcher. 708 // Prepare some items to the launcher.
689 LauncherID app_button_id = AddAppShortcut(); 709 LauncherID app_button_id = AddAppShortcut();
690 LauncherID tab_button_id = AddTabbedBrowser(); 710 LauncherID tab_button_id = AddTabbedBrowser();
691 711
692 internal::LauncherButton* app_button = GetButtonByID(app_button_id); 712 internal::LauncherButton* app_button = GetButtonByID(app_button_id);
693 internal::LauncherButton* tab_button = GetButtonByID(tab_button_id); 713 internal::LauncherButton* tab_button = GetButtonByID(tab_button_id);
694 714
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 const int app_list_button_index = test_api_->GetButtonCount() - 1; 850 const int app_list_button_index = test_api_->GetButtonCount() - 1;
831 const gfx::Rect& app_list_ideal_bounds = 851 const gfx::Rect& app_list_ideal_bounds =
832 test_api_->GetIdealBoundsByIndex(app_list_button_index); 852 test_api_->GetIdealBoundsByIndex(app_list_button_index);
833 const gfx::Rect& app_list_bounds = 853 const gfx::Rect& app_list_bounds =
834 test_api_->GetBoundsByIndex(app_list_button_index); 854 test_api_->GetBoundsByIndex(app_list_button_index);
835 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); 855 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds);
836 } 856 }
837 857
838 } // namespace test 858 } // namespace test
839 } // namespace ash 859 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_tooltip_manager_unittest.cc ('k') | ash/shell/widgets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698