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_SUPERVISED_SUPERVISED_USER_TEST_BASE_H_ 5#define CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_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/profiles/profile.h" 13#include "chrome/browser/supervised_user/supervised_user_registration_utility_stub.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 21namespace chromeos { 22 23const char kTestManager[] = "test-manager@gmail.com"; 24const char kTestOtherUser[] = "test-user@gmail.com"; 25 26const char kTestManagerPassword[] = "password"; 27const char kTestSupervisedUserDisplayName[] = "John Doe"; 28const char kTestSupervisedUserPassword[] = "simplepassword"; 29 30class SupervisedUsersSyncTestAdapter { 31 public: 32 explicit SupervisedUsersSyncTestAdapter(Profile* profile); 33 34 bool HasChanges() { return !processor_->changes().empty(); } 35 36 scoped_ptr< ::sync_pb::ManagedUserSpecifics> GetFirstChange(); 37 38 void AddChange(const ::sync_pb::ManagedUserSpecifics& proto, bool update); 39 40 syncer::FakeSyncChangeProcessor* processor_; 41 SupervisedUserSyncService* service_; 42 int next_sync_data_id_; 43}; 44 45class SupervisedUsersSharedSettingsSyncTestAdapter { 46 public: 47 explicit SupervisedUsersSharedSettingsSyncTestAdapter(Profile* profile); 48 49 bool HasChanges() { return !processor_->changes().empty(); } 50 51 scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> GetFirstChange(); 52 53 void AddChange(const ::sync_pb::ManagedUserSharedSettingSpecifics& proto, 54 bool update); 55 56 void AddChange(const std::string& mu_id, 57 const std::string& key, 58 const base::Value& value, 59 bool acknowledged, 60 bool update); 61 62 syncer::FakeSyncChangeProcessor* processor_; 63 SupervisedUserSharedSettingsService* service_; 64 int next_sync_data_id_; 65}; 66 67class SupervisedUserTestBase : public chromeos::LoginManagerTest { 68 public: 69 SupervisedUserTestBase(); 70 virtual ~SupervisedUserTestBase(); 71 72 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; 73 74 protected: 75 virtual void TearDown() OVERRIDE; 76 77 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; 78 79 void JSEval(const std::string& script); 80 81 void JSExpectAsync(const std::string& function); 82 83 void JSSetTextField(const std::string& element_selector, 84 const std::string& value); 85 86 void PrepareUsers(); 87 void StartFlowLoginAsManager(); 88 void FillNewUserData(const std::string& display_name); 89 void StartUserCreation(const std::string& button_id, 90 const std::string& expected_display_name); 91 void SigninAsSupervisedUser(bool check_homedir_calls, 92 int user_index, 93 const std::string& expected_display_name); 94 void SigninAsManager(int user_index); 95 void RemoveSupervisedUser(size_t original_user_count, 96 int user_index, 97 const std::string& expected_display_name); 98 99 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; 100 cryptohome::MockHomedirMethods* mock_homedir_methods_; 101 NetworkPortalDetectorTestImpl* network_portal_detector_; 102 SupervisedUserRegistrationUtilityStub* registration_utility_stub_; 103 scoped_ptr<ScopedTestingSupervisedUserRegistrationUtility> scoped_utility_; 104 scoped_ptr<SupervisedUsersSharedSettingsSyncTestAdapter> 105 shared_settings_adapter_; 106 scoped_ptr<SupervisedUsersSyncTestAdapter> supervised_users_adapter_; 107 108 private: 109 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTestBase); 110}; 111 112} // namespace chromeos 113 114#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_TEST_BASE_H_ 115