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 // clang-format off | 565 std::unique_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
566 std::string jsFindVisibility = R"( | 566 rfh, "var node = document.getElementById('" + node_id + |
567 (function isNodeVisible(node) { | 567 "');\n" |
568 if (!node) return 'node not found'; | 568 "if (node)\n" |
569 if (node.offsetWidth === 0 || node.offsetHeight === 0) return false; | 569 " node.offsetWidth > 0 && node.offsetHeight > 0;" |
570 // Don't check opacity, since the css transition may actually leave | 570 "else\n" |
571 // opacity at 0 after it's been unhidden | 571 " 'node not found';\n"); |
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 | |
585 if (!value.get()) | 572 if (!value.get()) |
586 return VISIBILITY_ERROR; | 573 return VISIBILITY_ERROR; |
587 | 574 |
588 bool result = false; | 575 bool result = false; |
589 if (!value->GetAsBoolean(&result)) | 576 if (!value->GetAsBoolean(&result)) |
590 return VISIBILITY_ERROR; | 577 return VISIBILITY_ERROR; |
591 | 578 |
592 return result ? VISIBLE : HIDDEN; | 579 return result ? VISIBLE : HIDDEN; |
593 } | 580 } |
594 | 581 |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 | 1473 |
1487 INSTANTIATE_TEST_CASE_P( | 1474 INSTANTIATE_TEST_CASE_P( |
1488 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1475 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1489 SafeBrowsingBlockingPageIDNTest, | 1476 SafeBrowsingBlockingPageIDNTest, |
1490 testing::Combine(testing::Values(false, true), | 1477 testing::Combine(testing::Values(false, true), |
1491 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1478 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1492 SB_THREAT_TYPE_URL_PHISHING, | 1479 SB_THREAT_TYPE_URL_PHISHING, |
1493 SB_THREAT_TYPE_URL_UNWANTED))); | 1480 SB_THREAT_TYPE_URL_UNWANTED))); |
1494 | 1481 |
1495 } // namespace safe_browsing | 1482 } // namespace safe_browsing |
OLD | NEW |