Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/app_list/arc/arc_app_dialog.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
| 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
| 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
| 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | |
| 15 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 16 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | |
| 17 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | |
| 18 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | |
| 19 #include "chrome/browser/ui/browser.h" | |
| 20 #include "chrome/browser/ui/browser_window.h" | |
| 21 #include "chrome/test/base/in_process_browser_test.h" | |
| 22 #include "chromeos/chromeos_switches.h" | |
| 23 #include "components/arc/arc_bridge_service.h" | |
| 24 #include "components/arc/common/app.mojom.h" | |
| 25 #include "components/arc/test/fake_app_instance.h" | |
| 26 #include "content/public/test/test_utils.h" | |
| 27 | |
| 28 namespace arc { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 chromeos::FakeChromeUserManager* GetUserManager() { | |
|
msw
2016/11/29 20:47:37
optional nit: inline and cache a ptr below. (I see
lgcheng
2016/11/30 19:28:47
These lines turn out to be not needed for browser_
| |
| 33 return static_cast<chromeos::FakeChromeUserManager*>( | |
| 34 user_manager::UserManager::Get()); | |
| 35 } | |
| 36 | |
| 37 const user_manager::User* CreateUserAndLogin(Profile* profile) { | |
| 38 std::string gaia_id = "1234567890"; | |
| 39 const AccountId account_id( | |
| 40 AccountId::FromUserEmailGaiaId(profile->GetProfileUserName(), gaia_id)); | |
| 41 const user_manager::User* user = GetUserManager()->AddUser(account_id); | |
| 42 GetUserManager()->LoginUser(account_id); | |
| 43 return user; | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 class ArcAppUninstallDialogViewBrowserTest : public InProcessBrowserTest { | |
| 49 public: | |
| 50 ArcAppUninstallDialogViewBrowserTest() {} | |
| 51 | |
| 52 // InProcessBrowserTest: | |
| 53 ~ArcAppUninstallDialogViewBrowserTest() override {} | |
| 54 | |
| 55 void SetUpAppInstance() { | |
|
msw
2016/11/29 20:47:37
It would be nice if there was a common utility fun
lgcheng
2016/11/30 19:28:47
ArcAppTest::Setup() is very different from what is
| |
| 56 user_manager_enabler_ = | |
| 57 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | |
| 58 new chromeos::FakeChromeUserManager()); | |
| 59 profile_ = browser()->profile(); | |
| 60 const user_manager::User* user = CreateUserAndLogin(profile_); | |
| 61 // Have the user-to-profile mapping ready to avoid using the real profile | |
| 62 // manager (which is null). | |
| 63 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | |
| 64 profile_); | |
| 65 | |
| 66 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 67 chromeos::switches::kEnableArc); | |
|
msw
2016/11/29 20:47:37
nit: indentation (run "git cl format")
lgcheng
2016/11/30 19:28:47
Done.
| |
| 68 | |
| 69 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and | |
| 70 // the Arc session manager. | |
| 71 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | |
| 72 if (!arc_app_list_pref_) { | |
|
msw
2016/11/29 20:47:37
Why is this conditional? It seems like we should k
lgcheng
2016/11/30 19:28:47
The browser_test env try to call ArcAppListPrefs::
msw
2016/11/30 23:26:57
Hmm, okay.
| |
| 73 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 74 profile_); | |
| 75 } | |
| 76 | |
| 77 DCHECK(ArcBridgeService::Get()); | |
| 78 ArcSessionManager* session_manager = ArcSessionManager::Get(); | |
| 79 DCHECK(session_manager); | |
| 80 ArcSessionManager::DisableUIForTesting(); | |
| 81 session_manager->OnPrimaryUserProfilePrepared(profile_); | |
| 82 session_manager->EnableArc(); | |
| 83 | |
| 84 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | |
| 85 DCHECK(arc_app_list_pref_); | |
| 86 | |
| 87 base::RunLoop run_loop; | |
| 88 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); | |
| 89 run_loop.Run(); | |
| 90 | |
| 91 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | |
| 92 arc_app_list_pref_->app_instance_holder()->SetInstance(app_instance_.get()); | |
| 93 | |
| 94 mojom::AppInfo app; | |
| 95 app.name = base::StringPrintf("Fake App %d", 0); | |
| 96 app.package_name = base::StringPrintf("fake.app.%d", 0); | |
| 97 app.activity = base::StringPrintf("fake.app.%d.activity", 0); | |
| 98 app.sticky = false; | |
| 99 app_instance_->SendRefreshAppList(std::vector<mojom::AppInfo>(1, app)); | |
| 100 | |
| 101 mojom::ArcPackageInfo package; | |
| 102 package.package_name = base::StringPrintf("fake.app.%d", 0); | |
| 103 package.package_version = 0; | |
| 104 package.last_backup_android_id = 0; | |
| 105 package.last_backup_time = 0; | |
| 106 package.sync = false; | |
| 107 app_instance_->SendRefreshPackageList( | |
| 108 std::vector<mojom::ArcPackageInfo>(1, package)); | |
| 109 } | |
| 110 | |
| 111 void TearDownOnMainThread() override { | |
| 112 ArcSessionManager::Get()->Shutdown(); | |
| 113 user_manager_enabler_.reset(); | |
| 114 InProcessBrowserTest::TearDownOnMainThread(); | |
| 115 } | |
| 116 | |
| 117 // Ensures the ArcAppDialogView is destoryed. | |
| 118 void TearDown() override { | |
| 119 ASSERT_FALSE(IsArcAppDialogViewAliveForTest()); | |
| 120 } | |
| 121 | |
| 122 ArcAppListPrefs* arc_app_list_pref() { return arc_app_list_pref_; } | |
| 123 | |
| 124 FakeAppInstance* instance() { return app_instance_.get(); } | |
| 125 | |
| 126 private: | |
| 127 ArcAppListPrefs* arc_app_list_pref_; | |
|
msw
2016/11/29 20:47:37
nit: = nullptr;
lgcheng
2016/11/30 19:28:47
Done.
| |
| 128 | |
| 129 Profile* profile_; | |
|
msw
2016/11/29 20:47:37
nit: = nullptr;
lgcheng
2016/11/30 19:28:47
Done.
| |
| 130 | |
| 131 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | |
| 132 | |
| 133 std::unique_ptr<arc::FakeAppInstance> app_instance_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(ArcAppUninstallDialogViewBrowserTest); | |
| 136 }; | |
| 137 | |
| 138 // User confirms/cancels Arc App uninstall. | |
| 139 IN_PROC_BROWSER_TEST_F(ArcAppUninstallDialogViewBrowserTest, | |
|
msw
2016/11/29 20:47:37
Nice test fixture; should we have a similar one fo
lgcheng
2016/11/30 19:28:47
Shortcut removal test added.
| |
| 140 UserConfirmsUninstall) { | |
| 141 SetUpAppInstance(); | |
| 142 | |
| 143 std::vector<std::string> app_ids = arc_app_list_pref()->GetAppIds(); | |
| 144 EXPECT_EQ(app_ids.size(), 1u); | |
| 145 std::string app_id = app_ids[0]; | |
| 146 | |
| 147 AppListService* service = AppListService::Get(); | |
| 148 ASSERT_TRUE(service); | |
| 149 service->ShowForProfile(browser()->profile()); | |
| 150 AppListControllerDelegate* controller(service->GetControllerDelegate()); | |
| 151 ASSERT_TRUE(controller); | |
| 152 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id, | |
| 153 base::Bind(UninstallArcApp)); | |
|
msw
2016/11/29 20:47:37
nit: indentation (run "git cl format")
lgcheng
2016/11/30 19:28:47
Done.
| |
| 154 content::RunAllPendingInMessageLoop(); | |
| 155 | |
| 156 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(false)); | |
| 157 content::RunAllPendingInMessageLoop(); | |
| 158 app_ids = arc_app_list_pref()->GetAppIds(); | |
| 159 EXPECT_EQ(app_ids.size(), 1u); | |
| 160 controller->DismissView(); | |
| 161 | |
| 162 service->ShowForProfile(browser()->profile()); | |
| 163 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id, | |
| 164 base::Bind(UninstallArcApp)); | |
|
msw
2016/11/29 20:47:37
nit: indentation (run "git cl format")
lgcheng
2016/11/30 19:28:47
Done.
| |
| 165 content::RunAllPendingInMessageLoop(); | |
| 166 | |
| 167 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(true)); | |
| 168 content::RunAllPendingInMessageLoop(); | |
| 169 app_ids = arc_app_list_pref()->GetAppIds(); | |
| 170 EXPECT_EQ(app_ids.size(), 0u); | |
| 171 controller->DismissView(); | |
| 172 } | |
| 173 | |
| 174 } // namespace arc | |
| OLD | NEW |