Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / content / browser / fileapi / sandbox_file_system_backend_delegate_unittest.cc
blob935f6ce2fe4ee4735ee54702429f926e524bdbdf
1 // Copyright 2013 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 "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h"
7 #include "base/basictypes.h"
8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h"
13 #include "content/public/test/test_file_system_options.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h"
16 #include "webkit/browser/fileapi/file_system_url.h"
18 using fileapi::FileSystemURL;
20 namespace content {
22 namespace {
24 FileSystemURL CreateFileSystemURL(const char* path) {
25 const GURL kOrigin("http://foo/");
26 return fileapi::FileSystemURL::CreateForTest(
27 kOrigin, fileapi::kFileSystemTypeTemporary,
28 base::FilePath::FromUTF8Unsafe(path));
31 } // namespace
33 class SandboxFileSystemBackendDelegateTest : public testing::Test {
34 protected:
35 virtual void SetUp() {
36 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
37 delegate_.reset(new fileapi::SandboxFileSystemBackendDelegate(
38 NULL /* quota_manager_proxy */,
39 base::MessageLoopProxy::current().get(),
40 data_dir_.path(),
41 NULL /* special_storage_policy */,
42 CreateAllowFileAccessOptions()));
45 bool IsAccessValid(const FileSystemURL& url) const {
46 return delegate_->IsAccessValid(url);
49 base::ScopedTempDir data_dir_;
50 base::MessageLoop message_loop_;
51 scoped_ptr<fileapi::SandboxFileSystemBackendDelegate> delegate_;
54 TEST_F(SandboxFileSystemBackendDelegateTest, IsAccessValid) {
55 // Normal case.
56 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("a")));
58 // Access to a path with parent references ('..') should be disallowed.
59 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("a/../b")));
61 // Access from non-allowed scheme should be disallowed.
62 EXPECT_FALSE(IsAccessValid(
63 FileSystemURL::CreateForTest(
64 GURL("unknown://bar"), fileapi::kFileSystemTypeTemporary,
65 base::FilePath::FromUTF8Unsafe("foo"))));
67 // Access with restricted name should be disallowed.
68 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(".")));
69 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("..")));
71 // This is also disallowed due to Windows XP parent path handling.
72 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL("...")));
74 // These are identified as unsafe cases due to weird path handling
75 // on Windows.
76 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(" ..")));
77 EXPECT_FALSE(IsAccessValid(CreateFileSystemURL(".. ")));
79 // Similar but safe cases.
80 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(" .")));
81 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(". ")));
82 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("b.")));
83 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL(".b")));
85 // A path that looks like a drive letter.
86 EXPECT_TRUE(IsAccessValid(CreateFileSystemURL("c:")));
89 } // namespace content