| 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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); | 103 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); |
| 104 DCHECK(arc::ArcAuthService::Get()); | 104 DCHECK(arc::ArcAuthService::Get()); |
| 105 arc::ArcAuthService::DisableUIForTesting(); | 105 arc::ArcAuthService::DisableUIForTesting(); |
| 106 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); | 106 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); |
| 107 auth_service_->EnableArc(); | 107 auth_service_->EnableArc(); |
| 108 | 108 |
| 109 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | 109 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 110 DCHECK(arc_app_list_pref_); | 110 DCHECK(arc_app_list_pref_); |
| 111 | 111 |
| 112 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 112 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 113 arc::mojom::AppInstancePtr instance; | 113 bridge_service_->app()->SetInstance(app_instance_.get()); |
| 114 app_instance_->Bind(mojo::GetProxy(&instance)); | |
| 115 bridge_service_->OnAppInstanceReady(std::move(instance)); | |
| 116 app_instance_->WaitForOnAppInstanceReady(); | |
| 117 | |
| 118 // Check initial conditions. | |
| 119 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); | |
| 120 EXPECT_TRUE(!arc::ArcBridgeService::Get()->available()); | |
| 121 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, | |
| 122 arc::ArcBridgeService::Get()->state()); | |
| 123 | |
| 124 // At this point we should have ArcAppListPrefs as observer of service. | |
| 125 EXPECT_TRUE(bridge_service_->HasObserver(arc_app_list_pref_)); | |
| 126 bridge_service()->SetReady(); | |
| 127 } | 114 } |
| 128 | 115 |
| 129 void ArcAppTest::TearDown() { | 116 void ArcAppTest::TearDown() { |
| 130 auth_service_.reset(); | 117 auth_service_.reset(); |
| 131 } | 118 } |
| 132 | 119 |
| 120 void ArcAppTest::StopArcInstance() { |
| 121 bridge_service_->app()->CloseChannel(); |
| 122 } |
| 123 |
| 124 void ArcAppTest::RestartArcInstance() { |
| 125 bridge_service_->app()->CloseChannel(); |
| 126 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 127 bridge_service_->app()->SetInstance(app_instance_.get()); |
| 128 } |
| 129 |
| 133 void ArcAppTest::CreateUserAndLogin() { | 130 void ArcAppTest::CreateUserAndLogin() { |
| 134 const AccountId account_id(AccountId::FromUserEmailGaiaId( | 131 const AccountId account_id(AccountId::FromUserEmailGaiaId( |
| 135 profile_->GetProfileUserName(), "1234567890")); | 132 profile_->GetProfileUserName(), "1234567890")); |
| 136 GetUserManager()->AddUser(account_id); | 133 GetUserManager()->AddUser(account_id); |
| 137 GetUserManager()->LoginUser(account_id); | 134 GetUserManager()->LoginUser(account_id); |
| 138 } | 135 } |
| 139 | 136 |
| 140 void ArcAppTest::AddPackage(const arc::mojom::ArcPackageInfo& package) { | 137 void ArcAppTest::AddPackage(const arc::mojom::ArcPackageInfo& package) { |
| 141 if (!FindPackage(package)) | 138 if (!FindPackage(package)) |
| 142 fake_packages_.push_back(package); | 139 fake_packages_.push_back(package); |
| 143 } | 140 } |
| 144 | 141 |
| 145 void ArcAppTest::RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 142 void ArcAppTest::RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 146 std::vector<arc::mojom::ArcPackageInfo>::iterator iter; | 143 std::vector<arc::mojom::ArcPackageInfo>::iterator iter; |
| 147 for (iter = fake_packages_.begin(); iter != fake_packages_.end(); iter++) { | 144 for (iter = fake_packages_.begin(); iter != fake_packages_.end(); iter++) { |
| 148 if ((*iter).package_name == package.package_name) { | 145 if ((*iter).package_name == package.package_name) { |
| 149 fake_packages_.erase(iter); | 146 fake_packages_.erase(iter); |
| 150 break; | 147 break; |
| 151 } | 148 } |
| 152 } | 149 } |
| 153 } | 150 } |
| 154 | 151 |
| 155 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 152 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
| 156 for (auto fake_package : fake_packages_) { | 153 for (auto fake_package : fake_packages_) { |
| 157 if (package.package_name == fake_package.package_name) | 154 if (package.package_name == fake_package.package_name) |
| 158 return true; | 155 return true; |
| 159 } | 156 } |
| 160 return false; | 157 return false; |
| 161 } | 158 } |
| OLD | NEW |