1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/location.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/test/thread_test_helper.h"
12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/content_browser_test.h"
19 #include "content/public/test/content_browser_test_utils.h"
20 #include "content/shell/browser/shell.h"
21 #include "storage/browser/quota/quota_manager.h"
23 using storage::QuotaManager
;
27 // This browser test is aimed towards exercising the FileAPI bindings and
28 // the actual implementation that lives in the browser side.
29 class FileSystemBrowserTest
: public ContentBrowserTest
{
31 FileSystemBrowserTest() {}
33 void SimpleTest(const GURL
& test_url
, bool incognito
= false) {
34 // The test page will perform tests on FileAPI, then navigate to either
35 // a #pass or #fail ref.
36 Shell
* the_browser
= incognito
? CreateOffTheRecordBrowser() : shell();
38 VLOG(0) << "Navigating to URL and blocking.";
39 NavigateToURLBlockUntilNavigationsComplete(the_browser
, test_url
, 2);
40 VLOG(0) << "Navigation done.";
42 the_browser
->web_contents()->GetLastCommittedURL().ref();
43 if (result
!= "pass") {
44 std::string js_result
;
45 ASSERT_TRUE(ExecuteScriptAndExtractString(
46 the_browser
->web_contents(),
47 "window.domAutomationController.send(getLog())",
49 FAIL() << "Failed: " << js_result
;
54 class FileSystemBrowserTestWithLowQuota
: public FileSystemBrowserTest
{
56 void SetUpOnMainThread() override
{
57 const int kInitialQuotaKilobytes
= 5000;
58 const int kTemporaryStorageQuotaMaxSize
=
59 kInitialQuotaKilobytes
* 1024 * QuotaManager::kPerHostTemporaryPortion
;
61 kTemporaryStorageQuotaMaxSize
,
62 BrowserContext::GetDefaultStoragePartition(
63 shell()->web_contents()->GetBrowserContext())->GetQuotaManager());
66 static void SetTempQuota(int64 bytes
, scoped_refptr
<QuotaManager
> qm
) {
67 if (!BrowserThread::CurrentlyOn(BrowserThread::IO
)) {
68 BrowserThread::PostTask(
69 BrowserThread::IO
, FROM_HERE
,
70 base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota
, bytes
,
74 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
75 qm
->SetTemporaryGlobalOverrideQuota(bytes
, storage::QuotaCallback());
76 // Don't return until the quota has been set.
77 scoped_refptr
<base::ThreadTestHelper
> helper(new base::ThreadTestHelper(
78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get()));
79 ASSERT_TRUE(helper
->Run());
83 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest
, RequestTest
) {
84 SimpleTest(GetTestUrl("fileapi", "request_test.html"));
87 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest
, CreateTest
) {
88 SimpleTest(GetTestUrl("fileapi", "create_test.html"));
91 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota
, QuotaTest
) {
92 SimpleTest(GetTestUrl("fileapi", "quota_test.html"));
95 } // namespace content