Commit 69075dde authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

Quota: Add regression tests for no BEST_EFFORT tasks.

Bug: 1006546,1005983,1004041
Change-Id: Ic50205176c645a4ea77948a30b7535908cb41286
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819804
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699441}
parent 7b4ff051
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/buildflag.h" #include "build/buildflag.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -247,3 +248,53 @@ IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTest, BlobXMLHttpRequest) { ...@@ -247,3 +248,53 @@ IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTest, BlobXMLHttpRequest) {
content::EvalJs( content::EvalJs(
browser()->tab_strip_model()->GetActiveWebContents(), kScript)); browser()->tab_strip_model()->GetActiveWebContents(), kScript));
} }
// A test specialization for verifying quota storage related operations do not
// use BEST_EFFORT tasks.
class NoBestEffortTasksTestWithQuota : public NoBestEffortTasksTest {
protected:
std::unique_ptr<storage::QuotaSettings> CreateQuotaSettings() override {
// Return nullptr to use the real quota subsystem.
return nullptr;
}
};
// Verify that cache_storage finishes without running BEST_EFFORT tasks.
// Regression test for https://crbug.com/1006546.
IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTestWithQuota, CacheStorage) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
embedded_test_server()->GetURL("/empty.html"));
const char kScript[] = R"(
(async function() {
const name = 'foo';
const url = '/';
const body = 'hello world';
let c = await caches.open(name);
await c.put(url, new Response(body));
let r = await c.match(url);
await r.text();
return 'DONE';
})();
)";
EXPECT_EQ("DONE",
content::EvalJs(
browser()->tab_strip_model()->GetActiveWebContents(), kScript));
}
// Verify that quota estimate() finishes without running BEST_EFFORT tasks.
// Regression test for https://crbug.com/1006546.
IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTestWithQuota, QuotaEstimate) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
embedded_test_server()->GetURL("/empty.html"));
const char kScript[] = R"(
(async function() {
await navigator.storage.estimate();
return 'DONE';
})();
)";
EXPECT_EQ("DONE",
content::EvalJs(
browser()->tab_strip_model()->GetActiveWebContents(), kScript));
}
...@@ -164,6 +164,14 @@ InProcessBrowserTest::InProcessBrowserTest( ...@@ -164,6 +164,14 @@ InProcessBrowserTest::InProcessBrowserTest(
} }
#endif #endif
std::unique_ptr<storage::QuotaSettings>
InProcessBrowserTest::CreateQuotaSettings() {
// By default use hardcoded quota settings to have a consistent testing
// environment.
const int kQuota = 5 * 1024 * 1024;
return std::make_unique<storage::QuotaSettings>(kQuota * 5, kQuota, 0, 0);
}
void InProcessBrowserTest::Initialize() { void InProcessBrowserTest::Initialize() {
CreateTestServer(GetChromeTestDataDir()); CreateTestServer(GetChromeTestDataDir());
base::FilePath src_dir; base::FilePath src_dir;
...@@ -277,11 +285,9 @@ void InProcessBrowserTest::SetUp() { ...@@ -277,11 +285,9 @@ void InProcessBrowserTest::SetUp() {
ash::ShellTestApi::SetTabletControllerUseScreenshotForTest(false); ash::ShellTestApi::SetTabletControllerUseScreenshotForTest(false);
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Use hardcoded quota settings to have a consistent testing environment. quota_settings_ = CreateQuotaSettings();
const int kQuota = 5 * 1024 * 1024;
quota_settings_ = storage::QuotaSettings(kQuota * 5, kQuota, 0, 0);
ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
&quota_settings_); quota_settings_.get());
// Redirect the default download directory to a temporary directory. // Redirect the default download directory to a temporary directory.
ASSERT_TRUE(default_download_dir_.CreateUniqueTempDir()); ASSERT_TRUE(default_download_dir_.CreateUniqueTempDir());
......
...@@ -264,6 +264,8 @@ class InProcessBrowserTest : public content::BrowserTestBase { ...@@ -264,6 +264,8 @@ class InProcessBrowserTest : public content::BrowserTestBase {
open_about_blank_on_browser_launch_ = value; open_about_blank_on_browser_launch_ = value;
} }
virtual std::unique_ptr<storage::QuotaSettings> CreateQuotaSettings();
private: private:
void Initialize(); void Initialize();
...@@ -291,8 +293,10 @@ class InProcessBrowserTest : public content::BrowserTestBase { ...@@ -291,8 +293,10 @@ class InProcessBrowserTest : public content::BrowserTestBase {
// True if the about:blank tab should be opened when the browser is launched. // True if the about:blank tab should be opened when the browser is launched.
bool open_about_blank_on_browser_launch_ = true; bool open_about_blank_on_browser_launch_ = true;
// We use hardcoded quota settings to have a consistent testing environment. // We use fake quota settings by default to have a consistent testing
storage::QuotaSettings quota_settings_; // environment. These can be overridden by subclasses via the
// CreateQuotaSettings() method.
std::unique_ptr<storage::QuotaSettings> quota_settings_;
// Use a default download directory to make sure downloads don't end up in the // Use a default download directory to make sure downloads don't end up in the
// system default location. // system default location.
......
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