| OLD | NEW |
| 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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/public/cpp/config.h" | 12 #include "ash/public/cpp/config.h" |
| 13 #include "ash/public/cpp/shelf_item_delegate.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 15 #include "ash/shelf/app_list_button.h" | 16 #include "ash/shelf/app_list_button.h" |
| 16 #include "ash/shelf/overflow_bubble.h" | 17 #include "ash/shelf/overflow_bubble.h" |
| 17 #include "ash/shelf/overflow_bubble_view.h" | 18 #include "ash/shelf/overflow_bubble_view.h" |
| 18 #include "ash/shelf/overflow_button.h" | 19 #include "ash/shelf/overflow_button.h" |
| 19 #include "ash/shelf/shelf_button.h" | 20 #include "ash/shelf/shelf_button.h" |
| 20 #include "ash/shelf/shelf_constants.h" | 21 #include "ash/shelf/shelf_constants.h" |
| 21 #include "ash/shelf/shelf_model.h" | 22 #include "ash/shelf/shelf_model.h" |
| 22 #include "ash/shelf/shelf_tooltip_manager.h" | 23 #include "ash/shelf/shelf_tooltip_manager.h" |
| 23 #include "ash/shelf/shelf_widget.h" | 24 #include "ash/shelf/shelf_widget.h" |
| 24 #include "ash/shelf/wm_shelf.h" | 25 #include "ash/shelf/wm_shelf.h" |
| 25 #include "ash/shelf/wm_shelf_observer.h" | 26 #include "ash/shelf/wm_shelf_observer.h" |
| 26 #include "ash/shell.h" | 27 #include "ash/shell.h" |
| 27 #include "ash/shell_port.h" | 28 #include "ash/shell_port.h" |
| 28 #include "ash/system/web_notification/web_notification_tray.h" | 29 #include "ash/system/web_notification/web_notification_tray.h" |
| 29 #include "ash/test/ash_test_base.h" | 30 #include "ash/test/ash_test_base.h" |
| 30 #include "ash/test/ash_test_helper.h" | 31 #include "ash/test/ash_test_helper.h" |
| 31 #include "ash/test/overflow_bubble_view_test_api.h" | 32 #include "ash/test/overflow_bubble_view_test_api.h" |
| 32 #include "ash/test/overflow_button_test_api.h" | 33 #include "ash/test/overflow_button_test_api.h" |
| 33 #include "ash/test/shelf_view_test_api.h" | 34 #include "ash/test/shelf_view_test_api.h" |
| 34 #include "ash/test/shell_test_api.h" | 35 #include "ash/test/shell_test_api.h" |
| 35 #include "ash/test/test_shelf_delegate.h" | |
| 36 #include "ash/test/test_shelf_item_delegate.h" | |
| 37 #include "ash/test/test_shell_delegate.h" | 36 #include "ash/test/test_shell_delegate.h" |
| 38 #include "ash/test/test_system_tray_delegate.h" | 37 #include "ash/test/test_system_tray_delegate.h" |
| 39 #include "ash/wm_window.h" | 38 #include "ash/wm_window.h" |
| 40 #include "base/i18n/rtl.h" | 39 #include "base/i18n/rtl.h" |
| 41 #include "base/macros.h" | 40 #include "base/macros.h" |
| 42 #include "base/memory/ptr_util.h" | 41 #include "base/memory/ptr_util.h" |
| 43 #include "base/numerics/safe_conversions.h" | 42 #include "base/numerics/safe_conversions.h" |
| 44 #include "base/run_loop.h" | 43 #include "base/run_loop.h" |
| 45 #include "base/strings/string_number_conversions.h" | 44 #include "base/strings/string_number_conversions.h" |
| 46 #include "base/strings/utf_string_conversions.h" | 45 #include "base/strings/utf_string_conversions.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 130 |
| 132 ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); } | 131 ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); } |
| 133 | 132 |
| 134 private: | 133 private: |
| 135 std::unique_ptr<TestWmShelfObserver> observer_; | 134 std::unique_ptr<TestWmShelfObserver> observer_; |
| 136 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; | 135 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; |
| 137 | 136 |
| 138 DISALLOW_COPY_AND_ASSIGN(WmShelfObserverIconTest); | 137 DISALLOW_COPY_AND_ASSIGN(WmShelfObserverIconTest); |
| 139 }; | 138 }; |
| 140 | 139 |
| 141 // TestShelfItemDelegate which tracks whether it gets selected. | 140 // A ShelfItemDelegate that tracks selections and reports a custom action. |
| 142 class ShelfItemSelectionTracker : public TestShelfItemDelegate { | 141 class ShelfItemSelectionTracker : public ShelfItemDelegate { |
| 143 public: | 142 public: |
| 144 ShelfItemSelectionTracker() | 143 ShelfItemSelectionTracker() : ShelfItemDelegate(AppLaunchId()) {} |
| 145 : TestShelfItemDelegate(NULL), | |
| 146 selected_(false), | |
| 147 item_selected_action_(SHELF_ACTION_NONE) {} | |
| 148 | |
| 149 ~ShelfItemSelectionTracker() override {} | 144 ~ShelfItemSelectionTracker() override {} |
| 150 | 145 |
| 151 // Resets to the initial state. | 146 size_t item_selected_count() const { return item_selected_count_; } |
| 152 void Reset() { selected_ = false; } | |
| 153 | |
| 154 void set_item_selected_action(ShelfAction item_selected_action) { | 147 void set_item_selected_action(ShelfAction item_selected_action) { |
| 155 item_selected_action_ = item_selected_action; | 148 item_selected_action_ = item_selected_action; |
| 156 } | 149 } |
| 157 | 150 |
| 158 // Returns true if the delegate was selected. | 151 // ShelfItemDelegate: |
| 159 bool WasSelected() { return selected_; } | |
| 160 | |
| 161 // TestShelfItemDelegate: | |
| 162 void ItemSelected(std::unique_ptr<ui::Event> event, | 152 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 163 int64_t display_id, | 153 int64_t display_id, |
| 164 ShelfLaunchSource source, | 154 ShelfLaunchSource source, |
| 165 const ItemSelectedCallback& callback) override { | 155 const ItemSelectedCallback& callback) override { |
| 166 selected_ = true; | 156 item_selected_count_++; |
| 167 callback.Run(item_selected_action_, base::nullopt); | 157 callback.Run(item_selected_action_, base::nullopt); |
| 168 } | 158 } |
| 159 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} |
| 160 void Close() override {} |
| 169 | 161 |
| 170 private: | 162 private: |
| 171 bool selected_; | 163 size_t item_selected_count_ = 0; |
| 172 | 164 ShelfAction item_selected_action_ = SHELF_ACTION_NONE; |
| 173 // The action reported by ItemSelected. | |
| 174 ShelfAction item_selected_action_; | |
| 175 | 165 |
| 176 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 166 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 177 }; | 167 }; |
| 178 | 168 |
| 179 TEST_F(WmShelfObserverIconTest, AddRemove) { | 169 TEST_F(WmShelfObserverIconTest, AddRemove) { |
| 180 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 170 ShelfItem item; |
| 181 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 171 item.type = TYPE_APP; |
| 182 params.bounds = gfx::Rect(0, 0, 200, 200); | 172 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 183 params.context = CurrentContext(); | 173 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); |
| 184 views::Widget widget; | |
| 185 widget.Init(params); | |
| 186 | |
| 187 TestShelfDelegate::instance()->AddShelfItem( | |
| 188 WmWindow::Get(widget.GetNativeWindow())); | |
| 189 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 174 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 190 EXPECT_TRUE(observer()->icon_positions_changed()); | 175 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 191 observer()->Reset(); | 176 observer()->Reset(); |
| 192 | 177 |
| 193 widget.Show(); | 178 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 194 widget.GetNativeWindow()->parent()->RemoveChild(widget.GetNativeWindow()); | 179 Shell::Get()->shelf_model()->RemoveItemAt(shelf_item_index); |
| 195 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 180 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 196 EXPECT_TRUE(observer()->icon_positions_changed()); | 181 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 197 observer()->Reset(); | 182 observer()->Reset(); |
| 198 } | 183 } |
| 199 | 184 |
| 200 // Make sure creating/deleting an window on one displays notifies a | 185 // Make sure creating/deleting an window on one displays notifies a |
| 201 // shelf on external display as well as one on primary. | 186 // shelf on external display as well as one on primary. |
| 202 TEST_F(WmShelfObserverIconTest, AddRemoveWithMultipleDisplays) { | 187 TEST_F(WmShelfObserverIconTest, AddRemoveWithMultipleDisplays) { |
| 203 // TODO: investigate failure in mash, http://crbug.com/695751. | 188 // TODO: investigate failure in mash, http://crbug.com/695751. |
| 204 if (Shell::GetAshConfig() == Config::MASH) | 189 if (Shell::GetAshConfig() == Config::MASH) |
| 205 return; | 190 return; |
| 206 | 191 |
| 207 UpdateDisplay("400x400,400x400"); | 192 UpdateDisplay("400x400,400x400"); |
| 193 observer()->Reset(); |
| 194 |
| 208 WmWindow* second_root = ShellPort::Get()->GetAllRootWindows()[1]; | 195 WmWindow* second_root = ShellPort::Get()->GetAllRootWindows()[1]; |
| 209 WmShelf* second_shelf = second_root->GetRootWindowController()->GetShelf(); | 196 WmShelf* second_shelf = second_root->GetRootWindowController()->GetShelf(); |
| 210 TestWmShelfObserver second_observer(second_shelf); | 197 TestWmShelfObserver second_observer(second_shelf); |
| 211 | 198 |
| 212 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 199 ShelfItem item; |
| 213 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 200 item.type = TYPE_APP; |
| 214 params.bounds = gfx::Rect(0, 0, 200, 200); | 201 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 215 params.context = CurrentContext(); | 202 EXPECT_FALSE(second_observer.icon_positions_changed()); |
| 216 views::Widget widget; | 203 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); |
| 217 widget.Init(params); | |
| 218 | |
| 219 TestShelfDelegate::instance()->AddShelfItem( | |
| 220 WmWindow::Get(widget.GetNativeWindow())); | |
| 221 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 204 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 222 EXPECT_TRUE(observer()->icon_positions_changed()); | 205 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 223 EXPECT_TRUE(second_observer.icon_positions_changed()); | 206 EXPECT_TRUE(second_observer.icon_positions_changed()); |
| 224 observer()->Reset(); | 207 observer()->Reset(); |
| 225 second_observer.Reset(); | 208 second_observer.Reset(); |
| 226 | 209 |
| 227 widget.GetNativeWindow()->parent()->RemoveChild(widget.GetNativeWindow()); | 210 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 211 EXPECT_FALSE(second_observer.icon_positions_changed()); |
| 212 Shell::Get()->shelf_model()->RemoveItemAt(shelf_item_index); |
| 228 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 213 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 229 EXPECT_TRUE(observer()->icon_positions_changed()); | 214 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 230 EXPECT_TRUE(second_observer.icon_positions_changed()); | 215 EXPECT_TRUE(second_observer.icon_positions_changed()); |
| 231 | 216 |
| 232 observer()->Reset(); | 217 observer()->Reset(); |
| 233 second_observer.Reset(); | 218 second_observer.Reset(); |
| 234 } | 219 } |
| 235 | 220 |
| 236 TEST_F(WmShelfObserverIconTest, BoundsChanged) { | 221 TEST_F(WmShelfObserverIconTest, BoundsChanged) { |
| 237 views::Widget* widget = | 222 views::Widget* widget = |
| 238 GetPrimaryShelf()->GetShelfViewForTesting()->GetWidget(); | 223 GetPrimaryShelf()->GetShelfViewForTesting()->GetWidget(); |
| 239 gfx::Rect shelf_bounds = widget->GetWindowBoundsInScreen(); | 224 gfx::Rect shelf_bounds = widget->GetWindowBoundsInScreen(); |
| 240 shelf_bounds.set_width(shelf_bounds.width() / 2); | 225 shelf_bounds.set_width(shelf_bounds.width() / 2); |
| 241 ASSERT_GT(shelf_bounds.width(), 0); | 226 ASSERT_GT(shelf_bounds.width(), 0); |
| 242 widget->SetBounds(shelf_bounds); | 227 widget->SetBounds(shelf_bounds); |
| 243 // No animation happens for ShelfView bounds change. | 228 // No animation happens for ShelfView bounds change. |
| 244 EXPECT_TRUE(observer()->icon_positions_changed()); | 229 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 245 observer()->Reset(); | 230 observer()->Reset(); |
| 246 } | 231 } |
| 247 | 232 |
| 248 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 249 // ShelfView tests. | 234 // ShelfView tests. |
| 250 | 235 |
| 251 // A ShelfDelegate test double that will always convert between ShelfIDs and app | |
| 252 // ids. This does not support pinning and unpinning operations and the return | |
| 253 // value of IsAppPinned(...) is configurable. | |
| 254 class TestShelfDelegateForShelfView : public TestShelfDelegate { | |
| 255 public: | |
| 256 TestShelfDelegateForShelfView() {} | |
| 257 ~TestShelfDelegateForShelfView() override {} | |
| 258 | |
| 259 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } | |
| 260 | |
| 261 // ShelfDelegate overrides: | |
| 262 ShelfID GetShelfIDForAppID(const std::string& app_id) override { | |
| 263 unsigned id = kInvalidShelfID; | |
| 264 EXPECT_TRUE(base::StringToUint(app_id, &id)); | |
| 265 return base::checked_cast<ShelfID>(id); | |
| 266 } | |
| 267 | |
| 268 const std::string& GetAppIDForShelfID(ShelfID id) override { | |
| 269 // Use |app_id_| member variable because returning a reference to local | |
| 270 // variable is not allowed. | |
| 271 app_id_ = base::IntToString(id); | |
| 272 return app_id_; | |
| 273 } | |
| 274 | |
| 275 void PinAppWithID(const std::string& app_id) override { NOTREACHED(); } | |
| 276 | |
| 277 bool IsAppPinned(const std::string& app_id) override { | |
| 278 return is_app_pinned_; | |
| 279 } | |
| 280 | |
| 281 void UnpinAppWithID(const std::string& app_id) override { NOTREACHED(); } | |
| 282 | |
| 283 private: | |
| 284 // Tracks whether apps are pinned or not. | |
| 285 bool is_app_pinned_ = false; | |
| 286 | |
| 287 // Temp member variable for returning a value. See the comment in the | |
| 288 // GetAppIDForShelfID(). | |
| 289 std::string app_id_; | |
| 290 | |
| 291 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); | |
| 292 }; | |
| 293 | |
| 294 class ShelfViewTest : public AshTestBase { | 236 class ShelfViewTest : public AshTestBase { |
| 295 public: | 237 public: |
| 296 static const char* | 238 static const char* |
| 297 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName; | 239 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName; |
| 298 | 240 |
| 299 ShelfViewTest() : model_(nullptr), shelf_view_(nullptr), browser_index_(1) {} | 241 ShelfViewTest() : model_(nullptr), shelf_view_(nullptr), browser_index_(1) {} |
| 300 ~ShelfViewTest() override {} | 242 ~ShelfViewTest() override {} |
| 301 | 243 |
| 302 void SetUp() override { | 244 void SetUp() override { |
| 303 AshTestBase::SetUp(); | 245 AshTestBase::SetUp(); |
| 304 model_ = Shell::Get()->shelf_model(); | 246 model_ = Shell::Get()->shelf_model(); |
| 305 shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting(); | 247 shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting(); |
| 306 | 248 |
| 307 WebNotificationTray::DisableAnimationsForTest(true); | 249 WebNotificationTray::DisableAnimationsForTest(true); |
| 308 | 250 |
| 309 // The bounds should be big enough for 4 buttons + overflow chevron. | 251 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 310 shelf_view_->SetBounds(0, 0, 500, GetShelfConstant(SHELF_SIZE)); | 252 shelf_view_->SetBounds(0, 0, 500, GetShelfConstant(SHELF_SIZE)); |
| 311 | 253 |
| 312 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 254 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
| 313 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 255 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| 314 | 256 |
| 315 ReplaceShelfDelegate(); | |
| 316 | |
| 317 // Add browser shortcut shelf item at index 0 for test. | 257 // Add browser shortcut shelf item at index 0 for test. |
| 318 AddBrowserShortcut(); | 258 AddItem(TYPE_BROWSER_SHORTCUT, true); |
| 319 } | 259 } |
| 320 | 260 |
| 321 void TearDown() override { | 261 void TearDown() override { |
| 322 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation | 262 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation |
| 323 | |
| 324 shelf_delegate_ = nullptr; | |
| 325 test_api_.reset(); | 263 test_api_.reset(); |
| 326 AshTestBase::TearDown(); | 264 AshTestBase::TearDown(); |
| 327 } | 265 } |
| 328 | 266 |
| 329 protected: | 267 protected: |
| 330 void CreateAndSetShelfItemDelegateForID(ShelfID id) { | 268 // Add shelf items of various types, and optionally wait for animations. |
| 331 model_->SetShelfItemDelegate( | 269 ShelfID AddItem(ShelfItemType type, bool wait_for_animations) { |
| 332 id, base::MakeUnique<TestShelfItemDelegate>(nullptr)); | 270 ShelfItem item; |
| 333 } | 271 item.type = type; |
| 334 | 272 if (type == TYPE_APP || type == TYPE_APP_PANEL) |
| 335 ShelfID AddBrowserShortcut() { | 273 item.status = STATUS_RUNNING; |
| 336 ShelfItem browser_shortcut; | |
| 337 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | |
| 338 | 274 |
| 339 ShelfID id = model_->next_id(); | 275 ShelfID id = model_->next_id(); |
| 340 model_->AddAt(browser_index_, browser_shortcut); | 276 item.app_launch_id = AppLaunchId(base::IntToString(id)); |
| 341 CreateAndSetShelfItemDelegateForID(id); | 277 model_->Add(item); |
| 342 test_api_->RunMessageLoopUntilAnimationsDone(); | 278 // Set a delegate; some tests require one to select the item. |
| 279 model_->SetShelfItemDelegate(id, |
| 280 base::MakeUnique<ShelfItemSelectionTracker>()); |
| 281 if (wait_for_animations) |
| 282 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 343 return id; | 283 return id; |
| 344 } | 284 } |
| 345 | 285 ShelfID AddAppShortcut() { return AddItem(TYPE_PINNED_APP, true); } |
| 346 ShelfID AddAppShortcut() { | 286 ShelfID AddPanel() { return AddItem(TYPE_APP_PANEL, true); } |
| 347 ShelfItem item; | 287 ShelfID AddAppNoWait() { return AddItem(TYPE_APP, false); } |
| 348 item.type = TYPE_PINNED_APP; | 288 ShelfID AddApp() { return AddItem(TYPE_APP, true); } |
| 349 item.status = STATUS_CLOSED; | |
| 350 | |
| 351 ShelfID id = model_->next_id(); | |
| 352 model_->Add(item); | |
| 353 CreateAndSetShelfItemDelegateForID(id); | |
| 354 test_api_->RunMessageLoopUntilAnimationsDone(); | |
| 355 return id; | |
| 356 } | |
| 357 | |
| 358 ShelfID AddPanel() { | |
| 359 ShelfID id = AddPanelNoWait(); | |
| 360 test_api_->RunMessageLoopUntilAnimationsDone(); | |
| 361 return id; | |
| 362 } | |
| 363 | |
| 364 ShelfID AddAppNoWait() { | |
| 365 ShelfItem item; | |
| 366 item.type = TYPE_APP; | |
| 367 item.status = STATUS_RUNNING; | |
| 368 | |
| 369 ShelfID id = model_->next_id(); | |
| 370 model_->Add(item); | |
| 371 CreateAndSetShelfItemDelegateForID(id); | |
| 372 return id; | |
| 373 } | |
| 374 | |
| 375 ShelfID AddPanelNoWait() { | |
| 376 ShelfItem item; | |
| 377 item.type = TYPE_APP_PANEL; | |
| 378 item.status = STATUS_RUNNING; | |
| 379 | |
| 380 ShelfID id = model_->next_id(); | |
| 381 model_->Add(item); | |
| 382 CreateAndSetShelfItemDelegateForID(id); | |
| 383 return id; | |
| 384 } | |
| 385 | |
| 386 ShelfID AddApp() { | |
| 387 ShelfID id = AddAppNoWait(); | |
| 388 test_api_->RunMessageLoopUntilAnimationsDone(); | |
| 389 return id; | |
| 390 } | |
| 391 | 289 |
| 392 void SetShelfItemTypeToAppShortcut(ShelfID id) { | 290 void SetShelfItemTypeToAppShortcut(ShelfID id) { |
| 393 int index = model_->ItemIndexByID(id); | 291 int index = model_->ItemIndexByID(id); |
| 394 DCHECK_GE(index, 0); | 292 DCHECK_GE(index, 0); |
| 395 | 293 |
| 396 ShelfItem item = model_->items()[index]; | 294 ShelfItem item = model_->items()[index]; |
| 397 | 295 |
| 398 if (item.type == TYPE_APP) { | 296 if (item.type == TYPE_APP) { |
| 399 item.type = TYPE_PINNED_APP; | 297 item.type = TYPE_PINNED_APP; |
| 400 model_->Set(index, item); | 298 model_->Set(index, item); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 573 } |
| 676 test_api_->HideOverflowBubble(); | 574 test_api_->HideOverflowBubble(); |
| 677 } | 575 } |
| 678 | 576 |
| 679 // Returns the item's ShelfID at |index|. | 577 // Returns the item's ShelfID at |index|. |
| 680 ShelfID GetItemId(int index) { | 578 ShelfID GetItemId(int index) { |
| 681 DCHECK_GE(index, 0); | 579 DCHECK_GE(index, 0); |
| 682 return model_->items()[index].id; | 580 return model_->items()[index].id; |
| 683 } | 581 } |
| 684 | 582 |
| 685 void ReplaceShelfDelegate() { | |
| 686 // Clear the value first to avoid TestShelfDelegate's singleton check. | |
| 687 test::ShellTestApi().SetShelfDelegate(nullptr); | |
| 688 shelf_delegate_ = new TestShelfDelegateForShelfView(); | |
| 689 test_api_->SetShelfDelegate(shelf_delegate_); | |
| 690 test::ShellTestApi().SetShelfDelegate(base::WrapUnique(shelf_delegate_)); | |
| 691 } | |
| 692 | |
| 693 // Returns the center coordinates for a button. Helper function for an event | 583 // Returns the center coordinates for a button. Helper function for an event |
| 694 // generator. | 584 // generator. |
| 695 gfx::Point GetButtonCenter(ShelfID button_id) { | 585 gfx::Point GetButtonCenter(ShelfID button_id) { |
| 696 return GetButtonCenter( | 586 return GetButtonCenter( |
| 697 test_api_->GetButton(model_->ItemIndexByID(button_id))); | 587 test_api_->GetButton(model_->ItemIndexByID(button_id))); |
| 698 } | 588 } |
| 699 | 589 |
| 700 gfx::Point GetButtonCenter(ShelfButton* button) { | 590 gfx::Point GetButtonCenter(ShelfButton* button) { |
| 701 return button->GetBoundsInScreen().CenterPoint(); | 591 return button->GetBoundsInScreen().CenterPoint(); |
| 702 } | 592 } |
| 703 | 593 |
| 704 ShelfModel* model_; | 594 ShelfModel* model_; |
| 705 ShelfView* shelf_view_; | 595 ShelfView* shelf_view_; |
| 706 int browser_index_; | 596 int browser_index_; |
| 707 | 597 |
| 708 // Owned by ash::ShellPort. | |
| 709 TestShelfDelegateForShelfView* shelf_delegate_; | |
| 710 | |
| 711 std::unique_ptr<ShelfViewTestAPI> test_api_; | 598 std::unique_ptr<ShelfViewTestAPI> test_api_; |
| 712 | 599 |
| 713 private: | 600 private: |
| 714 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); | 601 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); |
| 715 }; | 602 }; |
| 716 | 603 |
| 717 const char* | 604 const char* |
| 718 ShelfViewTest::kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName = | 605 ShelfViewTest::kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName = |
| 719 ShelfButtonPressedMetricTracker:: | 606 ShelfButtonPressedMetricTracker:: |
| 720 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName; | 607 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 | 1089 |
| 1203 // Tests that double-clicking an item does not activate it twice. | 1090 // Tests that double-clicking an item does not activate it twice. |
| 1204 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) { | 1091 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) { |
| 1205 // Watch for selection of the browser shortcut. | 1092 // Watch for selection of the browser shortcut. |
| 1206 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 1093 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 1207 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1094 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1208 model_->SetShelfItemDelegate( | 1095 model_->SetShelfItemDelegate( |
| 1209 browser_shelf_id, | 1096 browser_shelf_id, |
| 1210 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); | 1097 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1211 | 1098 |
| 1212 // A single click selects the item. | 1099 // A single click selects the item, but a double-click does not. |
| 1100 EXPECT_EQ(0u, selection_tracker->item_selected_count()); |
| 1213 SimulateClick(browser_index_); | 1101 SimulateClick(browser_index_); |
| 1214 EXPECT_TRUE(selection_tracker->WasSelected()); | 1102 EXPECT_EQ(1u, selection_tracker->item_selected_count()); |
| 1215 | |
| 1216 // A double-click does not select the item. | |
| 1217 selection_tracker->Reset(); | |
| 1218 SimulateDoubleClick(browser_index_); | 1103 SimulateDoubleClick(browser_index_); |
| 1219 EXPECT_FALSE(selection_tracker->WasSelected()); | 1104 EXPECT_EQ(1u, selection_tracker->item_selected_count()); |
| 1220 } | 1105 } |
| 1221 | 1106 |
| 1222 // Check that clicking an item and jittering the mouse a bit still selects the | 1107 // Check that very small mouse drags do not prevent shelf item selection. |
| 1223 // item. | |
| 1224 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { | 1108 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { |
| 1225 std::vector<std::pair<ShelfID, views::View*>> id_map; | 1109 std::vector<std::pair<ShelfID, views::View*>> id_map; |
| 1226 SetupForDragTest(&id_map); | 1110 SetupForDragTest(&id_map); |
| 1227 | 1111 |
| 1228 ShelfID shelf_id = (id_map.begin() + 1)->first; | 1112 ShelfID shelf_id = (id_map.begin() + 1)->first; |
| 1229 views::View* button = (id_map.begin() + 1)->second; | 1113 views::View* button = (id_map.begin() + 1)->second; |
| 1230 | 1114 |
| 1231 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether | 1115 // Install a ShelfItemDelegate that tracks when the shelf item is selected. |
| 1232 // the shelf item gets selected. | |
| 1233 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1116 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1234 model_->SetShelfItemDelegate( | 1117 model_->SetShelfItemDelegate( |
| 1235 shelf_id, base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); | 1118 shelf_id, base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1236 | 1119 |
| 1237 gfx::Vector2d press_offset(5, 30); | 1120 gfx::Vector2d press_offset(5, 30); |
| 1238 gfx::Point press_location = gfx::Point() + press_offset; | 1121 gfx::Point press_location = gfx::Point() + press_offset; |
| 1239 gfx::Point press_location_in_screen = | 1122 gfx::Point press_location_in_screen = |
| 1240 button->GetBoundsInScreen().origin() + press_offset; | 1123 button->GetBoundsInScreen().origin() + press_offset; |
| 1241 | 1124 |
| 1242 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, | 1125 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, |
| 1243 press_location_in_screen, ui::EventTimeForNow(), | 1126 press_location_in_screen, ui::EventTimeForNow(), |
| 1244 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1127 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1245 button->OnMousePressed(click_event); | 1128 button->OnMousePressed(click_event); |
| 1129 EXPECT_EQ(0u, selection_tracker->item_selected_count()); |
| 1246 | 1130 |
| 1247 ui::MouseEvent drag_event1( | 1131 ui::MouseEvent drag_event1( |
| 1248 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1), | 1132 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1), |
| 1249 press_location_in_screen + gfx::Vector2d(0, 1), ui::EventTimeForNow(), | 1133 press_location_in_screen + gfx::Vector2d(0, 1), ui::EventTimeForNow(), |
| 1250 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1134 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1251 button->OnMouseDragged(drag_event1); | 1135 button->OnMouseDragged(drag_event1); |
| 1252 | |
| 1253 ui::MouseEvent drag_event2( | 1136 ui::MouseEvent drag_event2( |
| 1254 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0), | 1137 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0), |
| 1255 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), | 1138 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), |
| 1256 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1139 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1257 button->OnMouseDragged(drag_event2); | 1140 button->OnMouseDragged(drag_event2); |
| 1141 EXPECT_EQ(0u, selection_tracker->item_selected_count()); |
| 1258 | 1142 |
| 1259 ui::MouseEvent release_event( | 1143 ui::MouseEvent release_event( |
| 1260 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0), | 1144 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0), |
| 1261 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), | 1145 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), |
| 1262 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1146 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1263 button->OnMouseReleased(release_event); | 1147 button->OnMouseReleased(release_event); |
| 1264 | 1148 EXPECT_EQ(1u, selection_tracker->item_selected_count()); |
| 1265 EXPECT_TRUE(selection_tracker->WasSelected()); | |
| 1266 } | 1149 } |
| 1267 | 1150 |
| 1268 // Confirm that item status changes are reflected in the buttons. | 1151 // Confirm that item status changes are reflected in the buttons. |
| 1269 TEST_F(ShelfViewTest, ShelfItemStatus) { | 1152 TEST_F(ShelfViewTest, ShelfItemStatus) { |
| 1270 // All buttons should be visible. | 1153 // All buttons should be visible. |
| 1271 ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1); | 1154 ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1); |
| 1272 | 1155 |
| 1273 // Add platform app button. | 1156 // Add platform app button. |
| 1274 ShelfID last_added = AddApp(); | 1157 ShelfID last_added = AddApp(); |
| 1275 ShelfItem item = GetItemByID(last_added); | 1158 ShelfItem item = GetItemByID(last_added); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 const int app_list_button_index = test_api_->GetButtonCount() - 1; | 1428 const int app_list_button_index = test_api_->GetButtonCount() - 1; |
| 1546 const gfx::Rect& app_list_ideal_bounds = | 1429 const gfx::Rect& app_list_ideal_bounds = |
| 1547 test_api_->GetIdealBoundsByIndex(app_list_button_index); | 1430 test_api_->GetIdealBoundsByIndex(app_list_button_index); |
| 1548 const gfx::Rect& app_list_bounds = | 1431 const gfx::Rect& app_list_bounds = |
| 1549 test_api_->GetBoundsByIndex(app_list_button_index); | 1432 test_api_->GetBoundsByIndex(app_list_button_index); |
| 1550 EXPECT_EQ(app_list_ideal_bounds, app_list_bounds); | 1433 EXPECT_EQ(app_list_ideal_bounds, app_list_bounds); |
| 1551 } | 1434 } |
| 1552 | 1435 |
| 1553 // Checks the overflow bubble size when an item is ripped off and re-inserted. | 1436 // Checks the overflow bubble size when an item is ripped off and re-inserted. |
| 1554 TEST_F(ShelfViewTest, OverflowBubbleSize) { | 1437 TEST_F(ShelfViewTest, OverflowBubbleSize) { |
| 1555 shelf_delegate_->set_is_app_pinned(true); | |
| 1556 AddButtonsUntilOverflow(); | 1438 AddButtonsUntilOverflow(); |
| 1557 // Add one more button to prevent the overflow bubble to disappear upon | 1439 // Add one more button to prevent the overflow bubble to disappear upon |
| 1558 // dragging an item out on windows (flakiness, see crbug.com/436131). | 1440 // dragging an item out on windows (flakiness, see crbug.com/436131). |
| 1559 AddAppShortcut(); | 1441 AddAppShortcut(); |
| 1560 | 1442 |
| 1561 // Show overflow bubble. | 1443 // Show overflow bubble. |
| 1562 test_api_->ShowOverflowBubble(); | 1444 test_api_->ShowOverflowBubble(); |
| 1563 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 1445 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 1564 | 1446 |
| 1565 ShelfViewTestAPI test_for_overflow_view( | 1447 ShelfViewTestAPI test_for_overflow_view( |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 } | 1887 } |
| 2006 | 1888 |
| 2007 std::unique_ptr<views::InkDrop> ink_drop_; | 1889 std::unique_ptr<views::InkDrop> ink_drop_; |
| 2008 std::vector<views::InkDropState> requested_states_; | 1890 std::vector<views::InkDropState> requested_states_; |
| 2009 | 1891 |
| 2010 private: | 1892 private: |
| 2011 DISALLOW_COPY_AND_ASSIGN(InkDropSpy); | 1893 DISALLOW_COPY_AND_ASSIGN(InkDropSpy); |
| 2012 }; | 1894 }; |
| 2013 | 1895 |
| 2014 // A ShelfItemDelegate that returns a menu for the shelf item. | 1896 // A ShelfItemDelegate that returns a menu for the shelf item. |
| 2015 class ListMenuShelfItemDelegate : public TestShelfItemDelegate { | 1897 class ListMenuShelfItemDelegate : public ShelfItemDelegate { |
| 2016 public: | 1898 public: |
| 2017 ListMenuShelfItemDelegate() : TestShelfItemDelegate(nullptr) {} | 1899 ListMenuShelfItemDelegate() : ShelfItemDelegate(AppLaunchId()) {} |
| 2018 ~ListMenuShelfItemDelegate() override {} | 1900 ~ListMenuShelfItemDelegate() override {} |
| 2019 | 1901 |
| 2020 private: | 1902 private: |
| 2021 // TestShelfItemDelegate: | 1903 // ShelfItemDelegate: |
| 2022 void ItemSelected(std::unique_ptr<ui::Event> event, | 1904 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 2023 int64_t display_id, | 1905 int64_t display_id, |
| 2024 ShelfLaunchSource source, | 1906 ShelfLaunchSource source, |
| 2025 const ItemSelectedCallback& callback) override { | 1907 const ItemSelectedCallback& callback) override { |
| 2026 // Two items are needed to show a menu; the data in the items is not tested. | 1908 // Two items are needed to show a menu; the data in the items is not tested. |
| 2027 std::vector<mojom::MenuItemPtr> items; | 1909 std::vector<mojom::MenuItemPtr> items; |
| 2028 items.push_back(ash::mojom::MenuItem::New()); | 1910 items.push_back(mojom::MenuItem::New()); |
| 2029 items.push_back(ash::mojom::MenuItem::New()); | 1911 items.push_back(mojom::MenuItem::New()); |
| 2030 callback.Run(ash::SHELF_ACTION_NONE, std::move(items)); | 1912 callback.Run(SHELF_ACTION_NONE, std::move(items)); |
| 2031 } | 1913 } |
| 1914 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} |
| 1915 void Close() override {} |
| 2032 | 1916 |
| 2033 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); | 1917 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); |
| 2034 }; | 1918 }; |
| 2035 | 1919 |
| 2036 } // namespace | 1920 } // namespace |
| 2037 | 1921 |
| 2038 // Test fixture for testing material design ink drop ripples on shelf. | 1922 // Test fixture for testing material design ink drop ripples on shelf. |
| 2039 class ShelfViewInkDropTest : public ShelfViewTest { | 1923 class ShelfViewInkDropTest : public ShelfViewTest { |
| 2040 public: | 1924 public: |
| 2041 ShelfViewInkDropTest() {} | 1925 ShelfViewInkDropTest() {} |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3131 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3015 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3132 overflow_button_ink_drop_->GetTargetInkDropState()); | 3016 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3133 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3017 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3134 IsEmpty()); | 3018 IsEmpty()); |
| 3135 | 3019 |
| 3136 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3020 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3137 } | 3021 } |
| 3138 | 3022 |
| 3139 } // namespace test | 3023 } // namespace test |
| 3140 } // namespace ash | 3024 } // namespace ash |
| OLD | NEW |