chooser_title_util_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2022 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 "components/permissions/chooser_title_util.h"
  5. #include "components/strings/grit/components_strings.h"
  6. #include "content/public/test/navigation_simulator.h"
  7. #include "content/public/test/test_renderer_host.h"
  8. #include "url/gurl.h"
  9. #include "url/origin.h"
  10. namespace permissions {
  11. namespace {
  12. constexpr int kTitleResourceId = IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN;
  13. using ChooserTitleTest = content::RenderViewHostTestHarness;
  14. TEST_F(ChooserTitleTest, NoFrame) {
  15. EXPECT_EQ(u"", CreateChooserTitle(nullptr, kTitleResourceId));
  16. }
  17. TEST_F(ChooserTitleTest, FrameTree) {
  18. NavigateAndCommit(GURL("https://main-frame.com"));
  19. content::RenderFrameHost* subframe =
  20. content::NavigationSimulator::NavigateAndCommitFromDocument(
  21. GURL("https://sub-frame.com"),
  22. content::RenderFrameHostTester::For(main_rfh())
  23. ->AppendChild("subframe"));
  24. EXPECT_EQ("main-frame.com", main_rfh()->GetLastCommittedOrigin().host());
  25. EXPECT_EQ(u"main-frame.com wants to connect",
  26. CreateChooserTitle(main_rfh(), kTitleResourceId));
  27. EXPECT_EQ("sub-frame.com", subframe->GetLastCommittedOrigin().host());
  28. EXPECT_EQ(u"main-frame.com wants to connect",
  29. CreateChooserTitle(subframe, kTitleResourceId));
  30. }
  31. } // namespace
  32. } // namespace permissions