Commit 94aa708f authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Chromium LUCI CQ

Added tests for one time permission for geolocation feature

Bug: 1165795
Change-Id: Iaf59a0dab7da5c7578a79e54d0a3cea9140e2b35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624788
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846155}
parent 49b0cf54
......@@ -47,6 +47,7 @@
#include "content/public/test/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "url/gurl.h"
#include "url/origin.h"
......@@ -100,6 +101,10 @@ class PermissionRequestManagerBrowserTest : public InProcessBrowserTest {
}
void TearDownOnMainThread() override {
ShutDownFirstTabMockPermissionPromptFactory();
}
void ShutDownFirstTabMockPermissionPromptFactory() {
mock_permission_prompt_factory_.reset();
}
......@@ -844,4 +849,105 @@ IN_PROC_BROWSER_TEST_F(PermissionRequestManagerWithBackForwardCacheBrowserTest,
GetPermissionRequestManager()->Closing();
}
class PermissionRequestManagerOneTimeGeolocationPermissionBrowserTest
: public PermissionRequestManagerBrowserTest {
public:
PermissionRequestManagerOneTimeGeolocationPermissionBrowserTest() {
scoped_feature_list_.InitAndEnableFeature(
permissions::features::kOneTimeGeolocationPermission);
geolocation_overrider_ =
std::make_unique<device::ScopedGeolocationOverrider>(0, 0);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<device::ScopedGeolocationOverrider> geolocation_overrider_;
};
IN_PROC_BROWSER_TEST_F(
PermissionRequestManagerOneTimeGeolocationPermissionBrowserTest,
RequestForPermission) {
const char kQueryCurrentPosition[] = R"(
navigator.geolocation.getCurrentPosition(
_ => domAutomationController.send('success'),
_ => domAutomationController.send('failure'));
)";
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), embedded_test_server()->GetURL("/title1.html"), 1);
bubble_factory()->set_response_type(
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ONCE);
// Request 'geolocation' permission.
std::string result = content::EvalJsWithManualReply(GetActiveMainFrame(),
kQueryCurrentPosition)
.ExtractString();
EXPECT_EQ("success", result);
EXPECT_EQ(1, bubble_factory()->TotalRequestCount());
// Request 'geolocation' permission. There should not be a 2nd prompt.
result = content::EvalJsWithManualReply(GetActiveMainFrame(),
kQueryCurrentPosition)
.ExtractString();
EXPECT_EQ("success", result);
EXPECT_EQ(1, bubble_factory()->TotalRequestCount());
// Open a new tab with same domain.
ui_test_utils::NavigateToURLWithDisposition(
browser(), embedded_test_server()->GetURL("/title1.html"),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
// Create a new mock permission prompt factory for the second tab.
std::unique_ptr<permissions::MockPermissionPromptFactory>
second_tab_bubble_factory(
std::make_unique<permissions::MockPermissionPromptFactory>(
GetPermissionRequestManager()));
// Request 'geolocation' permission.
result = content::EvalJsWithManualReply(GetActiveMainFrame(),
kQueryCurrentPosition)
.ExtractString();
EXPECT_EQ("success", result);
// There should be no permission prompt.
EXPECT_EQ(0, second_tab_bubble_factory.get()->TotalRequestCount());
// Open a new empty tab before closing the first two tabs.
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(url::kAboutBlankURL),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
// Need to close the mock permission managers before closing the tabs.
// Otherwise the tab instances can't be destroyed due to a DCHECK
ShutDownFirstTabMockPermissionPromptFactory();
second_tab_bubble_factory.reset();
// Close the first two tabs.
TabStripModel* tab_strip_model = browser()->tab_strip_model();
tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_USER_GESTURE);
tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_USER_GESTURE);
ASSERT_EQ(1, tab_strip_model->count());
// Create a new mock permission prompt factory for the third tab.
std::unique_ptr<permissions::MockPermissionPromptFactory>
third_tab_bubble_factory(
std::make_unique<permissions::MockPermissionPromptFactory>(
GetPermissionRequestManager()));
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), embedded_test_server()->GetURL("/title1.html"), 1);
third_tab_bubble_factory.get()->set_response_type(
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ONCE);
// Request 'geolocation' permission. We should get a prompt.
result = content::EvalJsWithManualReply(GetActiveMainFrame(),
kQueryCurrentPosition)
.ExtractString();
EXPECT_EQ("success", result);
EXPECT_EQ(1, third_tab_bubble_factory.get()->TotalRequestCount());
}
} // anonymous namespace
......@@ -349,3 +349,25 @@ IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
INSTANTIATE_TEST_SUITE_P(All,
PermissionPromptBubbleViewBrowserTest,
::testing::Values(false, true));
class OneTimePermissionPromptBubbleViewBrowserTest
: public PermissionPromptBubbleViewBrowserTest {
public:
OneTimePermissionPromptBubbleViewBrowserTest() {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
permissions::features::kOneTimeGeolocationPermission,
{{"OkButtonBehavesAsAllowAlways", GetParam() ? "true" : "false"}});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_P(OneTimePermissionPromptBubbleViewBrowserTest,
InvokeUi_geolocation) {
ShowAndVerifyUi();
}
INSTANTIATE_TEST_SUITE_P(All,
OneTimePermissionPromptBubbleViewBrowserTest,
::testing::Values(false, true));
......@@ -866,6 +866,9 @@ void PermissionRequestManager::LogWarningToConsole(const char* message) {
void PermissionRequestManager::DoAutoResponseForTesting() {
switch (auto_response_for_test_) {
case ACCEPT_ONCE:
AcceptThisTime();
break;
case ACCEPT_ALL:
Accept();
break;
......
......@@ -78,7 +78,7 @@ class PermissionRequestManager
virtual ~Observer() = default;
};
enum AutoResponseType { NONE, ACCEPT_ALL, DENY_ALL, DISMISS };
enum AutoResponseType { NONE, ACCEPT_ONCE, ACCEPT_ALL, DENY_ALL, DISMISS };
using UiDecision = NotificationPermissionUiSelector::Decision;
using QuietUiReason = NotificationPermissionUiSelector::QuietUiReason;
......
......@@ -14,6 +14,7 @@ GlobalErrorBubbleTest.*
HatsBubbleTest.*
HungRendererDialogViewBrowserTest.*
ImportLockDialogViewBrowserTest.*
OneTimePermissionPromptBubbleViewBrowserTest.*
OutdatedUpgradeBubbleTest.*
PageInfoBubbleViewBrowserTest.*
PasswordReuseModalWarningTest.*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment