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

Side by Side Diff: chrome/browser/extensions/api/settings_private/settings_private_apitest.cc

Issue 2861393003: MD Settings: Always provide recommended meta-data (Closed)
Patch Set: Use non cros specific pref for tests Created 3 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <memory> 5 #include <memory>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h" 11 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h"
12 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h" 12 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h"
13 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "chrome/common/extensions/api/settings_private.h" 14 #include "chrome/common/extensions/api/settings_private.h"
15 #include "chrome/common/pref_names.h"
15 #include "components/keyed_service/core/keyed_service.h" 16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/policy/core/browser/browser_policy_connector.h"
18 #include "components/policy/core/common/mock_configuration_policy_provider.h"
19 #include "components/policy/core/common/policy_map.h"
20 #include "components/policy/policy_constants.h"
16 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
17 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
18 #include "extensions/common/switches.h" 23 #include "extensions/common/switches.h"
24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h"
19 26
20 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
21 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
22 #endif 29 #endif
23 30
31 using testing::Mock;
32 using testing::Return;
33 using testing::_;
34
24 namespace extensions { 35 namespace extensions {
25 36
26 namespace { 37 namespace {
27 38
28 class SettingsPrivateApiTest : public ExtensionApiTest { 39 class SettingsPrivateApiTest : public ExtensionApiTest {
29 public: 40 public:
30 SettingsPrivateApiTest() {} 41 SettingsPrivateApiTest() {}
31 ~SettingsPrivateApiTest() override {} 42 ~SettingsPrivateApiTest() override {}
32 43
33 void SetUpCommandLine(base::CommandLine* command_line) override { 44 void SetUpCommandLine(base::CommandLine* command_line) override {
34 ExtensionApiTest::SetUpCommandLine(command_line); 45 ExtensionApiTest::SetUpCommandLine(command_line);
35 #if defined(OS_CHROMEOS) 46 #if defined(OS_CHROMEOS)
36 command_line->AppendSwitch(chromeos::switches::kStubCrosSettings); 47 command_line->AppendSwitch(chromeos::switches::kStubCrosSettings);
37 #endif 48 #endif
38 } 49 }
39 50
51 void SetUpInProcessBrowserTestFixture() override {
52 EXPECT_CALL(provider_, IsInitializationComplete(_))
53 .WillRepeatedly(Return(true));
54 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
55 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
56 }
57
40 protected: 58 protected:
41 bool RunSettingsSubtest(const std::string& subtest) { 59 bool RunSettingsSubtest(const std::string& subtest) {
42 return RunExtensionSubtest("settings_private", 60 return RunExtensionSubtest("settings_private", "main.html?" + subtest,
43 "main.html?" + subtest,
44 kFlagLoadAsComponent); 61 kFlagLoadAsComponent);
45 } 62 }
46 63
64 void SetPrefPolicy(const std::string& key, policy::PolicyLevel level) {
65 policy::PolicyMap policies;
66 policies.Set(key, level, policy::POLICY_SCOPE_USER,
67 policy::POLICY_SOURCE_CLOUD,
68 base::WrapUnique(new base::Value(true)), nullptr);
69 provider_.UpdateChromePolicy(policies);
70 DCHECK(base::MessageLoop::current());
71 base::RunLoop loop;
72 loop.RunUntilIdle();
73 }
74
47 private: 75 private:
76 policy::MockConfigurationPolicyProvider provider_;
77
48 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateApiTest); 78 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateApiTest);
49 }; 79 };
50 80
51 81
52 } // namespace 82 } // namespace
53 83
54 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, SetPref) { 84 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, SetPref) {
55 EXPECT_TRUE(RunSettingsSubtest("setPref")) << message_; 85 EXPECT_TRUE(RunSettingsSubtest("setPref")) << message_;
56 } 86 }
57 87
58 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref) { 88 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref) {
59 EXPECT_TRUE(RunSettingsSubtest("getPref")) << message_; 89 EXPECT_TRUE(RunSettingsSubtest("getPref")) << message_;
60 } 90 }
61 91
92 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetEnforcedPref) {
93 SetPrefPolicy(policy::key::kHomepageIsNewTabPage,
94 policy::POLICY_LEVEL_MANDATORY);
95 EXPECT_TRUE(RunSettingsSubtest("getEnforcedPref")) << message_;
96 }
97
98 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetRecommendedPref) {
99 SetPrefPolicy(policy::key::kHomepageIsNewTabPage,
100 policy::POLICY_LEVEL_RECOMMENDED);
101 EXPECT_TRUE(RunSettingsSubtest("getRecommendedPref")) << message_;
102 }
103
62 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetAllPrefs) { 104 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetAllPrefs) {
63 EXPECT_TRUE(RunSettingsSubtest("getAllPrefs")) << message_; 105 EXPECT_TRUE(RunSettingsSubtest("getAllPrefs")) << message_;
64 } 106 }
65 107
66 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged) { 108 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged) {
67 EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged")) << message_; 109 EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged")) << message_;
68 } 110 }
69 111
70 #if defined(OS_CHROMEOS) 112 #if defined(OS_CHROMEOS)
71 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref_CrOSSetting) { 113 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref_CrOSSetting) {
72 EXPECT_TRUE(RunSettingsSubtest("getPref_CrOSSetting")) << message_; 114 EXPECT_TRUE(RunSettingsSubtest("getPref_CrOSSetting")) << message_;
73 } 115 }
74 116
75 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, SetPref_CrOSSetting) { 117 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, SetPref_CrOSSetting) {
76 EXPECT_TRUE(RunSettingsSubtest("setPref_CrOSSetting")) << message_; 118 EXPECT_TRUE(RunSettingsSubtest("setPref_CrOSSetting")) << message_;
77 } 119 }
78 120
79 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged_CrOSSetting) { 121 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged_CrOSSetting) {
80 EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged_CrOSSetting")) << message_; 122 EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged_CrOSSetting")) << message_;
81 } 123 }
82 #endif 124 #endif
83 125
84 } // namespace extensions 126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698