page_info_browsertest.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <string>
  5. #include "base/strings/utf_string_conversions.h"
  6. #include "components/content_settings/core/common/content_settings.h"
  7. #include "components/page_info/android/page_info_client.h"
  8. #include "components/page_info/page_info_delegate.h"
  9. #include "third_party/blink/public/common/permissions/permission_utils.h"
  10. #include "url/origin.h"
  11. #include "weblayer/browser/tab_impl.h"
  12. #include "weblayer/browser/url_bar/page_info_delegate_impl.h"
  13. #include "weblayer/public/navigation_controller.h"
  14. #include "weblayer/public/tab.h"
  15. #include "weblayer/shell/browser/shell.h"
  16. #include "weblayer/test/weblayer_browser_test.h"
  17. #include "weblayer/test/weblayer_browser_test_utils.h"
  18. namespace weblayer {
  19. class PageInfoBrowserTest : public WebLayerBrowserTest {
  20. public:
  21. void SetUpOnMainThread() override {
  22. ASSERT_TRUE(embedded_test_server()->Start());
  23. }
  24. protected:
  25. content::WebContents* GetWebContents() {
  26. Tab* tab = shell()->tab();
  27. TabImpl* tab_impl = static_cast<TabImpl*>(tab);
  28. return tab_impl->web_contents();
  29. }
  30. GURL GetCurrentDisplayURL() {
  31. auto* navigation_controller = shell()->tab()->GetNavigationController();
  32. return navigation_controller->GetNavigationEntryDisplayURL(
  33. navigation_controller->GetNavigationListCurrentIndex());
  34. }
  35. };
  36. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, PageInfoClientSet) {
  37. EXPECT_TRUE(page_info::GetPageInfoClient());
  38. }
  39. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, ContentNotDisplayedInVrHeadset) {
  40. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  41. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  42. ASSERT_TRUE(page_info_delegate);
  43. EXPECT_FALSE(page_info_delegate->IsContentDisplayedInVrHeadset());
  44. }
  45. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, StatefulSSLHostStateDelegateSet) {
  46. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  47. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  48. ASSERT_TRUE(page_info_delegate);
  49. EXPECT_TRUE(page_info_delegate->GetStatefulSSLHostStateDelegate());
  50. }
  51. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, PermissionDecisionAutoblocker) {
  52. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  53. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  54. ASSERT_TRUE(page_info_delegate);
  55. EXPECT_TRUE(page_info_delegate->GetPermissionDecisionAutoblocker());
  56. }
  57. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, ContentSettings) {
  58. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  59. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  60. ASSERT_TRUE(page_info_delegate);
  61. EXPECT_TRUE(page_info_delegate->GetContentSettings());
  62. }
  63. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, PermissionResult) {
  64. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  65. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  66. ASSERT_TRUE(page_info_delegate);
  67. GURL url("https://example.com");
  68. auto* content_settings_map = page_info_delegate->GetContentSettings();
  69. ASSERT_TRUE(content_settings_map);
  70. content_settings_map->SetContentSettingDefaultScope(
  71. url, url, ContentSettingsType::BACKGROUND_SYNC, CONTENT_SETTING_BLOCK);
  72. // Check that |page_info_delegate| returns expected ContentSettingsType.
  73. EXPECT_EQ(page_info_delegate
  74. ->GetPermissionResult(blink::PermissionType::NOTIFICATIONS,
  75. url::Origin::Create(url))
  76. .content_setting,
  77. CONTENT_SETTING_BLOCK);
  78. }
  79. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest,
  80. PageSpecificContentSettingsDelegate) {
  81. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  82. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  83. ASSERT_TRUE(page_info_delegate);
  84. EXPECT_TRUE(page_info_delegate->GetPageSpecificContentSettingsDelegate());
  85. }
  86. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, EmbedderNameSet) {
  87. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  88. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  89. ASSERT_TRUE(page_info_delegate);
  90. std::u16string expected_embedder_name = u"WebLayerBrowserTests";
  91. EXPECT_EQ(expected_embedder_name,
  92. page_info_delegate->GetClientApplicationName().c_str());
  93. }
  94. IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, SubresourceFilterActivation) {
  95. std::unique_ptr<PageInfoDelegate> page_info_delegate =
  96. page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
  97. ASSERT_TRUE(page_info_delegate);
  98. NavigateAndWaitForCompletion(GURL("about:blank"), shell());
  99. EXPECT_FALSE(
  100. page_info_delegate->IsSubresourceFilterActivated(GetCurrentDisplayURL()));
  101. GURL test_url(embedded_test_server()->GetURL("/simple_page.html"));
  102. ActivateSubresourceFilterInWebContentsForURL(GetWebContents(), test_url);
  103. NavigateAndWaitForCompletion(test_url, shell());
  104. EXPECT_TRUE(
  105. page_info_delegate->IsSubresourceFilterActivated(GetCurrentDisplayURL()));
  106. }
  107. } // namespace weblayer