Commit 5a86ada3 authored by felt's avatar felt Committed by Commit bot

Update push messaging tests to use both infobars and bubbles (w/ autoresponse)

- This CL updates the Permission Bubble Manager to autorespond for browser tests.
  The test tells the Permission Bubble Manager which response is desired, and the
  Permission Bubble Manager will execute that response immediately after Show().

- This CL applies the new responder to parameterized PushMessagingBrowsertests.

BUG=438758

Review URL: https://codereview.chromium.org/1154943008

Cr-Commit-Position: refs/heads/master@{#333166}
parent 403f2058
......@@ -78,12 +78,14 @@ bool PermissionBubbleManager::Enabled() {
PermissionBubbleManager::PermissionBubbleManager(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
require_user_gesture_(false),
bubble_showing_(false),
view_(NULL),
request_url_has_loaded_(false),
weak_factory_(this) {}
: content::WebContentsObserver(web_contents),
require_user_gesture_(false),
bubble_showing_(false),
view_(NULL),
request_url_has_loaded_(false),
auto_response_for_test_(NONE),
weak_factory_(this) {
}
PermissionBubbleManager::~PermissionBubbleManager() {
if (view_ != NULL)
......@@ -346,6 +348,10 @@ void PermissionBubbleManager::TriggerShowBubble() {
// case we may do in-line calling of finalization.
bubble_showing_ = true;
view_->Show(requests_, accept_states_);
// If in testing mode, automatically respond to the bubble that was shown.
if (auto_response_for_test_ != NONE)
DoAutoResponseForTesting();
}
void PermissionBubbleManager::FinalizeBubble() {
......@@ -414,3 +420,18 @@ bool PermissionBubbleManager::HasUserGestureRequest(
return false;
}
void PermissionBubbleManager::DoAutoResponseForTesting() {
switch (auto_response_for_test_) {
case ACCEPT_ALL:
Accept();
break;
case DENY_ALL:
Deny();
break;
case DISMISS:
Closing();
break;
case NONE:
NOTREACHED();
}
}
......@@ -30,6 +30,13 @@ class PermissionBubbleManager
public content::WebContentsUserData<PermissionBubbleManager>,
public PermissionBubbleView::Delegate {
public:
enum AutoResponseType {
NONE,
ACCEPT_ALL,
DENY_ALL,
DISMISS
};
// Return the enabled state of permissions bubbles.
// Controlled by a flag and FieldTrial.
static bool Enabled();
......@@ -64,6 +71,14 @@ class PermissionBubbleManager
// comes in with a user gesture.
void RequireUserGesture(bool required);
// Do NOT use this methods in production code. Use this methods in browser
// tests that need to accept or deny permissions when requested in
// JavaScript. Your test needs to set this appropriately, and then the bubble
// will proceed as desired as soon as Show() is called.
void set_auto_response_for_test(AutoResponseType response) {
auto_response_for_test_ = response;
}
private:
friend class DownloadRequestLimiterTest;
friend class GeolocationBrowserTest;
......@@ -119,6 +134,8 @@ class PermissionBubbleManager
bool HasUserGestureRequest(
const std::vector<PermissionBubbleRequest*>& queue);
void DoAutoResponseForTesting();
// Whether to delay displaying the bubble until a request with a user gesture.
// False by default, unless RequireUserGesture(bool) changes the value.
bool require_user_gesture_;
......@@ -140,6 +157,8 @@ class PermissionBubbleManager
std::vector<bool> accept_states_;
AutoResponseType auto_response_for_test_;
base::WeakPtrFactory<PermissionBubbleManager> weak_factory_;
};
......
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