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

Side by Side 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: Fix display unit test 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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
5 #include "base/command_line.h"
6 #include "base/files/file_util.h"
7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
10 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
11 #include "chrome/browser/chromeos/settings/cros_settings.h"
12 #include "components/quirks/quirks_manager.h"
13 #include "components/quirks/switches.h"
14 #include "content/public/test/test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace chromeos {
18
19 const int64_t kProductId = 0x0000aaaa;
20 const char kFakeIccData[] = {0x00, 0x00, 0x08, 0x90, 0x20, 0x20,
21 0x20, 0x20, 0x02, 0x10, 0x00, 0x00};
22
23 class DeviceQuirksPolicyTest : public policy::DevicePolicyCrosBrowserTest {
24 public:
25 DeviceQuirksPolicyTest() {}
26
27 void SetUpCommandLine(base::CommandLine* command_line) override {
28 command_line->AppendSwitch(quirks::switches::kEnableQuirksClient);
29 }
30
31 void SetUpInProcessBrowserTestFixture() override {
32 InstallOwnerKey();
33 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
34 }
35
36 void SetUpOnMainThread() override {
37 // NOTE: QuirksManager::Initialize() isn't necessary here, since it'll be
38 // called in ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun().
39
40 // Create display_profiles subdirectory under temp profile directory.
41 base::FilePath path = quirks::QuirksManager::Get()
42 ->delegate()
43 ->GetDownloadDisplayProfileDirectory();
44 base::File::Error error = base::File::FILE_OK;
45 bool created = base::CreateDirectoryAndGetError(path, &error);
46 ASSERT_TRUE(created) << error;
47
48 // Create fake icc file.
49 path = path.Append(quirks::IdToFileName(kProductId));
50 int bytes_written =
51 base::WriteFile(path, kFakeIccData, sizeof(kFakeIccData));
52 ASSERT_EQ(sizeof(kFakeIccData), static_cast<size_t>(bytes_written));
53 }
54
55 protected:
56 void RefreshPolicyAndWaitDeviceSettingsUpdated() {
57 scoped_ptr<CrosSettings::ObserverSubscription> observer =
58 CrosSettings::Get()->AddSettingsObserver(
59 kDeviceQuirksDownloadEnabled,
60 base::MessageLoop::current()->QuitWhenIdleClosure());
61
62 RefreshDevicePolicy();
63 base::MessageLoop::current()->Run();
64 }
65
66 // Query QuirksManager for icc file, then run msg loop to wait for callback.
67 // This won't actually run a Quirks client: if Quirks is enabled, it will
68 // return the icc file in our fake downloads directory; if disabled, it will
69 // return before looking there.
70 bool TestQuirksEnabled() {
71 base::RunLoop run_loop;
72 end_message_loop_ = run_loop.QuitClosure();
73 icc_path_.clear();
74
75 quirks::QuirksManager::Get()->RequestIccProfilePath(
76 kProductId, base::Bind(&DeviceQuirksPolicyTest::OnQuirksClientFinished,
77 base::Unretained(this)));
78
79 run_loop.Run();
80
81 // Quirks only returns our fake file if it's enabled.
82 return !icc_path_.empty();
83 }
84
85 // Callback from RequestIccProfilePath().
86 void OnQuirksClientFinished(const base::FilePath& path, bool downloaded) {
87 ASSERT_FALSE(downloaded);
88 icc_path_ = path;
89 ASSERT_TRUE(!end_message_loop_.is_null());
90 end_message_loop_.Run();
91 }
92
93 base::Closure end_message_loop_; // Callback to terminate message loop.
94 base::FilePath icc_path_; // Path to icc file if found or downloaded.
95
96 private:
97 DISALLOW_COPY_AND_ASSIGN(DeviceQuirksPolicyTest);
98 };
99
100 IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckUnset) {
101 bool quirks_download_enabled;
102 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
103 &quirks_download_enabled));
104
105 // No policy set, default is enabled, so Quirks should find the fake icc file.
106 EXPECT_TRUE(TestQuirksEnabled());
107 }
108
109 IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckTrue) {
110 bool quirks_download_enabled;
111 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
112 &quirks_download_enabled));
113
114 enterprise_management::ChromeDeviceSettingsProto& proto(
115 device_policy()->payload());
116 proto.mutable_quirks_download_enabled()->set_quirks_download_enabled(true);
117 RefreshPolicyAndWaitDeviceSettingsUpdated();
118
119 quirks_download_enabled = false;
120 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
121 &quirks_download_enabled));
122 EXPECT_TRUE(quirks_download_enabled);
123
124 // With policy enabled, Quirks should find the fake icc file.
125 EXPECT_TRUE(TestQuirksEnabled());
126 }
127
128 IN_PROC_BROWSER_TEST_F(DeviceQuirksPolicyTest, CheckFalse) {
129 bool quirks_download_enabled;
130 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
131 &quirks_download_enabled));
132
133 enterprise_management::ChromeDeviceSettingsProto& proto(
134 device_policy()->payload());
135 proto.mutable_quirks_download_enabled()->set_quirks_download_enabled(false);
136 RefreshPolicyAndWaitDeviceSettingsUpdated();
137
138 quirks_download_enabled = true;
139 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled,
140 &quirks_download_enabled));
141 EXPECT_FALSE(quirks_download_enabled);
142
143 // With policy disabled, Quirks should abort and not find the fake icc file.
144 EXPECT_FALSE(TestQuirksEnabled());
145 }
146
147 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698