| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/i18n/rtl.h" | 5 #include "base/i18n/rtl.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 9 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" | 11 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 12 #include "chrome/common/extensions/manifest_handler.h" |
| 11 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 13 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 12 #include "chrome/common/extensions/manifest_url_handler.h" | 14 #include "chrome/common/extensions/manifest_url_handler.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 15 | 17 |
| 16 #if defined(TOOLKIT_GTK) | 18 #if defined(TOOLKIT_GTK) |
| 17 #include <gtk/gtk.h> | 19 #include <gtk/gtk.h> |
| 18 #endif | 20 #endif |
| 19 | 21 |
| 20 namespace errors = extension_manifest_errors; | 22 namespace errors = extension_manifest_errors; |
| 21 | 23 |
| 24 namespace extensions { |
| 25 |
| 22 class InitValueManifestTest : public ExtensionManifestTest { | 26 class InitValueManifestTest : public ExtensionManifestTest { |
| 27 protected: |
| 23 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
| 24 ExtensionManifestTest::SetUp(); | 29 ExtensionManifestTest::SetUp(); |
| 25 extensions::ManifestHandler::Register(extension_manifest_keys::kOptionsPage, | 30 ManifestHandler::Register(extension_manifest_keys::kIcons, |
| 26 new extensions::OptionsPageHandler); | 31 new IconsHandler); |
| 32 ManifestHandler::Register(extension_manifest_keys::kOptionsPage, |
| 33 new OptionsPageHandler); |
| 27 } | 34 } |
| 28 }; | 35 }; |
| 29 | 36 |
| 30 TEST_F(InitValueManifestTest, InitFromValueInvalid) { | 37 TEST_F(InitValueManifestTest, InitFromValueInvalid) { |
| 31 Testcase testcases[] = { | 38 Testcase testcases[] = { |
| 32 Testcase("init_invalid_version_missing.json", errors::kInvalidVersion), | 39 Testcase("init_invalid_version_missing.json", errors::kInvalidVersion), |
| 33 Testcase("init_invalid_version_invalid.json", errors::kInvalidVersion), | 40 Testcase("init_invalid_version_invalid.json", errors::kInvalidVersion), |
| 34 Testcase("init_invalid_name_missing.json", errors::kInvalidName), | 41 Testcase("init_invalid_name_missing.json", errors::kInvalidName), |
| 35 Testcase("init_invalid_name_invalid.json", errors::kInvalidName), | 42 Testcase("init_invalid_name_invalid.json", errors::kInvalidName), |
| 36 Testcase("init_invalid_description_invalid.json", | 43 Testcase("init_invalid_description_invalid.json", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 errors::kInvalidMinimumChromeVersion), | 80 errors::kInvalidMinimumChromeVersion), |
| 74 Testcase("init_invalid_chrome_version_too_low.json", | 81 Testcase("init_invalid_chrome_version_too_low.json", |
| 75 errors::kChromeVersionTooLow), | 82 errors::kChromeVersionTooLow), |
| 76 }; | 83 }; |
| 77 | 84 |
| 78 RunTestcases(testcases, arraysize(testcases), | 85 RunTestcases(testcases, arraysize(testcases), |
| 79 EXPECT_TYPE_ERROR); | 86 EXPECT_TYPE_ERROR); |
| 80 } | 87 } |
| 81 | 88 |
| 82 TEST_F(InitValueManifestTest, InitFromValueValid) { | 89 TEST_F(InitValueManifestTest, InitFromValueValid) { |
| 83 scoped_refptr<extensions::Extension> extension(LoadAndExpectSuccess( | 90 scoped_refptr<Extension> extension(LoadAndExpectSuccess( |
| 84 "init_valid_minimal.json")); | 91 "init_valid_minimal.json")); |
| 85 | 92 |
| 86 FilePath path; | 93 FilePath path; |
| 87 PathService::Get(chrome::DIR_TEST_DATA, &path); | 94 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 88 path = path.AppendASCII("extensions"); | 95 path = path.AppendASCII("extensions"); |
| 89 | 96 |
| 90 EXPECT_TRUE(extensions::Extension::IdIsValid(extension->id())); | 97 EXPECT_TRUE(Extension::IdIsValid(extension->id())); |
| 91 EXPECT_EQ("1.0.0.0", extension->VersionString()); | 98 EXPECT_EQ("1.0.0.0", extension->VersionString()); |
| 92 EXPECT_EQ("my extension", extension->name()); | 99 EXPECT_EQ("my extension", extension->name()); |
| 93 EXPECT_EQ(extension->id(), extension->url().host()); | 100 EXPECT_EQ(extension->id(), extension->url().host()); |
| 94 EXPECT_EQ(extension->path(), path); | 101 EXPECT_EQ(extension->path(), path); |
| 95 EXPECT_EQ(path, extension->path()); | 102 EXPECT_EQ(path, extension->path()); |
| 96 | 103 |
| 97 // Test permissions scheme. | 104 // Test permissions scheme. |
| 98 // We allow unknown API permissions, so this will be valid until we better | 105 // We allow unknown API permissions, so this will be valid until we better |
| 99 // distinguish between API and host permissions. | 106 // distinguish between API and host permissions. |
| 100 LoadAndExpectSuccess("init_valid_permissions.json"); | 107 LoadAndExpectSuccess("init_valid_permissions.json"); |
| 101 | 108 |
| 102 // Test with an options page. | 109 // Test with an options page. |
| 103 extension = LoadAndExpectSuccess("init_valid_options.json"); | 110 extension = LoadAndExpectSuccess("init_valid_options.json"); |
| 104 EXPECT_EQ("chrome-extension", | 111 EXPECT_EQ("chrome-extension", |
| 105 extensions::ManifestURL::GetOptionsPage(extension).scheme()); | 112 ManifestURL::GetOptionsPage(extension).scheme()); |
| 106 EXPECT_EQ("/options.html", | 113 EXPECT_EQ("/options.html", |
| 107 extensions::ManifestURL::GetOptionsPage(extension).path()); | 114 ManifestURL::GetOptionsPage(extension).path()); |
| 108 | 115 |
| 109 Testcase testcases[] = { | 116 Testcase testcases[] = { |
| 110 // Test that an empty list of page actions does not stop a browser action | 117 // Test that an empty list of page actions does not stop a browser action |
| 111 // from being loaded. | 118 // from being loaded. |
| 112 Testcase("init_valid_empty_page_actions.json"), | 119 Testcase("init_valid_empty_page_actions.json"), |
| 113 | 120 |
| 114 // Test with a minimum_chrome_version. | 121 // Test with a minimum_chrome_version. |
| 115 Testcase("init_valid_minimum_chrome.json"), | 122 Testcase("init_valid_minimum_chrome.json"), |
| 116 | 123 |
| 117 // Test a hosted app with a minimum_chrome_version. | 124 // Test a hosted app with a minimum_chrome_version. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 135 TEST_F(InitValueManifestTest, InitFromValueValidNameInRTL) { | 142 TEST_F(InitValueManifestTest, InitFromValueValidNameInRTL) { |
| 136 #if defined(TOOLKIT_GTK) | 143 #if defined(TOOLKIT_GTK) |
| 137 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); | 144 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); |
| 138 gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); | 145 gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); |
| 139 #else | 146 #else |
| 140 std::string locale = l10n_util::GetApplicationLocale(""); | 147 std::string locale = l10n_util::GetApplicationLocale(""); |
| 141 base::i18n::SetICUDefaultLocale("he"); | 148 base::i18n::SetICUDefaultLocale("he"); |
| 142 #endif | 149 #endif |
| 143 | 150 |
| 144 // No strong RTL characters in name. | 151 // No strong RTL characters in name. |
| 145 scoped_refptr<extensions::Extension> extension(LoadAndExpectSuccess( | 152 scoped_refptr<Extension> extension(LoadAndExpectSuccess( |
| 146 "init_valid_name_no_rtl.json")); | 153 "init_valid_name_no_rtl.json")); |
| 147 | 154 |
| 148 string16 localized_name(ASCIIToUTF16("Dictionary (by Google)")); | 155 string16 localized_name(ASCIIToUTF16("Dictionary (by Google)")); |
| 149 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 156 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
| 150 EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name())); | 157 EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name())); |
| 151 | 158 |
| 152 // Strong RTL characters in name. | 159 // Strong RTL characters in name. |
| 153 extension = LoadAndExpectSuccess("init_valid_name_strong_rtl.json"); | 160 extension = LoadAndExpectSuccess("init_valid_name_strong_rtl.json"); |
| 154 | 161 |
| 155 localized_name = WideToUTF16(L"Dictionary (\x05D1\x05D2"L" Google)"); | 162 localized_name = WideToUTF16(L"Dictionary (\x05D1\x05D2"L" Google)"); |
| 156 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 163 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
| 157 EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name())); | 164 EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name())); |
| 158 | 165 |
| 159 // Reset locale. | 166 // Reset locale. |
| 160 #if defined(TOOLKIT_GTK) | 167 #if defined(TOOLKIT_GTK) |
| 161 gtk_widget_set_default_direction(gtk_dir); | 168 gtk_widget_set_default_direction(gtk_dir); |
| 162 #else | 169 #else |
| 163 base::i18n::SetICUDefaultLocale(locale); | 170 base::i18n::SetICUDefaultLocale(locale); |
| 164 #endif | 171 #endif |
| 165 } | 172 } |
| 173 |
| 174 } // namespace extensions |
| OLD | NEW |