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

Side by Side Diff: chrome/browser/policy/policy_prefs_browsertest.cc

Issue 11728003: Change ExecuteJavaScript* helper functions in browser_test_utils.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding files for gpu_tests and NaCl browser tests. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Contains the testing details for a single pref affected by a policy. This is 74 // Contains the testing details for a single pref affected by a policy. This is
75 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json. 75 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json.
76 class PrefMapping { 76 class PrefMapping {
77 public: 77 public:
78 PrefMapping(const std::string& pref, 78 PrefMapping(const std::string& pref,
79 bool is_local_state, 79 bool is_local_state,
80 const std::string& indicator_test_setup_js, 80 const std::string& indicator_test_setup_js,
81 const std::string& indicator_selector) 81 const std::string& indicator_selector)
82 : pref_(pref), 82 : pref_(pref),
83 is_local_state_(is_local_state), 83 is_local_state_(is_local_state),
84 indicator_test_setup_js_(indicator_test_setup_js),
84 indicator_selector_(indicator_selector) { 85 indicator_selector_(indicator_selector) {
85 indicator_test_setup_js_ = ASCIIToWide(indicator_test_setup_js);
86 } 86 }
87 ~PrefMapping() {} 87 ~PrefMapping() {}
88 88
89 const std::string& pref() const { return pref_; } 89 const std::string& pref() const { return pref_; }
90 90
91 bool is_local_state() const { return is_local_state_; } 91 bool is_local_state() const { return is_local_state_; }
92 92
93 const std::wstring& indicator_test_setup_js() const { 93 const std::string& indicator_test_setup_js() const {
94 return indicator_test_setup_js_; 94 return indicator_test_setup_js_;
95 } 95 }
96 96
97 const std::string& indicator_selector() const { 97 const std::string& indicator_selector() const {
98 return indicator_selector_; 98 return indicator_selector_;
99 } 99 }
100 100
101 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { 101 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const {
102 return indicator_test_cases_; 102 return indicator_test_cases_;
103 } 103 }
104 void AddIndicatorTestCase(IndicatorTestCase* test_case) { 104 void AddIndicatorTestCase(IndicatorTestCase* test_case) {
105 indicator_test_cases_.push_back(test_case); 105 indicator_test_cases_.push_back(test_case);
106 } 106 }
107 107
108 private: 108 private:
109 std::string pref_; 109 std::string pref_;
110 bool is_local_state_; 110 bool is_local_state_;
111 std::wstring indicator_test_setup_js_; 111 std::string indicator_test_setup_js_;
112 std::string indicator_selector_; 112 std::string indicator_selector_;
113 ScopedVector<IndicatorTestCase> indicator_test_cases_; 113 ScopedVector<IndicatorTestCase> indicator_test_cases_;
114 114
115 DISALLOW_COPY_AND_ASSIGN(PrefMapping); 115 DISALLOW_COPY_AND_ASSIGN(PrefMapping);
116 }; 116 };
117 117
118 // Contains the testing details for a single policy. This is part of the data 118 // Contains the testing details for a single policy. This is part of the data
119 // loaded from chrome/test/data/policy/policy_test_cases.json. 119 // loaded from chrome/test/data/policy/policy_test_cases.json.
120 class PolicyTestCase { 120 class PolicyTestCase {
121 public: 121 public:
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 PolicyTestCaseMap* policy_test_cases_; 304 PolicyTestCaseMap* policy_test_cases_;
305 305
306 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases); 306 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases);
307 }; 307 };
308 308
309 void VerifyControlledSettingIndicators(Browser* browser, 309 void VerifyControlledSettingIndicators(Browser* browser,
310 const std::string& selector, 310 const std::string& selector,
311 const std::string& value, 311 const std::string& value,
312 const std::string& controlled_by, 312 const std::string& controlled_by,
313 bool readonly) { 313 bool readonly) {
314 std::wstringstream javascript; 314 std::stringstream javascript;
315 javascript << "var nodes = document.querySelectorAll(" 315 javascript << "var nodes = document.querySelectorAll("
316 << " 'span.controlled-setting-indicator" 316 << " 'span.controlled-setting-indicator"
317 << selector.c_str() << "');" 317 << selector.c_str() << "');"
318 << "var indicators = [];" 318 << "var indicators = [];"
319 << "for (var i = 0; i < nodes.length; i++) {" 319 << "for (var i = 0; i < nodes.length; i++) {"
320 << " var node = nodes[i];" 320 << " var node = nodes[i];"
321 << " var indicator = {};" 321 << " var indicator = {};"
322 << " indicator.value = node.value || '';" 322 << " indicator.value = node.value || '';"
323 << " indicator.controlledBy = node.controlledBy || '';" 323 << " indicator.controlledBy = node.controlledBy || '';"
324 << " indicator.readOnly = node.readOnly || false;" 324 << " indicator.readOnly = node.readOnly || false;"
325 << " indicator.visible =" 325 << " indicator.visible ="
326 << " window.getComputedStyle(node).display != 'none';" 326 << " window.getComputedStyle(node).display != 'none';"
327 << " indicators.push(indicator)" 327 << " indicators.push(indicator)"
328 << "}" 328 << "}"
329 << "domAutomationController.send(JSON.stringify(indicators));"; 329 << "domAutomationController.send(JSON.stringify(indicators));";
330 content::WebContents* contents = chrome::GetActiveWebContents(browser); 330 content::WebContents* contents = chrome::GetActiveWebContents(browser);
331 std::string json; 331 std::string json;
332 // Retrieve the state of all controlled setting indicators matching the 332 // Retrieve the state of all controlled setting indicators matching the
333 // |selector| as JSON. 333 // |selector| as JSON.
334 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 334 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
335 contents->GetRenderViewHost(), L"", javascript.str(), &json)); 335 contents->GetRenderViewHost(), "", javascript.str(), &json));
336 scoped_ptr<base::Value> value_ptr(base::JSONReader::Read(json)); 336 scoped_ptr<base::Value> value_ptr(base::JSONReader::Read(json));
337 const base::ListValue* indicators = NULL; 337 const base::ListValue* indicators = NULL;
338 ASSERT_TRUE(value_ptr.get()); 338 ASSERT_TRUE(value_ptr.get());
339 ASSERT_TRUE(value_ptr->GetAsList(&indicators)); 339 ASSERT_TRUE(value_ptr->GetAsList(&indicators));
340 // Verify that controlled setting indicators representing |value| are visible 340 // Verify that controlled setting indicators representing |value| are visible
341 // and have the correct state while those not representing |value| are 341 // and have the correct state while those not representing |value| are
342 // invisible. 342 // invisible.
343 if (!controlled_by.empty()) { 343 if (!controlled_by.empty()) {
344 EXPECT_GT(indicators->GetSize(), 0u) 344 EXPECT_GT(indicators->GetSize(), 0u)
345 << "Expected to find at least one controlled setting indicator."; 345 << "Expected to find at least one controlled setting indicator.";
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 pref_mapping != pref_mappings.end(); 485 pref_mapping != pref_mappings.end();
486 ++pref_mapping) { 486 ++pref_mapping) {
487 const ScopedVector<IndicatorTestCase>& 487 const ScopedVector<IndicatorTestCase>&
488 indicator_test_cases = (*pref_mapping)->indicator_test_cases(); 488 indicator_test_cases = (*pref_mapping)->indicator_test_cases();
489 if (indicator_test_cases.empty()) 489 if (indicator_test_cases.empty())
490 continue; 490 continue;
491 491
492 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); 492 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage));
493 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { 493 if (!(*pref_mapping)->indicator_test_setup_js().empty()) {
494 ASSERT_TRUE(content::ExecuteJavaScript( 494 ASSERT_TRUE(content::ExecuteJavaScript(
495 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", 495 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
496 "",
496 (*pref_mapping)->indicator_test_setup_js())); 497 (*pref_mapping)->indicator_test_setup_js()));
497 } 498 }
498 499
499 std::string indicator_selector = (*pref_mapping)->indicator_selector(); 500 std::string indicator_selector = (*pref_mapping)->indicator_selector();
500 if (indicator_selector.empty()) 501 if (indicator_selector.empty())
501 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; 502 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]";
502 for (ScopedVector<IndicatorTestCase>::const_iterator 503 for (ScopedVector<IndicatorTestCase>::const_iterator
503 indicator_test_case = indicator_test_cases.begin(); 504 indicator_test_case = indicator_test_cases.begin();
504 indicator_test_case != indicator_test_cases.end(); 505 indicator_test_case != indicator_test_cases.end();
505 ++indicator_test_case) { 506 ++indicator_test_case) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 555 }
555 } 556 }
556 557
557 INSTANTIATE_TEST_CASE_P( 558 INSTANTIATE_TEST_CASE_P(
558 PolicyPrefsTestInstance, 559 PolicyPrefsTestInstance,
559 PolicyPrefsTest, 560 PolicyPrefsTest,
560 testing::ValuesIn(GetChromePolicyDefinitionList()->begin, 561 testing::ValuesIn(GetChromePolicyDefinitionList()->begin,
561 GetChromePolicyDefinitionList()->end)); 562 GetChromePolicyDefinitionList()->end));
562 563
563 } // namespace policy 564 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | chrome/browser/popup_blocker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698