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 "chrome/common/extensions/api/extension_action/action_info.h" | 5 #include "chrome/common/extensions/api/extension_action/action_info.h" |
6 #include "chrome/common/extensions/extension.h" | 6 #include "chrome/common/extensions/extension.h" |
7 #include "chrome/common/extensions/extension_manifest_constants.h" | 7 #include "chrome/common/extensions/extension_manifest_constants.h" |
8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
9 #include "extensions/common/error_utils.h" | 9 #include "extensions/common/error_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace errors = extension_manifest_errors; | 12 namespace errors = extension_manifest_errors; |
13 namespace keys = extension_manifest_keys; | 13 namespace keys = extension_manifest_keys; |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 class PageActionManifestTest : public ExtensionManifestTest { | 17 class PageActionManifestTest : public ExtensionManifestTest { |
18 protected: | 18 protected: |
19 virtual const char* test_data_dir() OVERRIDE { | 19 virtual const char* test_data_dir() OVERRIDE { |
20 return "page_action"; | 20 return "page_action"; |
21 } | 21 } |
22 | 22 |
23 scoped_ptr<ActionInfo> LoadAction(const std::string& manifest_filename); | 23 scoped_ptr<ActionInfo> LoadAction(const std::string& manifest_filename); |
24 }; | 24 }; |
25 | 25 |
26 scoped_ptr<ActionInfo> PageActionManifestTest::LoadAction( | 26 scoped_ptr<ActionInfo> PageActionManifestTest::LoadAction( |
27 const std::string& manifest_filename) { | 27 const std::string& manifest_filename) { |
28 scoped_refptr<Extension> extension = LoadAndExpectSuccess( | 28 scoped_refptr<Extension> extension = LoadAndExpectSuccess( |
29 manifest_filename.c_str()); | 29 manifest_filename.c_str()); |
30 const ActionInfo* page_action_info = ActionInfo::GetPageActionInfo(extension); | 30 const ActionInfo* page_action_info = |
| 31 ActionInfo::GetPageActionInfo(extension.get()); |
31 EXPECT_TRUE(page_action_info); | 32 EXPECT_TRUE(page_action_info); |
32 if (page_action_info) { | 33 if (page_action_info) { |
33 return make_scoped_ptr(new ActionInfo(*page_action_info)); | 34 return make_scoped_ptr(new ActionInfo(*page_action_info)); |
34 } | 35 } |
35 ADD_FAILURE() << "Expected manifest in " << manifest_filename | 36 ADD_FAILURE() << "Expected manifest in " << manifest_filename |
36 << " to include a page_action section."; | 37 << " to include a page_action section."; |
37 return scoped_ptr<ActionInfo>(); | 38 return scoped_ptr<ActionInfo>(); |
38 } | 39 } |
39 | 40 |
40 TEST_F(PageActionManifestTest, ManifestVersion2) { | 41 TEST_F(PageActionManifestTest, ManifestVersion2) { |
41 scoped_refptr<Extension> extension( | 42 scoped_refptr<Extension> extension( |
42 LoadAndExpectSuccess("page_action_manifest_version_2.json")); | 43 LoadAndExpectSuccess("page_action_manifest_version_2.json")); |
43 ASSERT_TRUE(extension); | 44 ASSERT_TRUE(extension.get()); |
44 const ActionInfo* page_action_info = ActionInfo::GetPageActionInfo(extension); | 45 const ActionInfo* page_action_info = |
| 46 ActionInfo::GetPageActionInfo(extension.get()); |
45 ASSERT_TRUE(page_action_info); | 47 ASSERT_TRUE(page_action_info); |
46 | 48 |
47 EXPECT_EQ("", page_action_info->id); | 49 EXPECT_EQ("", page_action_info->id); |
48 EXPECT_TRUE(page_action_info->default_icon.empty()); | 50 EXPECT_TRUE(page_action_info->default_icon.empty()); |
49 EXPECT_EQ("", page_action_info->default_title); | 51 EXPECT_EQ("", page_action_info->default_title); |
50 EXPECT_TRUE(page_action_info->default_popup_url.is_empty()); | 52 EXPECT_TRUE(page_action_info->default_popup_url.is_empty()); |
51 | 53 |
52 LoadAndExpectError("page_action_manifest_version_2b.json", | 54 LoadAndExpectError("page_action_manifest_version_2b.json", |
53 errors::kInvalidPageActionPopup); | 55 errors::kInvalidPageActionPopup); |
54 } | 56 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 LoadAndExpectError("page_action_invalid_name_no_title.json", | 116 LoadAndExpectError("page_action_invalid_name_no_title.json", |
115 errors::kInvalidPageActionName); | 117 errors::kInvalidPageActionName); |
116 | 118 |
117 // Test that keys "popup" and "default_popup" both work, but can not | 119 // Test that keys "popup" and "default_popup" both work, but can not |
118 // be used at the same time. | 120 // be used at the same time. |
119 // These tests require an extension_url, so we also load the manifest. | 121 // These tests require an extension_url, so we also load the manifest. |
120 | 122 |
121 // Only use "popup", expect success. | 123 // Only use "popup", expect success. |
122 scoped_refptr<Extension> extension = | 124 scoped_refptr<Extension> extension = |
123 LoadAndExpectSuccess("page_action_popup.json"); | 125 LoadAndExpectSuccess("page_action_popup.json"); |
124 const ActionInfo* extension_action = ActionInfo::GetPageActionInfo(extension); | 126 const ActionInfo* extension_action = |
| 127 ActionInfo::GetPageActionInfo(extension.get()); |
125 ASSERT_TRUE(extension_action); | 128 ASSERT_TRUE(extension_action); |
126 ASSERT_STREQ( | 129 ASSERT_STREQ( |
127 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), | 130 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), |
128 extension_action->default_popup_url.spec().c_str()); | 131 extension_action->default_popup_url.spec().c_str()); |
129 | 132 |
130 // Use both "popup" and "default_popup", expect failure. | 133 // Use both "popup" and "default_popup", expect failure. |
131 LoadAndExpectError("page_action_popup_and_default_popup.json", | 134 LoadAndExpectError("page_action_popup_and_default_popup.json", |
132 ErrorUtils::FormatErrorMessage( | 135 ErrorUtils::FormatErrorMessage( |
133 errors::kInvalidPageActionOldAndNewKeys, | 136 errors::kInvalidPageActionOldAndNewKeys, |
134 keys::kPageActionDefaultPopup, | 137 keys::kPageActionDefaultPopup, |
135 keys::kPageActionPopup)); | 138 keys::kPageActionPopup)); |
136 | 139 |
137 // Use only "default_popup", expect success. | 140 // Use only "default_popup", expect success. |
138 extension = LoadAndExpectSuccess("page_action_popup.json"); | 141 extension = LoadAndExpectSuccess("page_action_popup.json"); |
139 extension_action = ActionInfo::GetPageActionInfo(extension); | 142 extension_action = ActionInfo::GetPageActionInfo(extension.get()); |
140 ASSERT_TRUE(extension_action); | 143 ASSERT_TRUE(extension_action); |
141 ASSERT_STREQ( | 144 ASSERT_STREQ( |
142 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), | 145 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), |
143 extension_action->default_popup_url.spec().c_str()); | 146 extension_action->default_popup_url.spec().c_str()); |
144 | 147 |
145 // Setting default_popup to "" is the same as having no popup. | 148 // Setting default_popup to "" is the same as having no popup. |
146 action = LoadAction("page_action_empty_default_popup.json"); | 149 action = LoadAction("page_action_empty_default_popup.json"); |
147 ASSERT_TRUE(action); | 150 ASSERT_TRUE(action); |
148 EXPECT_TRUE(action->default_popup_url.is_empty()); | 151 EXPECT_TRUE(action->default_popup_url.is_empty()); |
149 ASSERT_STREQ( | 152 ASSERT_STREQ( |
150 "", | 153 "", |
151 action->default_popup_url.spec().c_str()); | 154 action->default_popup_url.spec().c_str()); |
152 | 155 |
153 // Setting popup to "" is the same as having no popup. | 156 // Setting popup to "" is the same as having no popup. |
154 action = LoadAction("page_action_empty_popup.json"); | 157 action = LoadAction("page_action_empty_popup.json"); |
155 | 158 |
156 ASSERT_TRUE(action); | 159 ASSERT_TRUE(action); |
157 EXPECT_TRUE(action->default_popup_url.is_empty()); | 160 EXPECT_TRUE(action->default_popup_url.is_empty()); |
158 ASSERT_STREQ( | 161 ASSERT_STREQ( |
159 "", | 162 "", |
160 action->default_popup_url.spec().c_str()); | 163 action->default_popup_url.spec().c_str()); |
161 } | 164 } |
162 | 165 |
163 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |