Chromium Code Reviews| 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 // This test creates a fake safebrowsing service, where we can inject known- | 5 // This test creates a fake safebrowsing service, where we can inject known- |
| 6 // threat urls. It then uses a real browser to go to these urls, and sends | 6 // threat urls. It then uses a real browser to go to these urls, and sends |
| 7 // "goback" or "proceed" commands and verifies they work. | 7 // "goback" or "proceed" commands and verifies they work. |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 if (!interstitial) | 555 if (!interstitial) |
| 556 return false; | 556 return false; |
| 557 return content::WaitForRenderFrameReady(interstitial->GetMainFrame()); | 557 return content::WaitForRenderFrameReady(interstitial->GetMainFrame()); |
| 558 } | 558 } |
| 559 | 559 |
| 560 Visibility GetVisibility(const std::string& node_id) { | 560 Visibility GetVisibility(const std::string& node_id) { |
| 561 content::RenderFrameHost* rfh = GetRenderFrameHost(); | 561 content::RenderFrameHost* rfh = GetRenderFrameHost(); |
| 562 if (!rfh) | 562 if (!rfh) |
| 563 return VISIBILITY_ERROR; | 563 return VISIBILITY_ERROR; |
| 564 | 564 |
| 565 std::unique_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 565 // clang-format off |
| 566 rfh, "var node = document.getElementById('" + node_id + | 566 std::string jsFindVisibility = R"( |
| 567 "');\n" | 567 (function isNodeVisible(node) { |
| 568 "if (node)\n" | 568 if (!node) return 'node not found'; |
| 569 " node.offsetWidth > 0 && node.offsetHeight > 0;" | 569 if (node.offsetWidth === 0 || node.offsetHeight === 0) return false; |
| 570 "else\n" | 570 // Don't check opacity, since the css transition may actually leave |
|
Jialiu Lin
2017/04/28 18:14:08
nit: "Don't" -> "Do not"
codereview.chromium.org
Nate Fischer
2017/04/28 18:26:25
Done.
| |
| 571 " 'node not found';\n"); | 571 // opacity at 0 after it's been unhidden |
| 572 if (node.classList.contains('hidden')) return false; | |
| 573 // Otherwise, we must check all parent nodes | |
| 574 var parentVisibility = isNodeVisible(node.parentElement); | |
| 575 if (parentVisibility === 'node not found') { | |
| 576 return true; // none of the parents are set invisible | |
| 577 } | |
| 578 return parentVisibility; | |
| 579 }(document.getElementById(')" + node_id + R"(')));)"; | |
| 580 // clang-format on | |
| 581 | |
| 582 std::unique_ptr<base::Value> value = | |
| 583 content::ExecuteScriptAndGetValue(rfh, jsFindVisibility); | |
| 584 | |
| 572 if (!value.get()) | 585 if (!value.get()) |
| 573 return VISIBILITY_ERROR; | 586 return VISIBILITY_ERROR; |
| 574 | 587 |
| 575 bool result = false; | 588 bool result = false; |
| 576 if (!value->GetAsBoolean(&result)) | 589 if (!value->GetAsBoolean(&result)) |
| 577 return VISIBILITY_ERROR; | 590 return VISIBILITY_ERROR; |
| 578 | 591 |
| 579 return result ? VISIBLE : HIDDEN; | 592 return result ? VISIBLE : HIDDEN; |
| 580 } | 593 } |
| 581 | 594 |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1473 | 1486 |
| 1474 INSTANTIATE_TEST_CASE_P( | 1487 INSTANTIATE_TEST_CASE_P( |
| 1475 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1488 SafeBrowsingBlockingPageIDNTestWithThreatType, |
| 1476 SafeBrowsingBlockingPageIDNTest, | 1489 SafeBrowsingBlockingPageIDNTest, |
| 1477 testing::Combine(testing::Values(false, true), | 1490 testing::Combine(testing::Values(false, true), |
| 1478 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1491 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
| 1479 SB_THREAT_TYPE_URL_PHISHING, | 1492 SB_THREAT_TYPE_URL_PHISHING, |
| 1480 SB_THREAT_TYPE_URL_UNWANTED))); | 1493 SB_THREAT_TYPE_URL_UNWANTED))); |
| 1481 | 1494 |
| 1482 } // namespace safe_browsing | 1495 } // namespace safe_browsing |
| OLD | NEW |