Home | History | Annotate | Download | only in streams_private
      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.
      4 
      5 #include "base/strings/string_number_conversions.h"
      6 #include "chrome/common/extensions/extension_constants.h"
      7 #include "chrome/common/extensions/manifest_handlers/mime_types_handler.h"
      8 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
      9 #include "chrome/common/extensions/manifest_url_handler.h"
     10 #include "extensions/common/error_utils.h"
     11 #include "extensions/common/extension_builder.h"
     12 #include "extensions/common/manifest_constants.h"
     13 #include "extensions/common/value_builder.h"
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 
     16 namespace errors = extensions::manifest_errors;
     17 
     18 using extensions::DictionaryBuilder;
     19 using extensions::Extension;
     20 using extensions::ExtensionBuilder;
     21 using extensions::ListBuilder;
     22 
     23 namespace {
     24 
     25 class StreamsPrivateManifestTest : public ChromeManifestTest {
     26 };
     27 
     28 TEST_F(StreamsPrivateManifestTest, ValidMimeTypesHandlerMIMETypes) {
     29   scoped_refptr<const Extension> extension =
     30       ExtensionBuilder()
     31           .SetID(extension_misc::kQuickOfficeExtensionId)
     32           .SetManifest(
     33                DictionaryBuilder()
     34                    .Set("name", "MIME type handler test")
     35                    .Set("version", "1.0.0")
     36                    .Set("manifest_version", 2)
     37                    .Set("mime_types", ListBuilder().Append("text/plain")))
     38           .Build();
     39 
     40   ASSERT_TRUE(extension.get());
     41   MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension.get());
     42   ASSERT_TRUE(handler != NULL);
     43 
     44   EXPECT_FALSE(handler->CanHandleMIMEType("text/html"));
     45   EXPECT_TRUE(handler->CanHandleMIMEType("text/plain"));
     46 }
     47 
     48 TEST_F(StreamsPrivateManifestTest,
     49        MimeTypesHandlerMIMETypesNotWhitelisted) {
     50   scoped_refptr<const Extension> extension =
     51       ExtensionBuilder()
     52           .SetManifest(
     53                DictionaryBuilder()
     54                    .Set("name", "MIME types test")
     55                    .Set("version", "1.0.0")
     56                    .Set("manifest_version", 2)
     57                    .Set("mime_types", ListBuilder().Append("text/plain")))
     58           .Build();
     59 
     60   ASSERT_TRUE(extension.get());
     61 
     62   MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension.get());
     63   ASSERT_TRUE(handler == NULL);
     64 }
     65 
     66 }  // namespace
     67