Home | History | Annotate | Download | only in manifest_tests
      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 "chrome/common/extensions/extension_manifest_constants.h"
      6 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
      7 #include "chrome/common/extensions/manifest_url_handler.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 namespace errors = extension_manifest_errors;
     11 
     12 class OptionsPageManifestTest : public ExtensionManifestTest {
     13 };
     14 
     15 TEST_F(OptionsPageManifestTest, OptionsPageInApps) {
     16   scoped_refptr<extensions::Extension> extension;
     17 
     18   // Allow options page with absolute URL in hosted apps.
     19   extension = LoadAndExpectSuccess("hosted_app_absolute_options.json");
     20   EXPECT_STREQ("http",
     21                extensions::ManifestURL::GetOptionsPage(extension.get())
     22                    .scheme().c_str());
     23   EXPECT_STREQ(
     24       "example.com",
     25       extensions::ManifestURL::GetOptionsPage(extension.get()).host().c_str());
     26   EXPECT_STREQ("options.html",
     27                extensions::ManifestURL::GetOptionsPage(extension.get())
     28                    .ExtractFileName().c_str());
     29 
     30   extension = LoadAndExpectSuccess("platform_app_with_options_page.json");
     31   EXPECT_TRUE(extensions::ManifestURL::GetOptionsPage(extension.get())
     32                   .is_empty());
     33 
     34   Testcase testcases[] = {
     35     // Forbid options page with relative URL in hosted apps.
     36     Testcase("hosted_app_relative_options.json",
     37              errors::kInvalidOptionsPageInHostedApp),
     38 
     39     // Forbid options page with non-(http|https) scheme in hosted app.
     40     Testcase("hosted_app_file_options.json",
     41              errors::kInvalidOptionsPageInHostedApp),
     42 
     43     // Forbid absolute URL for options page in packaged apps.
     44     Testcase("packaged_app_absolute_options.json",
     45              errors::kInvalidOptionsPageExpectUrlInPackage)
     46   };
     47   RunTestcases(testcases, arraysize(testcases),
     48                EXPECT_TYPE_ERROR);
     49 }
     50