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

Unified Diff: chrome/browser/storage/durable_storage_browsertest.cc

Issue 1356813002: Autogrant the durable storage permission to bookmarked origins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT_EQ -> EXPECT_TRUE/FALSE Created 5 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/storage/durable_storage_permission_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/storage/durable_storage_browsertest.cc
diff --git a/chrome/browser/storage/durable_storage_browsertest.cc b/chrome/browser/storage/durable_storage_browsertest.cc
index a34eb2ac87b49d4259ca553b3698f4b6c9160a00..1c4224ef39a5033d8da0c2519e702ec8ce71c61a 100644
--- a/chrome/browser/storage/durable_storage_browsertest.cc
+++ b/chrome/browser/storage/durable_storage_browsertest.cc
@@ -5,14 +5,18 @@
#include <string>
#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/bookmarks/browser/bookmark_utils.h"
+#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
@@ -30,6 +34,14 @@ class DurableStorageBrowserTest : public InProcessBrowserTest {
content::RenderFrameHost* GetRenderFrameHost() {
return browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
}
+
+ void Bookmark() {
+ bookmarks::BookmarkModel* bookmark_model =
+ BookmarkModelFactory::GetForProfile(browser()->profile());
+ bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
+ bookmarks::AddIfNotBookmarked(bookmark_model, url_, base::ASCIIToUTF16(""));
+ }
+
GURL url_;
private:
@@ -49,19 +61,71 @@ void DurableStorageBrowserTest::SetUpOnMainThread() {
url_ = embedded_test_server()->GetURL("/durable/durability-permissions.html");
}
-IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, DenyString) {
+IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, QueryNonBookmarkedPage) {
+ ui_test_utils::NavigateToURL(browser(), url_);
+ std::string permission_string;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ GetRenderFrameHost(), "checkPermission()", &permission_string));
+ EXPECT_EQ("default", permission_string);
+}
+
+IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, RequestNonBookmarkedPage) {
ui_test_utils::NavigateToURL(browser(), url_);
- PermissionBubbleManager::FromWebContents(
- browser()->tab_strip_model()->GetActiveWebContents())
- ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
- bool default_box_is_persistent;
+ bool default_box_is_persistent = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
EXPECT_FALSE(default_box_is_persistent);
+}
+
+IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, QueryBookmarkedPage) {
+ // Documents that the current behavior is to return "default" if script
+ // hasn't requested the durable permission, even if it would be autogranted.
+ Bookmark();
+ ui_test_utils::NavigateToURL(browser(), url_);
std::string permission_string;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(
GetRenderFrameHost(), "checkPermission()", &permission_string));
- EXPECT_EQ("denied", permission_string);
+ EXPECT_EQ("default", permission_string);
+}
+
+IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, RequestBookmarkedPage) {
+ Bookmark();
+ ui_test_utils::NavigateToURL(browser(), url_);
+ bool default_box_is_persistent = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
+ EXPECT_TRUE(default_box_is_persistent);
+}
+
+IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, BookmarkThenUnbookmark) {
+ Bookmark();
+ ui_test_utils::NavigateToURL(browser(), url_);
+ bool default_box_is_persistent = false;
+ std::string permission_string;
+
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
+ EXPECT_TRUE(default_box_is_persistent);
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ GetRenderFrameHost(), "checkPermission()", &permission_string));
+ EXPECT_EQ("granted", permission_string);
+
+ bookmarks::BookmarkModel* bookmark_model =
+ BookmarkModelFactory::GetForProfile(browser()->profile());
+ bookmarks::RemoveAllBookmarks(bookmark_model, url_);
+
+ // Unbookmarking doesn't change the permission.
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ GetRenderFrameHost(), "checkPermission()", &permission_string));
+ EXPECT_EQ("granted", permission_string);
+ // Requesting after unbookmarking doesn't change the default box.
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
+ EXPECT_TRUE(default_box_is_persistent);
+ // Querying after requesting after unbookmarking still reports "granted".
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ GetRenderFrameHost(), "checkPermission()", &permission_string));
+ EXPECT_EQ("granted", permission_string);
}
IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, FirstTabSeesResult) {
@@ -73,9 +137,7 @@ IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, FirstTabSeesResult) {
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), url_);
- PermissionBubbleManager::FromWebContents(
- browser()->tab_strip_model()->GetActiveWebContents())
- ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
+ Bookmark();
bool default_box_is_persistent = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
« no previous file with comments | « no previous file | chrome/browser/storage/durable_storage_permission_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698