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/command_line.h" 6 #include "chrome/common/chrome_switches.h" 7 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension_manifest_constants.h" 9 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 11 #include "extensions/common/error_utils.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace errors = extension_manifest_errors; 15 namespace keys = extension_manifest_keys; 16 17 namespace extensions { 18 19 class AppLaunchManifestTest : public ExtensionManifestTest { 20 }; 21 22 TEST_F(AppLaunchManifestTest, AppLaunchContainer) { 23 scoped_refptr<Extension> extension; 24 25 extension = LoadAndExpectSuccess("launch_tab.json"); 26 EXPECT_EQ(extension_misc::LAUNCH_TAB, 27 AppLaunchInfo::GetLaunchContainer(extension.get())); 28 29 extension = LoadAndExpectSuccess("launch_panel.json"); 30 EXPECT_EQ(extension_misc::LAUNCH_PANEL, 31 AppLaunchInfo::GetLaunchContainer(extension.get())); 32 33 extension = LoadAndExpectSuccess("launch_default.json"); 34 EXPECT_EQ(extension_misc::LAUNCH_TAB, 35 AppLaunchInfo::GetLaunchContainer(extension.get())); 36 37 extension = LoadAndExpectSuccess("launch_width.json"); 38 EXPECT_EQ(640, AppLaunchInfo::GetLaunchWidth(extension.get())); 39 40 extension = LoadAndExpectSuccess("launch_height.json"); 41 EXPECT_EQ(480, AppLaunchInfo::GetLaunchHeight(extension.get())); 42 43 Testcase testcases[] = { 44 Testcase("launch_window.json", errors::kInvalidLaunchContainer), 45 Testcase("launch_container_invalid_type.json", 46 errors::kInvalidLaunchContainer), 47 Testcase("launch_container_invalid_value.json", 48 errors::kInvalidLaunchContainer), 49 Testcase("launch_container_without_launch_url.json", 50 errors::kLaunchURLRequired), 51 Testcase("launch_width_invalid.json", 52 ErrorUtils::FormatErrorMessage( 53 errors::kInvalidLaunchValueContainer, 54 keys::kLaunchWidth)), 55 Testcase("launch_width_negative.json", 56 ErrorUtils::FormatErrorMessage( 57 errors::kInvalidLaunchValue, 58 keys::kLaunchWidth)), 59 Testcase("launch_height_invalid.json", 60 ErrorUtils::FormatErrorMessage( 61 errors::kInvalidLaunchValueContainer, 62 keys::kLaunchHeight)), 63 Testcase("launch_height_negative.json", 64 ErrorUtils::FormatErrorMessage( 65 errors::kInvalidLaunchValue, 66 keys::kLaunchHeight)) 67 }; 68 RunTestcases(testcases, arraysize(testcases), 69 EXPECT_TYPE_ERROR); 70 } 71 72 TEST_F(AppLaunchManifestTest, AppLaunchURL) { 73 Testcase testcases[] = { 74 Testcase("launch_path_and_url.json", 75 errors::kLaunchPathAndURLAreExclusive), 76 Testcase("launch_path_and_extent.json", 77 errors::kLaunchPathAndExtentAreExclusive), 78 Testcase("launch_path_invalid_type.json", 79 ErrorUtils::FormatErrorMessage( 80 errors::kInvalidLaunchValue, 81 keys::kLaunchLocalPath)), 82 Testcase("launch_path_invalid_value.json", 83 ErrorUtils::FormatErrorMessage( 84 errors::kInvalidLaunchValue, 85 keys::kLaunchLocalPath)), 86 Testcase("launch_path_invalid_localized.json", 87 ErrorUtils::FormatErrorMessage( 88 errors::kInvalidLaunchValue, 89 keys::kLaunchLocalPath)), 90 Testcase("launch_url_invalid_type_1.json", 91 ErrorUtils::FormatErrorMessage( 92 errors::kInvalidLaunchValue, 93 keys::kLaunchWebURL)), 94 Testcase("launch_url_invalid_type_2.json", 95 ErrorUtils::FormatErrorMessage( 96 errors::kInvalidLaunchValue, 97 keys::kLaunchWebURL)), 98 Testcase("launch_url_invalid_type_3.json", 99 ErrorUtils::FormatErrorMessage( 100 errors::kInvalidLaunchValue, 101 keys::kLaunchWebURL)), 102 Testcase("launch_url_invalid_localized.json", 103 ErrorUtils::FormatErrorMessage( 104 errors::kInvalidLaunchValue, 105 keys::kLaunchWebURL)) 106 }; 107 RunTestcases(testcases, arraysize(testcases), 108 EXPECT_TYPE_ERROR); 109 110 scoped_refptr<Extension> extension; 111 extension = LoadAndExpectSuccess("launch_local_path.json"); 112 EXPECT_EQ(extension->url().spec() + "launch.html", 113 AppLaunchInfo::GetFullLaunchURL(extension.get()).spec()); 114 115 extension = LoadAndExpectSuccess("launch_local_path_localized.json"); 116 EXPECT_EQ(extension->url().spec() + "launch.html", 117 AppLaunchInfo::GetFullLaunchURL(extension.get()).spec()); 118 119 LoadAndExpectError("launch_web_url_relative.json", 120 ErrorUtils::FormatErrorMessage( 121 errors::kInvalidLaunchValue, 122 keys::kLaunchWebURL)); 123 124 extension = LoadAndExpectSuccess("launch_web_url_absolute.json"); 125 EXPECT_EQ(GURL("http://www.google.com/launch.html"), 126 AppLaunchInfo::GetFullLaunchURL(extension.get())); 127 extension = LoadAndExpectSuccess("launch_web_url_localized.json"); 128 EXPECT_EQ(GURL("http://www.google.com/launch.html"), 129 AppLaunchInfo::GetFullLaunchURL(extension.get())); 130 } 131 132 } // namespace extensions 133