1// Copyright 2014 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.
4
5#include "base/command_line.h"
6#include "base/prefs/pref_service.h"
7#include "base/values.h"
8#include "chrome/browser/profiles/profile.h"
9#include "chrome/browser/supervised_user/supervised_user_constants.h"
10#include "chrome/browser/supervised_user/supervised_user_service.h"
11#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
12#include "chrome/browser/supervised_user/supervised_user_settings_service.h"
13#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
14#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
15#include "chrome/browser/sync/test/integration/sync_test.h"
16#include "chrome/common/chrome_switches.h"
17
18class SingleClientSupervisedUserSettingsSyncTest : public SyncTest {
19 public:
20  SingleClientSupervisedUserSettingsSyncTest() : SyncTest(SINGLE_CLIENT) {}
21
22  virtual ~SingleClientSupervisedUserSettingsSyncTest() {}
23
24  // SyncTest overrides:
25  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
26    SyncTest::SetUpCommandLine(command_line);
27    command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
28  }
29};
30
31IN_PROC_BROWSER_TEST_F(SingleClientSupervisedUserSettingsSyncTest, Sanity) {
32  ASSERT_TRUE(SetupClients());
33  for (int i = 0; i < num_clients(); ++i) {
34    Profile* profile = GetProfile(i);
35    // Supervised users are prohibited from signing into the browser. Currently
36    // that means they're also unable to sync anything, so override that for
37    // this test.
38    // TODO(pamg): Remove this override (and the supervised user setting it
39    // requires) once sync and signin are properly separated for supervised
40    // users.
41    // See http://crbug.com/239785.
42    SupervisedUserSettingsService* settings_service =
43        SupervisedUserSettingsServiceFactory::GetForProfile(profile);
44    scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
45    settings_service->SetLocalSettingForTesting(
46        supervised_users::kSigninAllowed,
47        allow_signin.Pass());
48
49    // The user should not be signed in.
50    std::string username;
51    // ProfileSyncServiceHarness sets the password, which can't be empty.
52    std::string password = "password";
53    GetClient(i)->SetCredentials(username, password);
54  }
55  ASSERT_TRUE(SetupSync());
56}
57