| 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const char kLaunchUrl[] = "http://example.com/drive"; | 41 const char kLaunchUrl[] = "http://example.com/drive"; |
| 42 | 42 |
| 43 // App id of hosted_app.crx. | 43 // App id of hosted_app.crx. |
| 44 const char kChromeAppId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; | 44 const char kChromeAppId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
| 45 | 45 |
| 46 // Stub drive service bridge. | 46 // Stub drive service bridge. |
| 47 class TestDriveServiceBridge : public DriveServiceBridge { | 47 class TestDriveServiceBridge : public DriveServiceBridge { |
| 48 public: | 48 public: |
| 49 explicit TestDriveServiceBridge(drive::DriveAppRegistry* registry) | 49 explicit TestDriveServiceBridge(drive::DriveAppRegistry* registry) |
| 50 : registry_(registry) {} | 50 : registry_(registry) {} |
| 51 virtual ~TestDriveServiceBridge() {} | 51 ~TestDriveServiceBridge() override {} |
| 52 | 52 |
| 53 virtual drive::DriveAppRegistry* GetAppRegistry() override { | 53 drive::DriveAppRegistry* GetAppRegistry() override { return registry_; } |
| 54 return registry_; | |
| 55 } | |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 drive::DriveAppRegistry* registry_; | 56 drive::DriveAppRegistry* registry_; |
| 59 | 57 |
| 60 DISALLOW_COPY_AND_ASSIGN(TestDriveServiceBridge); | 58 DISALLOW_COPY_AND_ASSIGN(TestDriveServiceBridge); |
| 61 }; | 59 }; |
| 62 | 60 |
| 63 class FakeUninstallSyncService : public DriveAppUninstallSyncService { | 61 class FakeUninstallSyncService : public DriveAppUninstallSyncService { |
| 64 public: | 62 public: |
| 65 FakeUninstallSyncService() {} | 63 FakeUninstallSyncService() {} |
| 66 virtual ~FakeUninstallSyncService() {} | 64 ~FakeUninstallSyncService() override {} |
| 67 | 65 |
| 68 bool IsUninstallTracked(const std::string& drive_app_id) const { | 66 bool IsUninstallTracked(const std::string& drive_app_id) const { |
| 69 return uninstalled_app_ids_.find(drive_app_id) != | 67 return uninstalled_app_ids_.find(drive_app_id) != |
| 70 uninstalled_app_ids_.end(); | 68 uninstalled_app_ids_.end(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 // DriveAppUninstallSyncService | 71 // DriveAppUninstallSyncService |
| 74 virtual void TrackUninstalledDriveApp( | 72 void TrackUninstalledDriveApp(const std::string& drive_app_id) override { |
| 75 const std::string& drive_app_id) override { | |
| 76 uninstalled_app_ids_.insert(drive_app_id); | 73 uninstalled_app_ids_.insert(drive_app_id); |
| 77 } | 74 } |
| 78 virtual void UntrackUninstalledDriveApp( | 75 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override { |
| 79 const std::string& drive_app_id) override { | |
| 80 auto it = uninstalled_app_ids_.find(drive_app_id); | 76 auto it = uninstalled_app_ids_.find(drive_app_id); |
| 81 if (it == uninstalled_app_ids_.end()) | 77 if (it == uninstalled_app_ids_.end()) |
| 82 return; | 78 return; |
| 83 uninstalled_app_ids_.erase(it); | 79 uninstalled_app_ids_.erase(it); |
| 84 } | 80 } |
| 85 | 81 |
| 86 private: | 82 private: |
| 87 std::set<std::string> uninstalled_app_ids_; | 83 std::set<std::string> uninstalled_app_ids_; |
| 88 | 84 |
| 89 DISALLOW_COPY_AND_ASSIGN(FakeUninstallSyncService); | 85 DISALLOW_COPY_AND_ASSIGN(FakeUninstallSyncService); |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 } // namespace | 88 } // namespace |
| 93 | 89 |
| 94 class DriveAppProviderTest : public ExtensionBrowserTest, | 90 class DriveAppProviderTest : public ExtensionBrowserTest, |
| 95 public extensions::InstallObserver { | 91 public extensions::InstallObserver { |
| 96 public: | 92 public: |
| 97 DriveAppProviderTest() {} | 93 DriveAppProviderTest() {} |
| 98 virtual ~DriveAppProviderTest() {} | 94 virtual ~DriveAppProviderTest() {} |
| 99 | 95 |
| 100 // ExtensionBrowserTest: | 96 // ExtensionBrowserTest: |
| 101 virtual void SetUpOnMainThread() override { | 97 void SetUpOnMainThread() override { |
| 102 ExtensionBrowserTest::SetUpOnMainThread(); | 98 ExtensionBrowserTest::SetUpOnMainThread(); |
| 103 | 99 |
| 104 fake_drive_service_.reset(new drive::FakeDriveService); | 100 fake_drive_service_.reset(new drive::FakeDriveService); |
| 105 fake_drive_service_->LoadAppListForDriveApi("drive/applist_empty.json"); | 101 fake_drive_service_->LoadAppListForDriveApi("drive/applist_empty.json"); |
| 106 apps_registry_.reset( | 102 apps_registry_.reset( |
| 107 new drive::DriveAppRegistry(fake_drive_service_.get())); | 103 new drive::DriveAppRegistry(fake_drive_service_.get())); |
| 108 | 104 |
| 109 fake_uninstall_sync_service_.reset(new FakeUninstallSyncService); | 105 fake_uninstall_sync_service_.reset(new FakeUninstallSyncService); |
| 110 | 106 |
| 111 provider_.reset( | 107 provider_.reset( |
| 112 new DriveAppProvider(profile(), fake_uninstall_sync_service_.get())); | 108 new DriveAppProvider(profile(), fake_uninstall_sync_service_.get())); |
| 113 provider_->SetDriveServiceBridgeForTest( | 109 provider_->SetDriveServiceBridgeForTest( |
| 114 make_scoped_ptr(new TestDriveServiceBridge(apps_registry_.get()))); | 110 make_scoped_ptr(new TestDriveServiceBridge(apps_registry_.get()))); |
| 115 | 111 |
| 116 // The DriveAppProvider in AppListSyncalbeService interferes with the | 112 // The DriveAppProvider in AppListSyncalbeService interferes with the |
| 117 // test. So resets it. | 113 // test. So resets it. |
| 118 app_list::AppListSyncableServiceFactory::GetForProfile(profile()) | 114 app_list::AppListSyncableServiceFactory::GetForProfile(profile()) |
| 119 ->ResetDriveAppProviderForTest(); | 115 ->ResetDriveAppProviderForTest(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 virtual void TearDownOnMainThread() override { | 118 void TearDownOnMainThread() override { |
| 123 provider_.reset(); | 119 provider_.reset(); |
| 124 apps_registry_.reset(); | 120 apps_registry_.reset(); |
| 125 fake_drive_service_.reset(); | 121 fake_drive_service_.reset(); |
| 126 | 122 |
| 127 ExtensionBrowserTest::TearDownOnMainThread(); | 123 ExtensionBrowserTest::TearDownOnMainThread(); |
| 128 } | 124 } |
| 129 | 125 |
| 130 const Extension* InstallChromeApp(int expected_change) { | 126 const Extension* InstallChromeApp(int expected_change) { |
| 131 base::FilePath test_data_path; | 127 base::FilePath test_data_path; |
| 132 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_path)) { | 128 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_path)) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 DriveAppProvider* provider() { return provider_.get(); } | 196 DriveAppProvider* provider() { return provider_.get(); } |
| 201 DriveAppMapping* mapping() { return provider_->mapping_.get(); } | 197 DriveAppMapping* mapping() { return provider_->mapping_.get(); } |
| 202 | 198 |
| 203 private: | 199 private: |
| 204 void OnPendingDriveAppConverterCheckTimer() { | 200 void OnPendingDriveAppConverterCheckTimer() { |
| 205 if (!HasPendingConverters()) | 201 if (!HasPendingConverters()) |
| 206 runner_->Quit(); | 202 runner_->Quit(); |
| 207 } | 203 } |
| 208 | 204 |
| 209 // extensions::InstallObserver | 205 // extensions::InstallObserver |
| 210 virtual void OnFinishCrxInstall(const std::string& extension_id, | 206 void OnFinishCrxInstall(const std::string& extension_id, |
| 211 bool success) override { | 207 bool success) override { |
| 212 runner_->Quit(); | 208 runner_->Quit(); |
| 213 } | 209 } |
| 214 | 210 |
| 215 scoped_ptr<drive::FakeDriveService> fake_drive_service_; | 211 scoped_ptr<drive::FakeDriveService> fake_drive_service_; |
| 216 scoped_ptr<FakeUninstallSyncService> fake_uninstall_sync_service_; | 212 scoped_ptr<FakeUninstallSyncService> fake_uninstall_sync_service_; |
| 217 scoped_ptr<drive::DriveAppRegistry> apps_registry_; | 213 scoped_ptr<drive::DriveAppRegistry> apps_registry_; |
| 218 scoped_ptr<DriveAppProvider> provider_; | 214 scoped_ptr<DriveAppProvider> provider_; |
| 219 | 215 |
| 220 base::RepeatingTimer<DriveAppProviderTest> | 216 base::RepeatingTimer<DriveAppProviderTest> |
| 221 pending_drive_app_converter_check_timer_; | 217 pending_drive_app_converter_check_timer_; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 chrome_app_id, ExtensionRegistry::EVERYTHING)); | 574 chrome_app_id, ExtensionRegistry::EVERYTHING)); |
| 579 | 575 |
| 580 // Uninstall is removed from sync and the app is added again. | 576 // Uninstall is removed from sync and the app is added again. |
| 581 provider()->RemoveUninstalledDriveAppFromSync(kDriveAppId); | 577 provider()->RemoveUninstalledDriveAppFromSync(kDriveAppId); |
| 582 WaitForPendingDriveAppConverters(); | 578 WaitForPendingDriveAppConverters(); |
| 583 chrome_app_id = mapping()->GetChromeApp(kDriveAppId); | 579 chrome_app_id = mapping()->GetChromeApp(kDriveAppId); |
| 584 EXPECT_FALSE(chrome_app_id.empty()); | 580 EXPECT_FALSE(chrome_app_id.empty()); |
| 585 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById( | 581 EXPECT_TRUE(ExtensionRegistry::Get(profile())->GetExtensionById( |
| 586 chrome_app_id, ExtensionRegistry::EVERYTHING)); | 582 chrome_app_id, ExtensionRegistry::EVERYTHING)); |
| 587 } | 583 } |
| OLD | NEW |