| Index: chrome/browser/chromeos/policy/device_local_account_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
|
| index 99346085fd361ec2fa65cd618a00aa2070ab084f..6a24f9bff058df3d82286e5e7f923e9d321b3c80 100644
|
| --- a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
|
| +++ b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
|
| @@ -14,10 +14,14 @@
|
| #include "base/files/file_path.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/json/json_reader.h"
|
| +#include "base/location.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/message_loop/message_loop_proxy.h"
|
| #include "base/path_service.h"
|
| #include "base/run_loop.h"
|
| +#include "base/sequenced_task_runner.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| @@ -35,15 +39,25 @@
|
| #include "chrome/browser/chromeos/login/user_manager.h"
|
| #include "chrome/browser/chromeos/login/webui_login_view.h"
|
| #include "chrome/browser/chromeos/login/wizard_controller.h"
|
| +#include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h"
|
| +#include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.h"
|
| #include "chrome/browser/chromeos/policy/device_local_account.h"
|
| +#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
|
| #include "chrome/browser/chromeos/policy/device_policy_builder.h"
|
| #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/lifetime/application_lifetime.h"
|
| +#include "chrome/browser/policy/browser_policy_connector.h"
|
| #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
|
| +#include "chrome/browser/policy/cloud/cloud_policy_core.h"
|
| +#include "chrome/browser/policy/cloud/cloud_policy_store.h"
|
| #include "chrome/browser/policy/cloud/policy_builder.h"
|
| +#include "chrome/browser/policy/external_data_fetcher.h"
|
| +#include "chrome/browser/policy/policy_map.h"
|
| #include "chrome/browser/policy/policy_service.h"
|
| +#include "chrome/browser/policy/profile_policy_connector.h"
|
| +#include "chrome/browser/policy/profile_policy_connector_factory.h"
|
| #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
|
| #include "chrome/browser/policy/test/local_policy_test_server.h"
|
| #include "chrome/browser/prefs/session_startup_pref.h"
|
| @@ -66,6 +80,7 @@
|
| #include "chromeos/dbus/dbus_method_call_status.h"
|
| #include "chromeos/dbus/fake_session_manager_client.h"
|
| #include "chromeos/dbus/session_manager_client.h"
|
| +#include "components/policy/core/common/policy_namespace.h"
|
| #include "content/public/browser/notification_details.h"
|
| #include "content/public/browser/notification_source.h"
|
| #include "content/public/browser/web_contents.h"
|
| @@ -80,6 +95,9 @@
|
| #include "net/test/embedded_test_server/embedded_test_server.h"
|
| #include "net/test/embedded_test_server/http_request.h"
|
| #include "net/test/embedded_test_server/http_response.h"
|
| +#include "net/url_request/test_url_fetcher_factory.h"
|
| +#include "net/url_request/url_fetcher_delegate.h"
|
| +#include "policy/policy_constants.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "third_party/cros_system_api/dbus/service_constants.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -122,6 +140,9 @@ const char kGoodExtensionID[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
|
| const char kGoodExtensionCRXPath[] = "extensions/good.crx";
|
| const char kGoodExtensionVersion[] = "1.0";
|
|
|
| +const char kExternalData[] = "External data";
|
| +const char kExternalDataURL[] = "http://localhost/external_data";
|
| +
|
| // Helper that serves extension update manifests to Chrome.
|
| class TestingUpdateManifestProvider {
|
| public:
|
| @@ -229,6 +250,18 @@ bool DoesInstallFailureReferToId(const std::string& id,
|
| string16::npos;
|
| }
|
|
|
| +scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher(
|
| + scoped_refptr<base::SequencedTaskRunner> task_runner,
|
| + const base::Closure& callback,
|
| + const GURL& url,
|
| + net::URLFetcherDelegate* delegate,
|
| + const std::string& response_data,
|
| + net::HttpStatusCode response_code) {
|
| + task_runner->PostTask(FROM_HERE, callback);
|
| + return make_scoped_ptr(new net::FakeURLFetcher(
|
| + url, delegate, response_data, response_code));
|
| +}
|
| +
|
| } // namespace
|
|
|
| class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest {
|
| @@ -253,8 +286,12 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest {
|
|
|
| ASSERT_TRUE(extension_cache_root_dir_.CreateUniqueTempDir());
|
| extension_cache_root_dir_override_.reset(new base::ScopedPathOverride(
|
| - chromeos::DIR_DEVICE_LOCAL_ACCOUNT_CACHE,
|
| + chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
|
| extension_cache_root_dir_.path()));
|
| + ASSERT_TRUE(external_data_cache_dir_.CreateUniqueTempDir());
|
| + external_data_cache_dir_override_.reset(new base::ScopedPathOverride(
|
| + chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA,
|
| + external_data_cache_dir_.path()));
|
|
|
| DevicePolicyCrosBrowserTest::SetUp();
|
| }
|
| @@ -361,7 +398,9 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest {
|
| const std::string user_id_2_;
|
|
|
| base::ScopedTempDir extension_cache_root_dir_;
|
| + base::ScopedTempDir external_data_cache_dir_;
|
| scoped_ptr<base::ScopedPathOverride> extension_cache_root_dir_override_;
|
| + scoped_ptr<base::ScopedPathOverride> external_data_cache_dir_override_;
|
|
|
| UserPolicyBuilder device_local_account_policy_;
|
| LocalPolicyTestServer test_server_;
|
| @@ -769,6 +808,125 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsCached) {
|
| EXPECT_FALSE(PathExists(cached_extension));
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) {
|
| + CloudExternalDataManagerBase::SetMaxExternalDataSizeForTesting(1000);
|
| +
|
| + UploadAndInstallDeviceLocalAccountPolicy();
|
| + AddPublicSessionToDevicePolicy(kAccountId1);
|
| +
|
| + // This observes the display name becoming available as this indicates
|
| + // device-local account policy is fully loaded.
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
|
| +
|
| + scoped_ptr<base::DictionaryValue> metadata =
|
| + test::ConstructExternalDataReference(kExternalDataURL, kExternalData);
|
| + DeviceLocalAccountPolicyBroker* broker =
|
| + g_browser_process->browser_policy_connector()->
|
| + GetDeviceLocalAccountPolicyService()->GetBrokerForUser(user_id_1_);
|
| + ASSERT_TRUE(broker);
|
| +
|
| + // Start serving external data at |kExternalDataURL|.
|
| + scoped_ptr<base::RunLoop> run_loop(new base::RunLoop);
|
| + scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory(
|
| + new net::FakeURLFetcherFactory(
|
| + NULL,
|
| + base::Bind(&RunCallbackAndReturnFakeURLFetcher,
|
| + base::MessageLoopProxy::current(),
|
| + run_loop->QuitClosure())));
|
| + fetcher_factory->SetFakeResponse(GURL(kExternalDataURL),
|
| + kExternalData,
|
| + net::HTTP_OK);
|
| +
|
| + // TODO(bartfab): The test injects an ExternalDataFetcher for an arbitrary
|
| + // policy. This is only done because there are no policies that reference
|
| + // external data yet. Once the first such policy is added, switch the test to
|
| + // that policy and stop injecting a manually instantiated ExternalDataFetcher.
|
| + test::SetExternalDataReference(broker->core(),
|
| + key::kHomepageLocation,
|
| + make_scoped_ptr(metadata->DeepCopy()));
|
| +
|
| + // The external data should be fetched and cached automatically. Wait for this
|
| + // fetch.
|
| + run_loop->Run();
|
| +
|
| + // Stop serving external data at |kExternalDataURL|.
|
| + fetcher_factory.reset();
|
| +
|
| + const PolicyMap::Entry* policy_entry =
|
| + broker->core()->store()->policy_map().Get(key::kHomepageLocation);
|
| + ASSERT_TRUE(policy_entry);
|
| + ASSERT_TRUE(policy_entry->external_data_fetcher);
|
| +
|
| + // Retrieve the external data. Although the data is no longer being served at
|
| + // |kExternalDataURL|, the retrieval should succeed because the data has been
|
| + // cached.
|
| + run_loop.reset(new base::RunLoop);
|
| + scoped_ptr<std::string> fetched_external_data;
|
| + policy_entry->external_data_fetcher->Fetch(base::Bind(
|
| + &test::ExternalDataFetchCallback,
|
| + &fetched_external_data,
|
| + run_loop->QuitClosure()));
|
| + run_loop->Run();
|
| +
|
| + ASSERT_TRUE(fetched_external_data);
|
| + EXPECT_EQ(kExternalData, *fetched_external_data);
|
| +
|
| + // Wait for the login UI to be ready.
|
| + chromeos::LoginDisplayHostImpl* host =
|
| + reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
|
| + chromeos::LoginDisplayHostImpl::default_host());
|
| + ASSERT_TRUE(host);
|
| + chromeos::OobeUI* oobe_ui = host->GetOobeUI();
|
| + ASSERT_TRUE(oobe_ui);
|
| + run_loop.reset(new base::RunLoop);
|
| + const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop->QuitClosure());
|
| + if (!oobe_ui_ready)
|
| + run_loop->Run();
|
| +
|
| + // Ensure that the browser stays alive, even though no windows are opened
|
| + // during session start.
|
| + chrome::StartKeepAlive();
|
| +
|
| + // Start login into the device-local account.
|
| + host->StartSignInScreen();
|
| + chromeos::ExistingUserController* controller =
|
| + chromeos::ExistingUserController::current_controller();
|
| + ASSERT_TRUE(controller);
|
| + controller->LoginAsPublicAccount(user_id_1_);
|
| +
|
| + // Wait for the session to start.
|
| + content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED,
|
| + base::Bind(IsSessionStarted)).Wait();
|
| +
|
| + // Verify that the external data reference has propagated to the device-local
|
| + // account's ProfilePolicyConnector.
|
| + ProfilePolicyConnector* policy_connector =
|
| + ProfilePolicyConnectorFactory::GetForProfile(
|
| + ProfileManager::GetDefaultProfile());
|
| + ASSERT_TRUE(policy_connector);
|
| + const PolicyMap& policies = policy_connector->policy_service()->GetPolicies(
|
| + PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
|
| + policy_entry = policies.Get(key::kHomepageLocation);
|
| + ASSERT_TRUE(policy_entry);
|
| + EXPECT_TRUE(base::Value::Equals(metadata.get(), policy_entry->value));
|
| + ASSERT_TRUE(policy_entry->external_data_fetcher);
|
| +
|
| + // Retrieve the external data via the ProfilePolicyConnector. The retrieval
|
| + // should succeed because the data has been cached.
|
| + run_loop.reset(new base::RunLoop);
|
| + fetched_external_data.reset();
|
| + policy_entry->external_data_fetcher->Fetch(base::Bind(
|
| + &test::ExternalDataFetchCallback,
|
| + &fetched_external_data,
|
| + run_loop->QuitClosure()));
|
| + run_loop->Run();
|
| +
|
| + ASSERT_TRUE(fetched_external_data);
|
| + EXPECT_EQ(kExternalData, *fetched_external_data);
|
| +}
|
| +
|
| class TermsOfServiceTest : public DeviceLocalAccountTest,
|
| public testing::WithParamInterface<bool> {
|
| };
|
|
|