| 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 <memory> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 5 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 6 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 7 #include "chrome/common/extensions/api/extension_action/action_info.h" | 10 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 8 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" | 11 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" |
| 9 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
| 10 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
| 11 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 12 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 17 |
| 15 namespace extensions { | 18 namespace extensions { |
| 16 | 19 |
| 17 namespace errors = manifest_errors; | 20 namespace errors = manifest_errors; |
| 18 namespace keys = manifest_keys; | 21 namespace keys = manifest_keys; |
| 19 | 22 |
| 20 class PageActionManifestTest : public ChromeManifestTest { | 23 class PageActionManifestTest : public ChromeManifestTest { |
| 21 protected: | 24 protected: |
| 22 base::FilePath GetTestDataDir() override { | 25 base::FilePath GetTestDataDir() override { |
| 23 base::FilePath path; | 26 base::FilePath path; |
| 24 PathService::Get(chrome::DIR_TEST_DATA, &path); | 27 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 25 return path.AppendASCII("extensions").AppendASCII("page_action"); | 28 return path.AppendASCII("extensions").AppendASCII("page_action"); |
| 26 } | 29 } |
| 27 | 30 |
| 28 scoped_ptr<ActionInfo> LoadAction(const std::string& manifest_filename); | 31 std::unique_ptr<ActionInfo> LoadAction(const std::string& manifest_filename); |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 scoped_ptr<ActionInfo> PageActionManifestTest::LoadAction( | 34 std::unique_ptr<ActionInfo> PageActionManifestTest::LoadAction( |
| 32 const std::string& manifest_filename) { | 35 const std::string& manifest_filename) { |
| 33 scoped_refptr<Extension> extension = LoadAndExpectSuccess( | 36 scoped_refptr<Extension> extension = LoadAndExpectSuccess( |
| 34 manifest_filename.c_str()); | 37 manifest_filename.c_str()); |
| 35 const ActionInfo* page_action_info = | 38 const ActionInfo* page_action_info = |
| 36 ActionInfo::GetPageActionInfo(extension.get()); | 39 ActionInfo::GetPageActionInfo(extension.get()); |
| 37 EXPECT_TRUE(page_action_info); | 40 EXPECT_TRUE(page_action_info); |
| 38 if (page_action_info) { | 41 if (page_action_info) { |
| 39 return make_scoped_ptr(new ActionInfo(*page_action_info)); | 42 return base::WrapUnique(new ActionInfo(*page_action_info)); |
| 40 } | 43 } |
| 41 ADD_FAILURE() << "Expected manifest in " << manifest_filename | 44 ADD_FAILURE() << "Expected manifest in " << manifest_filename |
| 42 << " to include a page_action section."; | 45 << " to include a page_action section."; |
| 43 return scoped_ptr<ActionInfo>(); | 46 return std::unique_ptr<ActionInfo>(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 TEST_F(PageActionManifestTest, ManifestVersion2) { | 49 TEST_F(PageActionManifestTest, ManifestVersion2) { |
| 47 scoped_refptr<Extension> extension( | 50 scoped_refptr<Extension> extension( |
| 48 LoadAndExpectSuccess("page_action_manifest_version_2.json")); | 51 LoadAndExpectSuccess("page_action_manifest_version_2.json")); |
| 49 ASSERT_TRUE(extension.get()); | 52 ASSERT_TRUE(extension.get()); |
| 50 const ActionInfo* page_action_info = | 53 const ActionInfo* page_action_info = |
| 51 ActionInfo::GetPageActionInfo(extension.get()); | 54 ActionInfo::GetPageActionInfo(extension.get()); |
| 52 ASSERT_TRUE(page_action_info); | 55 ASSERT_TRUE(page_action_info); |
| 53 | 56 |
| 54 EXPECT_EQ("", page_action_info->id); | 57 EXPECT_EQ("", page_action_info->id); |
| 55 EXPECT_TRUE(page_action_info->default_icon.empty()); | 58 EXPECT_TRUE(page_action_info->default_icon.empty()); |
| 56 EXPECT_EQ("", page_action_info->default_title); | 59 EXPECT_EQ("", page_action_info->default_title); |
| 57 EXPECT_TRUE(page_action_info->default_popup_url.is_empty()); | 60 EXPECT_TRUE(page_action_info->default_popup_url.is_empty()); |
| 58 | 61 |
| 59 LoadAndExpectError("page_action_manifest_version_2b.json", | 62 LoadAndExpectError("page_action_manifest_version_2b.json", |
| 60 errors::kInvalidPageActionPopup); | 63 errors::kInvalidPageActionPopup); |
| 61 } | 64 } |
| 62 | 65 |
| 63 TEST_F(PageActionManifestTest, LoadPageActionHelper) { | 66 TEST_F(PageActionManifestTest, LoadPageActionHelper) { |
| 64 scoped_ptr<ActionInfo> action; | 67 std::unique_ptr<ActionInfo> action; |
| 65 | 68 |
| 66 // First try with an empty dictionary. | 69 // First try with an empty dictionary. |
| 67 action = LoadAction("page_action_empty.json"); | 70 action = LoadAction("page_action_empty.json"); |
| 68 ASSERT_TRUE(action); | 71 ASSERT_TRUE(action); |
| 69 | 72 |
| 70 // Now setup some values to use in the action. | 73 // Now setup some values to use in the action. |
| 71 const std::string id("MyExtensionActionId"); | 74 const std::string id("MyExtensionActionId"); |
| 72 const std::string name("MyExtensionActionName"); | 75 const std::string name("MyExtensionActionName"); |
| 73 std::string img1("image1.png"); | 76 std::string img1("image1.png"); |
| 74 | 77 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 action = LoadAction("page_action_empty_popup.json"); | 165 action = LoadAction("page_action_empty_popup.json"); |
| 163 | 166 |
| 164 ASSERT_TRUE(action); | 167 ASSERT_TRUE(action); |
| 165 EXPECT_TRUE(action->default_popup_url.is_empty()); | 168 EXPECT_TRUE(action->default_popup_url.is_empty()); |
| 166 ASSERT_STREQ( | 169 ASSERT_STREQ( |
| 167 "", | 170 "", |
| 168 action->default_popup_url.spec().c_str()); | 171 action->default_popup_url.spec().c_str()); |
| 169 } | 172 } |
| 170 | 173 |
| 171 } // namespace extensions | 174 } // namespace extensions |
| OLD | NEW |