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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_unittest.cc

Issue 2763893004: arc: Fix regression in handling ARC shelf item. (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #include "extensions/browser/app_window/native_app_window.h" 104 #include "extensions/browser/app_window/native_app_window.h"
105 #include "extensions/common/extension.h" 105 #include "extensions/common/extension.h"
106 #include "extensions/common/manifest_constants.h" 106 #include "extensions/common/manifest_constants.h"
107 #include "testing/gtest/include/gtest/gtest.h" 107 #include "testing/gtest/include/gtest/gtest.h"
108 #include "ui/aura/client/window_parenting_client.h" 108 #include "ui/aura/client/window_parenting_client.h"
109 #include "ui/aura/window.h" 109 #include "ui/aura/window.h"
110 #include "ui/base/models/menu_model.h" 110 #include "ui/base/models/menu_model.h"
111 #include "ui/display/display.h" 111 #include "ui/display/display.h"
112 #include "ui/display/display_switches.h" 112 #include "ui/display/display_switches.h"
113 #include "ui/display/screen.h" 113 #include "ui/display/screen.h"
114 #include "ui/events/base_event_utils.h"
114 #include "ui/events/event_constants.h" 115 #include "ui/events/event_constants.h"
115 #include "ui/views/widget/widget.h" 116 #include "ui/views/widget/widget.h"
116 117
117 using base::ASCIIToUTF16; 118 using base::ASCIIToUTF16;
118 using extensions::Extension; 119 using extensions::Extension;
119 using extensions::Manifest; 120 using extensions::Manifest;
120 using extensions::UnloadedExtensionInfo; 121 using extensions::UnloadedExtensionInfo;
121 using arc::mojom::OrientationLock; 122 using arc::mojom::OrientationLock;
122 123
123 namespace { 124 namespace {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 void UnpinAppWithID(const std::string& app_id) override { 316 void UnpinAppWithID(const std::string& app_id) override {
316 return controller_->UnpinAppWithID(app_id); 317 return controller_->UnpinAppWithID(app_id);
317 } 318 }
318 319
319 private: 320 private:
320 ChromeLauncherControllerImpl* const controller_; 321 ChromeLauncherControllerImpl* const controller_;
321 322
322 DISALLOW_COPY_AND_ASSIGN(ProxyShelfDelegate); 323 DISALLOW_COPY_AND_ASSIGN(ProxyShelfDelegate);
323 }; 324 };
324 325
326 // A callback that does nothing after shelf item selection handling.
327 void NoopCallback(ash::ShelfAction action, base::Optional<MenuItemList>) {}
328
329 // Simulates selection of the shelf item.
330 void SelectItem(ash::mojom::ShelfItemDelegate* delegate) {
331 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::MouseEvent>(
332 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
333 ui::EF_NONE, 0);
334 delegate->ItemSelected(std::move(event), display::kInvalidDisplayId,
335 ash::LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback));
336 }
337
325 } // namespace 338 } // namespace
326 339
327 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { 340 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest {
328 protected: 341 protected:
329 ChromeLauncherControllerImplTest() 342 ChromeLauncherControllerImplTest()
330 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} 343 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {}
331 344
332 ~ChromeLauncherControllerImplTest() override {} 345 ~ChromeLauncherControllerImplTest() override {}
333 346
334 void SetUp() override { 347 void SetUp() override {
(...skipping 3431 matching lines...) Expand 10 before | Expand all | Expand 10 after
3766 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED, 3779 ValidateArcState(false, false, arc::ArcSessionManager::State::STOPPED,
3767 "AppList, Chrome"); 3780 "AppList, Chrome");
3768 3781
3769 // Even if re-enable it again, Play Store pin does not appear automatically. 3782 // Even if re-enable it again, Play Store pin does not appear automatically.
3770 EnablePlayStore(true); 3783 EnablePlayStore(true);
3771 ValidateArcState(true, false, 3784 ValidateArcState(true, false,
3772 arc::ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE, 3785 arc::ArcSessionManager::State::NEGOTIATING_TERMS_OF_SERVICE,
3773 "AppList, Chrome"); 3786 "AppList, Chrome");
3774 } 3787 }
3775 3788
3789 // Test that validates correctness of switching multiple shelf item for the same
msw 2017/03/22 00:30:15 nit: maybe "Test the application menu of a shelf i
khmel 2017/03/22 00:39:57 Done.
3790 // ARC app.
3791 TEST_P(ChromeLauncherControllerImplWithArcTest, MultipleItemsInShelf) {
msw 2017/03/22 00:30:15 nit: maybe s/MultipleItemsInShelf/ShelfItemWithMul
khmel 2017/03/22 00:39:57 Done.
3792 InitLauncherControllerWithBrowser();
3793
3794 arc::mojom::AppInfo appinfo =
3795 CreateAppInfo("Test1", "test", "com.example.app", OrientationLock::NONE);
3796 AddArcAppAndShortcut(appinfo);
3797
3798 // Widgets will be deleted by the system.
3799 NotifyOnTaskCreated(appinfo, 1 /* task_id */);
3800 views::Widget* window1 = CreateArcWindow("org.chromium.arc.1");
3801 ASSERT_TRUE(window1);
3802 EXPECT_TRUE(window1->IsActive());
3803
3804 NotifyOnTaskCreated(appinfo, 2 /* task_id */);
3805 views::Widget* window2 = CreateArcWindow("org.chromium.arc.2");
3806 ASSERT_TRUE(window2);
3807
3808 EXPECT_FALSE(window1->IsActive());
3809 EXPECT_TRUE(window2->IsActive());
3810
3811 const std::string app_id = ArcAppTest::GetAppId(appinfo);
3812
3813 const ash::ShelfID shelf_app_id =
msw 2017/03/22 00:30:15 nit: name this |shelf_id|, it's not an app_id stri
khmel 2017/03/22 00:39:58 Done.
3814 launcher_controller_->GetShelfIDForAppID(app_id);
3815 LauncherItemController* item_controller =
3816 launcher_controller_->GetLauncherItemController(shelf_app_id);
3817 ASSERT_TRUE(item_controller);
3818
3819 // Selecting the item does not change active window.
msw 2017/03/22 00:30:15 nit: maybe "Selecting the item will show its appli
khmel 2017/03/22 00:39:57 Done.
3820 SelectItem(item_controller);
3821 EXPECT_FALSE(window1->IsActive());
3822 EXPECT_TRUE(window2->IsActive());
3823
3824 // Command ids is just app window indices. Note, apps is registered in
msw 2017/03/22 00:30:15 nit: s/is/are/ in both cases
khmel 2017/03/22 00:39:57 Done.
3825 // opposite order. Last created goes in front.
3826 MenuItemList items = item_controller->GetAppMenuItems(0);
3827 ASSERT_EQ(items.size(), 2U);
3828 EXPECT_EQ(items[0]->command_id, 0U);
3829 EXPECT_EQ(items[1]->command_id, 1U);
3830
3831 // Execute command to activate first window.
3832 item_controller->ExecuteCommand(items[1]->command_id, 0);
3833 EXPECT_TRUE(window1->IsActive());
3834 EXPECT_FALSE(window2->IsActive());
3835
3836 // Selecting the item does not change active window.
3837 SelectItem(item_controller);
3838 EXPECT_TRUE(window1->IsActive());
3839 EXPECT_FALSE(window2->IsActive());
3840
3841 // Execute command to activate second window.
3842 item_controller->ExecuteCommand(items[0]->command_id, 0);
3843 EXPECT_FALSE(window1->IsActive());
3844 EXPECT_TRUE(window2->IsActive());
3845 }
3846
3776 namespace { 3847 namespace {
3777 3848
3778 class ChromeLauncherControllerOrientationTest 3849 class ChromeLauncherControllerOrientationTest
3779 : public ChromeLauncherControllerImplWithArcTest { 3850 : public ChromeLauncherControllerImplWithArcTest {
3780 public: 3851 public:
3781 ChromeLauncherControllerOrientationTest() {} 3852 ChromeLauncherControllerOrientationTest() {}
3782 ~ChromeLauncherControllerOrientationTest() override {} 3853 ~ChromeLauncherControllerOrientationTest() override {}
3783 3854
3784 protected: 3855 protected:
3785 void InitApps() { 3856 void InitApps() {
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
4351 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4422 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4352 shelf_controller->auto_hide()); 4423 shelf_controller->auto_hide());
4353 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4424 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4354 4425
4355 PrefService* prefs = profile()->GetTestingPrefService(); 4426 PrefService* prefs = profile()->GetTestingPrefService();
4356 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4427 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4357 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4428 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4358 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4429 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4359 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4430 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4360 } 4431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698