| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_delegate.h" | 5 #include "ash/shelf/shelf_delegate.h" |
| 6 #include "ash/shelf/shelf_util.h" | 6 #include "ash/shelf/shelf_util.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
| 12 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 13 #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/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/arc_app_deferred_launcher_controller.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 17 #include "chromeos/chromeos_switches.h" | 18 #include "chromeos/chromeos_switches.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 19 #include "mojo/common/common_type_converters.h" | 20 #include "mojo/common/common_type_converters.h" |
| 20 | 21 |
| 21 namespace mojo { | 22 namespace mojo { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 107 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 107 app_prefs()->GetApp(GetTestApp1Id()); | 108 app_prefs()->GetApp(GetTestApp1Id()); |
| 108 ASSERT_TRUE(app_info); | 109 ASSERT_TRUE(app_info); |
| 109 EXPECT_TRUE(app_info->ready); | 110 EXPECT_TRUE(app_info->ready); |
| 110 if (multi_app) { | 111 if (multi_app) { |
| 111 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info2 = | 112 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info2 = |
| 112 app_prefs()->GetApp(GetTestApp2Id()); | 113 app_prefs()->GetApp(GetTestApp2Id()); |
| 113 ASSERT_TRUE(app_info2); | 114 ASSERT_TRUE(app_info2); |
| 114 EXPECT_TRUE(app_info2->ready); | 115 EXPECT_TRUE(app_info2->ready); |
| 115 } | 116 } |
| 117 } |
| 116 | 118 |
| 119 void SendPackageAdded(bool package_synced) { |
| 117 arc::mojom::ArcPackageInfo package_info; | 120 arc::mojom::ArcPackageInfo package_info; |
| 118 package_info.package_name = kTestAppPackage; | 121 package_info.package_name = kTestAppPackage; |
| 119 package_info.package_version = 1; | 122 package_info.package_version = 1; |
| 120 package_info.last_backup_android_id = 1; | 123 package_info.last_backup_android_id = 1; |
| 121 package_info.last_backup_time = 1; | 124 package_info.last_backup_time = 1; |
| 122 package_info.sync = false; | 125 package_info.sync = package_synced; |
| 126 package_info.system = false; |
| 123 app_host()->OnPackageAdded(arc::mojom::ArcPackageInfo::From(package_info)); | 127 app_host()->OnPackageAdded(arc::mojom::ArcPackageInfo::From(package_info)); |
| 124 | 128 |
| 125 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 126 } | 130 } |
| 127 | 131 |
| 128 void SendPackageUpdated(bool multi_app) { | 132 void SendPackageUpdated(bool multi_app) { |
| 129 app_host()->OnPackageAppListRefreshed(kTestAppPackage, | 133 app_host()->OnPackageAppListRefreshed(kTestAppPackage, |
| 130 GetTestAppsList(multi_app)); | 134 GetTestAppsList(multi_app)); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void SendPackageRemoved() { app_host()->OnPackageRemoved(kTestAppPackage); } | 137 void SendPackageRemoved() { app_host()->OnPackageRemoved(kTestAppPackage); } |
| 134 | 138 |
| 135 void StartInstance() { | 139 void StartInstance() { |
| 136 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 140 if (auth_service()->profile() != profile()) |
| 141 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 137 app_instance_observer()->OnInstanceReady(); | 142 app_instance_observer()->OnInstanceReady(); |
| 138 } | 143 } |
| 139 | 144 |
| 140 void StopInstance() { | 145 void StopInstance() { |
| 141 auth_service()->Shutdown(); | 146 auth_service()->Shutdown(); |
| 142 app_instance_observer()->OnInstanceClosed(); | 147 app_instance_observer()->OnInstanceClosed(); |
| 143 } | 148 } |
| 144 | 149 |
| 145 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } | 150 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } |
| 146 | 151 |
| 147 // Returns as AppHost interface in order to access to private implementation | 152 // Returns as AppHost interface in order to access to private implementation |
| 148 // of the interface. | 153 // of the interface. |
| 149 arc::mojom::AppHost* app_host() { return app_prefs(); } | 154 arc::mojom::AppHost* app_host() { return app_prefs(); } |
| 150 | 155 |
| 151 // Returns as AppInstance observer interface in order to access to private | 156 // Returns as AppInstance observer interface in order to access to private |
| 152 // implementation of the interface. | 157 // implementation of the interface. |
| 153 arc::InstanceHolder<arc::mojom::AppInstance>::Observer* | 158 arc::InstanceHolder<arc::mojom::AppInstance>::Observer* |
| 154 app_instance_observer() { | 159 app_instance_observer() { |
| 155 return app_prefs(); | 160 return app_prefs(); |
| 156 } | 161 } |
| 157 | 162 |
| 158 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); } | 163 arc::ArcAuthService* auth_service() { return arc::ArcAuthService::Get(); } |
| 159 | 164 |
| 160 private: | 165 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest); | 166 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherBrowserTest); |
| 162 }; | 167 }; |
| 163 | 168 |
| 164 // This tests validates pin state on package update and remove. | 169 // This tests validates pin state on package update and remove. |
| 165 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { | 170 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { |
| 171 StartInstance(); |
| 166 InstallTestApps(true); | 172 InstallTestApps(true); |
| 173 SendPackageAdded(false); |
| 167 | 174 |
| 168 const std::string app_id1 = GetTestApp1Id(); | 175 const std::string app_id1 = GetTestApp1Id(); |
| 169 const std::string app_id2 = GetTestApp2Id(); | 176 const std::string app_id2 = GetTestApp2Id(); |
| 170 shelf_delegate()->PinAppWithID(app_id1); | 177 shelf_delegate()->PinAppWithID(app_id1); |
| 171 shelf_delegate()->PinAppWithID(app_id2); | 178 shelf_delegate()->PinAppWithID(app_id2); |
| 172 const ash::ShelfID shelf_id1_before = | 179 const ash::ShelfID shelf_id1_before = |
| 173 shelf_delegate()->GetShelfIDForAppID(app_id1); | 180 shelf_delegate()->GetShelfIDForAppID(app_id1); |
| 174 EXPECT_TRUE(shelf_id1_before); | 181 EXPECT_TRUE(shelf_id1_before); |
| 175 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2)); | 182 EXPECT_TRUE(shelf_delegate()->GetShelfIDForAppID(app_id2)); |
| 176 | 183 |
| 177 // Package contains only one app. | 184 // Package contains only one app. App list is not shown for updated package. |
| 178 SendPackageUpdated(false); | 185 SendPackageUpdated(false); |
| 179 // Second pin should gone. | 186 // Second pin should gone. |
| 180 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); | 187 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); |
| 181 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); | 188 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); |
| 182 | 189 |
| 183 // Package contains two apps. | 190 // Package contains two apps. App list is not shown for updated package. |
| 184 SendPackageUpdated(true); | 191 SendPackageUpdated(true); |
| 185 // Second pin should not appear. | 192 // Second pin should not appear. |
| 186 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); | 193 EXPECT_EQ(shelf_id1_before, shelf_delegate()->GetShelfIDForAppID(app_id1)); |
| 187 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); | 194 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); |
| 188 | 195 |
| 189 // Package removed. | 196 // Package removed. |
| 190 SendPackageRemoved(); | 197 SendPackageRemoved(); |
| 191 // No pin is expected. | 198 // No pin is expected. |
| 192 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1)); | 199 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id1)); |
| 193 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); | 200 EXPECT_FALSE(shelf_delegate()->GetShelfIDForAppID(app_id2)); |
| 194 } | 201 } |
| 202 |
| 203 // This test validates that app list is shown on new package and not shown |
| 204 // on package update. |
| 205 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { |
| 206 StartInstance(); |
| 207 AppListService* app_list_service = AppListService::Get(); |
| 208 ASSERT_TRUE(app_list_service); |
| 209 |
| 210 EXPECT_FALSE(app_list_service->IsAppListVisible()); |
| 211 |
| 212 // New package is available. Show app list. |
| 213 InstallTestApps(false); |
| 214 SendPackageAdded(true); |
| 215 EXPECT_TRUE(app_list_service->IsAppListVisible()); |
| 216 |
| 217 app_list_service->DismissAppList(); |
| 218 EXPECT_FALSE(app_list_service->IsAppListVisible()); |
| 219 |
| 220 // Send package update event. App list is not shown. |
| 221 SendPackageAdded(true); |
| 222 EXPECT_FALSE(app_list_service->IsAppListVisible()); |
| 223 } |
| OLD | NEW |