OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/run_loop.h" |
8 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 8 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
9 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 9 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
10 #include "chrome/browser/chromeos/settings/cros_settings.h" | 10 #include "chrome/browser/chromeos/settings/cros_settings.h" |
11 #include "components/quirks/quirks_manager.h" | 11 #include "components/quirks/quirks_manager.h" |
12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 const int64_t kProductId = 0x0000aaaa; | 17 const int64_t kProductId = 0x0000aaaa; |
(...skipping 23 matching lines...) Expand all Loading... |
41 | 41 |
42 // Create fake icc file. | 42 // Create fake icc file. |
43 path = path.Append(quirks::IdToFileName(kProductId)); | 43 path = path.Append(quirks::IdToFileName(kProductId)); |
44 int bytes_written = | 44 int bytes_written = |
45 base::WriteFile(path, kFakeIccData, sizeof(kFakeIccData)); | 45 base::WriteFile(path, kFakeIccData, sizeof(kFakeIccData)); |
46 ASSERT_EQ(sizeof(kFakeIccData), static_cast<size_t>(bytes_written)); | 46 ASSERT_EQ(sizeof(kFakeIccData), static_cast<size_t>(bytes_written)); |
47 } | 47 } |
48 | 48 |
49 protected: | 49 protected: |
50 void RefreshPolicyAndWaitDeviceSettingsUpdated() { | 50 void RefreshPolicyAndWaitDeviceSettingsUpdated() { |
| 51 base::RunLoop run_loop; |
51 std::unique_ptr<CrosSettings::ObserverSubscription> observer = | 52 std::unique_ptr<CrosSettings::ObserverSubscription> observer = |
52 CrosSettings::Get()->AddSettingsObserver( | 53 CrosSettings::Get()->AddSettingsObserver( |
53 kDeviceQuirksDownloadEnabled, | 54 kDeviceQuirksDownloadEnabled, run_loop.QuitWhenIdleClosure()); |
54 base::MessageLoop::current()->QuitWhenIdleClosure()); | |
55 | 55 |
56 RefreshDevicePolicy(); | 56 RefreshDevicePolicy(); |
57 base::MessageLoop::current()->Run(); | 57 run_loop.Run(); |
58 } | 58 } |
59 | 59 |
60 // Query QuirksManager for icc file, then run msg loop to wait for callback. | 60 // Query QuirksManager for icc file, then run msg loop to wait for callback. |
61 // This won't actually run a Quirks client: if Quirks is enabled, it will | 61 // This won't actually run a Quirks client: if Quirks is enabled, it will |
62 // return the icc file in our fake downloads directory; if disabled, it will | 62 // return the icc file in our fake downloads directory; if disabled, it will |
63 // return before looking there. | 63 // return before looking there. |
64 bool TestQuirksEnabled() { | 64 bool TestQuirksEnabled() { |
65 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
66 end_message_loop_ = run_loop.QuitClosure(); | 66 end_message_loop_ = run_loop.QuitClosure(); |
67 icc_path_.clear(); | 67 icc_path_.clear(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 quirks_download_enabled = true; | 132 quirks_download_enabled = true; |
133 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled, | 133 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kDeviceQuirksDownloadEnabled, |
134 &quirks_download_enabled)); | 134 &quirks_download_enabled)); |
135 EXPECT_FALSE(quirks_download_enabled); | 135 EXPECT_FALSE(quirks_download_enabled); |
136 | 136 |
137 // With policy disabled, Quirks should abort and not find the fake icc file. | 137 // With policy disabled, Quirks should abort and not find the fake icc file. |
138 EXPECT_FALSE(TestQuirksEnabled()); | 138 EXPECT_FALSE(TestQuirksEnabled()); |
139 } | 139 } |
140 | 140 |
141 } // namespace chromeos | 141 } // namespace chromeos |
OLD | NEW |