| 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 "chrome/browser/ui/app_list/arc/arc_app_test.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 11 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.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 "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 14 #include "components/arc/arc_bridge_service.h" | 15 #include "components/arc/arc_bridge_service.h" |
| 15 #include "components/arc/test/fake_app_instance.h" | 16 #include "components/arc/test/fake_app_instance.h" |
| 16 #include "components/arc/test/fake_arc_bridge_service.h" | 17 #include "components/arc/test/fake_arc_bridge_service.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { | 44 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { |
| 44 return static_cast<chromeos::FakeChromeUserManager*>( | 45 return static_cast<chromeos::FakeChromeUserManager*>( |
| 45 user_manager::UserManager::Get()); | 46 user_manager::UserManager::Get()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void ArcAppTest::SetUp(Profile* profile) { | 49 void ArcAppTest::SetUp(Profile* profile) { |
| 49 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 50 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 50 chromeos::switches::kEnableArc); | 51 chromeos::switches::kEnableArc); |
| 51 DCHECK(!profile_); | 52 DCHECK(!profile_); |
| 52 profile_ = profile; | 53 profile_ = profile; |
| 53 CreateUserAndLogin(); | 54 const user_manager::User* user = CreateUserAndLogin(); |
| 55 |
| 56 // If for any reason the garbage collector kicks in while we are waiting for |
| 57 // an icon, have the user-to-profile mapping ready to avoid using the real |
| 58 // profile manager (which is null). |
| 59 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
| 60 profile_); |
| 54 | 61 |
| 55 // Make sure we have enough data for test. | 62 // Make sure we have enough data for test. |
| 56 for (int i = 0; i < 3; ++i) { | 63 for (int i = 0; i < 3; ++i) { |
| 57 arc::mojom::AppInfo app; | 64 arc::mojom::AppInfo app; |
| 58 app.name = base::StringPrintf("Fake App %d", i); | 65 app.name = base::StringPrintf("Fake App %d", i); |
| 59 app.package_name = base::StringPrintf("fake.app.%d", i); | 66 app.package_name = base::StringPrintf("fake.app.%d", i); |
| 60 app.activity = base::StringPrintf("fake.app.%d.activity", i); | 67 app.activity = base::StringPrintf("fake.app.%d.activity", i); |
| 61 app.sticky = false; | 68 app.sticky = false; |
| 62 fake_apps_.push_back(app); | 69 fake_apps_.push_back(app); |
| 63 } | 70 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 129 |
| 123 // At this point we should have ArcAppListPrefs as observer of service. | 130 // At this point we should have ArcAppListPrefs as observer of service. |
| 124 EXPECT_TRUE(bridge_service_->HasObserver(arc_app_list_pref_)); | 131 EXPECT_TRUE(bridge_service_->HasObserver(arc_app_list_pref_)); |
| 125 bridge_service()->SetReady(); | 132 bridge_service()->SetReady(); |
| 126 } | 133 } |
| 127 | 134 |
| 128 void ArcAppTest::TearDown() { | 135 void ArcAppTest::TearDown() { |
| 129 auth_service_.reset(); | 136 auth_service_.reset(); |
| 130 } | 137 } |
| 131 | 138 |
| 132 void ArcAppTest::CreateUserAndLogin() { | 139 const user_manager::User* ArcAppTest::CreateUserAndLogin() { |
| 133 const AccountId account_id(AccountId::FromUserEmailGaiaId( | 140 const AccountId account_id(AccountId::FromUserEmailGaiaId( |
| 134 profile_->GetProfileUserName(), "1234567890")); | 141 profile_->GetProfileUserName(), "1234567890")); |
| 135 GetUserManager()->AddUser(account_id); | 142 const user_manager::User* user = GetUserManager()->AddUser(account_id); |
| 136 GetUserManager()->LoginUser(account_id); | 143 GetUserManager()->LoginUser(account_id); |
| 144 return user; |
| 137 } | 145 } |
| 138 | 146 |
| 139 void ArcAppTest::AddPackage(const arc::mojom::ArcPackageInfo& package) { | 147 void ArcAppTest::AddPackage(const arc::mojom::ArcPackageInfo& package) { |
| 140 if (!FindPackage(package)) | 148 if (!FindPackage(package)) |
| 141 fake_packages_.push_back(package); | 149 fake_packages_.push_back(package); |
| 142 } | 150 } |
| 143 | 151 |
| 144 void ArcAppTest::RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 152 void ArcAppTest::RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 145 std::vector<arc::mojom::ArcPackageInfo>::iterator iter; | 153 std::vector<arc::mojom::ArcPackageInfo>::iterator iter; |
| 146 for (iter = fake_packages_.begin(); iter != fake_packages_.end(); iter++) { | 154 for (iter = fake_packages_.begin(); iter != fake_packages_.end(); iter++) { |
| 147 if ((*iter).package_name == package.package_name) { | 155 if ((*iter).package_name == package.package_name) { |
| 148 fake_packages_.erase(iter); | 156 fake_packages_.erase(iter); |
| 149 break; | 157 break; |
| 150 } | 158 } |
| 151 } | 159 } |
| 152 } | 160 } |
| 153 | 161 |
| 154 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 162 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
| 155 for (auto fake_package : fake_packages_) { | 163 for (auto fake_package : fake_packages_) { |
| 156 if (package.package_name == fake_package.package_name) | 164 if (package.package_name == fake_package.package_name) |
| 157 return true; | 165 return true; |
| 158 } | 166 } |
| 159 return false; | 167 return false; |
| 160 } | 168 } |
| OLD | NEW |