OLD | NEW |
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 <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 EXPECT_EQ(url, contents->GetURL()); | 163 EXPECT_EQ(url, contents->GetURL()); |
164 string16 title = UTF8ToUTF16(url.spec() + " is not available"); | 164 string16 title = UTF8ToUTF16(url.spec() + " is not available"); |
165 EXPECT_EQ(title, contents->GetTitle()); | 165 EXPECT_EQ(title, contents->GetTitle()); |
166 | 166 |
167 // Verify that the expected error page is being displayed. | 167 // Verify that the expected error page is being displayed. |
168 // (error 138 == NETWORK_ACCESS_DENIED) | 168 // (error 138 == NETWORK_ACCESS_DENIED) |
169 bool result = false; | 169 bool result = false; |
170 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 170 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
171 contents->GetRenderViewHost(), | 171 contents->GetRenderViewHost(), |
172 std::wstring(), | 172 std::wstring(), |
173 ASCIIToWide( | 173 L"var hasError = false;" |
174 "var hasError = false;" | 174 L"var error = document.getElementById('errorDetails');" |
175 "var error = document.getElementById('errorDetails');" | 175 L"if (error)" |
176 "if (error)" | 176 L" hasError = error.textContent.indexOf('Error 138') == 0;" |
177 " hasError = error.textContent.indexOf('Error 138') == 0;" | 177 L"domAutomationController.send(hasError);", |
178 "domAutomationController.send(hasError);"), | |
179 &result)); | 178 &result)); |
180 EXPECT_TRUE(result); | 179 EXPECT_TRUE(result); |
181 } | 180 } |
182 | 181 |
183 // Downloads a file named |file| and expects it to be saved to |dir|, which | 182 // Downloads a file named |file| and expects it to be saved to |dir|, which |
184 // must be empty. | 183 // must be empty. |
185 void DownloadAndVerifyFile( | 184 void DownloadAndVerifyFile( |
186 Browser* browser, const FilePath& dir, const FilePath& file) { | 185 Browser* browser, const FilePath& dir, const FilePath& file) { |
187 content::DownloadManager* download_manager = | 186 content::DownloadManager* download_manager = |
188 content::BrowserContext::GetDownloadManager(browser->profile()); | 187 content::BrowserContext::GetDownloadManager(browser->profile()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 std::wstring(), | 226 std::wstring(), |
228 L"var canvas = document.createElement('canvas');" | 227 L"var canvas = document.createElement('canvas');" |
229 L"var context = canvas.getContext('experimental-webgl');" | 228 L"var context = canvas.getContext('experimental-webgl');" |
230 L"domAutomationController.send(context != null);", | 229 L"domAutomationController.send(context != null);", |
231 &result)); | 230 &result)); |
232 return result; | 231 return result; |
233 } | 232 } |
234 | 233 |
235 bool IsJavascriptEnabled(content::WebContents* contents) { | 234 bool IsJavascriptEnabled(content::WebContents* contents) { |
236 content::RenderViewHost* rvh = contents->GetRenderViewHost(); | 235 content::RenderViewHost* rvh = contents->GetRenderViewHost(); |
237 base::Value* value = rvh->ExecuteJavascriptAndGetValue( | 236 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( |
238 string16(), | 237 string16(), |
239 ASCIIToUTF16("123")); | 238 ASCIIToUTF16("123"))); |
240 int result = 0; | 239 int result = 0; |
241 if (!value->GetAsInteger(&result)) | 240 if (!value->GetAsInteger(&result)) |
242 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); | 241 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); |
243 return result == 123; | 242 return result == 123; |
244 } | 243 } |
245 | 244 |
246 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, | 245 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, |
247 const std::vector<webkit::WebPluginInfo>& in) { | 246 const std::vector<webkit::WebPluginInfo>& in) { |
248 *out = in; | 247 *out = in; |
249 MessageLoop::current()->QuitWhenIdle(); | 248 MessageLoop::current()->QuitWhenIdle(); |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 | 1575 |
1577 INSTANTIATE_TEST_CASE_P( | 1576 INSTANTIATE_TEST_CASE_P( |
1578 RestoreOnStartupPolicyTestInstance, | 1577 RestoreOnStartupPolicyTestInstance, |
1579 RestoreOnStartupPolicyTest, | 1578 RestoreOnStartupPolicyTest, |
1580 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP, | 1579 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP, |
1581 &RestoreOnStartupPolicyTest::HomepageIsNTP, | 1580 &RestoreOnStartupPolicyTest::HomepageIsNTP, |
1582 &RestoreOnStartupPolicyTest::ListOfURLs, | 1581 &RestoreOnStartupPolicyTest::ListOfURLs, |
1583 &RestoreOnStartupPolicyTest::NTP, | 1582 &RestoreOnStartupPolicyTest::NTP, |
1584 &RestoreOnStartupPolicyTest::Last)); | 1583 &RestoreOnStartupPolicyTest::Last)); |
1585 | 1584 |
| 1585 // Similar to PolicyTest but sets a couple of policies before the browser is |
| 1586 // started. |
| 1587 class PolicyStatisticsCollectorTest : public PolicyTest { |
| 1588 public: |
| 1589 PolicyStatisticsCollectorTest() {} |
| 1590 virtual ~PolicyStatisticsCollectorTest() {} |
| 1591 |
| 1592 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 1593 PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 1594 PolicyMap policies; |
| 1595 policies.Set( |
| 1596 key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 1597 base::Value::CreateBooleanValue(true)); |
| 1598 policies.Set( |
| 1599 key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 1600 base::Value::CreateBooleanValue(false)); |
| 1601 policies.Set( |
| 1602 key::kHomepageLocation, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 1603 base::Value::CreateStringValue("http://chromium.org")); |
| 1604 provider_.UpdateChromePolicy(policies); |
| 1605 } |
| 1606 }; |
| 1607 |
| 1608 IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) { |
| 1609 // Verifies that policy usage histograms are collected at startup. |
| 1610 |
| 1611 // BrowserPolicyConnector::Init() has already been called. Make sure the |
| 1612 // CompleteInitialization() task has executed as well. |
| 1613 content::RunAllPendingInMessageLoop(); |
| 1614 |
| 1615 GURL kAboutHistograms = GURL(std::string(chrome::kAboutScheme) + |
| 1616 std::string(content::kStandardSchemeSeparator) + |
| 1617 std::string(chrome::kChromeUIHistogramHost)); |
| 1618 ui_test_utils::NavigateToURL(browser(), kAboutHistograms); |
| 1619 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
| 1620 std::string text; |
| 1621 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 1622 contents->GetRenderViewHost(), |
| 1623 std::wstring(), |
| 1624 L"var nodes = document.querySelectorAll('body > pre');" |
| 1625 L"var result = '';" |
| 1626 L"for (var i = 0; i < nodes.length; ++i) {" |
| 1627 L" var text = nodes[i].innerHTML;" |
| 1628 L" if (text.indexOf('Histogram: Enterprise.Policies') === 0) {" |
| 1629 L" result = text;" |
| 1630 L" break;" |
| 1631 L" }" |
| 1632 L"}" |
| 1633 L"domAutomationController.send(result);", |
| 1634 &text)); |
| 1635 ASSERT_FALSE(text.empty()); |
| 1636 const std::string kExpectedLabel = |
| 1637 "Histogram: Enterprise.Policies recorded 3 samples"; |
| 1638 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); |
| 1639 // HomepageLocation has policy ID 1. |
| 1640 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); |
| 1641 // ShowHomeButton has policy ID 35. |
| 1642 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); |
| 1643 // BookmarkBarEnabled has policy ID 82. |
| 1644 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); |
| 1645 } |
| 1646 |
1586 } // namespace policy | 1647 } // namespace policy |
OLD | NEW |