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" |
17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/message_loop/message_loop_proxy.h" |
19 #include "base/path_service.h" | 22 #include "base/path_service.h" |
20 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
| 24 #include "base/sequenced_task_runner.h" |
21 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
25 #include "base/test/scoped_path_override.h" | 29 #include "base/test/scoped_path_override.h" |
26 #include "base/values.h" | 30 #include "base/values.h" |
27 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 32 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 33 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
30 #include "chrome/browser/chromeos/login/login_display_host.h" | 34 #include "chrome/browser/chromeos/login/login_display_host.h" |
31 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 35 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
32 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" | 36 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" |
33 #include "chrome/browser/chromeos/login/screens/wizard_screen.h" | 37 #include "chrome/browser/chromeos/login/screens/wizard_screen.h" |
34 #include "chrome/browser/chromeos/login/user.h" | 38 #include "chrome/browser/chromeos/login/user.h" |
35 #include "chrome/browser/chromeos/login/user_manager.h" | 39 #include "chrome/browser/chromeos/login/user_manager.h" |
36 #include "chrome/browser/chromeos/login/webui_login_view.h" | 40 #include "chrome/browser/chromeos/login/webui_login_view.h" |
37 #include "chrome/browser/chromeos/login/wizard_controller.h" | 41 #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" |
38 #include "chrome/browser/chromeos/policy/device_local_account.h" | 44 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 45 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
39 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 46 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
40 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 47 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
41 #include "chrome/browser/extensions/extension_service.h" | 48 #include "chrome/browser/extensions/extension_service.h" |
42 #include "chrome/browser/extensions/extension_system.h" | 49 #include "chrome/browser/extensions/extension_system.h" |
43 #include "chrome/browser/lifetime/application_lifetime.h" | 50 #include "chrome/browser/lifetime/application_lifetime.h" |
| 51 #include "chrome/browser/policy/browser_policy_connector.h" |
44 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 52 #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" |
45 #include "chrome/browser/policy/cloud/policy_builder.h" | 55 #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" |
46 #include "chrome/browser/policy/policy_service.h" | 58 #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" |
47 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 61 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
48 #include "chrome/browser/policy/test/local_policy_test_server.h" | 62 #include "chrome/browser/policy/test/local_policy_test_server.h" |
49 #include "chrome/browser/prefs/session_startup_pref.h" | 63 #include "chrome/browser/prefs/session_startup_pref.h" |
50 #include "chrome/browser/profiles/profile.h" | 64 #include "chrome/browser/profiles/profile.h" |
51 #include "chrome/browser/profiles/profile_manager.h" | 65 #include "chrome/browser/profiles/profile_manager.h" |
52 #include "chrome/browser/ui/browser.h" | 66 #include "chrome/browser/ui/browser.h" |
53 #include "chrome/browser/ui/browser_commands.h" | 67 #include "chrome/browser/ui/browser_commands.h" |
54 #include "chrome/browser/ui/browser_finder.h" | 68 #include "chrome/browser/ui/browser_finder.h" |
55 #include "chrome/browser/ui/browser_list.h" | 69 #include "chrome/browser/ui/browser_list.h" |
56 #include "chrome/browser/ui/browser_window.h" | 70 #include "chrome/browser/ui/browser_window.h" |
57 #include "chrome/browser/ui/host_desktop.h" | 71 #include "chrome/browser/ui/host_desktop.h" |
58 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 72 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
59 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 73 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
60 #include "chrome/common/chrome_paths.h" | 74 #include "chrome/common/chrome_paths.h" |
61 #include "chrome/common/chrome_switches.h" | 75 #include "chrome/common/chrome_switches.h" |
62 #include "chrome/common/extensions/extension.h" | 76 #include "chrome/common/extensions/extension.h" |
63 #include "chromeos/chromeos_paths.h" | 77 #include "chromeos/chromeos_paths.h" |
64 #include "chromeos/chromeos_switches.h" | 78 #include "chromeos/chromeos_switches.h" |
65 #include "chromeos/dbus/cryptohome_client.h" | 79 #include "chromeos/dbus/cryptohome_client.h" |
66 #include "chromeos/dbus/dbus_method_call_status.h" | 80 #include "chromeos/dbus/dbus_method_call_status.h" |
67 #include "chromeos/dbus/fake_session_manager_client.h" | 81 #include "chromeos/dbus/fake_session_manager_client.h" |
68 #include "chromeos/dbus/session_manager_client.h" | 82 #include "chromeos/dbus/session_manager_client.h" |
| 83 #include "components/policy/core/common/policy_namespace.h" |
69 #include "content/public/browser/notification_details.h" | 84 #include "content/public/browser/notification_details.h" |
70 #include "content/public/browser/notification_source.h" | 85 #include "content/public/browser/notification_source.h" |
71 #include "content/public/browser/web_contents.h" | 86 #include "content/public/browser/web_contents.h" |
72 #include "content/public/browser/web_ui.h" | 87 #include "content/public/browser/web_ui.h" |
73 #include "content/public/test/browser_test_utils.h" | 88 #include "content/public/test/browser_test_utils.h" |
74 #include "content/public/test/test_utils.h" | 89 #include "content/public/test/test_utils.h" |
75 #include "crypto/rsa_private_key.h" | 90 #include "crypto/rsa_private_key.h" |
76 #include "grit/chromium_strings.h" | 91 #include "grit/chromium_strings.h" |
77 #include "grit/generated_resources.h" | 92 #include "grit/generated_resources.h" |
78 #include "net/base/url_util.h" | 93 #include "net/base/url_util.h" |
79 #include "net/http/http_status_code.h" | 94 #include "net/http/http_status_code.h" |
80 #include "net/test/embedded_test_server/embedded_test_server.h" | 95 #include "net/test/embedded_test_server/embedded_test_server.h" |
81 #include "net/test/embedded_test_server/http_request.h" | 96 #include "net/test/embedded_test_server/http_request.h" |
82 #include "net/test/embedded_test_server/http_response.h" | 97 #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" |
83 #include "testing/gmock/include/gmock/gmock.h" | 101 #include "testing/gmock/include/gmock/gmock.h" |
84 #include "third_party/cros_system_api/dbus/service_constants.h" | 102 #include "third_party/cros_system_api/dbus/service_constants.h" |
85 #include "ui/base/l10n/l10n_util.h" | 103 #include "ui/base/l10n/l10n_util.h" |
86 #include "url/gurl.h" | 104 #include "url/gurl.h" |
87 | 105 |
88 namespace em = enterprise_management; | 106 namespace em = enterprise_management; |
89 | 107 |
90 using testing::InvokeWithoutArgs; | 108 using testing::InvokeWithoutArgs; |
91 using testing::Return; | 109 using testing::Return; |
92 using testing::_; | 110 using testing::_; |
(...skipping 22 matching lines...) Expand all Loading... |
115 " </app>\n"; | 133 " </app>\n"; |
116 const char kUpdateManifestFooter[] = | 134 const char kUpdateManifestFooter[] = |
117 "</gupdate>\n"; | 135 "</gupdate>\n"; |
118 const char kHostedAppID[] = "kbmnembihfiondgfjekmnmcbddelicoi"; | 136 const char kHostedAppID[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
119 const char kHostedAppCRXPath[] = "extensions/hosted_app.crx"; | 137 const char kHostedAppCRXPath[] = "extensions/hosted_app.crx"; |
120 const char kHostedAppVersion[] = "1.0.0.0"; | 138 const char kHostedAppVersion[] = "1.0.0.0"; |
121 const char kGoodExtensionID[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 139 const char kGoodExtensionID[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
122 const char kGoodExtensionCRXPath[] = "extensions/good.crx"; | 140 const char kGoodExtensionCRXPath[] = "extensions/good.crx"; |
123 const char kGoodExtensionVersion[] = "1.0"; | 141 const char kGoodExtensionVersion[] = "1.0"; |
124 | 142 |
| 143 const char kExternalData[] = "External data"; |
| 144 const char kExternalDataURL[] = "http://localhost/external_data"; |
| 145 |
125 // Helper that serves extension update manifests to Chrome. | 146 // Helper that serves extension update manifests to Chrome. |
126 class TestingUpdateManifestProvider { | 147 class TestingUpdateManifestProvider { |
127 public: | 148 public: |
128 | 149 |
129 // Update manifests will be served at |relative_update_url|. | 150 // Update manifests will be served at |relative_update_url|. |
130 explicit TestingUpdateManifestProvider( | 151 explicit TestingUpdateManifestProvider( |
131 const std::string& relative_update_url); | 152 const std::string& relative_update_url); |
132 ~TestingUpdateManifestProvider(); | 153 ~TestingUpdateManifestProvider(); |
133 | 154 |
134 // When an update manifest is requested for the given extension |id|, indicate | 155 // 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... |
222 extension->id() == id; | 243 extension->id() == id; |
223 } | 244 } |
224 | 245 |
225 bool DoesInstallFailureReferToId(const std::string& id, | 246 bool DoesInstallFailureReferToId(const std::string& id, |
226 const content::NotificationSource& source, | 247 const content::NotificationSource& source, |
227 const content::NotificationDetails& details) { | 248 const content::NotificationDetails& details) { |
228 return content::Details<const string16>(details)->find(UTF8ToUTF16(id)) != | 249 return content::Details<const string16>(details)->find(UTF8ToUTF16(id)) != |
229 string16::npos; | 250 string16::npos; |
230 } | 251 } |
231 | 252 |
| 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 |
232 } // namespace | 265 } // namespace |
233 | 266 |
234 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest { | 267 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest { |
235 protected: | 268 protected: |
236 DeviceLocalAccountTest() | 269 DeviceLocalAccountTest() |
237 : user_id_1_(GenerateDeviceLocalAccountUserId( | 270 : user_id_1_(GenerateDeviceLocalAccountUserId( |
238 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)), | 271 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)), |
239 user_id_2_(GenerateDeviceLocalAccountUserId( | 272 user_id_2_(GenerateDeviceLocalAccountUserId( |
240 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {} | 273 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {} |
241 | 274 |
242 virtual ~DeviceLocalAccountTest() {} | 275 virtual ~DeviceLocalAccountTest() {} |
243 | 276 |
244 virtual void SetUp() OVERRIDE { | 277 virtual void SetUp() OVERRIDE { |
245 // Configure and start the test server. | 278 // Configure and start the test server. |
246 scoped_ptr<crypto::RSAPrivateKey> signing_key( | 279 scoped_ptr<crypto::RSAPrivateKey> signing_key( |
247 PolicyBuilder::CreateTestSigningKey()); | 280 PolicyBuilder::CreateTestSigningKey()); |
248 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); | 281 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); |
249 signing_key.reset(); | 282 signing_key.reset(); |
250 test_server_.RegisterClient(PolicyBuilder::kFakeToken, | 283 test_server_.RegisterClient(PolicyBuilder::kFakeToken, |
251 PolicyBuilder::kFakeDeviceId); | 284 PolicyBuilder::kFakeDeviceId); |
252 ASSERT_TRUE(test_server_.Start()); | 285 ASSERT_TRUE(test_server_.Start()); |
253 | 286 |
254 ASSERT_TRUE(extension_cache_root_dir_.CreateUniqueTempDir()); | 287 ASSERT_TRUE(extension_cache_root_dir_.CreateUniqueTempDir()); |
255 extension_cache_root_dir_override_.reset(new base::ScopedPathOverride( | 288 extension_cache_root_dir_override_.reset(new base::ScopedPathOverride( |
256 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_CACHE, | 289 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
257 extension_cache_root_dir_.path())); | 290 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())); |
258 | 295 |
259 DevicePolicyCrosBrowserTest::SetUp(); | 296 DevicePolicyCrosBrowserTest::SetUp(); |
260 } | 297 } |
261 | 298 |
262 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 299 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
263 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 300 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
264 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 301 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
265 command_line->AppendSwitchASCII( | 302 command_line->AppendSwitchASCII( |
266 switches::kDeviceManagementUrl, test_server_.GetServiceURL().spec()); | 303 switches::kDeviceManagementUrl, test_server_.GetServiceURL().spec()); |
267 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | 304 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 const std::string& id, | 391 const std::string& id, |
355 const std::string& version) { | 392 const std::string& version) { |
356 return GetCacheDirectoryForAccountID(account_id) | 393 return GetCacheDirectoryForAccountID(account_id) |
357 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); | 394 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); |
358 } | 395 } |
359 | 396 |
360 const std::string user_id_1_; | 397 const std::string user_id_1_; |
361 const std::string user_id_2_; | 398 const std::string user_id_2_; |
362 | 399 |
363 base::ScopedTempDir extension_cache_root_dir_; | 400 base::ScopedTempDir extension_cache_root_dir_; |
| 401 base::ScopedTempDir external_data_cache_dir_; |
364 scoped_ptr<base::ScopedPathOverride> extension_cache_root_dir_override_; | 402 scoped_ptr<base::ScopedPathOverride> extension_cache_root_dir_override_; |
| 403 scoped_ptr<base::ScopedPathOverride> external_data_cache_dir_override_; |
365 | 404 |
366 UserPolicyBuilder device_local_account_policy_; | 405 UserPolicyBuilder device_local_account_policy_; |
367 LocalPolicyTestServer test_server_; | 406 LocalPolicyTestServer test_server_; |
368 }; | 407 }; |
369 | 408 |
370 static bool IsKnownUser(const std::string& account_id) { | 409 static bool IsKnownUser(const std::string& account_id) { |
371 return chromeos::UserManager::Get()->IsKnownUser(account_id); | 410 return chromeos::UserManager::Get()->IsKnownUser(account_id); |
372 } | 411 } |
373 | 412 |
374 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { | 413 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 // Verify that the extension was not installed. | 801 // Verify that the extension was not installed. |
763 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); | 802 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); |
764 | 803 |
765 // Verify that the app is still in the account's extension cache. | 804 // Verify that the app is still in the account's extension cache. |
766 EXPECT_TRUE(PathExists(cached_hosted_app)); | 805 EXPECT_TRUE(PathExists(cached_hosted_app)); |
767 | 806 |
768 // Verify that the extension was removed from the account's extension cache. | 807 // Verify that the extension was removed from the account's extension cache. |
769 EXPECT_FALSE(PathExists(cached_extension)); | 808 EXPECT_FALSE(PathExists(cached_extension)); |
770 } | 809 } |
771 | 810 |
| 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 |
772 class TermsOfServiceTest : public DeviceLocalAccountTest, | 930 class TermsOfServiceTest : public DeviceLocalAccountTest, |
773 public testing::WithParamInterface<bool> { | 931 public testing::WithParamInterface<bool> { |
774 }; | 932 }; |
775 | 933 |
776 IN_PROC_BROWSER_TEST_P(TermsOfServiceTest, TermsOfServiceScreen) { | 934 IN_PROC_BROWSER_TEST_P(TermsOfServiceTest, TermsOfServiceScreen) { |
777 // Specify Terms of Service URL. | 935 // Specify Terms of Service URL. |
778 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 936 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
779 device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value( | 937 device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value( |
780 embedded_test_server()->GetURL( | 938 embedded_test_server()->GetURL( |
781 std::string("/") + | 939 std::string("/") + |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 if (!IsSessionStarted()) { | 1081 if (!IsSessionStarted()) { |
924 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, | 1082 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, |
925 base::Bind(IsSessionStarted)).Wait(); | 1083 base::Bind(IsSessionStarted)).Wait(); |
926 } | 1084 } |
927 } | 1085 } |
928 | 1086 |
929 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance, | 1087 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance, |
930 TermsOfServiceTest, testing::Bool()); | 1088 TermsOfServiceTest, testing::Bool()); |
931 | 1089 |
932 } // namespace policy | 1090 } // namespace policy |
OLD | NEW |