Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_file_system_browser_host_unittest.cc
blobccc9c610d21b9e91b092f1ba7780f37f24847819
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 "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/renderer_host/pepper/browser_ppapi_host_test.h"
12 #include "ppapi/c/pp_instance.h"
13 #include "ppapi/c/pp_resource.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace content {
18 class PepperFileSystemBrowserHostTest : public testing::Test,
19 public BrowserPpapiHostTest {
20 public:
21 PepperFileSystemBrowserHostTest() {}
22 ~PepperFileSystemBrowserHostTest() override {}
24 void SetUp() override {
25 PP_Instance pp_instance = 12345;
26 PP_Resource pp_resource = 67890;
27 host_.reset(new PepperFileSystemBrowserHost(GetBrowserPpapiHost(),
28 pp_instance,
29 pp_resource,
30 PP_FILESYSTEMTYPE_ISOLATED));
33 void TearDown() override { host_.reset(); }
35 protected:
36 std::string GeneratePluginId(const std::string& mime_type) {
37 return host_->GeneratePluginId(mime_type);
40 private:
41 scoped_ptr<PepperFileSystemBrowserHost> host_;
43 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHostTest);
46 TEST_F(PepperFileSystemBrowserHostTest, GeneratePluginId) {
47 // Should not contain wild card characters.
48 EXPECT_TRUE(GeneratePluginId("*").empty());
49 EXPECT_TRUE(GeneratePluginId("*/*").empty());
51 // Should contain only one slash.
52 EXPECT_TRUE(GeneratePluginId(".").empty());
53 EXPECT_TRUE(GeneratePluginId("..").empty());
54 EXPECT_TRUE(GeneratePluginId("application").empty());
55 EXPECT_TRUE(GeneratePluginId("application/mime/type").empty());
57 // Should start with "legal_top_level_types"
58 // (ex. "application", "audio", "x-"). See "mime_util.cc" for more details.
59 EXPECT_TRUE(GeneratePluginId("/mime").empty());
60 EXPECT_TRUE(GeneratePluginId("./mime").empty());
61 EXPECT_TRUE(GeneratePluginId("../mime").empty());
62 EXPECT_TRUE(GeneratePluginId("app/mime").empty());
64 // Should not contain characters other than alphanumeric or "._-".
65 EXPECT_TRUE(GeneratePluginId("application/mime+type").empty());
66 EXPECT_TRUE(GeneratePluginId("application/mime:type").empty());
67 EXPECT_TRUE(GeneratePluginId("application/mime;type").empty());
69 // Valid cases.
70 EXPECT_EQ("application_mime", GeneratePluginId("application/mime"));
71 EXPECT_EQ("x-app_mime", GeneratePluginId("x-app/mime"));
72 EXPECT_EQ("application_mime.type", GeneratePluginId("application/mime.type"));
73 EXPECT_EQ("application_mime_type", GeneratePluginId("application/mime_type"));
74 EXPECT_EQ("application_mime-type", GeneratePluginId("application/mime-type"));
75 EXPECT_EQ("application_..", GeneratePluginId("application/.."));
78 } // namespace content