Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / pepper / pepper_file_system_browser_host_unittest.cc
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.
4
5 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h"
6
7 #include <string>
8
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"
15
16 namespace content {
17
18 class PepperFileSystemBrowserHostTest : public testing::Test,
19                                         public BrowserPpapiHostTest {
20  public:
21   PepperFileSystemBrowserHostTest() {}
22   virtual ~PepperFileSystemBrowserHostTest() {}
23
24   virtual 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));
31   }
32
33   virtual void TearDown() OVERRIDE { host_.reset(); }
34
35  protected:
36   std::string GeneratePluginId(const std::string& mime_type) {
37     return host_->GeneratePluginId(mime_type);
38   }
39
40  private:
41   scoped_ptr<PepperFileSystemBrowserHost> host_;
42
43   DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHostTest);
44 };
45
46 TEST_F(PepperFileSystemBrowserHostTest, GeneratePluginId) {
47   // Should not contain wild card characters.
48   EXPECT_TRUE(GeneratePluginId("*").empty());
49   EXPECT_TRUE(GeneratePluginId("*/*").empty());
50
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());
56
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());
63
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());
68
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/.."));
76 }
77
78 }  // namespace content