Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / fileapi / file_system_browsertest.cc
blob5c84915a3804e13c9f1f11936ff60bc57c095f5e
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.
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/test/thread_test_helper.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/storage_partition.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h"
18 #include "content/shell/browser/shell.h"
19 #include "webkit/browser/quota/quota_manager.h"
21 using storage::QuotaManager;
23 namespace content {
25 // This browser test is aimed towards exercising the FileAPI bindings and
26 // the actual implementation that lives in the browser side.
27 class FileSystemBrowserTest : public ContentBrowserTest {
28 public:
29 FileSystemBrowserTest() {}
31 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.
34 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell();
36 VLOG(0) << "Navigating to URL and blocking.";
37 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2);
38 VLOG(0) << "Navigation done.";
39 std::string result =
40 the_browser->web_contents()->GetLastCommittedURL().ref();
41 if (result != "pass") {
42 std::string js_result;
43 ASSERT_TRUE(ExecuteScriptAndExtractString(
44 the_browser->web_contents(),
45 "window.domAutomationController.send(getLog())",
46 &js_result));
47 FAIL() << "Failed: " << js_result;
52 class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
53 public:
54 virtual void SetUpOnMainThread() OVERRIDE {
55 const int kInitialQuotaKilobytes = 5000;
56 const int kTemporaryStorageQuotaMaxSize =
57 kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion;
58 SetTempQuota(
59 kTemporaryStorageQuotaMaxSize,
60 BrowserContext::GetDefaultStoragePartition(
61 shell()->web_contents()->GetBrowserContext())->GetQuotaManager());
64 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
65 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
66 BrowserThread::PostTask(
67 BrowserThread::IO, FROM_HERE,
68 base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota, bytes,
69 qm));
70 return;
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
73 qm->SetTemporaryGlobalOverrideQuota(bytes, storage::QuotaCallback());
74 // Don't return until the quota has been set.
75 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper(
76 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get()));
77 ASSERT_TRUE(helper->Run());
81 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) {
82 SimpleTest(GetTestUrl("fileapi", "request_test.html"));
85 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) {
86 SimpleTest(GetTestUrl("fileapi", "create_test.html"));
89 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) {
90 SimpleTest(GetTestUrl("fileapi", "quota_test.html"));
93 } // namespace content