| 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/command_line.h" |   10 #include "base/command_line.h" | 
|   11 #include "base/file_util.h" |   11 #include "base/file_util.h" | 
|   12 #include "base/files/file_path.h" |   12 #include "base/files/file_path.h" | 
|   13 #include "base/files/scoped_temp_dir.h" |   13 #include "base/files/scoped_temp_dir.h" | 
|   14 #include "base/message_loop.h" |   14 #include "base/message_loop.h" | 
|   15 #include "base/path_service.h" |   15 #include "base/path_service.h" | 
|   16 #include "base/run_loop.h" |   16 #include "base/run_loop.h" | 
|   17 #include "base/stl_util.h" |   17 #include "base/stl_util.h" | 
|   18 #include "base/strings/string_util.h" |   18 #include "base/strings/string_util.h" | 
|   19 #include "base/strings/utf_string_conversions.h" |   19 #include "base/strings/utf_string_conversions.h" | 
|   20 #include "chrome/browser/browser_process.h" |   20 #include "chrome/browser/browser_process.h" | 
|   21 #include "chrome/browser/chromeos/login/existing_user_controller.h" |   21 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 
|   22 #include "chrome/browser/chromeos/login/login_display_host.h" |   22 #include "chrome/browser/chromeos/login/login_display_host.h" | 
|   23 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |   23 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 
|   24 #include "chrome/browser/chromeos/login/user.h" |   24 #include "chrome/browser/chromeos/login/user.h" | 
|   25 #include "chrome/browser/chromeos/login/user_manager.h" |   25 #include "chrome/browser/chromeos/login/user_manager.h" | 
|   26 #include "chrome/browser/chromeos/policy/device_local_account.h" |   26 #include "chrome/browser/chromeos/policy/device_local_account.h" | 
|   27 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |   27 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 
|   28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |   28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 
|   29 #include "chrome/browser/lifetime/application_lifetime.h" |   29 #include "chrome/browser/lifetime/application_lifetime.h" | 
|   30 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |   30 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 
|   31 #include "chrome/browser/policy/cloud/policy_builder.h" |   31 #include "chrome/browser/policy/cloud/policy_builder.h" | 
|   32 #include "chrome/browser/policy/policy_service.h" |   32 #include "chrome/browser/policy/policy_service.h" | 
|   33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |   33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 
|   34 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h" |  | 
|   35 #include "chrome/browser/policy/test/local_policy_test_server.h" |   34 #include "chrome/browser/policy/test/local_policy_test_server.h" | 
|   36 #include "chrome/browser/prefs/session_startup_pref.h" |   35 #include "chrome/browser/prefs/session_startup_pref.h" | 
|   37 #include "chrome/browser/ui/browser.h" |   36 #include "chrome/browser/ui/browser.h" | 
|   38 #include "chrome/browser/ui/browser_finder.h" |   37 #include "chrome/browser/ui/browser_finder.h" | 
|   39 #include "chrome/browser/ui/host_desktop.h" |   38 #include "chrome/browser/ui/host_desktop.h" | 
|   40 #include "chrome/browser/ui/tabs/tab_strip_model.h" |   39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
|   41 #include "chrome/common/chrome_notification_types.h" |   40 #include "chrome/common/chrome_notification_types.h" | 
|   42 #include "chrome/common/chrome_switches.h" |   41 #include "chrome/common/chrome_switches.h" | 
|   43 #include "chrome/test/base/in_process_browser_test.h" |   42 #include "chrome/test/base/in_process_browser_test.h" | 
|   44 #include "chromeos/chromeos_paths.h" |   43 #include "chromeos/chromeos_paths.h" | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  110  |  109  | 
|  111     // Clear command-line arguments (but keep command-line switches) so the |  110     // Clear command-line arguments (but keep command-line switches) so the | 
|  112     // startup pages policy takes effect. |  111     // startup pages policy takes effect. | 
|  113     CommandLine* command_line = CommandLine::ForCurrentProcess(); |  112     CommandLine* command_line = CommandLine::ForCurrentProcess(); | 
|  114     CommandLine::StringVector argv(command_line->argv()); |  113     CommandLine::StringVector argv(command_line->argv()); | 
|  115     argv.erase(argv.begin() + argv.size() - command_line->GetArgs().size(), |  114     argv.erase(argv.begin() + argv.size() - command_line->GetArgs().size(), | 
|  116                argv.end()); |  115                argv.end()); | 
|  117     command_line->InitFromArgv(argv); |  116     command_line->InitFromArgv(argv); | 
|  118  |  117  | 
|  119     // Mark the device enterprise-enrolled. |  118     // Mark the device enterprise-enrolled. | 
|  120     SetUpInstallAttributes(); |  119     DevicePolicyCrosBrowserTest::MarkAsEnterpriseOwned(&temp_dir_); | 
|  121  |  120  | 
|  122     // Redirect session_manager DBus calls to FakeSessionManagerClient. |  121     // Redirect session_manager DBus calls to FakeSessionManagerClient. | 
|  123     chromeos::MockDBusThreadManagerWithoutGMock* dbus_thread_manager = |  122     chromeos::MockDBusThreadManagerWithoutGMock* dbus_thread_manager = | 
|  124         new chromeos::MockDBusThreadManagerWithoutGMock(); |  123         new chromeos::MockDBusThreadManagerWithoutGMock(); | 
|  125     session_manager_client_ = |  124     session_manager_client_ = | 
|  126         dbus_thread_manager->fake_session_manager_client(); |  125         dbus_thread_manager->fake_session_manager_client(); | 
|  127     chromeos::DBusThreadManager::InitializeForTesting(dbus_thread_manager); |  126     chromeos::DBusThreadManager::InitializeForTesting(dbus_thread_manager); | 
|  128  |  127  | 
|  129     SetUpPolicy(); |  128     SetUpPolicy(); | 
|  130   } |  129   } | 
|  131  |  130  | 
|  132   virtual void CleanUpOnMainThread() OVERRIDE { |  131   virtual void CleanUpOnMainThread() OVERRIDE { | 
|  133     // This shuts down the login UI. |  132     // This shuts down the login UI. | 
|  134     base::MessageLoop::current()->PostTask(FROM_HERE, |  133     base::MessageLoop::current()->PostTask(FROM_HERE, | 
|  135                                            base::Bind(&chrome::AttemptExit)); |  134                                            base::Bind(&chrome::AttemptExit)); | 
|  136     base::RunLoop().RunUntilIdle(); |  135     base::RunLoop().RunUntilIdle(); | 
|  137   } |  136   } | 
|  138  |  137  | 
|  139   void SetUpInstallAttributes() { |  | 
|  140     cryptohome::SerializedInstallAttributes install_attrs_proto; |  | 
|  141     cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL; |  | 
|  142  |  | 
|  143     attribute = install_attrs_proto.add_attributes(); |  | 
|  144     attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned); |  | 
|  145     attribute->set_value("true"); |  | 
|  146  |  | 
|  147     attribute = install_attrs_proto.add_attributes(); |  | 
|  148     attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser); |  | 
|  149     attribute->set_value(PolicyBuilder::kFakeUsername); |  | 
|  150  |  | 
|  151     base::FilePath install_attrs_file = |  | 
|  152         temp_dir_.path().AppendASCII("install_attributes.pb"); |  | 
|  153     const std::string install_attrs_blob( |  | 
|  154         install_attrs_proto.SerializeAsString()); |  | 
|  155     ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), |  | 
|  156               file_util::WriteFile(install_attrs_file, |  | 
|  157                                    install_attrs_blob.c_str(), |  | 
|  158                                    install_attrs_blob.size())); |  | 
|  159     ASSERT_TRUE(PathService::Override(chromeos::FILE_INSTALL_ATTRIBUTES, |  | 
|  160                                       install_attrs_file)); |  | 
|  161   } |  | 
|  162  |  | 
|  163   void SetUpPolicy() { |  138   void SetUpPolicy() { | 
|  164     // Configure two device-local accounts in device settings. |  139     // Configure two device-local accounts in device settings. | 
|  165     DevicePolicyBuilder device_policy; |  140     DevicePolicyBuilder device_policy; | 
|  166     device_policy.policy_data().set_public_key_version(1); |  141     device_policy.policy_data().set_public_key_version(1); | 
|  167     em::ChromeDeviceSettingsProto& proto(device_policy.payload()); |  142     em::ChromeDeviceSettingsProto& proto(device_policy.payload()); | 
|  168     proto.mutable_show_user_names()->set_show_user_names(true); |  143     proto.mutable_show_user_names()->set_show_user_names(true); | 
|  169     em::DeviceLocalAccountInfoProto* account1 = |  144     em::DeviceLocalAccountInfoProto* account1 = | 
|  170         proto.mutable_device_local_accounts()->add_account(); |  145         proto.mutable_device_local_accounts()->add_account(); | 
|  171     account1->set_account_id(kAccountId1); |  146     account1->set_account_id(kAccountId1); | 
|  172     account1->set_type( |  147     account1->set_type( | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  357  |  332  | 
|  358   TabStripModel* tabs = browser->tab_strip_model(); |  333   TabStripModel* tabs = browser->tab_strip_model(); | 
|  359   ASSERT_TRUE(tabs); |  334   ASSERT_TRUE(tabs); | 
|  360   int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); |  335   int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); | 
|  361   EXPECT_EQ(expected_tab_count, tabs->count()); |  336   EXPECT_EQ(expected_tab_count, tabs->count()); | 
|  362   for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) |  337   for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) | 
|  363     EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL()); |  338     EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL()); | 
|  364 } |  339 } | 
|  365  |  340  | 
|  366 }  // namespace policy |  341 }  // namespace policy | 
| OLD | NEW |