blob: c5d8c16379600dcc7477bab8e2112188bc30d22c [file] [log] [blame]
[email protected]16dd6e22012-03-01 19:08:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b44492062011-09-06 12:47:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4d99be52011-10-18 14:11:035#include "base/bind.h"
[email protected]b44492062011-09-06 12:47:476#include "base/command_line.h"
[email protected]57999812013-02-24 05:40:527#include "base/files/file_path.h"
[email protected]b44492062011-09-06 12:47:478#include "base/memory/ref_counted.h"
9#include "base/test/thread_test_helper.h"
[email protected]93ddb3c2012-04-11 21:44:2910#include "content/browser/web_contents/web_contents_impl.h"
[email protected]4cdc9a22012-07-26 03:39:3111#include "content/public/browser/browser_context.h"
12#include "content/public/browser/browser_thread.h"
[email protected]f13b2682012-08-22 00:37:5513#include "content/public/browser/storage_partition.h"
[email protected]c08950d22011-10-13 22:20:2914#include "content/public/common/content_switches.h"
[email protected]7d478cb2012-07-24 17:19:4215#include "content/public/test/browser_test_utils.h"
[email protected]4cdc9a22012-07-26 03:39:3116#include "content/shell/shell.h"
17#include "content/test/content_browser_test.h"
18#include "content/test/content_browser_test_utils.h"
[email protected]7660ec92013-05-30 05:12:3919#include "webkit/browser/quota/quota_manager.h"
[email protected]b44492062011-09-06 12:47:4720
21using quota::QuotaManager;
22
[email protected]4cdc9a22012-07-26 03:39:3123namespace content {
24
[email protected]b44492062011-09-06 12:47:4725// This browser test is aimed towards exercising the FileAPI bindings and
26// the actual implementation that lives in the browser side.
[email protected]4cdc9a22012-07-26 03:39:3127class FileSystemBrowserTest : public ContentBrowserTest {
[email protected]b44492062011-09-06 12:47:4728 public:
[email protected]90ca44272012-07-18 18:15:4829 FileSystemBrowserTest() {}
[email protected]b44492062011-09-06 12:47:4730
[email protected]b44492062011-09-06 12:47:4731 void SimpleTest(const GURL& test_url, bool incognito = false) {
32 // The test page will perform tests on FileAPI, then navigate to either
33 // a #pass or #fail ref.
[email protected]4cdc9a22012-07-26 03:39:3134 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell();
[email protected]b44492062011-09-06 12:47:4735
36 LOG(INFO) << "Navigating to URL and blocking.";
[email protected]4cdc9a22012-07-26 03:39:3137 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2);
[email protected]b44492062011-09-06 12:47:4738 LOG(INFO) << "Navigation done.";
[email protected]4cdc9a22012-07-26 03:39:3139 std::string result = the_browser->web_contents()->GetURL().ref();
[email protected]b44492062011-09-06 12:47:4740 if (result != "pass") {
41 std::string js_result;
[email protected]b6987e02013-01-04 18:30:4342 ASSERT_TRUE(ExecuteScriptAndExtractString(
43 the_browser->web_contents(),
[email protected]06bc5d92013-01-02 22:44:1344 "window.domAutomationController.send(getLog())",
45 &js_result));
[email protected]b44492062011-09-06 12:47:4746 FAIL() << "Failed: " << js_result;
47 }
48 }
49};
50
51class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
52 public:
[email protected]c3e35892013-02-12 02:08:0153 virtual void SetUpOnMainThread() OVERRIDE {
[email protected]b44492062011-09-06 12:47:4754 const int kInitialQuotaKilobytes = 5000;
55 const int kTemporaryStorageQuotaMaxSize =
56 kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion;
57 SetTempQuota(
[email protected]55eb70e762012-02-20 17:38:3958 kTemporaryStorageQuotaMaxSize,
[email protected]f13b2682012-08-22 00:37:5559 BrowserContext::GetDefaultStoragePartition(
60 shell()->web_contents()->GetBrowserContext())->GetQuotaManager());
[email protected]b44492062011-09-06 12:47:4761 }
62
[email protected]b44492062011-09-06 12:47:4763 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
64 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
[email protected]80751052011-11-12 17:10:5865 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE,
67 base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota, bytes,
68 qm));
[email protected]b44492062011-09-06 12:47:4769 return;
70 }
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]4d99be52011-10-18 14:11:0372 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback());
[email protected]b44492062011-09-06 12:47:4773 // Don't return until the quota has been set.
74 scoped_refptr<base::ThreadTestHelper> helper(
75 new base::ThreadTestHelper(
76 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
77 ASSERT_TRUE(helper->Run());
78 }
79};
80
[email protected]b44492062011-09-06 12:47:4781IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) {
[email protected]4cdc9a22012-07-26 03:39:3182 SimpleTest(GetTestUrl("fileapi", "request_test.html"));
[email protected]b44492062011-09-06 12:47:4783}
84
85IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) {
[email protected]4cdc9a22012-07-26 03:39:3186 SimpleTest(GetTestUrl("fileapi", "create_test.html"));
[email protected]b44492062011-09-06 12:47:4787}
88
89IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) {
[email protected]4cdc9a22012-07-26 03:39:3190 SimpleTest(GetTestUrl("fileapi", "quota_test.html"));
[email protected]b44492062011-09-06 12:47:4791}
[email protected]4cdc9a22012-07-26 03:39:3192
[email protected]4cdc9a22012-07-26 03:39:3193} // namespace content