OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | |
8 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/chrome_switches.h" | |
17 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
20 #include "components/policy/core/browser/browser_policy_connector.h" | 22 #include "components/policy/core/browser/browser_policy_connector.h" |
21 #include "components/policy/core/common/external_data_fetcher.h" | 23 #include "components/policy/core/common/external_data_fetcher.h" |
22 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 24 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
23 #include "components/policy/core/common/policy_map.h" | 25 #include "components/policy/core/common/policy_map.h" |
24 #include "components/policy/core/common/policy_types.h" | 26 #include "components/policy/core/common/policy_types.h" |
25 #include "components/policy/core/common/schema.h" | 27 #include "components/policy/core/common/schema.h" |
26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 return expected_policy; | 88 return expected_policy; |
87 } | 89 } |
88 | 90 |
89 } // namespace | 91 } // namespace |
90 | 92 |
91 class PolicyUITest : public InProcessBrowserTest { | 93 class PolicyUITest : public InProcessBrowserTest { |
92 public: | 94 public: |
93 PolicyUITest(); | 95 PolicyUITest(); |
94 ~PolicyUITest() override; | 96 ~PolicyUITest() override; |
95 | 97 |
98 void SetUpCommandLine(base::CommandLine* command_line) override; | |
bartfab (slow)
2015/09/23 12:57:48
Nit: // InProcessBrowserTest:
fhorschig
2015/09/23 16:18:26
Done.
| |
99 | |
96 protected: | 100 protected: |
97 // InProcessBrowserTest implementation. | 101 // InProcessBrowserTest implementation. |
98 void SetUpInProcessBrowserTestFixture() override; | 102 void SetUpInProcessBrowserTestFixture() override; |
99 | 103 |
100 void UpdateProviderPolicy(const policy::PolicyMap& policy); | 104 void UpdateProviderPolicy(const policy::PolicyMap& policy); |
101 | 105 |
102 void VerifyPolicies(const std::vector<std::vector<std::string> >& expected); | 106 void VerifyPolicies(const std::vector<std::vector<std::string> >& expected); |
103 | 107 |
104 protected: | 108 protected: |
105 policy::MockConfigurationPolicyProvider provider_; | 109 policy::MockConfigurationPolicyProvider provider_; |
106 | 110 |
107 private: | 111 private: |
108 DISALLOW_COPY_AND_ASSIGN(PolicyUITest); | 112 DISALLOW_COPY_AND_ASSIGN(PolicyUITest); |
109 }; | 113 }; |
110 | 114 |
111 PolicyUITest::PolicyUITest() { | 115 PolicyUITest::PolicyUITest() { |
112 } | 116 } |
113 | 117 |
114 PolicyUITest::~PolicyUITest() { | 118 PolicyUITest::~PolicyUITest() { |
115 } | 119 } |
116 | 120 |
121 void PolicyUITest::SetUpCommandLine(base::CommandLine* command_line) { | |
122 InProcessBrowserTest::SetUpCommandLine(command_line); | |
123 command_line->AppendSwitch(switches::kEnableMaterialDesignPolicyPage); | |
124 } | |
125 | |
117 void PolicyUITest::SetUpInProcessBrowserTestFixture() { | 126 void PolicyUITest::SetUpInProcessBrowserTestFixture() { |
118 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 127 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
119 .WillRepeatedly(Return(true)); | 128 .WillRepeatedly(Return(true)); |
120 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 129 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
121 } | 130 } |
122 | 131 |
123 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) { | 132 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) { |
124 provider_.UpdateChromePolicy(policy); | 133 provider_.UpdateChromePolicy(policy); |
125 base::RunLoop loop; | 134 base::RunLoop loop; |
126 loop.RunUntilIdle(); | 135 loop.RunUntilIdle(); |
127 } | 136 } |
128 | 137 |
129 void PolicyUITest::VerifyPolicies( | 138 void PolicyUITest::VerifyPolicies( |
130 const std::vector<std::vector<std::string> >& expected_policies) { | 139 const std::vector<std::vector<std::string> >& expected_policies) { |
131 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy")); | 140 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy-internal")); |
bartfab (slow)
2015/09/23 12:57:48
Since the MD page is not on by default yet, we nee
fhorschig
2015/09/23 16:18:26
Done.
| |
132 | 141 |
133 // Retrieve the text contents of the policy table cells for all policies. | 142 // Retrieve the text contents of the policy table cells for all policies. |
134 const std::string javascript = | 143 const std::string javascript = |
135 "var entries = document.querySelectorAll(" | 144 "var entries = document.querySelectorAll(" |
136 " 'section.policy-table-section > * > tbody');" | 145 " 'section.policy-table-section > * > tbody');" |
137 "var policies = [];" | 146 "var policies = [];" |
138 "for (var i = 0; i < entries.length; ++i) {" | 147 "for (var i = 0; i < entries.length; ++i) {" |
139 " var items = entries[i].querySelectorAll('tr > td');" | 148 " var items = entries[i].querySelectorAll('tr > td');" |
140 " var values = [];" | 149 " var values = [];" |
141 " for (var j = 0; j < items.length; ++j) {" | 150 " for (var j = 0; j < items.length; ++j) {" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 PopulateExpectedPolicy( | 342 PopulateExpectedPolicy( |
334 it.key(), std::string(), std::string(), nullptr, false)); | 343 it.key(), std::string(), std::string(), nullptr, false)); |
335 } | 344 } |
336 // Add newly added policy to expected policy list. | 345 // Add newly added policy to expected policy list. |
337 expected_policies.push_back(PopulateExpectedPolicy( | 346 expected_policies.push_back(PopulateExpectedPolicy( |
338 newly_added_policy_name, std::string(), std::string(), nullptr, false)); | 347 newly_added_policy_name, std::string(), std::string(), nullptr, false)); |
339 | 348 |
340 // Verify if policy UI includes policy that extension have. | 349 // Verify if policy UI includes policy that extension have. |
341 VerifyPolicies(expected_policies); | 350 VerifyPolicies(expected_policies); |
342 } | 351 } |
OLD | NEW |