Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1211)

Unified Diff: chrome/browser/chromeos/policy/device_quirks_policy_browsertest.cc

Issue 1775023002: Enterprise policy to prevent queries to the Quirks Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove default_for_enterprise_users Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_quirks_policy_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_quirks_policy_browsertest.cc b/chrome/browser/chromeos/policy/device_quirks_policy_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea364f29f66edadeb7175fd3476dee7fbba8d2bd
--- /dev/null
+++ b/chrome/browser/chromeos/policy/device_quirks_policy_browsertest.cc
@@ -0,0 +1,147 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
+#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
+#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "components/quirks/quirks_manager.h"
+#include "components/quirks/switches.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+const int64_t kProductId = 0x0000aaaa;
+const char kFakeIccData[] = {0x00, 0x00, 0x08, 0x90, 0x20, 0x20,
+ 0x20, 0x20, 0x02, 0x10, 0x00, 0x00};
+
+class DeviceQuirksPolicyTest : public policy::DevicePolicyCrosBrowserTest {
+ public:
+ DeviceQuirksPolicyTest() {}
+
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitch(quirks::switches::kEnableQuirksClient);
+ }
+
+ void SetUpInProcessBrowserTestFixture() override {
+ InstallOwnerKey();
+ DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
+ }
+
+ void SetUpOnMainThread() override {
+ // NOTE: QuirksManager::Initialize() isn't necessary here, since it'll be
+ // called in ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun().
+
+ // Create display_profiles subdirectory under temp profile directory.
+ base::FilePath path = quirks::QuirksManager::Get()
+ ->delegate()
+ ->GetDownloadDisplayProfileDirectory();
+ base::File::Error error = base::File::FILE_OK;
+ bool created = base::CreateDirectoryAndGetError(path, &error);
+ ASSERT_TRUE(created) << error;
+
+ // Create fake icc file.
+ path = path.Append(quirks::IdToFileName(kProductId));
+ int bytes_written =
+ base::WriteFile(path, kFakeIccData, sizeof(kFakeIccData));
+ ASSERT_EQ(sizeof(kFakeIccData), static_cast<size_t>(bytes_written));
+ }
+
+ protected:
+ void RefreshPolicyAndWaitDeviceSettingsUpdated() {
+ scoped_ptr<CrosSettings::ObserverSubscription> observer =
+ CrosSettings::Get()->AddSettingsObserver(
+ kDeviceQuirksDownloadEnabled,
+ base::MessageLoop::current()->QuitWhenIdleClosure());
+
+ RefreshDevicePolicy();
+ base::MessageLoop::current()->Run();
+ }
+
+ // Query QuirksManager for icc file, then run msg loop to wait for callback.
+ // This won't actually run a Quirks client: if Quirks is enabled, it will
+ // return the icc file in our fake downloads directory; if disabled, it will
+ // return before looking there.
+ bool TestQuirksEnabled() {
+ base::RunLoop run_loop;
+ end_message_loop_ = run_loop.QuitClosure();
+ icc_path_.clear();
+
+ quirks::QuirksManager::Get()->RequestIccProfilePath(
+ kProductId, base::Bind(&DeviceQuirksPolicyTest::OnQuirksClientFinished,
+ base::Unretained(this)));
+
+ run_loop.Run();
+
+ // Quirks only returns our fake file if it's enabled.
+ return !icc_path_.empty();
+ }
+
+ // Callback from RequestIccProfilePath().
+ void OnQuirksClientFinished(const base::FilePath& path, bool downloaded) {
+ ASSERT_FALSE(downloaded);
+ icc_path_ = path;
+ ASSERT_TRUE(!end_message_loop_.is_null());
+ end_message_loop_.Run();
+ }
+
+ base::Closure end_message_loop_; // Callback to terminate message loop.
+ base::FilePath icc_path_; // Path to icc file if found or downloaded.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DeviceQuirksPolicyTest);
+};
+
+IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckUnset) {
+ bool quirks_download_enabled;
+ EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
+ &quirks_download_enabled));
+
+ // No policy set, default is enabled, so Quirks should find the fake icc file.
+ EXPECT_TRUE(TestQuirksEnabled());
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckTrue) {
+ bool quirks_download_enabled;
+ EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
+ &quirks_download_enabled));
+
+ enterprise_management::ChromeDeviceSettingsProto& proto(
+ device_policy()->payload());
+ proto.mutable_quirks_download_enabled()->set_quirks_download_enabled(true);
+ RefreshPolicyAndWaitDeviceSettingsUpdated();
+
+ quirks_download_enabled = false;
+ EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
+ &quirks_download_enabled));
+ EXPECT_TRUE(quirks_download_enabled);
+
+ // With policy enabled, Quirks should find the fake icc file.
+ EXPECT_TRUE(TestQuirksEnabled());
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckFalse) {
+ bool quirks_download_enabled;
+ EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
+ &quirks_download_enabled));
+
+ enterprise_management::ChromeDeviceSettingsProto& proto(
+ device_policy()->payload());
+ proto.mutable_quirks_download_enabled()->set_quirks_download_enabled(false);
+ RefreshPolicyAndWaitDeviceSettingsUpdated();
+
+ quirks_download_enabled = true;
+ EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
+ &quirks_download_enabled));
+ EXPECT_FALSE(quirks_download_enabled);
+
+ // With policy disabled, Quirks should abort and not find the fake icc file.
+ EXPECT_FALSE(TestQuirksEnabled());
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698