| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/compiler_specific.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/logging.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "base/macros.h" | 7 #include "chrome/browser/browser_process_platform_part.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 8 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 10 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 9 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 11 #include "chrome/test/base/testing_browser_process.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 12 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace policy { | 15 namespace policy { |
| 15 namespace { | |
| 16 | 16 |
| 17 // A test fixture simulating a browser that is already managed. | 17 class DeviceCloudPolicyBrowserTest : public InProcessBrowserTest { |
| 18 class DeviceCloudPolicyManagedBrowserTest : public DevicePolicyCrosBrowserTest { | 18 public: |
| 19 protected: | 19 DeviceCloudPolicyBrowserTest() : mock_client_(new MockCloudPolicyClient) { |
| 20 DeviceCloudPolicyManagedBrowserTest() {} | |
| 21 | |
| 22 void SetUpInProcessBrowserTestFixture() override { | |
| 23 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 24 | |
| 25 InstallOwnerKey(); | |
| 26 MarkAsEnterpriseOwned(); | |
| 27 RefreshDevicePolicy(); | |
| 28 } | 20 } |
| 29 | 21 |
| 30 private: | 22 MockCloudPolicyClient* mock_client_; |
| 31 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagedBrowserTest); | |
| 32 }; | 23 }; |
| 33 | 24 |
| 34 IN_PROC_BROWSER_TEST_F(DeviceCloudPolicyManagedBrowserTest, NoInitializer) { | 25 IN_PROC_BROWSER_TEST_F(DeviceCloudPolicyBrowserTest, Initializer) { |
| 35 BrowserPolicyConnectorChromeOS* connector = | 26 BrowserPolicyConnectorChromeOS* connector = |
| 36 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 27 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 28 // Initializer exists at first. |
| 29 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); |
| 30 |
| 31 // Initializer is deleted when the manager connects. |
| 32 connector->GetDeviceCloudPolicyManager()->StartConnection( |
| 33 make_scoped_ptr(mock_client_), |
| 34 connector->GetInstallAttributes()); |
| 37 EXPECT_FALSE(connector->GetDeviceCloudPolicyInitializer()); | 35 EXPECT_FALSE(connector->GetDeviceCloudPolicyInitializer()); |
| 38 } | |
| 39 | 36 |
| 40 // A test fixture simulating a browser that is still unmanaged. | 37 // Initializer is restarted when the manager disconnects. |
| 41 class DeviceCloudPolicyUnmanagedBrowserTest | 38 connector->GetDeviceCloudPolicyManager()->Disconnect(); |
| 42 : public DevicePolicyCrosBrowserTest { | |
| 43 protected: | |
| 44 DeviceCloudPolicyUnmanagedBrowserTest() {} | |
| 45 | |
| 46 void SetUpInProcessBrowserTestFixture() override { | |
| 47 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyUnmanagedBrowserTest); | |
| 52 }; | |
| 53 | |
| 54 IN_PROC_BROWSER_TEST_F(DeviceCloudPolicyUnmanagedBrowserTest, | |
| 55 StillHasInitializer) { | |
| 56 BrowserPolicyConnectorChromeOS* connector = | |
| 57 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 58 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); | 39 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); |
| 59 } | 40 } |
| 60 | 41 |
| 61 } // namespace | |
| 62 } // namespace policy | 42 } // namespace policy |
| OLD | NEW |