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
3 // found in the LICENSE file.
5 #include "chrome/browser/apps/drive/drive_app_provider.h"
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/timer/timer.h"
16 #include "chrome/browser/apps/drive/drive_app_mapping.h"
17 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h"
18 #include "chrome/browser/apps/drive/drive_service_bridge.h"
19 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/extension_browsertest.h"
21 #include "chrome/browser/extensions/install_tracker.h"
22 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
23 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
26 #include "chrome/common/web_application_info.h"
27 #include "components/drive/drive_app_registry.h"
28 #include "components/drive/service/fake_drive_service.h"
29 #include "content/public/test/test_utils.h"
30 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h"
33 using extensions::AppLaunchInfo
;
34 using extensions::Extension
;
35 using extensions::ExtensionRegistry
;
39 const char kDriveAppId
[] = "drive_app_id";
40 const char kDriveAppName
[] = "Fake Drive App";
41 const char kLaunchUrl
[] = "http://example.com/drive";
43 // App id of hosted_app.crx.
44 const char kChromeAppId
[] = "kbmnembihfiondgfjekmnmcbddelicoi";
46 // Stub drive service bridge.
47 class TestDriveServiceBridge
: public DriveServiceBridge
{
49 explicit TestDriveServiceBridge(drive::DriveAppRegistry
* registry
)
50 : registry_(registry
) {}
51 ~TestDriveServiceBridge() override
{}
53 drive::DriveAppRegistry
* GetAppRegistry() override
{ return registry_
; }
56 drive::DriveAppRegistry
* registry_
;
58 DISALLOW_COPY_AND_ASSIGN(TestDriveServiceBridge
);
61 class FakeUninstallSyncService
: public DriveAppUninstallSyncService
{
63 FakeUninstallSyncService() {}
64 ~FakeUninstallSyncService() override
{}
66 bool IsUninstallTracked(const std::string
& drive_app_id
) const {
67 return uninstalled_app_ids_
.find(drive_app_id
) !=
68 uninstalled_app_ids_
.end();
71 // DriveAppUninstallSyncService
72 void TrackUninstalledDriveApp(const std::string
& drive_app_id
) override
{
73 uninstalled_app_ids_
.insert(drive_app_id
);
75 void UntrackUninstalledDriveApp(const std::string
& drive_app_id
) override
{
76 auto it
= uninstalled_app_ids_
.find(drive_app_id
);
77 if (it
== uninstalled_app_ids_
.end())
79 uninstalled_app_ids_
.erase(it
);
83 std::set
<std::string
> uninstalled_app_ids_
;
85 DISALLOW_COPY_AND_ASSIGN(FakeUninstallSyncService
);
90 class DriveAppProviderTest
: public ExtensionBrowserTest
,
91 public extensions::InstallObserver
{
93 DriveAppProviderTest() {}
94 ~DriveAppProviderTest() override
{}
96 // ExtensionBrowserTest:
97 void SetUpOnMainThread() override
{
98 ExtensionBrowserTest::SetUpOnMainThread();
100 fake_drive_service_
.reset(new drive::FakeDriveService
);
101 fake_drive_service_
->LoadAppListForDriveApi("drive/applist_empty.json");
102 apps_registry_
.reset(
103 new drive::DriveAppRegistry(fake_drive_service_
.get()));
105 fake_uninstall_sync_service_
.reset(new FakeUninstallSyncService
);
108 new DriveAppProvider(profile(), fake_uninstall_sync_service_
.get()));
109 provider_
->SetDriveServiceBridgeForTest(
110 make_scoped_ptr(new TestDriveServiceBridge(apps_registry_
.get())));
112 // The DriveAppProvider in AppListSyncalbeService interferes with the
113 // test. So resets it.
114 app_list::AppListSyncableServiceFactory::GetForProfile(profile())
115 ->ResetDriveAppProviderForTest();
118 void TearDownOnMainThread() override
{
120 apps_registry_
.reset();
121 fake_drive_service_
.reset();
123 ExtensionBrowserTest::TearDownOnMainThread();
126 const Extension
* InstallChromeApp(int expected_change
) {
127 base::FilePath test_data_path
;
128 if (!PathService::Get(chrome::DIR_TEST_DATA
, &test_data_path
)) {
133 test_data_path
.AppendASCII("extensions").AppendASCII("hosted_app.crx");
134 const Extension
* extension
=
135 InstallExtension(test_data_path
, expected_change
);
139 void RefreshDriveAppRegistry() {
140 apps_registry_
->Update();
141 content::RunAllPendingInMessageLoop();
144 void WaitForPendingDriveAppConverters() {
145 DCHECK(!runner_
.get());
147 if (provider_
->pending_converters_
.empty())
150 runner_
= new content::MessageLoopRunner
;
152 pending_drive_app_converter_check_timer_
.Start(
154 base::TimeDelta::FromMilliseconds(50),
155 base::Bind(&DriveAppProviderTest::OnPendingDriveAppConverterCheckTimer
,
156 base::Unretained(this)));
160 pending_drive_app_converter_check_timer_
.Stop();
164 void InstallUserUrlApp(const std::string
& url
) {
165 DCHECK(!runner_
.get());
166 runner_
= new content::MessageLoopRunner
;
168 WebApplicationInfo web_app
;
169 web_app
.title
= base::ASCIIToUTF16("User installed Url app");
170 web_app
.app_url
= GURL(url
);
172 scoped_refptr
<extensions::CrxInstaller
> crx_installer
=
173 extensions::CrxInstaller::CreateSilent(
174 extensions::ExtensionSystem::Get(profile())->extension_service());
175 crx_installer
->set_creation_flags(Extension::FROM_BOOKMARK
);
176 extensions::InstallTracker::Get(profile())->AddObserver(this);
177 crx_installer
->InstallWebApp(web_app
);
181 extensions::InstallTracker::Get(profile())->RemoveObserver(this);
183 content::RunAllPendingInMessageLoop();
186 bool HasPendingConverters() const {
187 return !provider_
->pending_converters_
.empty();
190 drive::FakeDriveService
* fake_drive_service() {
191 return fake_drive_service_
.get();
193 FakeUninstallSyncService
* fake_uninstall_sync_service() {
194 return fake_uninstall_sync_service_
.get();
196 DriveAppProvider
* provider() { return provider_
.get(); }
197 DriveAppMapping
* mapping() { return provider_
->mapping_
.get(); }
200 void OnPendingDriveAppConverterCheckTimer() {
201 if (!HasPendingConverters())
205 // extensions::InstallObserver
206 void OnFinishCrxInstall(const std::string
& extension_id
,
207 bool success
) override
{
211 scoped_ptr
<drive::FakeDriveService
> fake_drive_service_
;
212 scoped_ptr
<FakeUninstallSyncService
> fake_uninstall_sync_service_
;
213 scoped_ptr
<drive::DriveAppRegistry
> apps_registry_
;
214 scoped_ptr
<DriveAppProvider
> provider_
;
216 base::RepeatingTimer
<DriveAppProviderTest
>
217 pending_drive_app_converter_check_timer_
;
218 scoped_refptr
<content::MessageLoopRunner
> runner_
;
220 DISALLOW_COPY_AND_ASSIGN(DriveAppProviderTest
);
223 // A Drive app maps to an existing Chrome app that has a matching id.
224 // Uninstalling the chrome app would also disconnect the drive app.
225 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, ExistingChromeApp
) {
226 // Prepare an existing chrome app.
227 const Extension
* chrome_app
= InstallChromeApp(1);
228 ASSERT_TRUE(chrome_app
);
230 // Prepare a Drive app that matches the chrome app id.
231 fake_drive_service()->AddApp(
232 kDriveAppId
, kDriveAppName
, chrome_app
->id(), kLaunchUrl
, true);
233 RefreshDriveAppRegistry();
234 EXPECT_FALSE(HasPendingConverters());
236 // The Drive app should use the matching chrome app.
237 EXPECT_EQ(chrome_app
->id(), mapping()->GetChromeApp(kDriveAppId
));
238 EXPECT_FALSE(mapping()->IsChromeAppGenerated(chrome_app
->id()));
240 // Unintalling chrome app should disconnect the Drive app on server.
241 EXPECT_TRUE(fake_drive_service()->HasApp(kDriveAppId
));
242 UninstallExtension(chrome_app
->id());
243 EXPECT_FALSE(fake_drive_service()->HasApp(kDriveAppId
));
246 // A Drive app creates an URL app when no matching Chrome app presents.
247 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, CreateUrlApp
) {
248 // Prepare a Drive app with no underlying chrome app.
249 fake_drive_service()->AddApp(
250 kDriveAppId
, kDriveAppName
, "", kLaunchUrl
, true);
251 RefreshDriveAppRegistry();
252 WaitForPendingDriveAppConverters();
254 // An Url app should be created.
255 const Extension
* chrome_app
=
256 ExtensionRegistry::Get(profile())->GetExtensionById(
257 mapping()->GetChromeApp(kDriveAppId
), ExtensionRegistry::EVERYTHING
);
258 ASSERT_TRUE(chrome_app
);
259 EXPECT_EQ(kDriveAppName
, chrome_app
->name());
260 EXPECT_TRUE(chrome_app
->is_hosted_app());
261 EXPECT_TRUE(chrome_app
->from_bookmark());
262 EXPECT_EQ(GURL(kLaunchUrl
), AppLaunchInfo::GetLaunchWebURL(chrome_app
));
264 EXPECT_EQ(chrome_app
->id(), mapping()->GetChromeApp(kDriveAppId
));
265 EXPECT_TRUE(mapping()->IsChromeAppGenerated(chrome_app
->id()));
267 // Unintalling the chrome app should disconnect the Drive app on server.
268 EXPECT_TRUE(fake_drive_service()->HasApp(kDriveAppId
));
269 UninstallExtension(chrome_app
->id());
270 EXPECT_FALSE(fake_drive_service()->HasApp(kDriveAppId
));
273 // A matching Chrome app replaces the created URL app.
274 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, MatchingChromeAppInstalled
) {
275 // Prepare a Drive app that matches the not-yet-installed kChromeAppId.
276 fake_drive_service()->AddApp(
277 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
278 RefreshDriveAppRegistry();
279 WaitForPendingDriveAppConverters();
281 // An Url app should be created.
282 const Extension
* url_app
=
283 ExtensionRegistry::Get(profile())->GetExtensionById(
284 mapping()->GetChromeApp(kDriveAppId
), ExtensionRegistry::EVERYTHING
);
285 EXPECT_TRUE(url_app
->is_hosted_app());
286 EXPECT_TRUE(url_app
->from_bookmark());
288 const std::string url_app_id
= url_app
->id();
289 EXPECT_NE(kChromeAppId
, url_app_id
);
290 EXPECT_EQ(url_app_id
, mapping()->GetChromeApp(kDriveAppId
));
291 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id
));
293 // Installs a chrome app with matching id.
296 // The Drive app should be mapped to chrome app.
297 EXPECT_EQ(kChromeAppId
, mapping()->GetChromeApp(kDriveAppId
));
298 EXPECT_FALSE(mapping()->IsChromeAppGenerated(kChromeAppId
));
300 // Url app should be auto uninstalled.
301 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
302 url_app_id
, ExtensionRegistry::EVERYTHING
));
305 // Tests that the corresponding URL app is uninstalled when a Drive app is
307 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
,
308 DisconnectDriveAppUninstallUrlApp
) {
309 // Prepare a Drive app that matches the not-yet-installed kChromeAppId.
310 fake_drive_service()->AddApp(
311 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
312 RefreshDriveAppRegistry();
313 WaitForPendingDriveAppConverters();
315 // Url app is created.
316 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
317 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
318 url_app_id
, ExtensionRegistry::EVERYTHING
));
320 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
321 RefreshDriveAppRegistry();
323 // Url app is auto uninstalled.
324 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
325 url_app_id
, ExtensionRegistry::EVERYTHING
));
328 // Tests that the matching Chrome app is preserved when a Drive app is
330 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
,
331 DisconnectDriveAppPreserveChromeApp
) {
332 // Prepare an existing chrome app.
333 const Extension
* chrome_app
= InstallChromeApp(1);
334 ASSERT_TRUE(chrome_app
);
336 // Prepare a Drive app that matches the chrome app id.
337 fake_drive_service()->AddApp(
338 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
339 RefreshDriveAppRegistry();
340 EXPECT_FALSE(HasPendingConverters());
342 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
343 RefreshDriveAppRegistry();
345 // Chrome app is still present after the Drive app is disconnected.
346 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
347 kChromeAppId
, ExtensionRegistry::EVERYTHING
));
350 // The "generated" flag of an app should stay across Drive app conversion.
351 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, KeepGeneratedFlagBetweenUpdates
) {
352 // Prepare a Drive app with no underlying chrome app.
353 fake_drive_service()->AddApp(
354 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
355 RefreshDriveAppRegistry();
356 WaitForPendingDriveAppConverters();
358 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
359 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id
));
361 // Change name to trigger an update.
362 const char kChangedName
[] = "Changed name";
363 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
364 fake_drive_service()->AddApp(
365 kDriveAppId
, kChangedName
, kChromeAppId
, kLaunchUrl
, true);
366 RefreshDriveAppRegistry();
367 WaitForPendingDriveAppConverters();
369 // It should still map to the same url app id and tagged as generated.
370 EXPECT_EQ(url_app_id
, mapping()->GetChromeApp(kDriveAppId
));
371 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id
));
374 // A new URL app replaces the existing one and keeps existing// position when a
375 // Drive app changes its name or URL.
376 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, DriveAppChanged
) {
377 // Prepare a Drive app with no underlying chrome app.
378 fake_drive_service()->AddApp(
379 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
380 RefreshDriveAppRegistry();
381 WaitForPendingDriveAppConverters();
383 // An Url app should be created.
384 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
385 const Extension
* url_app
=
386 ExtensionRegistry::Get(profile())
387 ->GetExtensionById(url_app_id
, ExtensionRegistry::EVERYTHING
);
388 ASSERT_TRUE(url_app
);
389 EXPECT_EQ(kDriveAppName
, url_app
->name());
390 EXPECT_TRUE(url_app
->is_hosted_app());
391 EXPECT_TRUE(url_app
->from_bookmark());
392 EXPECT_EQ(GURL(kLaunchUrl
), AppLaunchInfo::GetLaunchWebURL(url_app
));
393 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id
));
395 // Register the Drive app with a different name and URL.
396 const char kAnotherName
[] = "Another drive app name";
397 const char kAnotherLaunchUrl
[] = "http://example.com/another_end_point";
398 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
399 fake_drive_service()->AddApp(
400 kDriveAppId
, kAnotherName
, kChromeAppId
, kAnotherLaunchUrl
, true);
401 RefreshDriveAppRegistry();
402 WaitForPendingDriveAppConverters();
404 // Old URL app should be auto uninstalled.
405 url_app
= ExtensionRegistry::Get(profile())
406 ->GetExtensionById(url_app_id
, ExtensionRegistry::EVERYTHING
);
407 EXPECT_FALSE(url_app
);
409 // New URL app should be used.
410 const std::string new_url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
411 EXPECT_NE(new_url_app_id
, url_app_id
);
412 EXPECT_TRUE(mapping()->IsChromeAppGenerated(new_url_app_id
));
414 const Extension
* new_url_app
=
415 ExtensionRegistry::Get(profile())
416 ->GetExtensionById(new_url_app_id
, ExtensionRegistry::EVERYTHING
);
417 ASSERT_TRUE(new_url_app
);
418 EXPECT_EQ(kAnotherName
, new_url_app
->name());
419 EXPECT_TRUE(new_url_app
->is_hosted_app());
420 EXPECT_TRUE(new_url_app
->from_bookmark());
421 EXPECT_EQ(GURL(kAnotherLaunchUrl
),
422 AppLaunchInfo::GetLaunchWebURL(new_url_app
));
425 // An existing URL app is not changed when underlying drive app data (name and
426 // URL) is not changed.
427 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, NoChange
) {
428 // Prepare one Drive app.
429 fake_drive_service()->AddApp(
430 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
431 RefreshDriveAppRegistry();
432 WaitForPendingDriveAppConverters();
434 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
435 const Extension
* url_app
=
436 ExtensionRegistry::Get(profile())
437 ->GetExtensionById(url_app_id
, ExtensionRegistry::EVERYTHING
);
439 // Refresh with no actual change.
440 RefreshDriveAppRegistry();
441 EXPECT_FALSE(HasPendingConverters());
443 // Url app should remain unchanged.
444 const std::string new_url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
445 EXPECT_EQ(new_url_app_id
, url_app_id
);
447 const Extension
* new_url_app
=
448 ExtensionRegistry::Get(profile())
449 ->GetExtensionById(new_url_app_id
, ExtensionRegistry::EVERYTHING
);
450 EXPECT_EQ(url_app
, new_url_app
);
453 // User installed url app before Drive app conversion should not be tagged
454 // as generated and not auto uninstalled.
455 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, UserInstalledBeforeDriveApp
) {
456 InstallUserUrlApp(kLaunchUrl
);
458 fake_drive_service()->AddApp(
459 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
460 RefreshDriveAppRegistry();
461 WaitForPendingDriveAppConverters();
463 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
464 EXPECT_FALSE(mapping()->IsChromeAppGenerated(url_app_id
));
466 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
467 RefreshDriveAppRegistry();
469 // Url app is still present after the Drive app is disconnected.
470 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
471 url_app_id
, ExtensionRegistry::EVERYTHING
));
474 // Similar to UserInstalledBeforeDriveApp but test the case where user
475 // installation happens after Drive app conversion.
476 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, UserInstalledAfterDriveApp
) {
477 fake_drive_service()->AddApp(
478 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
479 RefreshDriveAppRegistry();
480 WaitForPendingDriveAppConverters();
482 // Drive app converted and tagged as generated.
483 const std::string url_app_id
= mapping()->GetChromeApp(kDriveAppId
);
484 EXPECT_TRUE(mapping()->IsChromeAppGenerated(url_app_id
));
486 // User installation resets the generated flag.
487 InstallUserUrlApp(kLaunchUrl
);
488 EXPECT_FALSE(mapping()->IsChromeAppGenerated(url_app_id
));
490 fake_drive_service()->RemoveAppByProductId(kChromeAppId
);
491 RefreshDriveAppRegistry();
493 // Url app is still present after the Drive app is disconnected.
494 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
495 url_app_id
, ExtensionRegistry::EVERYTHING
));
498 // Tests that uninstalling of a unremovable Drive app is tracked in
499 // DriveAppUninstallSyncService.
500 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, UninstallUnremovableDriveApp
) {
501 // Add an unremovable Drive app.
502 fake_drive_service()->AddApp(
503 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, false);
504 RefreshDriveAppRegistry();
505 WaitForPendingDriveAppConverters();
507 const std::string chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
508 ASSERT_FALSE(chrome_app_id
.empty());
510 // Simulate user uninstall.
511 UninstallExtension(chrome_app_id
);
512 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
513 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
515 // Trigger a refresh and the app should stay uninstalled.
516 RefreshDriveAppRegistry();
517 WaitForPendingDriveAppConverters();
518 EXPECT_TRUE(mapping()->GetChromeApp(kDriveAppId
).empty());
519 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
520 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
522 // Drive service still has the app.
523 EXPECT_TRUE(fake_drive_service()->HasApp(kDriveAppId
));
524 // Uninstall is tracked by DriveAppUninstallSyncService and mapping.
525 EXPECT_TRUE(fake_uninstall_sync_service()->IsUninstallTracked(kDriveAppId
));
526 EXPECT_TRUE(mapping()->IsUninstalledDriveApp(kDriveAppId
));
529 // Tests that user install removes the uninstall tracking from
530 // DriveAppUninstallSyncService.
531 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
,
532 UserInstallResetsUninstallTracking
) {
533 // Add an unremovable Drive app.
534 fake_drive_service()->AddApp(
535 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, false);
536 RefreshDriveAppRegistry();
537 WaitForPendingDriveAppConverters();
539 const std::string chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
540 ASSERT_FALSE(chrome_app_id
.empty());
542 // Simulate user uninstall and uninstall should be tracked.
543 UninstallExtension(chrome_app_id
);
544 EXPECT_TRUE(fake_uninstall_sync_service()->IsUninstallTracked(kDriveAppId
));
545 EXPECT_TRUE(mapping()->IsUninstalledDriveApp(kDriveAppId
));
547 // Simulate user install and uninstall is no longer tracked.
549 EXPECT_FALSE(fake_uninstall_sync_service()->IsUninstallTracked(kDriveAppId
));
550 EXPECT_FALSE(mapping()->IsUninstalledDriveApp(kDriveAppId
));
553 // Tests that Drive app is removed when uninstall is added from sync and
554 // added back when uninstall is removed from sync.
555 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
, UninstallChangedFromSync
) {
556 // Add an unremovable Drive app.
557 fake_drive_service()->AddApp(
558 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, false);
559 RefreshDriveAppRegistry();
560 WaitForPendingDriveAppConverters();
562 // The Drive app is present in the system.
563 std::string chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
564 EXPECT_FALSE(chrome_app_id
.empty());
565 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
566 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
568 // Uninstall is added from sync and the app is removed.
569 provider()->AddUninstalledDriveAppFromSync(kDriveAppId
);
570 content::RunAllPendingInMessageLoop();
571 WaitForPendingDriveAppConverters();
572 chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
573 EXPECT_TRUE(chrome_app_id
.empty());
574 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
575 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
577 // Uninstall is removed from sync and the app is added again.
578 provider()->RemoveUninstalledDriveAppFromSync(kDriveAppId
);
579 content::RunAllPendingInMessageLoop();
580 WaitForPendingDriveAppConverters();
581 chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
582 EXPECT_FALSE(chrome_app_id
.empty());
583 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
584 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
587 // Tests that sync changes are processed after DriveAppRegistry is updated.
588 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
,
589 PRE_UpdateAfterDriveAppRegistryUpdate
) {
591 fake_drive_service()->AddApp(
592 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
593 RefreshDriveAppRegistry();
594 WaitForPendingDriveAppConverters();
596 // The Drive app is present in the system.
597 std::string chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
598 EXPECT_FALSE(chrome_app_id
.empty());
599 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
600 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
602 IN_PROC_BROWSER_TEST_F(DriveAppProviderTest
,
603 UpdateAfterDriveAppRegistryUpdate
) {
604 // On the next run, uninstall from sync before DriveAppRegistry updates.
605 provider()->AddUninstalledDriveAppFromSync(kDriveAppId
);
606 content::RunAllPendingInMessageLoop();
607 WaitForPendingDriveAppConverters();
609 // The app should still be there.
610 std::string chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
611 EXPECT_FALSE(chrome_app_id
.empty());
612 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById(
613 chrome_app_id
, ExtensionRegistry::EVERYTHING
));
615 // Now update DriveAppRegistry.
616 fake_drive_service()->AddApp(
617 kDriveAppId
, kDriveAppName
, kChromeAppId
, kLaunchUrl
, true);
618 RefreshDriveAppRegistry();
619 WaitForPendingDriveAppConverters();
621 // The app should be gone.
622 chrome_app_id
= mapping()->GetChromeApp(kDriveAppId
);
623 EXPECT_TRUE(chrome_app_id
.empty());
624 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById(
625 chrome_app_id
, ExtensionRegistry::EVERYTHING
));