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

Side by Side Diff: chrome/browser/ui/views/arc_app_dialog_view_browsertest.cc

Issue 2529783002: arc: Implement uninstall confirmation dialog for Arc app. (Closed)
Patch Set: Address minor comments. Rebase. Created 4 years 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
« no previous file with comments | « chrome/browser/ui/views/arc_app_dialog_view.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/profiles/profile.h"
11 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
12 #include "chrome/browser/ui/app_list/app_list_service.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
14 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
15 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "components/arc/arc_bridge_service.h"
21 #include "components/arc/common/app.mojom.h"
22 #include "components/arc/test/fake_app_instance.h"
23 #include "content/public/test/test_utils.h"
24
25 namespace arc {
26
27 class ArcAppUninstallDialogViewBrowserTest : public InProcessBrowserTest {
28 public:
29 ArcAppUninstallDialogViewBrowserTest() {}
30
31 // InProcessBrowserTest:
32 ~ArcAppUninstallDialogViewBrowserTest() override {}
33
34 void SetUpAppInstance() {
35 profile_ = browser()->profile();
36
37 base::CommandLine::ForCurrentProcess()->AppendSwitch(
38 chromeos::switches::kEnableArc);
39
40 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and
41 // the Arc session manager.
42 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_);
43 if (!arc_app_list_pref_) {
44 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting(
45 profile_);
46 }
47
48 DCHECK(ArcBridgeService::Get());
49 ArcSessionManager* session_manager = ArcSessionManager::Get();
50 DCHECK(session_manager);
51 ArcSessionManager::DisableUIForTesting();
52 session_manager->OnPrimaryUserProfilePrepared(profile_);
53 session_manager->EnableArc();
54
55 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_);
56 DCHECK(arc_app_list_pref_);
57
58 base::RunLoop run_loop;
59 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure());
60 run_loop.Run();
61
62 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_));
63 arc_app_list_pref_->app_instance_holder()->SetInstance(app_instance_.get());
64
65 // In this setup, we have one app and one shortcut which share one package.
66 mojom::AppInfo app;
67 app.name = base::StringPrintf("Fake App %d", 0);
68 app.package_name = base::StringPrintf("fake.package.%d", 0);
69 app.activity = base::StringPrintf("fake.app.%d.activity", 0);
70 app.sticky = false;
71 app_instance_->SendRefreshAppList(std::vector<mojom::AppInfo>(1, app));
72
73 mojom::ShortcutInfo shortcut;
74 shortcut.name = base::StringPrintf("Fake Shortcut %d", 0);
75 shortcut.package_name = base::StringPrintf("fake.package.%d", 0);
76 shortcut.intent_uri = base::StringPrintf("Fake Shortcut uri %d", 0);
77 app_instance_->SendInstallShortcut(shortcut);
78
79 mojom::ArcPackageInfo package;
80 package.package_name = base::StringPrintf("fake.package.%d", 0);
81 package.package_version = 0;
82 package.last_backup_android_id = 0;
83 package.last_backup_time = 0;
84 package.sync = false;
85 app_instance_->SendRefreshPackageList(
86 std::vector<mojom::ArcPackageInfo>(1, package));
87 }
88
89 void TearDownOnMainThread() override {
90 ArcSessionManager::Get()->Shutdown();
91 InProcessBrowserTest::TearDownOnMainThread();
92 }
93
94 // Ensures the ArcAppDialogView is destoryed.
95 void TearDown() override { ASSERT_FALSE(IsArcAppDialogViewAliveForTest()); }
96
97 ArcAppListPrefs* arc_app_list_pref() { return arc_app_list_pref_; }
98
99 FakeAppInstance* instance() { return app_instance_.get(); }
100
101 private:
102 ArcAppListPrefs* arc_app_list_pref_ = nullptr;
103
104 Profile* profile_ = nullptr;
105
106 std::unique_ptr<arc::FakeAppInstance> app_instance_;
107
108 DISALLOW_COPY_AND_ASSIGN(ArcAppUninstallDialogViewBrowserTest);
109 };
110
111 // User confirms/cancels Arc app uninstall. Note that the shortcut is removed
112 // when the app and the package are uninstalled since the shortcut and the app
113 // share same package.
114 IN_PROC_BROWSER_TEST_F(ArcAppUninstallDialogViewBrowserTest,
115 UserConfirmsUninstall) {
116 SetUpAppInstance();
117
118 std::vector<std::string> app_ids = arc_app_list_pref()->GetAppIds();
119 EXPECT_EQ(app_ids.size(), 2u);
120 std::string package_name = base::StringPrintf("fake.package.%d", 0);
121 std::string app_activity = base::StringPrintf("fake.app.%d.activity", 0);
122 std::string app_id =
123 arc_app_list_pref()->GetAppId(package_name, app_activity);
124
125 AppListService* service = AppListService::Get();
126 ASSERT_TRUE(service);
127 service->ShowForProfile(browser()->profile());
128 AppListControllerDelegate* controller(service->GetControllerDelegate());
129 ASSERT_TRUE(controller);
130 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id);
131 content::RunAllPendingInMessageLoop();
132
133 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(false));
134 content::RunAllPendingInMessageLoop();
135 app_ids = arc_app_list_pref()->GetAppIds();
136 EXPECT_EQ(app_ids.size(), 2u);
137
138 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id);
139 content::RunAllPendingInMessageLoop();
140
141 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(true));
142 content::RunAllPendingInMessageLoop();
143 app_ids = arc_app_list_pref()->GetAppIds();
144 EXPECT_EQ(app_ids.size(), 0u);
145 controller->DismissView();
146 }
147
148 // User confirms/cancels Arc app shortcut removal. Note that the app is not
149 // uninstalled when the shortcut is removed.
150 IN_PROC_BROWSER_TEST_F(ArcAppUninstallDialogViewBrowserTest,
151 UserConfirmsUninstallShortcut) {
152 SetUpAppInstance();
153
154 std::vector<std::string> app_ids = arc_app_list_pref()->GetAppIds();
155 EXPECT_EQ(app_ids.size(), 2u);
156 std::string package_name = base::StringPrintf("fake.package.%d", 0);
157 std::string intent_uri = base::StringPrintf("Fake Shortcut uri %d", 0);
158 std::string app_id = arc_app_list_pref()->GetAppId(package_name, intent_uri);
159
160 AppListService* service = AppListService::Get();
161 ASSERT_TRUE(service);
162 service->ShowForProfile(browser()->profile());
163 AppListControllerDelegate* controller(service->GetControllerDelegate());
164 ASSERT_TRUE(controller);
165 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id);
166 content::RunAllPendingInMessageLoop();
167
168 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(false));
169 content::RunAllPendingInMessageLoop();
170 app_ids = arc_app_list_pref()->GetAppIds();
171 EXPECT_EQ(app_ids.size(), 2u);
172
173 ShowArcAppUninstallDialog(browser()->profile(), controller, app_id);
174 content::RunAllPendingInMessageLoop();
175
176 EXPECT_TRUE(CloseAppDialogViewAndConfirmForTest(true));
177 content::RunAllPendingInMessageLoop();
178 app_ids = arc_app_list_pref()->GetAppIds();
179 EXPECT_EQ(app_ids.size(), 1u);
180 controller->DismissView();
181 }
182
183 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/arc_app_dialog_view.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698