| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/drive/drive_app_provider.h" | 5 #include "chrome/browser/apps/drive/drive_app_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 EXPECT_FALSE(fake_drive_service()->HasApp(kDriveAppId)); | 270 EXPECT_FALSE(fake_drive_service()->HasApp(kDriveAppId)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // A matching Chrome app replaces the created URL app. | 273 // A matching Chrome app replaces the created URL app. |
| 274 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest, MatchingChromeAppInstalled) { | 274 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest, MatchingChromeAppInstalled) { |
| 275 // Prepare a Drive app that matches the not-yet-installed kChromeAppId. | 275 // Prepare a Drive app that matches the not-yet-installed kChromeAppId. |
| 276 fake_drive_service()->AddApp( | 276 fake_drive_service()->AddApp( |
| 277 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); | 277 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); |
| 278 RefreshDriveAppRegistry(); | 278 RefreshDriveAppRegistry(); |
| 279 WaitForPendingDriveAppConverters(); | 279 WaitForPendingDriveAppConverters(); |
| 280 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 280 | 281 |
| 281 // An Url app should be created. | 282 // An Url app should be created. |
| 282 const Extension* url_app = | 283 const Extension* url_app = registry->GetExtensionById( |
| 283 ExtensionRegistry::Get(profile())->GetExtensionById( | 284 mapping()->GetChromeApp(kDriveAppId), ExtensionRegistry::EVERYTHING); |
| 284 mapping()->GetChromeApp(kDriveAppId), ExtensionRegistry::EVERYTHING); | |
| 285 EXPECT_TRUE(url_app->is_hosted_app()); | 285 EXPECT_TRUE(url_app->is_hosted_app()); |
| 286 EXPECT_TRUE(url_app->from_bookmark()); | 286 EXPECT_TRUE(url_app->from_bookmark()); |
| 287 | 287 |
| 288 const std::string url_app_id = url_app->id(); | 288 const std::string url_app_id = url_app->id(); |
| 289 EXPECT_NE(kChromeAppId, url_app_id); | 289 EXPECT_NE(kChromeAppId, url_app_id); |
| 290 EXPECT_EQ(url_app_id, mapping()->GetChromeApp(kDriveAppId)); | 290 EXPECT_EQ(url_app_id, mapping()->GetChromeApp(kDriveAppId)); |
| 291 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id)); | 291 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id)); |
| 292 | 292 |
| 293 // Installs a chrome app with matching id. | 293 // Install a chrome app with matching id. |
| 294 InstallChromeApp(0); | 294 size_t num_before = registry->enabled_extensions().size(); |
| 295 InstallChromeApp(1); |
| 296 // Url app should be auto uninstalled. This happens asynchronously after the |
| 297 // installation of the app that replaces it, so the task might still be |
| 298 // pending. |
| 299 content::RunAllPendingInMessageLoop(); |
| 300 EXPECT_FALSE( |
| 301 registry->GetExtensionById(url_app_id, ExtensionRegistry::EVERYTHING)); |
| 302 EXPECT_EQ(num_before, registry->enabled_extensions().size()); |
| 295 | 303 |
| 296 // The Drive app should be mapped to chrome app. | 304 // The Drive app should be mapped to chrome app. |
| 297 EXPECT_EQ(kChromeAppId, mapping()->GetChromeApp(kDriveAppId)); | 305 EXPECT_EQ(kChromeAppId, mapping()->GetChromeApp(kDriveAppId)); |
| 298 EXPECT_FALSE(mapping()->IsChromeAppGenerated(kChromeAppId)); | 306 EXPECT_FALSE(mapping()->IsChromeAppGenerated(kChromeAppId)); |
| 299 | |
| 300 // Url app should be auto uninstalled. | |
| 301 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById( | |
| 302 url_app_id, ExtensionRegistry::EVERYTHING)); | |
| 303 } | 307 } |
| 304 | 308 |
| 305 // Tests that the corresponding URL app is uninstalled when a Drive app is | 309 // Tests that the corresponding URL app is uninstalled when a Drive app is |
| 306 // disconnected. | 310 // disconnected. |
| 307 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest, | 311 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest, |
| 308 DisconnectDriveAppUninstallUrlApp) { | 312 DisconnectDriveAppUninstallUrlApp) { |
| 309 // Prepare a Drive app that matches the not-yet-installed kChromeAppId. | 313 // Prepare a Drive app that matches the not-yet-installed kChromeAppId. |
| 310 fake_drive_service()->AddApp( | 314 fake_drive_service()->AddApp( |
| 311 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); | 315 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); |
| 312 RefreshDriveAppRegistry(); | 316 RefreshDriveAppRegistry(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); | 621 kDriveAppId, kDriveAppName, kChromeAppId, kLaunchUrl, true); |
| 618 RefreshDriveAppRegistry(); | 622 RefreshDriveAppRegistry(); |
| 619 WaitForPendingDriveAppConverters(); | 623 WaitForPendingDriveAppConverters(); |
| 620 | 624 |
| 621 // The app should be gone. | 625 // The app should be gone. |
| 622 chrome_app_id = mapping()->GetChromeApp(kDriveAppId); | 626 chrome_app_id = mapping()->GetChromeApp(kDriveAppId); |
| 623 EXPECT_TRUE(chrome_app_id.empty()); | 627 EXPECT_TRUE(chrome_app_id.empty()); |
| 624 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById( | 628 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById( |
| 625 chrome_app_id, ExtensionRegistry::EVERYTHING)); | 629 chrome_app_id, ExtensionRegistry::EVERYTHING)); |
| 626 } | 630 } |
| OLD | NEW |