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

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

Issue 2263013002: [Merge-M53] arc: Add package app list updated event. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2785
Patch Set: resolve browser_tests Created 4 years, 4 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
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_unittest.cc ('k') | chrome/chrome_tests.gypi » ('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 "ash/shelf/shelf_delegate.h"
6 #include "ash/shelf/shelf_util.h"
7 #include "ash/shell.h"
8 #include "ash/wm/window_util.h"
9 #include "base/macros.h"
10 #include "base/run_loop.h"
11 #include "chrome/browser/extensions/extension_browsertest.h"
12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
14 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "mojo/common/common_type_converters.h"
20
21 namespace mojo {
22
23 template <>
24 struct TypeConverter<arc::mojom::AppInfoPtr, arc::mojom::AppInfo> {
25 static arc::mojom::AppInfoPtr Convert(const arc::mojom::AppInfo& app_info) {
26 return app_info.Clone();
27 }
28 };
29
30 template <>
31 struct TypeConverter<arc::mojom::ArcPackageInfoPtr,
32 arc::mojom::ArcPackageInfo> {
33 static arc::mojom::ArcPackageInfoPtr Convert(
34 const arc::mojom::ArcPackageInfo& package_info) {
35 return package_info.Clone();
36 }
37 };
38
39 } // namespace mojo
40
41 namespace {
42
43 const char kTestAppName[] = "Test Arc App";
44 const char kTestAppName2[] = "Test Arc App 2";
45 const char kTestAppPackage[] = "test.arc.app.package";
46 const char kTestAppActivity[] = "test.arc.app.package.activity";
47 const char kTestAppActivity2[] = "test.arc.app.package.activity2";
48
49 std::string GetTestApp1Id() {
50 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity);
51 }
52
53 std::string GetTestApp2Id() {
54 return ArcAppListPrefs::GetAppId(kTestAppPackage, kTestAppActivity2);
55 }
56
57 mojo::Array<arc::mojom::AppInfoPtr> GetTestAppsList(bool multi_app) {
58 std::vector<arc::mojom::AppInfo> apps;
59
60 arc::mojom::AppInfo app;
61 app.name = kTestAppName;
62 app.package_name = kTestAppPackage;
63 app.activity = kTestAppActivity;
64 app.sticky = false;
65 apps.push_back(app);
66
67 if (multi_app) {
68 app.name = kTestAppName2;
69 app.package_name = kTestAppPackage;
70 app.activity = kTestAppActivity2;
71 app.sticky = false;
72 apps.push_back(app);
73 }
74
75 return mojo::Array<arc::mojom::AppInfoPtr>::From(apps);
76 }
77
78 ash::ShelfDelegate* shelf_delegate() {
79 return ash::Shell::GetInstance()->GetShelfDelegate();
80 }
81
82 } // namespace
83
84 class ArcAppLauncherBrowserTest : public ExtensionBrowserTest {
85 public:
86 ArcAppLauncherBrowserTest() {}
87 ~ArcAppLauncherBrowserTest() override {}
88
89 protected:
90 // content::BrowserTestBase:
91 void SetUpCommandLine(base::CommandLine* command_line) override {
92 ExtensionBrowserTest::SetUpCommandLine(command_line);
93 command_line->AppendSwitch(chromeos::switches::kEnableArc);
94 }
95
96 void SetUpInProcessBrowserTestFixture() override {
97 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
98 arc::ArcAuthService::DisableUIForTesting();
99 }
100
101 void SetUpOnMainThread() override { arc::ArcAuthService::Get()->EnableArc(); }
102
103 void InstallTestApps(bool multi_app) {
104 app_host()->OnAppListRefreshed(GetTestAppsList(multi_app));
105
106 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
107 app_prefs()->GetApp(GetTestApp1Id());
108 ASSERT_TRUE(app_info);
109 EXPECT_TRUE(app_info->ready);
110 if (multi_app) {
111 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info2 =
112 app_prefs()->GetApp(GetTestApp2Id());
113 ASSERT_TRUE(app_info2);
114 EXPECT_TRUE(app_info2->ready);
115 }
116
117 arc::mojom::ArcPackageInfo package_info;
118 package_info.package_name = kTestAppPackage;
119 package_info.package_version = 1;
120 package_info.last_backup_android_id = 1;
121 package_info.last_backup_time = 1;
122 package_info.sync = false;
123 app_host()->OnPackageAdded(arc::mojom::ArcPackageInfo::From(package_info));
124
125 base::RunLoop().RunUntilIdle();
126 }
127
128 void SendPackageUpdated(bool multi_app) {
129 app_host()->OnPackageAppListRefreshed(kTestAppPackage,
130 GetTestAppsList(multi_app));
131 }
132
133 void SendPackageRemoved() { app_host()->OnPackageRemoved(kTestAppPackage); }
134
135 void StartInstance() {
136 auth_service()->OnPrimaryUserProfilePrepared(profile());
137 app_instance_observer()->OnInstanceReady();
138 }
139
140 void StopInstance() {
141 auth_service()->Shutdown();
142 app_instance_observer()->OnInstanceClosed();
143 }
144
145 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); }
146
147 // Returns as AppHost interface in order to access to private implementation
148 // of the interface.
149 arc::mojom::AppHost* app_host() { return app_prefs(); }
150
151 // Returns as AppInstance observer interface in order to access to private
152 // implementation of the interface.
153 arc::InstanceHolder<arc::mojom::AppInstance>::Observer*
154 app_instance_observer() {
155 return app_prefs();
156 }
157
158 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); }
159
160 private:
161 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest);
162 };
163
164 // This tests validates pin state on package update and remove.
165 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) {
166 InstallTestApps(true);
167
168 const std::string app_id1 = GetTestApp1Id();
169 const std::string app_id2 = GetTestApp2Id();
170 shelf_delegate()->PinAppWithID(app_id1);
171 shelf_delegate()->PinAppWithID(app_id2);
172 const ash::ShelfID shelf_id1_before =
173 shelf_delegate()->GetShelfIDForAppID(app_id1);
174 EXPECT_TRUE(shelf_id1_before);
175 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2));
176
177 // Package contains only one app.
178 SendPackageUpdated(false);
179 // Second pin should gone.
180 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
181 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
182
183 // Package contains two apps.
184 SendPackageUpdated(true);
185 // Second pin should not appear.
186 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1));
187 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
188
189 // Package removed.
190 SendPackageRemoved();
191 // No pin is expected.
192 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1));
193 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2));
194 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698