cryptohome: Merge FakeCryptohomeClient and CryptohomeClinentStubImpl
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_local_account_browsertest.cc
blob59eb85be77a6a69c85f3d90b8e037f88261c3301
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
3 // found in the LICENSE file.
5 #include <map>
6 #include <string>
8 #include "base/basictypes.h"
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/file_util.h"
13 #include "base/files/file_path.h"
14 #include "base/json/json_reader.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h"
18 #include "base/run_loop.h"
19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/chromeos/login/existing_user_controller.h"
25 #include "chrome/browser/chromeos/login/login_display_host.h"
26 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
27 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h"
28 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
29 #include "chrome/browser/chromeos/login/user.h"
30 #include "chrome/browser/chromeos/login/user_manager.h"
31 #include "chrome/browser/chromeos/login/webui_login_view.h"
32 #include "chrome/browser/chromeos/login/wizard_controller.h"
33 #include "chrome/browser/chromeos/policy/device_local_account.h"
34 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
35 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
36 #include "chrome/browser/lifetime/application_lifetime.h"
37 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
38 #include "chrome/browser/policy/cloud/policy_builder.h"
39 #include "chrome/browser/policy/policy_service.h"
40 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
41 #include "chrome/browser/policy/test/local_policy_test_server.h"
42 #include "chrome/browser/prefs/session_startup_pref.h"
43 #include "chrome/browser/profiles/profile.h"
44 #include "chrome/browser/profiles/profile_manager.h"
45 #include "chrome/browser/ui/browser.h"
46 #include "chrome/browser/ui/browser_commands.h"
47 #include "chrome/browser/ui/browser_finder.h"
48 #include "chrome/browser/ui/browser_list.h"
49 #include "chrome/browser/ui/browser_window.h"
50 #include "chrome/browser/ui/host_desktop.h"
51 #include "chrome/browser/ui/tabs/tab_strip_model.h"
52 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
53 #include "chrome/common/chrome_paths.h"
54 #include "chrome/common/chrome_switches.h"
55 #include "chromeos/chromeos_switches.h"
56 #include "chromeos/dbus/cryptohome_client.h"
57 #include "chromeos/dbus/dbus_method_call_status.h"
58 #include "chromeos/dbus/fake_session_manager_client.h"
59 #include "chromeos/dbus/session_manager_client.h"
60 #include "content/public/browser/web_contents.h"
61 #include "content/public/browser/web_ui.h"
62 #include "content/public/test/browser_test_utils.h"
63 #include "content/public/test/test_utils.h"
64 #include "crypto/rsa_private_key.h"
65 #include "grit/chromium_strings.h"
66 #include "grit/generated_resources.h"
67 #include "net/test/embedded_test_server/embedded_test_server.h"
68 #include "testing/gmock/include/gmock/gmock.h"
69 #include "third_party/cros_system_api/dbus/service_constants.h"
70 #include "ui/base/l10n/l10n_util.h"
71 #include "url/gurl.h"
73 namespace em = enterprise_management;
75 using testing::InvokeWithoutArgs;
76 using testing::Return;
77 using testing::_;
79 namespace policy {
81 namespace {
83 const char kDomain[] = "example.com";
84 const char kAccountId1[] = "dla1@example.com";
85 const char kAccountId2[] = "dla2@example.com";
86 const char kDisplayName[] = "display name";
87 const char* kStartupURLs[] = {
88 "chrome://policy",
89 "chrome://about",
91 const char kExistentTermsOfServicePath[] = "chromeos/enterprise/tos.txt";
92 const char kNonexistentTermsOfServicePath[] = "chromeos/enterprise/tos404.txt";
94 } // namespace
96 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest {
97 protected:
98 DeviceLocalAccountTest()
99 : user_id_1_(GenerateDeviceLocalAccountUserId(
100 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
101 user_id_2_(GenerateDeviceLocalAccountUserId(
102 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {}
104 virtual ~DeviceLocalAccountTest() {}
106 virtual void SetUp() OVERRIDE {
107 // Configure and start the test server.
108 scoped_ptr<crypto::RSAPrivateKey> signing_key(
109 PolicyBuilder::CreateTestSigningKey());
110 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get()));
111 signing_key.reset();
112 test_server_.RegisterClient(PolicyBuilder::kFakeToken,
113 PolicyBuilder::kFakeDeviceId);
114 ASSERT_TRUE(test_server_.Start());
116 DevicePolicyCrosBrowserTest::SetUp();
119 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
120 command_line->AppendSwitch(chromeos::switches::kLoginManager);
121 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
122 command_line->AppendSwitchASCII(
123 switches::kDeviceManagementUrl, test_server_.GetServiceURL().spec());
124 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
127 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
128 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
130 // Clear command-line arguments (but keep command-line switches) so the
131 // startup pages policy takes effect.
132 CommandLine* command_line = CommandLine::ForCurrentProcess();
133 CommandLine::StringVector argv(command_line->argv());
134 argv.erase(argv.begin() + argv.size() - command_line->GetArgs().size(),
135 argv.end());
136 command_line->InitFromArgv(argv);
138 InstallOwnerKey();
139 MarkAsEnterpriseOwned();
141 InitializePolicy();
144 virtual void CleanUpOnMainThread() OVERRIDE {
145 // This shuts down the login UI.
146 base::MessageLoop::current()->PostTask(FROM_HERE,
147 base::Bind(&chrome::AttemptExit));
148 base::RunLoop().RunUntilIdle();
151 void InitializePolicy() {
152 device_policy()->policy_data().set_public_key_version(1);
153 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
154 proto.mutable_show_user_names()->set_show_user_names(true);
156 device_local_account_policy_.policy_data().set_policy_type(
157 dm_protocol::kChromePublicAccountPolicyType);
158 device_local_account_policy_.policy_data().set_username(kAccountId1);
159 device_local_account_policy_.policy_data().set_settings_entity_id(
160 kAccountId1);
161 device_local_account_policy_.policy_data().set_public_key_version(1);
162 device_local_account_policy_.payload().mutable_userdisplayname()->set_value(
163 kDisplayName);
166 void BuildDeviceLocalAccountPolicy() {
167 device_local_account_policy_.SetDefaultSigningKey();
168 device_local_account_policy_.Build();
171 void UploadDeviceLocalAccountPolicy() {
172 BuildDeviceLocalAccountPolicy();
173 ASSERT_TRUE(session_manager_client()->device_local_account_policy(
174 kAccountId1).empty());
175 test_server_.UpdatePolicy(
176 dm_protocol::kChromePublicAccountPolicyType, kAccountId1,
177 device_local_account_policy_.payload().SerializeAsString());
180 void UploadAndInstallDeviceLocalAccountPolicy() {
181 UploadDeviceLocalAccountPolicy();
182 session_manager_client()->set_device_local_account_policy(
183 kAccountId1, device_local_account_policy_.GetBlob());
186 void AddPublicSessionToDevicePolicy(const std::string& username) {
187 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
188 em::DeviceLocalAccountInfoProto* account =
189 proto.mutable_device_local_accounts()->add_account();
190 account->set_account_id(username);
191 account->set_type(
192 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
193 RefreshDevicePolicy();
194 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType,
195 std::string(), proto.SerializeAsString());
198 void CheckPublicSessionPresent(const std::string& id) {
199 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id);
200 ASSERT_TRUE(user);
201 EXPECT_EQ(id, user->email());
202 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType());
205 const std::string user_id_1_;
206 const std::string user_id_2_;
208 UserPolicyBuilder device_local_account_policy_;
209 LocalPolicyTestServer test_server_;
212 static bool IsKnownUser(const std::string& account_id) {
213 return chromeos::UserManager::Get()->IsKnownUser(account_id);
216 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
217 AddPublicSessionToDevicePolicy(kAccountId1);
218 AddPublicSessionToDevicePolicy(kAccountId2);
220 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
221 base::Bind(&IsKnownUser, user_id_1_))
222 .Wait();
223 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
224 base::Bind(&IsKnownUser, user_id_2_))
225 .Wait();
227 CheckPublicSessionPresent(user_id_1_);
228 CheckPublicSessionPresent(user_id_2_);
231 static bool DisplayNameMatches(const std::string& account_id,
232 const std::string& display_name) {
233 const chromeos::User* user =
234 chromeos::UserManager::Get()->FindUser(account_id);
235 if (!user || user->display_name().empty())
236 return false;
237 EXPECT_EQ(UTF8ToUTF16(display_name), user->display_name());
238 return true;
241 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) {
242 UploadAndInstallDeviceLocalAccountPolicy();
243 AddPublicSessionToDevicePolicy(kAccountId1);
245 content::WindowedNotificationObserver(
246 chrome::NOTIFICATION_USER_LIST_CHANGED,
247 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
250 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) {
251 UploadDeviceLocalAccountPolicy();
252 AddPublicSessionToDevicePolicy(kAccountId1);
254 // Policy for the account is not installed in session_manager_client. Because
255 // of this, the presence of the display name (which comes from policy) can be
256 // used as a signal that indicates successful policy download.
257 content::WindowedNotificationObserver(
258 chrome::NOTIFICATION_USER_LIST_CHANGED,
259 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
261 // Sanity check: The policy should be present now.
262 ASSERT_FALSE(session_manager_client()->device_local_account_policy(
263 kAccountId1).empty());
266 static bool IsNotKnownUser(const std::string& account_id) {
267 return !IsKnownUser(account_id);
270 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) {
271 AddPublicSessionToDevicePolicy(kAccountId1);
272 AddPublicSessionToDevicePolicy(kAccountId2);
274 // Wait until the login screen is up.
275 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
276 base::Bind(&IsKnownUser, user_id_1_))
277 .Wait();
278 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
279 base::Bind(&IsKnownUser, user_id_2_))
280 .Wait();
282 // Update policy to remove kAccountId2.
283 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
284 proto.mutable_device_local_accounts()->clear_account();
285 AddPublicSessionToDevicePolicy(kAccountId1);
287 em::ChromeDeviceSettingsProto policy;
288 policy.mutable_show_user_names()->set_show_user_names(true);
289 em::DeviceLocalAccountInfoProto* account1 =
290 policy.mutable_device_local_accounts()->add_account();
291 account1->set_account_id(kAccountId1);
292 account1->set_type(
293 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
295 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(),
296 policy.SerializeAsString());
297 g_browser_process->policy_service()->RefreshPolicies(base::Closure());
299 // Make sure the second device-local account disappears.
300 content::WindowedNotificationObserver(
301 chrome::NOTIFICATION_USER_LIST_CHANGED,
302 base::Bind(&IsNotKnownUser, user_id_2_)).Wait();
305 static bool IsSessionStarted() {
306 return chromeos::UserManager::Get()->IsSessionStarted();
309 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) {
310 // Specify startup pages.
311 device_local_account_policy_.payload().mutable_restoreonstartup()->set_value(
312 SessionStartupPref::kPrefValueURLs);
313 em::StringListPolicyProto* startup_urls_proto =
314 device_local_account_policy_.payload().mutable_restoreonstartupurls();
315 for (size_t i = 0; i < arraysize(kStartupURLs); ++i)
316 startup_urls_proto->mutable_value()->add_entries(kStartupURLs[i]);
317 UploadAndInstallDeviceLocalAccountPolicy();
318 AddPublicSessionToDevicePolicy(kAccountId1);
320 // This observes the display name becoming available as this indicates
321 // device-local account policy is fully loaded, which is a prerequisite for
322 // successful login.
323 content::WindowedNotificationObserver(
324 chrome::NOTIFICATION_USER_LIST_CHANGED,
325 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
327 // Wait for the login UI to be ready.
328 chromeos::LoginDisplayHostImpl* host =
329 reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
330 chromeos::LoginDisplayHostImpl::default_host());
331 ASSERT_TRUE(host);
332 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
333 ASSERT_TRUE(oobe_ui);
334 base::RunLoop run_loop;
335 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
336 if (!oobe_ui_ready)
337 run_loop.Run();
339 // Start login into the device-local account.
340 host->StartSignInScreen();
341 chromeos::ExistingUserController* controller =
342 chromeos::ExistingUserController::current_controller();
343 ASSERT_TRUE(controller);
344 controller->LoginAsPublicAccount(user_id_1_);
346 // Wait for the session to start.
347 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED,
348 base::Bind(IsSessionStarted)).Wait();
350 // Check that the startup pages specified in policy were opened.
351 BrowserList* browser_list =
352 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
353 EXPECT_EQ(1U, browser_list->size());
354 Browser* browser = browser_list->get(0);
355 ASSERT_TRUE(browser);
357 TabStripModel* tabs = browser->tab_strip_model();
358 ASSERT_TRUE(tabs);
359 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
360 EXPECT_EQ(expected_tab_count, tabs->count());
361 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) {
362 EXPECT_EQ(GURL(kStartupURLs[i]),
363 tabs->GetWebContentsAt(i)->GetVisibleURL());
367 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, FullscreenDisallowed) {
368 UploadAndInstallDeviceLocalAccountPolicy();
369 AddPublicSessionToDevicePolicy(kAccountId1);
371 // This observes the display name becoming available as this indicates
372 // device-local account policy is fully loaded, which is a prerequisite for
373 // successful login.
374 content::WindowedNotificationObserver(
375 chrome::NOTIFICATION_USER_LIST_CHANGED,
376 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
378 // Wait for the login UI to be ready.
379 chromeos::LoginDisplayHostImpl* host =
380 reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
381 chromeos::LoginDisplayHostImpl::default_host());
382 ASSERT_TRUE(host);
383 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
384 ASSERT_TRUE(oobe_ui);
385 base::RunLoop run_loop;
386 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
387 if (!oobe_ui_ready)
388 run_loop.Run();
390 // Ensure that the browser stays alive, even though no windows are opened
391 // during session start.
392 chrome::StartKeepAlive();
394 // Start login into the device-local account.
395 host->StartSignInScreen();
396 chromeos::ExistingUserController* controller =
397 chromeos::ExistingUserController::current_controller();
398 ASSERT_TRUE(controller);
399 controller->LoginAsPublicAccount(user_id_1_);
401 // Wait for the session to start.
402 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED,
403 base::Bind(IsSessionStarted)).Wait();
405 // Open a browser window.
406 chrome::NewEmptyWindow(ProfileManager::GetDefaultProfile(),
407 chrome::HOST_DESKTOP_TYPE_ASH);
408 BrowserList* browser_list =
409 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
410 EXPECT_EQ(1U, browser_list->size());
411 Browser* browser = browser_list->get(0);
412 ASSERT_TRUE(browser);
413 BrowserWindow* browser_window = browser->window();
414 ASSERT_TRUE(browser_window);
415 chrome::EndKeepAlive();
417 // Verify that an attempt to enter fullscreen mode is denied.
418 EXPECT_FALSE(browser_window->IsFullscreen());
419 chrome::ToggleFullscreenMode(browser);
420 EXPECT_FALSE(browser_window->IsFullscreen());
423 class TermsOfServiceTest : public DeviceLocalAccountTest,
424 public testing::WithParamInterface<bool> {
427 IN_PROC_BROWSER_TEST_P(TermsOfServiceTest, TermsOfServiceScreen) {
428 // Specify Terms of Service URL.
429 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
430 device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value(
431 embedded_test_server()->GetURL(
432 std::string("/") +
433 (GetParam() ? kExistentTermsOfServicePath
434 : kNonexistentTermsOfServicePath)).spec());
435 UploadAndInstallDeviceLocalAccountPolicy();
436 AddPublicSessionToDevicePolicy(kAccountId1);
438 // Wait for the device-local account policy to be fully loaded.
439 content::WindowedNotificationObserver(
440 chrome::NOTIFICATION_USER_LIST_CHANGED,
441 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
443 // Wait for the login UI to be ready.
444 chromeos::LoginDisplayHostImpl* host =
445 reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
446 chromeos::LoginDisplayHostImpl::default_host());
447 ASSERT_TRUE(host);
448 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
449 ASSERT_TRUE(oobe_ui);
450 base::RunLoop oobe_ui_wait_run_loop;
451 const bool oobe_ui_ready =
452 oobe_ui->IsJSReady(oobe_ui_wait_run_loop.QuitClosure());
453 if (!oobe_ui_ready)
454 oobe_ui_wait_run_loop.Run();
456 // Start login into the device-local account.
457 host->StartSignInScreen();
458 chromeos::ExistingUserController* controller =
459 chromeos::ExistingUserController::current_controller();
460 ASSERT_TRUE(controller);
461 controller->LoginAsPublicAccount(user_id_1_);
463 // Set up an observer that will quit the message loop when login has succeeded
464 // and the first wizard screen, if any, is being shown.
465 base::RunLoop login_wait_run_loop;
466 chromeos::MockConsumer login_status_consumer;
467 EXPECT_CALL(login_status_consumer, OnLoginSuccess(_, false, false))
468 .Times(1)
469 .WillOnce(InvokeWithoutArgs(&login_wait_run_loop, &base::RunLoop::Quit));
471 // Spin the loop until the observer fires. Then, unregister the observer.
472 controller->set_login_status_consumer(&login_status_consumer);
473 login_wait_run_loop.Run();
474 controller->set_login_status_consumer(NULL);
476 // Verify that the Terms of Service screen is being shown.
477 chromeos::WizardController* wizard_controller =
478 chromeos::WizardController::default_controller();
479 ASSERT_TRUE(wizard_controller);
480 ASSERT_TRUE(wizard_controller->current_screen());
481 EXPECT_EQ(chromeos::WizardController::kTermsOfServiceScreenName,
482 wizard_controller->current_screen()->GetName());
484 // Wait for the Terms of Service to finish downloading, then get the status of
485 // the screen's UI elements.
486 chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
487 ASSERT_TRUE(web_ui_login_view);
488 content::WebUI* web_ui = web_ui_login_view->GetWebUI();
489 ASSERT_TRUE(web_ui);
490 content::WebContents* contents = web_ui->GetWebContents();
491 ASSERT_TRUE(contents);
492 std::string json;
493 ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
494 "var screen = document.getElementById('terms-of-service');"
495 "function SendReplyIfDownloadDone() {"
496 " if (screen.classList.contains('tos-loading'))"
497 " return false;"
498 " var status = {};"
499 " status.heading = document.getElementById('tos-heading').textContent;"
500 " status.subheading ="
501 " document.getElementById('tos-subheading').textContent;"
502 " status.contentHeading ="
503 " document.getElementById('tos-content-heading').textContent;"
504 " status.content ="
505 " document.getElementById('tos-content-main').textContent;"
506 " status.error = screen.classList.contains('error');"
507 " status.acceptEnabled ="
508 " !document.getElementById('tos-accept-button').disabled;"
509 " domAutomationController.send(JSON.stringify(status));"
510 " observer.disconnect();"
511 " return true;"
513 "var observer = new MutationObserver(SendReplyIfDownloadDone);"
514 "if (!SendReplyIfDownloadDone()) {"
515 " var options = { attributes: true, attributeFilter: [ 'class' ] };"
516 " observer.observe(screen, options);"
517 "}",
518 &json));
519 scoped_ptr<base::Value> value_ptr(base::JSONReader::Read(json));
520 const base::DictionaryValue* status = NULL;
521 ASSERT_TRUE(value_ptr.get());
522 ASSERT_TRUE(value_ptr->GetAsDictionary(&status));
523 std::string heading;
524 EXPECT_TRUE(status->GetString("heading", &heading));
525 std::string subheading;
526 EXPECT_TRUE(status->GetString("subheading", &subheading));
527 std::string content_heading;
528 EXPECT_TRUE(status->GetString("contentHeading", &content_heading));
529 std::string content;
530 EXPECT_TRUE(status->GetString("content", &content));
531 bool error;
532 EXPECT_TRUE(status->GetBoolean("error", &error));
533 bool accept_enabled;
534 EXPECT_TRUE(status->GetBoolean("acceptEnabled", &accept_enabled));
536 // Verify that the screen's headings have been set correctly.
537 EXPECT_EQ(
538 l10n_util::GetStringFUTF8(IDS_TERMS_OF_SERVICE_SCREEN_HEADING,
539 UTF8ToUTF16(kDomain)),
540 heading);
541 EXPECT_EQ(
542 l10n_util::GetStringFUTF8(IDS_TERMS_OF_SERVICE_SCREEN_SUBHEADING,
543 UTF8ToUTF16(kDomain)),
544 subheading);
545 EXPECT_EQ(
546 l10n_util::GetStringFUTF8(IDS_TERMS_OF_SERVICE_SCREEN_CONTENT_HEADING,
547 UTF8ToUTF16(kDomain)),
548 content_heading);
550 if (!GetParam()) {
551 // The Terms of Service URL was invalid. Verify that the screen is showing
552 // an error and the accept button is disabled.
553 EXPECT_TRUE(error);
554 EXPECT_FALSE(accept_enabled);
555 return;
558 // The Terms of Service URL was valid. Verify that the screen is showing the
559 // downloaded Terms of Service and the accept button is enabled.
560 base::FilePath test_dir;
561 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
562 std::string terms_of_service;
563 ASSERT_TRUE(base::ReadFileToString(
564 test_dir.Append(kExistentTermsOfServicePath), &terms_of_service));
565 EXPECT_EQ(terms_of_service, content);
566 EXPECT_FALSE(error);
567 EXPECT_TRUE(accept_enabled);
569 // Click the accept button.
570 ASSERT_TRUE(content::ExecuteScript(contents,
571 "$('tos-accept-button').click();"));
573 // Wait for the session to start.
574 if (!IsSessionStarted()) {
575 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED,
576 base::Bind(IsSessionStarted)).Wait();
580 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance,
581 TermsOfServiceTest, testing::Bool());
583 } // namespace policy