| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 15 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
| 22 #include "net/dns/mock_host_resolver.h" | 23 #include "net/dns/mock_host_resolver.h" |
| 23 | 24 |
| 24 namespace chromeos { | 25 namespace chromeos { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 124 } |
| 124 | 125 |
| 125 std::string GetAppIds() const { | 126 std::string GetAppIds() const { |
| 126 KioskAppManager::Apps apps; | 127 KioskAppManager::Apps apps; |
| 127 manager()->GetApps(&apps); | 128 manager()->GetApps(&apps); |
| 128 | 129 |
| 129 std::string str; | 130 std::string str; |
| 130 for (size_t i = 0; i < apps.size(); ++i) { | 131 for (size_t i = 0; i < apps.size(); ++i) { |
| 131 if (i > 0) | 132 if (i > 0) |
| 132 str += ','; | 133 str += ','; |
| 133 str += apps[i].id; | 134 str += apps[i].app_id; |
| 134 } | 135 } |
| 135 | 136 |
| 136 return str; | 137 return str; |
| 137 } | 138 } |
| 138 | 139 |
| 139 KioskAppManager* manager() const { return KioskAppManager::Get(); } | 140 KioskAppManager* manager() const { return KioskAppManager::Get(); } |
| 140 | 141 |
| 141 private: | 142 private: |
| 142 std::string test_gallery_url_; | 143 std::string test_gallery_url_; |
| 143 base::ShadowingAtExitManager exit_manager_; | 144 base::ShadowingAtExitManager exit_manager_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 dict_update->Set(KioskAppManager::kKeyApps, apps_dict.release()); | 197 dict_update->Set(KioskAppManager::kKeyApps, apps_dict.release()); |
| 197 | 198 |
| 198 // Make the app appear in device settings. | 199 // Make the app appear in device settings. |
| 199 base::ListValue device_local_accounts; | 200 base::ListValue device_local_accounts; |
| 200 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 201 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 201 entry->SetStringWithoutPathExpansion( | 202 entry->SetStringWithoutPathExpansion( |
| 202 kAccountsPrefDeviceLocalAccountsKeyId, | 203 kAccountsPrefDeviceLocalAccountsKeyId, |
| 203 "app_1_id"); | 204 "app_1_id"); |
| 204 entry->SetIntegerWithoutPathExpansion( | 205 entry->SetIntegerWithoutPathExpansion( |
| 205 kAccountsPrefDeviceLocalAccountsKeyType, | 206 kAccountsPrefDeviceLocalAccountsKeyType, |
| 206 DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP); | 207 policy::DeviceLocalAccount::TYPE_KIOSK_APP); |
| 207 entry->SetStringWithoutPathExpansion( | 208 entry->SetStringWithoutPathExpansion( |
| 208 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 209 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| 209 "app_1"); | 210 "app_1"); |
| 210 device_local_accounts.Append(entry.release()); | 211 device_local_accounts.Append(entry.release()); |
| 211 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, | 212 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, |
| 212 device_local_accounts); | 213 device_local_accounts); |
| 213 | 214 |
| 214 AppDataLoadWaiter waiter(manager()); | 215 AppDataLoadWaiter waiter(manager()); |
| 215 waiter.Wait(); | 216 waiter.Wait(); |
| 216 EXPECT_TRUE(waiter.loaded()); | 217 EXPECT_TRUE(waiter.loaded()); |
| 217 | 218 |
| 218 KioskAppManager::Apps apps; | 219 KioskAppManager::Apps apps; |
| 219 manager()->GetApps(&apps); | 220 manager()->GetApps(&apps); |
| 220 EXPECT_EQ(1u, apps.size()); | 221 EXPECT_EQ(1u, apps.size()); |
| 221 EXPECT_EQ("app_1", apps[0].id); | 222 EXPECT_EQ("app_1", apps[0].app_id); |
| 222 EXPECT_EQ("App1 Name", apps[0].name); | 223 EXPECT_EQ("App1 Name", apps[0].name); |
| 223 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | 224 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| 224 } | 225 } |
| 225 | 226 |
| 226 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { | 227 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { |
| 227 manager()->AddApp("unknown_app"); | 228 manager()->AddApp("unknown_app"); |
| 228 | 229 |
| 229 TestKioskAppManagerObserver observer(manager()); | 230 TestKioskAppManagerObserver observer(manager()); |
| 230 | 231 |
| 231 AppDataLoadWaiter waiter(manager()); | 232 AppDataLoadWaiter waiter(manager()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 242 manager()->AddApp("app_1"); | 243 manager()->AddApp("app_1"); |
| 243 | 244 |
| 244 AppDataLoadWaiter waiter(manager()); | 245 AppDataLoadWaiter waiter(manager()); |
| 245 waiter.Wait(); | 246 waiter.Wait(); |
| 246 EXPECT_TRUE(waiter.loaded()); | 247 EXPECT_TRUE(waiter.loaded()); |
| 247 | 248 |
| 248 // Check data is correct. | 249 // Check data is correct. |
| 249 KioskAppManager::Apps apps; | 250 KioskAppManager::Apps apps; |
| 250 manager()->GetApps(&apps); | 251 manager()->GetApps(&apps); |
| 251 EXPECT_EQ(1u, apps.size()); | 252 EXPECT_EQ(1u, apps.size()); |
| 252 EXPECT_EQ("app_1", apps[0].id); | 253 EXPECT_EQ("app_1", apps[0].app_id); |
| 253 EXPECT_EQ("Name of App 1", apps[0].name); | 254 EXPECT_EQ("Name of App 1", apps[0].name); |
| 254 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | 255 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| 255 | 256 |
| 256 // Check data is cached in local state. | 257 // Check data is cached in local state. |
| 257 PrefService* local_state = g_browser_process->local_state(); | 258 PrefService* local_state = g_browser_process->local_state(); |
| 258 const base::DictionaryValue* dict = | 259 const base::DictionaryValue* dict = |
| 259 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); | 260 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 260 | 261 |
| 261 std::string name; | 262 std::string name; |
| 262 EXPECT_TRUE(dict->GetString("apps.app_1.name", &name)); | 263 EXPECT_TRUE(dict->GetString("apps.app_1.name", &name)); |
| 263 EXPECT_EQ(apps[0].name, name); | 264 EXPECT_EQ(apps[0].name, name); |
| 264 | 265 |
| 265 std::string icon_path_string; | 266 std::string icon_path_string; |
| 266 EXPECT_TRUE(dict->GetString("apps.app_1.icon", &icon_path_string)); | 267 EXPECT_TRUE(dict->GetString("apps.app_1.icon", &icon_path_string)); |
| 267 | 268 |
| 268 base::FilePath expected_icon_path; | 269 base::FilePath expected_icon_path; |
| 269 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); | 270 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| 270 expected_icon_path = expected_icon_path. | 271 expected_icon_path = expected_icon_path. |
| 271 AppendASCII(KioskAppManager::kIconCacheDir). | 272 AppendASCII(KioskAppManager::kIconCacheDir). |
| 272 AppendASCII(apps[0].id).AddExtension(".png"); | 273 AppendASCII(apps[0].app_id).AddExtension(".png"); |
| 273 EXPECT_EQ(expected_icon_path.value(), icon_path_string); | 274 EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| 274 } | 275 } |
| 275 | 276 |
| 276 } // namespace chromeos | 277 } // namespace chromeos |
| OLD | NEW |