Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / fileapi / file_system_browsertest.cc
blob5ff96006abcc5c3ec435589bfc165bfcde7af581
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/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;
25 namespace content {
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 {
30 public:
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.";
41 std::string result =
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())",
48 &js_result));
49 FAIL() << "Failed: " << js_result;
54 class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
55 public:
56 void SetUpOnMainThread() override {
57 const int kInitialQuotaKilobytes = 5000;
58 const int kTemporaryStorageQuotaMaxSize =
59 kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion;
60 SetTempQuota(
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,
71 qm));
72 return;
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