| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/location.h" | |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 21 #include "base/message_loop/message_loop_proxy.h" | |
| 22 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 23 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 24 #include "base/sequenced_task_runner.h" | |
| 25 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/test/scoped_path_override.h" | 25 #include "base/test/scoped_path_override.h" |
| 30 #include "base/values.h" | 26 #include "base/values.h" |
| 31 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 32 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| 33 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 29 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 34 #include "chrome/browser/chromeos/login/login_display_host.h" | 30 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 35 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 31 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 36 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" | 32 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" |
| 37 #include "chrome/browser/chromeos/login/screens/wizard_screen.h" | 33 #include "chrome/browser/chromeos/login/screens/wizard_screen.h" |
| 38 #include "chrome/browser/chromeos/login/user.h" | 34 #include "chrome/browser/chromeos/login/user.h" |
| 39 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
| 40 #include "chrome/browser/chromeos/login/webui_login_view.h" | 36 #include "chrome/browser/chromeos/login/webui_login_view.h" |
| 41 #include "chrome/browser/chromeos/login/wizard_controller.h" | 37 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 42 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" | |
| 43 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" | |
| 44 #include "chrome/browser/chromeos/policy/device_local_account.h" | 38 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 45 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | |
| 46 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 39 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 47 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 40 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 48 #include "chrome/browser/extensions/extension_service.h" | 41 #include "chrome/browser/extensions/extension_service.h" |
| 49 #include "chrome/browser/extensions/extension_system.h" | 42 #include "chrome/browser/extensions/extension_system.h" |
| 50 #include "chrome/browser/lifetime/application_lifetime.h" | 43 #include "chrome/browser/lifetime/application_lifetime.h" |
| 51 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 52 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 44 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 53 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | |
| 54 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | |
| 55 #include "chrome/browser/policy/cloud/policy_builder.h" | 45 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 56 #include "chrome/browser/policy/external_data_fetcher.h" | |
| 57 #include "chrome/browser/policy/policy_map.h" | |
| 58 #include "chrome/browser/policy/policy_service.h" | 46 #include "chrome/browser/policy/policy_service.h" |
| 59 #include "chrome/browser/policy/profile_policy_connector.h" | |
| 60 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
| 61 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 47 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
| 62 #include "chrome/browser/policy/test/local_policy_test_server.h" | 48 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 63 #include "chrome/browser/prefs/session_startup_pref.h" | 49 #include "chrome/browser/prefs/session_startup_pref.h" |
| 64 #include "chrome/browser/profiles/profile.h" | 50 #include "chrome/browser/profiles/profile.h" |
| 65 #include "chrome/browser/profiles/profile_manager.h" | 51 #include "chrome/browser/profiles/profile_manager.h" |
| 66 #include "chrome/browser/ui/browser.h" | 52 #include "chrome/browser/ui/browser.h" |
| 67 #include "chrome/browser/ui/browser_commands.h" | 53 #include "chrome/browser/ui/browser_commands.h" |
| 68 #include "chrome/browser/ui/browser_finder.h" | 54 #include "chrome/browser/ui/browser_finder.h" |
| 69 #include "chrome/browser/ui/browser_list.h" | 55 #include "chrome/browser/ui/browser_list.h" |
| 70 #include "chrome/browser/ui/browser_window.h" | 56 #include "chrome/browser/ui/browser_window.h" |
| 71 #include "chrome/browser/ui/host_desktop.h" | 57 #include "chrome/browser/ui/host_desktop.h" |
| 72 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 58 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 73 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 59 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 74 #include "chrome/common/chrome_paths.h" | 60 #include "chrome/common/chrome_paths.h" |
| 75 #include "chrome/common/chrome_switches.h" | 61 #include "chrome/common/chrome_switches.h" |
| 76 #include "chrome/common/extensions/extension.h" | 62 #include "chrome/common/extensions/extension.h" |
| 77 #include "chromeos/chromeos_paths.h" | 63 #include "chromeos/chromeos_paths.h" |
| 78 #include "chromeos/chromeos_switches.h" | 64 #include "chromeos/chromeos_switches.h" |
| 79 #include "chromeos/dbus/cryptohome_client.h" | 65 #include "chromeos/dbus/cryptohome_client.h" |
| 80 #include "chromeos/dbus/dbus_method_call_status.h" | 66 #include "chromeos/dbus/dbus_method_call_status.h" |
| 81 #include "chromeos/dbus/fake_session_manager_client.h" | 67 #include "chromeos/dbus/fake_session_manager_client.h" |
| 82 #include "chromeos/dbus/session_manager_client.h" | 68 #include "chromeos/dbus/session_manager_client.h" |
| 83 #include "components/policy/core/common/policy_namespace.h" | |
| 84 #include "content/public/browser/notification_details.h" | 69 #include "content/public/browser/notification_details.h" |
| 85 #include "content/public/browser/notification_source.h" | 70 #include "content/public/browser/notification_source.h" |
| 86 #include "content/public/browser/web_contents.h" | 71 #include "content/public/browser/web_contents.h" |
| 87 #include "content/public/browser/web_ui.h" | 72 #include "content/public/browser/web_ui.h" |
| 88 #include "content/public/test/browser_test_utils.h" | 73 #include "content/public/test/browser_test_utils.h" |
| 89 #include "content/public/test/test_utils.h" | 74 #include "content/public/test/test_utils.h" |
| 90 #include "crypto/rsa_private_key.h" | 75 #include "crypto/rsa_private_key.h" |
| 91 #include "grit/chromium_strings.h" | 76 #include "grit/chromium_strings.h" |
| 92 #include "grit/generated_resources.h" | 77 #include "grit/generated_resources.h" |
| 93 #include "net/base/url_util.h" | 78 #include "net/base/url_util.h" |
| 94 #include "net/http/http_status_code.h" | 79 #include "net/http/http_status_code.h" |
| 95 #include "net/test/embedded_test_server/embedded_test_server.h" | 80 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 96 #include "net/test/embedded_test_server/http_request.h" | 81 #include "net/test/embedded_test_server/http_request.h" |
| 97 #include "net/test/embedded_test_server/http_response.h" | 82 #include "net/test/embedded_test_server/http_response.h" |
| 98 #include "net/url_request/test_url_fetcher_factory.h" | |
| 99 #include "net/url_request/url_fetcher_delegate.h" | |
| 100 #include "policy/policy_constants.h" | |
| 101 #include "testing/gmock/include/gmock/gmock.h" | 83 #include "testing/gmock/include/gmock/gmock.h" |
| 102 #include "third_party/cros_system_api/dbus/service_constants.h" | 84 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 103 #include "ui/base/l10n/l10n_util.h" | 85 #include "ui/base/l10n/l10n_util.h" |
| 104 #include "url/gurl.h" | 86 #include "url/gurl.h" |
| 105 | 87 |
| 106 namespace em = enterprise_management; | 88 namespace em = enterprise_management; |
| 107 | 89 |
| 108 using testing::InvokeWithoutArgs; | 90 using testing::InvokeWithoutArgs; |
| 109 using testing::Return; | 91 using testing::Return; |
| 110 using testing::_; | 92 using testing::_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 133 " </app>\n"; | 115 " </app>\n"; |
| 134 const char kUpdateManifestFooter[] = | 116 const char kUpdateManifestFooter[] = |
| 135 "</gupdate>\n"; | 117 "</gupdate>\n"; |
| 136 const char kHostedAppID[] = "kbmnembihfiondgfjekmnmcbddelicoi"; | 118 const char kHostedAppID[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
| 137 const char kHostedAppCRXPath[] = "extensions/hosted_app.crx"; | 119 const char kHostedAppCRXPath[] = "extensions/hosted_app.crx"; |
| 138 const char kHostedAppVersion[] = "1.0.0.0"; | 120 const char kHostedAppVersion[] = "1.0.0.0"; |
| 139 const char kGoodExtensionID[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 121 const char kGoodExtensionID[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 140 const char kGoodExtensionCRXPath[] = "extensions/good.crx"; | 122 const char kGoodExtensionCRXPath[] = "extensions/good.crx"; |
| 141 const char kGoodExtensionVersion[] = "1.0"; | 123 const char kGoodExtensionVersion[] = "1.0"; |
| 142 | 124 |
| 143 const char kExternalData[] = "External data"; | |
| 144 const char kExternalDataURL[] = "http://localhost/external_data"; | |
| 145 | |
| 146 // Helper that serves extension update manifests to Chrome. | 125 // Helper that serves extension update manifests to Chrome. |
| 147 class TestingUpdateManifestProvider { | 126 class TestingUpdateManifestProvider { |
| 148 public: | 127 public: |
| 149 | 128 |
| 150 // Update manifests will be served at |relative_update_url|. | 129 // Update manifests will be served at |relative_update_url|. |
| 151 explicit TestingUpdateManifestProvider( | 130 explicit TestingUpdateManifestProvider( |
| 152 const std::string& relative_update_url); | 131 const std::string& relative_update_url); |
| 153 ~TestingUpdateManifestProvider(); | 132 ~TestingUpdateManifestProvider(); |
| 154 | 133 |
| 155 // When an update manifest is requested for the given extension |id|, indicate | 134 // When an update manifest is requested for the given extension |id|, indicate |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 extension->id() == id; | 222 extension->id() == id; |
| 244 } | 223 } |
| 245 | 224 |
| 246 bool DoesInstallFailureReferToId(const std::string& id, | 225 bool DoesInstallFailureReferToId(const std::string& id, |
| 247 const content::NotificationSource& source, | 226 const content::NotificationSource& source, |
| 248 const content::NotificationDetails& details) { | 227 const content::NotificationDetails& details) { |
| 249 return content::Details<const string16>(details)->find(UTF8ToUTF16(id)) != | 228 return content::Details<const string16>(details)->find(UTF8ToUTF16(id)) != |
| 250 string16::npos; | 229 string16::npos; |
| 251 } | 230 } |
| 252 | 231 |
| 253 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( | |
| 254 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
| 255 const base::Closure& callback, | |
| 256 const GURL& url, | |
| 257 net::URLFetcherDelegate* delegate, | |
| 258 const std::string& response_data, | |
| 259 bool success) { | |
| 260 task_runner->PostTask(FROM_HERE, callback); | |
| 261 return make_scoped_ptr(new net::FakeURLFetcher( | |
| 262 url, delegate, response_data, success)); | |
| 263 } | |
| 264 | |
| 265 } // namespace | 232 } // namespace |
| 266 | 233 |
| 267 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest { | 234 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest { |
| 268 protected: | 235 protected: |
| 269 DeviceLocalAccountTest() | 236 DeviceLocalAccountTest() |
| 270 : user_id_1_(GenerateDeviceLocalAccountUserId( | 237 : user_id_1_(GenerateDeviceLocalAccountUserId( |
| 271 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)), | 238 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)), |
| 272 user_id_2_(GenerateDeviceLocalAccountUserId( | 239 user_id_2_(GenerateDeviceLocalAccountUserId( |
| 273 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {} | 240 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {} |
| 274 | 241 |
| 275 virtual ~DeviceLocalAccountTest() {} | 242 virtual ~DeviceLocalAccountTest() {} |
| 276 | 243 |
| 277 virtual void SetUp() OVERRIDE { | 244 virtual void SetUp() OVERRIDE { |
| 278 // Configure and start the test server. | 245 // Configure and start the test server. |
| 279 scoped_ptr<crypto::RSAPrivateKey> signing_key( | 246 scoped_ptr<crypto::RSAPrivateKey> signing_key( |
| 280 PolicyBuilder::CreateTestSigningKey()); | 247 PolicyBuilder::CreateTestSigningKey()); |
| 281 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); | 248 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); |
| 282 signing_key.reset(); | 249 signing_key.reset(); |
| 283 test_server_.RegisterClient(PolicyBuilder::kFakeToken, | 250 test_server_.RegisterClient(PolicyBuilder::kFakeToken, |
| 284 PolicyBuilder::kFakeDeviceId); | 251 PolicyBuilder::kFakeDeviceId); |
| 285 ASSERT_TRUE(test_server_.Start()); | 252 ASSERT_TRUE(test_server_.Start()); |
| 286 | 253 |
| 287 ASSERT_TRUE(extension_cache_root_dir_.CreateUniqueTempDir()); | 254 ASSERT_TRUE(extension_cache_root_dir_.CreateUniqueTempDir()); |
| 288 extension_cache_root_dir_override_.reset(new base::ScopedPathOverride( | 255 extension_cache_root_dir_override_.reset(new base::ScopedPathOverride( |
| 289 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | 256 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_CACHE, |
| 290 extension_cache_root_dir_.path())); | 257 extension_cache_root_dir_.path())); |
| 291 ASSERT_TRUE(external_data_cache_dir_.CreateUniqueTempDir()); | |
| 292 external_data_cache_dir_override_.reset(new base::ScopedPathOverride( | |
| 293 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA, | |
| 294 external_data_cache_dir_.path())); | |
| 295 | 258 |
| 296 DevicePolicyCrosBrowserTest::SetUp(); | 259 DevicePolicyCrosBrowserTest::SetUp(); |
| 297 } | 260 } |
| 298 | 261 |
| 299 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 262 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 300 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 263 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 301 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 264 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 302 command_line->AppendSwitchASCII( | 265 command_line->AppendSwitchASCII( |
| 303 switches::kDeviceManagementUrl, test_server_.GetServiceURL().spec()); | 266 switches::kDeviceManagementUrl, test_server_.GetServiceURL().spec()); |
| 304 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | 267 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const std::string& id, | 354 const std::string& id, |
| 392 const std::string& version) { | 355 const std::string& version) { |
| 393 return GetCacheDirectoryForAccountID(account_id) | 356 return GetCacheDirectoryForAccountID(account_id) |
| 394 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); | 357 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); |
| 395 } | 358 } |
| 396 | 359 |
| 397 const std::string user_id_1_; | 360 const std::string user_id_1_; |
| 398 const std::string user_id_2_; | 361 const std::string user_id_2_; |
| 399 | 362 |
| 400 base::ScopedTempDir extension_cache_root_dir_; | 363 base::ScopedTempDir extension_cache_root_dir_; |
| 401 base::ScopedTempDir external_data_cache_dir_; | |
| 402 scoped_ptr<base::ScopedPathOverride> extension_cache_root_dir_override_; | 364 scoped_ptr<base::ScopedPathOverride> extension_cache_root_dir_override_; |
| 403 scoped_ptr<base::ScopedPathOverride> external_data_cache_dir_override_; | |
| 404 | 365 |
| 405 UserPolicyBuilder device_local_account_policy_; | 366 UserPolicyBuilder device_local_account_policy_; |
| 406 LocalPolicyTestServer test_server_; | 367 LocalPolicyTestServer test_server_; |
| 407 }; | 368 }; |
| 408 | 369 |
| 409 static bool IsKnownUser(const std::string& account_id) { | 370 static bool IsKnownUser(const std::string& account_id) { |
| 410 return chromeos::UserManager::Get()->IsKnownUser(account_id); | 371 return chromeos::UserManager::Get()->IsKnownUser(account_id); |
| 411 } | 372 } |
| 412 | 373 |
| 413 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { | 374 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // Verify that the extension was not installed. | 762 // Verify that the extension was not installed. |
| 802 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); | 763 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); |
| 803 | 764 |
| 804 // Verify that the app is still in the account's extension cache. | 765 // Verify that the app is still in the account's extension cache. |
| 805 EXPECT_TRUE(PathExists(cached_hosted_app)); | 766 EXPECT_TRUE(PathExists(cached_hosted_app)); |
| 806 | 767 |
| 807 // Verify that the extension was removed from the account's extension cache. | 768 // Verify that the extension was removed from the account's extension cache. |
| 808 EXPECT_FALSE(PathExists(cached_extension)); | 769 EXPECT_FALSE(PathExists(cached_extension)); |
| 809 } | 770 } |
| 810 | 771 |
| 811 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) { | |
| 812 CloudExternalDataManagerBase::SetMaxExternalDataSizeForTesting(1000); | |
| 813 | |
| 814 UploadAndInstallDeviceLocalAccountPolicy(); | |
| 815 AddPublicSessionToDevicePolicy(kAccountId1); | |
| 816 | |
| 817 // This observes the display name becoming available as this indicates | |
| 818 // device-local account policy is fully loaded. | |
| 819 content::WindowedNotificationObserver( | |
| 820 chrome::NOTIFICATION_USER_LIST_CHANGED, | |
| 821 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait(); | |
| 822 | |
| 823 scoped_ptr<base::DictionaryValue> metadata = | |
| 824 test::ConstructExternalDataReference(kExternalDataURL, kExternalData); | |
| 825 DeviceLocalAccountPolicyBroker* broker = | |
| 826 g_browser_process->browser_policy_connector()-> | |
| 827 GetDeviceLocalAccountPolicyService()->GetBrokerForUser(user_id_1_); | |
| 828 ASSERT_TRUE(broker); | |
| 829 | |
| 830 // Start serving external data at |kExternalDataURL|. | |
| 831 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop); | |
| 832 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory( | |
| 833 new net::FakeURLFetcherFactory( | |
| 834 NULL, | |
| 835 base::Bind(&RunCallbackAndReturnFakeURLFetcher, | |
| 836 base::MessageLoopProxy::current(), | |
| 837 run_loop->QuitClosure()))); | |
| 838 fetcher_factory->SetFakeResponse(GURL(kExternalDataURL), | |
| 839 kExternalData, | |
| 840 true); | |
| 841 | |
| 842 // TODO(bartfab): The test injects an ExternalDataFetcher for an arbitrary | |
| 843 // policy. This is only done because there are no policies that reference | |
| 844 // external data yet. Once the first such policy is added, switch the test to | |
| 845 // that policy and stop injecting a manually instantiated ExternalDataFetcher. | |
| 846 test::SetExternalDataReference(broker->core(), | |
| 847 key::kHomepageLocation, | |
| 848 make_scoped_ptr(metadata->DeepCopy())); | |
| 849 | |
| 850 // The external data should be fetched and cached automatically. Wait for this | |
| 851 // fetch. | |
| 852 run_loop->Run(); | |
| 853 | |
| 854 // Stop serving external data at |kExternalDataURL|. | |
| 855 fetcher_factory.reset(); | |
| 856 | |
| 857 const PolicyMap::Entry* policy_entry = | |
| 858 broker->core()->store()->policy_map().Get(key::kHomepageLocation); | |
| 859 ASSERT_TRUE(policy_entry); | |
| 860 ASSERT_TRUE(policy_entry->external_data_fetcher); | |
| 861 | |
| 862 // Retrieve the external data. Although the data is no longer being served at | |
| 863 // |kExternalDataURL|, the retrieval should succeed because the data has been | |
| 864 // cached. | |
| 865 run_loop.reset(new base::RunLoop); | |
| 866 scoped_ptr<std::string> fetched_external_data; | |
| 867 policy_entry->external_data_fetcher->Fetch(base::Bind( | |
| 868 &test::ExternalDataFetchCallback, | |
| 869 &fetched_external_data, | |
| 870 run_loop->QuitClosure())); | |
| 871 run_loop->Run(); | |
| 872 | |
| 873 ASSERT_TRUE(fetched_external_data); | |
| 874 EXPECT_EQ(kExternalData, *fetched_external_data); | |
| 875 | |
| 876 // Wait for the login UI to be ready. | |
| 877 chromeos::LoginDisplayHostImpl* host = | |
| 878 reinterpret_cast<chromeos::LoginDisplayHostImpl*>( | |
| 879 chromeos::LoginDisplayHostImpl::default_host()); | |
| 880 ASSERT_TRUE(host); | |
| 881 chromeos::OobeUI* oobe_ui = host->GetOobeUI(); | |
| 882 ASSERT_TRUE(oobe_ui); | |
| 883 run_loop.reset(new base::RunLoop); | |
| 884 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop->QuitClosure()); | |
| 885 if (!oobe_ui_ready) | |
| 886 run_loop->Run(); | |
| 887 | |
| 888 // Ensure that the browser stays alive, even though no windows are opened | |
| 889 // during session start. | |
| 890 chrome::StartKeepAlive(); | |
| 891 | |
| 892 // Start login into the device-local account. | |
| 893 host->StartSignInScreen(); | |
| 894 chromeos::ExistingUserController* controller = | |
| 895 chromeos::ExistingUserController::current_controller(); | |
| 896 ASSERT_TRUE(controller); | |
| 897 controller->LoginAsPublicAccount(user_id_1_); | |
| 898 | |
| 899 // Wait for the session to start. | |
| 900 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, | |
| 901 base::Bind(IsSessionStarted)).Wait(); | |
| 902 | |
| 903 // Verify that the external data reference has propagated to the device-local | |
| 904 // account's ProfilePolicyConnector. | |
| 905 ProfilePolicyConnector* policy_connector = | |
| 906 ProfilePolicyConnectorFactory::GetForProfile( | |
| 907 ProfileManager::GetDefaultProfile()); | |
| 908 ASSERT_TRUE(policy_connector); | |
| 909 const PolicyMap& policies = policy_connector->policy_service()->GetPolicies( | |
| 910 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | |
| 911 policy_entry = policies.Get(key::kHomepageLocation); | |
| 912 ASSERT_TRUE(policy_entry); | |
| 913 EXPECT_TRUE(base::Value::Equals(metadata.get(), policy_entry->value)); | |
| 914 ASSERT_TRUE(policy_entry->external_data_fetcher); | |
| 915 | |
| 916 // Retrieve the external data via the ProfilePolicyConnector. The retrieval | |
| 917 // should succeed because the data has been cached. | |
| 918 run_loop.reset(new base::RunLoop); | |
| 919 fetched_external_data.reset(); | |
| 920 policy_entry->external_data_fetcher->Fetch(base::Bind( | |
| 921 &test::ExternalDataFetchCallback, | |
| 922 &fetched_external_data, | |
| 923 run_loop->QuitClosure())); | |
| 924 run_loop->Run(); | |
| 925 | |
| 926 ASSERT_TRUE(fetched_external_data); | |
| 927 EXPECT_EQ(kExternalData, *fetched_external_data); | |
| 928 } | |
| 929 | |
| 930 class TermsOfServiceTest : public DeviceLocalAccountTest, | 772 class TermsOfServiceTest : public DeviceLocalAccountTest, |
| 931 public testing::WithParamInterface<bool> { | 773 public testing::WithParamInterface<bool> { |
| 932 }; | 774 }; |
| 933 | 775 |
| 934 IN_PROC_BROWSER_TEST_P(TermsOfServiceTest, TermsOfServiceScreen) { | 776 IN_PROC_BROWSER_TEST_P(TermsOfServiceTest, TermsOfServiceScreen) { |
| 935 // Specify Terms of Service URL. | 777 // Specify Terms of Service URL. |
| 936 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 778 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 937 device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value( | 779 device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value( |
| 938 embedded_test_server()->GetURL( | 780 embedded_test_server()->GetURL( |
| 939 std::string("/") + | 781 std::string("/") + |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 if (!IsSessionStarted()) { | 923 if (!IsSessionStarted()) { |
| 1082 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, | 924 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, |
| 1083 base::Bind(IsSessionStarted)).Wait(); | 925 base::Bind(IsSessionStarted)).Wait(); |
| 1084 } | 926 } |
| 1085 } | 927 } |
| 1086 | 928 |
| 1087 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance, | 929 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance, |
| 1088 TermsOfServiceTest, testing::Bool()); | 930 TermsOfServiceTest, testing::Bool()); |
| 1089 | 931 |
| 1090 } // namespace policy | 932 } // namespace policy |
| OLD | NEW |