0
Files
src/content/browser/fileapi/file_system_browsertest.cc
michaeln@google.com f13b26860d Access the QuotaManager via a StoragePartition to support the isolated app feature.
BUG=85121
Review URL: https://chromiumcodereview.appspot.com/10834264

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152695 0039d316-1c4b-4281-b951-d872f2087c98
2012-08-22 00:37:55 +00:00

94 lines
3.4 KiB
C++

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/test/thread_test_helper.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "net/test/test_server.h"
#include "webkit/quota/quota_manager.h"
using quota::QuotaManager;
namespace content {
// This browser test is aimed towards exercising the FileAPI bindings and
// the actual implementation that lives in the browser side.
class FileSystemBrowserTest : public ContentBrowserTest {
public:
FileSystemBrowserTest() {}
void SimpleTest(const GURL& test_url, bool incognito = false) {
// The test page will perform tests on FileAPI, then navigate to either
// a #pass or #fail ref.
Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell();
LOG(INFO) << "Navigating to URL and blocking.";
NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2);
LOG(INFO) << "Navigation done.";
std::string result = the_browser->web_contents()->GetURL().ref();
if (result != "pass") {
std::string js_result;
ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
the_browser->web_contents()->GetRenderViewHost(), L"",
L"window.domAutomationController.send(getLog())", &js_result));
FAIL() << "Failed: " << js_result;
}
}
};
class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
public:
virtual void SetUpOnMainThread() {
const int kInitialQuotaKilobytes = 5000;
const int kTemporaryStorageQuotaMaxSize =
kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion;
SetTempQuota(
kTemporaryStorageQuotaMaxSize,
BrowserContext::GetDefaultStoragePartition(
shell()->web_contents()->GetBrowserContext())->GetQuotaManager());
}
static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota, bytes,
qm));
return;
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback());
// Don't return until the quota has been set.
scoped_refptr<base::ThreadTestHelper> helper(
new base::ThreadTestHelper(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
ASSERT_TRUE(helper->Run());
}
};
IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) {
SimpleTest(GetTestUrl("fileapi", "request_test.html"));
}
IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) {
SimpleTest(GetTestUrl("fileapi", "create_test.html"));
}
IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) {
SimpleTest(GetTestUrl("fileapi", "quota_test.html"));
}
} // namespace content