Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / managed / managed_user_test_base.h
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_
5 #define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_
6
7 #include <string>
8
9 #include "base/compiler_specific.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
12 #include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chromeos/cryptohome/mock_async_method_caller.h"
15 #include "chromeos/cryptohome/mock_homedir_methods.h"
16 #include "sync/api/fake_sync_change_processor.h"
17 #include "sync/api/sync_change.h"
18 #include "sync/api/sync_error_factory_mock.h"
19 #include "sync/protocol/sync.pb.h"
20
21 namespace chromeos {
22
23 const char kStubEthernetServicePath[] = "eth0";
24
25 const char kTestManager[] = "test-manager@gmail.com";
26 const char kTestOtherUser[] = "test-user@gmail.com";
27
28 const char kTestManagerPassword[] = "password";
29 const char kTestSupervisedUserDisplayName[] = "John Doe";
30 const char kTestSupervisedUserPassword[] = "simplepassword";
31
32 class ManagedUsersSyncTestAdapter {
33  public:
34   explicit ManagedUsersSyncTestAdapter(Profile* profile);
35
36   bool HasChanges() { return !processor_->changes().empty(); }
37
38   scoped_ptr< ::sync_pb::ManagedUserSpecifics> GetFirstChange();
39
40   void AddChange(const ::sync_pb::ManagedUserSpecifics& proto, bool update);
41
42   syncer::FakeSyncChangeProcessor* processor_;
43   ManagedUserSyncService* service_;
44   int next_sync_data_id_;
45 };
46
47 class ManagedUsersSharedSettingsSyncTestAdapter {
48  public:
49   explicit ManagedUsersSharedSettingsSyncTestAdapter(Profile* profile);
50
51   bool HasChanges() { return !processor_->changes().empty(); }
52
53   scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> GetFirstChange();
54
55   void AddChange(const ::sync_pb::ManagedUserSharedSettingSpecifics& proto,
56                  bool update);
57
58   void AddChange(const std::string& mu_id,
59                  const std::string& key,
60                  const base::Value& value,
61                  bool acknowledged,
62                  bool update);
63
64   syncer::FakeSyncChangeProcessor* processor_;
65   ManagedUserSharedSettingsService* service_;
66   int next_sync_data_id_;
67 };
68
69 class ManagedUserTestBase : public chromeos::LoginManagerTest {
70  public:
71   ManagedUserTestBase();
72   virtual ~ManagedUserTestBase();
73
74   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
75   virtual void CleanUpOnMainThread() OVERRIDE;
76
77  protected:
78   virtual void TearDown() OVERRIDE;
79
80   virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
81
82   void JSEval(const std::string& script);
83
84   void JSExpectAsync(const std::string& function);
85
86   void JSSetTextField(const std::string& element_selector,
87                       const std::string& value);
88
89   void PrepareUsers();
90   void StartFlowLoginAsManager();
91   void FillNewUserData(const std::string& display_name);
92   void StartUserCreation(const std::string& button_id,
93                          const std::string& expected_display_name);
94   void SigninAsSupervisedUser(bool check_homedir_calls,
95                               int user_index,
96                               const std::string& expected_display_name);
97   void SigninAsManager(int user_index);
98   void RemoveSupervisedUser(unsigned long original_user_count,
99                             int user_index,
100                             const std::string& expected_display_name);
101
102   cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
103   cryptohome::MockHomedirMethods* mock_homedir_methods_;
104   NetworkPortalDetectorTestImpl* network_portal_detector_;
105   ManagedUserRegistrationUtilityStub* registration_utility_stub_;
106   scoped_ptr<ScopedTestingManagedUserRegistrationUtility> scoped_utility_;
107   scoped_ptr<ManagedUsersSharedSettingsSyncTestAdapter>
108       shared_settings_adapter_;
109   scoped_ptr<ManagedUsersSyncTestAdapter> managed_users_adapter_;
110
111  private:
112   DISALLOW_COPY_AND_ASSIGN(ManagedUserTestBase);
113 };
114
115 }  // namespace chromeos
116
117 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_