Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2988)

Unified Diff: chrome/browser/notifications/notification_browsertest.cc

Issue 341833004: [WebsiteSettings] Enable permission bubbles by default. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_browsertest.cc
diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc
index 0da4987c58428d34acc37f6ad1f96f65085ec5e1..187731312634547960385e9317b9990062068721 100644
--- a/chrome/browser/notifications/notification_browsertest.cc
+++ b/chrome/browser/notifications/notification_browsertest.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_pattern.h"
#include "chrome/test/base/in_process_browser_test.h"
@@ -51,7 +52,7 @@ namespace {
const char kExpectedIconUrl[] = "/notifications/no_such_file.png";
-enum InfobarAction {
+enum PromptAction {
DISMISS = 0,
ALLOW,
DENY,
@@ -114,6 +115,64 @@ class MessageCenterChangeObserver
DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
};
+class MockView : public PermissionBubbleView {
+ public:
+ MockView() : shown_(false), can_accept_updates_(true), delegate_(NULL) {}
+ virtual ~MockView() {}
+
+ void Clear() {
+ shown_ = false;
+ can_accept_updates_ = true;
+ delegate_ = NULL;
+ permission_requests_.clear();
+ permission_states_.clear();
+ }
+
+ // PermissionBubbleView:
+ virtual void SetDelegate(Delegate* delegate) OVERRIDE {
+ delegate_ = delegate;
+ }
+
+ virtual void Show(
+ const std::vector<PermissionBubbleRequest*>& requests,
+ const std::vector<bool>& accept_state,
+ bool customization_state_) OVERRIDE {
+ shown_ = true;
+ permission_requests_ = requests;
+ permission_states_ = accept_state;
+ }
+
+ virtual void Hide() OVERRIDE {
+ shown_ = false;
+ }
+
+ virtual bool IsVisible() OVERRIDE {
+ return shown_;
+ }
+
+ virtual bool CanAcceptRequestUpdate() OVERRIDE {
+ return can_accept_updates_;
+ }
+
+ void Accept() {
+ delegate_->Accept();
+ }
+
+ void Deny() {
+ delegate_->Deny();
+ }
+
+ void Close() {
+ delegate_->Closing();
+ }
+
+ bool shown_;
+ bool can_accept_updates_;
+ Delegate* delegate_;
+ std::vector<PermissionBubbleRequest*> permission_requests_;
+ std::vector<bool> permission_states_;
+};
+
} // namespace
class NotificationsTest : public InProcessBrowserTest {
@@ -132,7 +191,7 @@ class NotificationsTest : public InProcessBrowserTest {
void AllowAllOrigins();
void SetDefaultContentSetting(ContentSetting setting);
- void VerifyInfoBar(const Browser* browser, int index);
+ void VerifyPrompt(const Browser* browser, int index);
std::string CreateNotification(Browser* browser,
bool wait_for_new_balloon,
const char* icon,
@@ -143,10 +202,10 @@ class NotificationsTest : public InProcessBrowserTest {
bool wait_for_new_balloon);
bool RequestPermissionAndWait(Browser* browser);
bool CancelNotification(const char* notification_id, Browser* browser);
- bool PerformActionOnInfoBar(Browser* browser,
- InfobarAction action,
- size_t infobar_index,
- int tab_index);
+ bool PerformAction(Browser* browser,
+ PromptAction action,
+ size_t index,
+ int tab_index);
void GetPrefsByContentSetting(ContentSetting setting,
ContentSettingsForOneType* settings);
bool CheckOriginInSetting(const ContentSettingsForOneType& settings,
@@ -157,8 +216,11 @@ class NotificationsTest : public InProcessBrowserTest {
"/notifications/notification_tester.html");
}
+ int GetBubblesQueueSize(PermissionBubbleManager* mgr);
+
private:
void DropOriginPreference(const GURL& origin);
+ MockView mock_bubble_view_;
};
int NotificationsTest::GetNotificationCount() {
@@ -203,17 +265,25 @@ void NotificationsTest::SetDefaultContentSetting(ContentSetting setting) {
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
}
-void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) {
- InfoBarService* infobar_service = InfoBarService::FromWebContents(
- browser->tab_strip_model()->GetWebContentsAt(index));
-
- ASSERT_EQ(1U, infobar_service->infobar_count());
- ConfirmInfoBarDelegate* confirm_infobar =
- infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(confirm_infobar);
- int buttons = confirm_infobar->GetButtons();
- EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
- EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
+void NotificationsTest::VerifyPrompt(const Browser* browser, int index) {
+ if (!PermissionBubbleManager::Enabled()) {
+ InfoBarService* infobar_service = InfoBarService::FromWebContents(
+ browser->tab_strip_model()->GetWebContentsAt(index));
+
+ ASSERT_EQ(1U, infobar_service->infobar_count());
+ ConfirmInfoBarDelegate* confirm_infobar =
+ infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(confirm_infobar);
+ int buttons = confirm_infobar->GetButtons();
+ EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
+ EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
+ } else {
+ PermissionBubbleManager* permission_manager =
+ PermissionBubbleManager::FromWebContents(
+ browser->tab_strip_model()->GetWebContentsAt(0));
+LOG(INFO) << "Get queue size";
+ ASSERT_EQ(1, GetBubblesQueueSize(permission_manager));
+ }
}
std::string NotificationsTest::CreateNotification(
@@ -251,18 +321,36 @@ std::string NotificationsTest::CreateSimpleNotification(
bool NotificationsTest::RequestPermissionAndWait(Browser* browser) {
InfoBarService* infobar_service = InfoBarService::FromWebContents(
browser->tab_strip_model()->GetActiveWebContents());
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
- content::Source<InfoBarService>(infobar_service));
- std::string result;
- bool success = content::ExecuteScriptAndExtractString(
- browser->tab_strip_model()->GetActiveWebContents(),
- "requestPermission();",
- &result);
- if (!success || result != "1")
- return false;
- observer.Wait();
- return true;
+ PermissionBubbleManager* permission_manager =
+ PermissionBubbleManager::FromWebContents(
+ browser->tab_strip_model()->GetWebContentsAt(0));
+ permission_manager->SetView(&mock_bubble_view_);
+ if (!PermissionBubbleManager::Enabled()) {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
+ content::Source<InfoBarService>(infobar_service));
+ std::string result;
+ bool success = content::ExecuteScriptAndExtractString(
+ browser->tab_strip_model()->GetActiveWebContents(),
+ "requestPermission();",
+ &result);
+ if (!success || result != "1")
+ return false;
+ observer.Wait();
+ return true;
+ } else {
+ std::string result;
+ bool success = content::ExecuteScriptAndExtractString(
+ browser->tab_strip_model()->GetActiveWebContents(),
+ "requestPermission();",
+ &result);
+ if (!success || result != "1")
+ return false;
+ while (!mock_bubble_view_.shown_) {
+ (new content::MessageLoopRunner())->Run();
+ }
+ return true;
+ }
}
bool NotificationsTest::CancelNotification(
@@ -283,47 +371,71 @@ bool NotificationsTest::CancelNotification(
return observer.Wait();
}
-bool NotificationsTest::PerformActionOnInfoBar(
+bool NotificationsTest::PerformAction(
Browser* browser,
- InfobarAction action,
- size_t infobar_index,
+ PromptAction action,
+ size_t index,
int tab_index) {
InfoBarService* infobar_service = InfoBarService::FromWebContents(
browser->tab_strip_model()->GetWebContentsAt(tab_index));
- if (infobar_index >= infobar_service->infobar_count()) {
- ADD_FAILURE();
- return false;
+ PermissionBubbleManager* permission_manager =
+ PermissionBubbleManager::FromWebContents(
+ browser->tab_strip_model()->GetWebContentsAt(0));
+ if (!PermissionBubbleManager::Enabled()) {
+ if (index >= infobar_service->infobar_count()) {
+ ADD_FAILURE();
+ return false;
+ }
+ } else {
+ if (static_cast<int>(index) >= GetBubblesQueueSize(permission_manager)) {
+ ADD_FAILURE();
+ return false;
+ }
}
- infobars::InfoBar* infobar = infobar_service->infobar_at(infobar_index);
- infobars::InfoBarDelegate* infobar_delegate = infobar->delegate();
- switch (action) {
- case DISMISS:
- infobar_delegate->InfoBarDismissed();
- infobar_service->RemoveInfoBar(infobar);
- return true;
-
- case ALLOW: {
- ConfirmInfoBarDelegate* confirm_infobar_delegate =
- infobar_delegate->AsConfirmInfoBarDelegate();
- if (!confirm_infobar_delegate) {
- ADD_FAILURE();
- } else if (confirm_infobar_delegate->Accept()) {
+ if (!PermissionBubbleManager::Enabled()) {
+ infobars::InfoBar* infobar = infobar_service->infobar_at(index);
+ infobars::InfoBarDelegate* infobar_delegate = infobar->delegate();
+ switch (action) {
+ case DISMISS:
+ infobar_delegate->InfoBarDismissed();
infobar_service->RemoveInfoBar(infobar);
return true;
+
+ case ALLOW: {
+ ConfirmInfoBarDelegate* confirm_infobar_delegate =
+ infobar_delegate->AsConfirmInfoBarDelegate();
+ if (!confirm_infobar_delegate) {
+ ADD_FAILURE();
+ } else if (confirm_infobar_delegate->Accept()) {
+ infobar_service->RemoveInfoBar(infobar);
+ return true;
+ }
}
- }
- case DENY: {
- ConfirmInfoBarDelegate* confirm_infobar_delegate =
- infobar_delegate->AsConfirmInfoBarDelegate();
- if (!confirm_infobar_delegate) {
- ADD_FAILURE();
- } else if (confirm_infobar_delegate->Cancel()) {
- infobar_service->RemoveInfoBar(infobar);
- return true;
+ case DENY: {
+ ConfirmInfoBarDelegate* confirm_infobar_delegate =
+ infobar_delegate->AsConfirmInfoBarDelegate();
+ if (!confirm_infobar_delegate) {
+ ADD_FAILURE();
+ } else if (confirm_infobar_delegate->Cancel()) {
+ infobar_service->RemoveInfoBar(infobar);
+ return true;
+ }
}
}
+ } else {
+ switch (action) {
+ case DISMISS:
+ mock_bubble_view_.Close();
+ return true;
+ case ALLOW:
+ mock_bubble_view_.Accept();
+ return true;
+ case DENY:
+ mock_bubble_view_.Deny();
+ return true;
+ }
}
return false;
@@ -361,8 +473,14 @@ void NotificationsTest::DropOriginPreference(const GURL& origin) {
ContentSettingsPattern::FromURLNoWildcard(origin));
}
+int NotificationsTest::GetBubblesQueueSize(
+ PermissionBubbleManager* mgr) {
+LOG(INFO) << "Have " << mgr->requests_.size();
+ return static_cast<int>(mgr->requests_.size());
+}
+
// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
-IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) {
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGesture) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ui_test_utils::NavigateToURL(
@@ -381,7 +499,13 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) {
InfoBarService* infobar_service = InfoBarService::FromWebContents(
browser()->tab_strip_model()->GetWebContentsAt(0));
- EXPECT_EQ(1U, infobar_service->infobar_count());
+ PermissionBubbleManager* permission_manager =
+ PermissionBubbleManager::FromWebContents(
+ browser()->tab_strip_model()->GetWebContentsAt(0));
+ if (!PermissionBubbleManager::Enabled())
+ EXPECT_EQ(1U, infobar_service->infobar_count());
+ else
+ EXPECT_EQ(1, GetBubblesQueueSize(permission_manager));
}
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
@@ -439,7 +563,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) {
ASSERT_EQ(0, GetNotificationCount());
}
-IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) {
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionPromptAppears) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Requests notification privileges and verifies the infobar appears.
@@ -447,10 +571,11 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) {
ASSERT_TRUE(RequestPermissionAndWait(browser()));
ASSERT_EQ(0, GetNotificationCount());
- ASSERT_NO_FATAL_FAILURE(VerifyInfoBar(browser(), 0));
+LOG(INFO) << "VerifyPrompt";
+ ASSERT_NO_FATAL_FAILURE(VerifyPrompt(browser(), 0));
}
-IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) {
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermission) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Tries to create a notification and clicks allow on the infobar.
@@ -460,20 +585,20 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) {
ASSERT_EQ(0, GetNotificationCount());
ASSERT_TRUE(RequestPermissionAndWait(browser()));
- ASSERT_TRUE(PerformActionOnInfoBar(browser(), ALLOW, 0, 0));
+ ASSERT_TRUE(PerformAction(browser(), ALLOW, 0, 0));
CreateSimpleNotification(browser(), true);
EXPECT_EQ(1, GetNotificationCount());
}
-IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) {
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermission) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Test that no notification is created
// when Deny is chosen from permission infobar.
ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
ASSERT_TRUE(RequestPermissionAndWait(browser()));
- PerformActionOnInfoBar(browser(), DENY, 0, 0);
+ PerformAction(browser(), DENY, 0, 0);
CreateSimpleNotification(browser(), false);
ASSERT_EQ(0, GetNotificationCount());
ContentSettingsForOneType settings;
@@ -481,13 +606,13 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) {
EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL()));
}
-IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) {
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermission) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Test that no notification is created when permission infobar is dismissed.
ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
ASSERT_TRUE(RequestPermissionAndWait(browser()));
- PerformActionOnInfoBar(browser(), DISMISS, 0, 0);
+ PerformAction(browser(), DISMISS, 0, 0);
CreateSimpleNotification(browser(), false);
ASSERT_EQ(0, GetNotificationCount());
ContentSettingsForOneType settings;
@@ -612,13 +737,13 @@ IN_PROC_BROWSER_TEST_F(
Browser* incognito = CreateIncognitoBrowser();
ui_test_utils::NavigateToURL(incognito, GetTestPageURL());
ASSERT_TRUE(RequestPermissionAndWait(incognito));
- PerformActionOnInfoBar(incognito, DENY, 0, 0);
+ PerformAction(incognito, DENY, 0, 0);
CloseBrowserWindow(incognito);
incognito = CreateIncognitoBrowser();
ui_test_utils::NavigateToURL(incognito, GetTestPageURL());
ASSERT_TRUE(RequestPermissionAndWait(incognito));
- PerformActionOnInfoBar(incognito, ALLOW, 0, 0);
+ PerformAction(incognito, ALLOW, 0, 0);
CreateSimpleNotification(incognito, true);
ASSERT_EQ(1, GetNotificationCount());
CloseBrowserWindow(incognito);
@@ -674,7 +799,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
ui_test_utils::NavigateToURL(browser, GetTestPageURL());
browser->tab_strip_model()->ActivateTabAt(0, true);
ASSERT_TRUE(RequestPermissionAndWait(browser));
- PerformActionOnInfoBar(browser, ALLOW, 0, 0);
+ PerformAction(browser, ALLOW, 0, 0);
CreateSimpleNotification(browser, true);
ASSERT_EQ(1, GetNotificationCount());
}
@@ -700,7 +825,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) {
IN_PROC_BROWSER_TEST_F(
NotificationsTest,
- TestNavigateAwayWithPermissionInfobar) {
+ TestNavigateAwayWithPermission) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Test navigating away when an infobar is present,
@@ -715,7 +840,7 @@ IN_PROC_BROWSER_TEST_F(
ASSERT_TRUE(RequestPermissionAndWait(browser()));
ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
ASSERT_TRUE(RequestPermissionAndWait(browser()));
- PerformActionOnInfoBar(browser(), ALLOW, 0, 0);
+ PerformAction(browser(), ALLOW, 0, 0);
CreateSimpleNotification(browser(), true);
ASSERT_EQ(1, GetNotificationCount());
}
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/browser/ui/website_settings/permission_bubble_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698